BaseRpc.h

Go to the documentation of this file.
00001 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation; either version 2
00006 // of the License, or (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00016 //
00017 
00026 #ifndef __BASERPC_H_
00027 #define __BASERPC_H_
00028 
00029 #include <oversim_mapset.h>
00030 
00031 #include <omnetpp.h>
00032 
00033 #include <RpcState.h>
00034 #include <RpcListener.h>
00035 #include <RpcMacros.h>
00036 
00037 #include <ProxNodeHandle.h>
00038 
00039 class UnderlayConfigurator;
00040 class GlobalStatistics;
00041 class GlobalParameters;
00042 class NeighborCache;
00043 class CryptoModule;
00044 class WaitingContexts;
00045 class BaseOverlay;
00046 
00047 class ProxListener;
00048 
00059 class BaseRpc : public RpcListener,
00060                 public cSimpleModule
00061 {
00062 public:
00063 
00064     BaseRpc();
00065 
00071     const NodeHandle& getThisNode() { return thisNode; };
00072 
00073     simtime_t getUdpTimeout() { return rpcUdpTimeout; };
00074 
00075 protected:
00076 
00077     // overlay identity
00078     NodeHandle thisNode;   
00080     BaseOverlay* overlay;
00081 
00082     // overlay common parameters
00083     bool debugOutput;           
00085     // references to global modules
00086     GlobalStatistics* globalStatistics;  
00097     virtual bool internalHandleRpcCall(BaseCallMessage* msg);
00098 
00112     virtual void internalHandleRpcResponse(BaseResponseMessage* msg,
00113                                            cPolymorphic* context, int rpcId,
00114                                            simtime_t rtt);
00115 
00132     virtual void internalHandleRpcTimeout(BaseCallMessage* msg,
00133                                           const TransportAddress& dest,
00134                                           cPolymorphic* context,
00135                                           int rpcId, const OverlayKey& destKey);
00139     void initRpcs();
00140 
00144     void finishRpcs();
00145 
00152     virtual void internalHandleRpcMessage(BaseRpcMessage* msg);
00153 
00178     inline uint32_t sendRouteRpcCall(CompType destComp,
00179                                      const TransportAddress& dest,
00180                                      const OverlayKey& destKey,
00181                                      BaseCallMessage* msg,
00182                                      cPolymorphic* context = NULL,
00183                                      RoutingType routingType = DEFAULT_ROUTING,
00184                                      simtime_t timeout = -1,
00185                                      int retries = 0,
00186                                      int rpcId = -1,
00187                                      RpcListener* rpcListener = NULL)
00188     {
00189         if (dest.isUnspecified() && destKey.isUnspecified())
00190             opp_error("BaseRpc::sendRouteRpcCall() with both key and "
00191                       "transportAddress unspecified!");
00192         return sendRpcCall(ROUTE_TRANSPORT, destComp, dest, destKey, msg,
00193                            context, routingType, timeout, retries,
00194                            rpcId, rpcListener);
00195     }
00196 
00219     inline uint32_t sendRouteRpcCall(CompType destComp,
00220                                      const OverlayKey& destKey,
00221                                      BaseCallMessage* msg,
00222                                      cPolymorphic* context = NULL,
00223                                      RoutingType routingType = DEFAULT_ROUTING,
00224                                      simtime_t timeout = -1,
00225                                      int retries = 0,
00226                                      int rpcId = -1,
00227                                      RpcListener* rpcListener = NULL)
00228     {
00229         return sendRpcCall(ROUTE_TRANSPORT, destComp,
00230                            TransportAddress::UNSPECIFIED_NODE,
00231                            destKey, msg, context, routingType, timeout,
00232                            retries, rpcId, rpcListener);
00233     }
00234 
00258     inline uint32_t sendRouteRpcCall(CompType destComp,
00259                                      const TransportAddress& dest,
00260                                      BaseCallMessage* msg,
00261                                      cPolymorphic* context = NULL,
00262                                      RoutingType routingType = DEFAULT_ROUTING,
00263                                      simtime_t timeout = -1,
00264                                      int retries = 0,
00265                                      int rpcId = -1,
00266                                      RpcListener* rpcListener = NULL)
00267     {
00268         return sendRpcCall(ROUTE_TRANSPORT, destComp, dest,
00269                            OverlayKey::UNSPECIFIED_KEY, msg, context,
00270                            routingType, timeout, retries, rpcId, rpcListener);
00271     }
00272 
00293     inline uint32_t sendUdpRpcCall(const TransportAddress& dest,
00294                                    BaseCallMessage* msg,
00295                                    cPolymorphic* context = NULL,
00296                                    simtime_t timeout = -1,
00297                                    int retries = 0, int rpcId = -1,
00298                                    RpcListener* rpcListener = NULL)
00299     {
00300         return sendRpcCall(UDP_TRANSPORT, INVALID_COMP, dest,
00301                            OverlayKey::UNSPECIFIED_KEY, msg, context,
00302                            NO_OVERLAY_ROUTING, timeout, retries, rpcId,
00303                            rpcListener);
00304     }
00305 
00326     inline uint32_t sendInternalRpcCall(CompType destComp,
00327                                         BaseCallMessage* msg,
00328                                         cPolymorphic* context = NULL,
00329                                         simtime_t timeout = -1,
00330                                         int retries = 0,
00331                                         int rpcId = -1,
00332                                         RpcListener* rpcListener = NULL)
00333     {
00334         return sendRpcCall(INTERNAL_TRANSPORT, destComp,
00335                            TransportAddress::UNSPECIFIED_NODE,
00336                            OverlayKey::UNSPECIFIED_KEY, msg, context,
00337                            NO_OVERLAY_ROUTING, timeout, retries, rpcId,
00338                            rpcListener);
00339     }
00340 
00346     void cancelRpcMessage(uint32_t nonce);
00347 
00351     void cancelAllRpcs();
00352 
00365     void sendRpcResponse(TransportType transportType,
00366                          CompType destComp,
00367                          const TransportAddress &dest,
00368                          const OverlayKey &destKey,
00369                          BaseCallMessage* call,
00370                          BaseResponseMessage* response);
00371 
00379     void sendRpcResponse(BaseCallMessage* call,
00380                          BaseResponseMessage* response);
00381 
00398     int pingNode(const TransportAddress& dest,
00399                   simtime_t timeout = -1,
00400                   int retries = 0,
00401                   cPolymorphic* context = NULL,
00402                   const char* caption = "PING",
00403                   RpcListener* rpcListener = NULL,
00404                   int rpcId = -1,
00405                   TransportType transportType = INVALID_TRANSPORT);
00406 
00415     virtual bool handleRpcCall(BaseCallMessage* msg);
00416 
00425     virtual CompType getThisCompType() = 0;
00426 
00427     CompType thisCompType;
00428 
00429     virtual void sendMessageToUDP(const TransportAddress& addr,
00430                                   cPacket* message)
00431     {
00432         throw cRuntimeError("sendMessageToUDP() not implemented");
00433     }
00434 
00435     virtual void pingResponse(PingResponse* pingResponse,
00436                               cPolymorphic* context, int rpcId,
00437                               simtime_t rtt);
00438 
00439     virtual void pingTimeout(PingCall* pingCall,
00440                              const TransportAddress& dest,
00441                              cPolymorphic* context,
00442                              int rpcId);
00443 
00444     NeighborCache *neighborCache; 
00445     CryptoModule *cryptoModule; 
00447     int numPingSent;
00448     int bytesPingSent;
00449     int numPingResponseSent;
00450     int bytesPingResponseSent;
00451 
00452     bool internalHandleMessage(cMessage* msg);
00453 
00454 
00455 private:
00456 
00457     virtual void handleTimerEvent(cMessage* msg);
00458 
00487     uint32_t sendRpcCall(TransportType transportType,
00488                          CompType destComp,
00489                          const TransportAddress& dest,
00490                          const OverlayKey& destKey,
00491                          BaseCallMessage* msg,
00492                          cPolymorphic* context,
00493                          RoutingType routingType,
00494                          simtime_t timeout, int retries,
00495                          int rpcId, RpcListener* rpcListener);
00496 
00497     void sendRpcMessageWithTransport(TransportType transportType,
00498                                      CompType destComp,
00499                                      RoutingType routingType,
00500                                      const std::vector<TransportAddress>& sourceRoute,
00501                                      const OverlayKey& destKey,
00502                                      BaseRpcMessage* message);
00503 
00504     virtual void internalSendRouteRpc(BaseRpcMessage* message,
00505                                       const OverlayKey& destKey,
00506                                       const std::vector<TransportAddress>&
00507                                       sourceRoute,
00508                                       RoutingType routingType) = 0;
00509 
00510     virtual void internalSendRpcResponse(BaseCallMessage* call,
00511                                          BaseResponseMessage* response) = 0;
00512 
00513     void pingRpcCall(PingCall* call);
00514     void pingRpcResponse(PingResponse* response, cPolymorphic* context,
00515                          int rpcId, simtime_t rtt);
00516     void pingRpcTimeout(PingCall* pingCall, const TransportAddress& dest,
00517                         cPolymorphic* context, int rpcId);
00518 
00519     typedef UNORDERED_MAP<int,RpcState> RpcStates;
00520 
00521     int rpcsPending;
00522     RpcListener* defaultRpcListener;
00523     RpcStates rpcStates;
00524     simtime_t rpcUdpTimeout, rpcKeyTimeout;
00525     bool optimizeTimeouts;
00526     bool rpcExponentialBackoff;
00527 };
00528 
00529 #endif
Generated on Wed May 26 16:21:13 2010 for OverSim by  doxygen 1.6.3