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 
00025 #ifndef __BASERPC_H_
00026 #define __BASERPC_H_
00027 
00028 #include <oversim_mapset.h>
00029 
00030 #include <omnetpp.h>
00031 
00032 #include <RpcListener.h>
00033 #include <RpcMacros.h>
00034 
00035 class GlobalNodeList;
00036 class UnderlayConfigurator;
00037 class GlobalStatistics;
00038 class GlobalParameters;
00039 class NeighborCache;
00040 class BaseOverlay;
00041 
00052 class BaseRpc : public RpcListener,
00053                 public cSimpleModule
00054 {
00055 public:
00056 
00057     BaseRpc();
00058 
00064     const NodeHandle& getThisNode() { return thisNode; };
00065 
00066 protected:
00067 
00068     // overlay identity
00069     NodeHandle thisNode;   
00071     BaseOverlay* overlay;
00072 
00073     // overlay common parameters
00074     bool debugOutput;           
00076     // references to global modules
00077     GlobalStatistics* globalStatistics;  
00088     virtual bool internalHandleRpc( BaseCallMessage* msg );
00089 
00104     virtual bool internalHandleRpcResponse(BaseResponseMessage* msg,
00105                                            cPolymorphic* context, int rpcId,
00106                                            simtime_t rtt);
00107 
00124     virtual void internalHandleRpcTimeout(BaseCallMessage* msg,
00125                                           const TransportAddress& dest,
00126                                           cPolymorphic* context,
00127                                           int rpcId, const OverlayKey& destKey);
00131     void initRpcs();
00132 
00136     void finishRpcs();
00137 
00144     virtual void internalHandleRpcMessage(BaseRpcMessage* msg);
00145 
00146 protected:
00147 
00172     inline uint32_t sendRouteRpcCall(CompType destComp,
00173                                      const TransportAddress& dest,
00174                                      const OverlayKey& destKey,
00175                                      BaseCallMessage* msg,
00176                                      cPolymorphic* context = NULL,
00177                                      RoutingType routingType = DEFAULT_ROUTING,
00178                                      simtime_t timeout = -1,
00179                                      int retries = 0,
00180                                      int rpcId = -1,
00181                                      RpcListener* rpcListener = NULL)
00182     {
00183         if (dest.isUnspecified() && destKey.isUnspecified())
00184             opp_error("BaseRpc::sendRouteRpcCall() with both key and "
00185                       "transportAddress unspecified!");
00186         return sendRpcCall(ROUTE_TRANSPORT, destComp, dest, destKey, msg,
00187                            context, routingType, timeout, retries,
00188                            rpcId, rpcListener);
00189     }
00190 
00213     inline uint32_t sendRouteRpcCall(CompType destComp,
00214                                      const OverlayKey& destKey,
00215                                      BaseCallMessage* msg,
00216                                      cPolymorphic* context = NULL,
00217                                      RoutingType routingType = DEFAULT_ROUTING,
00218                                      simtime_t timeout = -1,
00219                                      int retries = 0,
00220                                      int rpcId = -1,
00221                                      RpcListener* rpcListener = NULL)
00222     {
00223         return sendRpcCall(ROUTE_TRANSPORT, destComp,
00224                            TransportAddress::UNSPECIFIED_NODE,
00225                            destKey, msg, context, routingType, timeout,
00226                            retries, rpcId, rpcListener);
00227     }
00228 
00252     inline uint32_t sendRouteRpcCall(CompType destComp,
00253                                      const TransportAddress& dest,
00254                                      BaseCallMessage* msg,
00255                                      cPolymorphic* context = NULL,
00256                                      RoutingType routingType = DEFAULT_ROUTING,
00257                                      simtime_t timeout = -1,
00258                                      int retries = 0,
00259                                      int rpcId = -1,
00260                                      RpcListener* rpcListener = NULL)
00261     {
00262         return sendRpcCall(ROUTE_TRANSPORT, destComp, dest,
00263                            OverlayKey::UNSPECIFIED_KEY, msg, context,
00264                            routingType, timeout, retries, rpcId, rpcListener);
00265     }
00266 
00287     inline uint32_t sendUdpRpcCall(const TransportAddress& dest,
00288                                    BaseCallMessage* msg,
00289                                    cPolymorphic* context = NULL,
00290                                    simtime_t timeout = -1,
00291                                    int retries = 0, int rpcId = -1,
00292                                    RpcListener* rpcListener = NULL)
00293     {
00294         return sendRpcCall(UDP_TRANSPORT, INVALID_COMP, dest,
00295                            OverlayKey::UNSPECIFIED_KEY, msg, context,
00296                            NO_OVERLAY_ROUTING, timeout, retries, rpcId,
00297                            rpcListener);
00298     }
00299 
00320     inline uint32_t sendInternalRpcCall(CompType destComp,
00321                                         BaseCallMessage* msg,
00322                                         cPolymorphic* context = NULL,
00323                                         simtime_t timeout = -1,
00324                                         int retries = 0,
00325                                         int rpcId = -1,
00326                                         RpcListener* rpcListener = NULL)
00327     {
00328         return sendRpcCall(INTERNAL_TRANSPORT, destComp,
00329                            TransportAddress::UNSPECIFIED_NODE,
00330                            OverlayKey::UNSPECIFIED_KEY, msg, context,
00331                            NO_OVERLAY_ROUTING, timeout, retries, rpcId,
00332                            rpcListener);
00333     }
00334 
00340     void cancelRpcMessage(uint32_t nonce);
00341 
00345     void cancelAllRpcs();
00346 
00359     void sendRpcResponse(TransportType transportType,
00360                          CompType destComp,
00361                          const TransportAddress &dest,
00362                          const OverlayKey &destKey,
00363                          BaseCallMessage* call,
00364                          BaseResponseMessage* response);
00365 
00373     void sendRpcResponse(BaseCallMessage* call,
00374                          BaseResponseMessage* response);
00375 
00392     void pingNode(const TransportAddress& dest,
00393                   simtime_t timeout = -1,
00394                   int retries = 0,
00395                   cPolymorphic* context = NULL,
00396                   const char* caption = "PING",
00397                   RpcListener* rpcListener = NULL,
00398                   int rpcId = -1,
00399                   TransportType transportType = INVALID_TRANSPORT,
00400                   bool overrideCache = true);
00401 
00410     virtual bool handleRpc( BaseCallMessage* msg );
00411 
00420     virtual CompType getThisCompType() = 0;
00421 
00422     CompType thisCompType;
00423 
00424     virtual void sendMessageToUDP(const TransportAddress& addr,
00425                                   cPacket* message)
00426     {
00427         throw cRuntimeError("sendMessageToUDP() not implemented");
00428     }
00429 
00430     virtual void pingResponse(PingResponse* pingResponse,
00431                               cPolymorphic* context, int rpcId,
00432                               simtime_t rtt);
00433 
00434     virtual void pingTimeout(PingCall* pingCall,
00435                              const TransportAddress& dest,
00436                              cPolymorphic* context,
00437                              int rpcId);
00438 
00439     NeighborCache *neighborCache;
00440 
00441     int numPingSent;
00442     int bytesPingSent;
00443     int numPingResponseSent;
00444     int bytesPingResponseSent;
00445 
00446 private:
00447 
00476     uint32_t sendRpcCall(TransportType transportType,
00477                          CompType destComp,
00478                          const TransportAddress& dest,
00479                          const OverlayKey& destKey,
00480                          BaseCallMessage* msg,
00481                          cPolymorphic* context,
00482                          RoutingType routingType,
00483                          simtime_t timeout, int retries,
00484                          int rpcId, RpcListener* rpcListener);
00485 
00486     void sendRpcMessageWithTransport(TransportType transportType,
00487                                      CompType destComp,
00488                                      RoutingType routingType,
00489                                      const std::vector<TransportAddress>& sourceRoute,
00490                                      const OverlayKey& destKey,
00491                                      BaseRpcMessage* message);
00492 
00493     virtual void internalSendRouteRpc(BaseRpcMessage* message,
00494                                       const OverlayKey& destKey,
00495                                       const std::vector<TransportAddress>&
00496                                       sourceRoute,
00497                                       RoutingType routingType) = 0;
00498 
00499     virtual void internalSendRpcResponse(BaseCallMessage* call,
00500                                          BaseResponseMessage* response) = 0;
00501 
00502 
00503 
00504     void pingRpc(PingCall* call);
00505     void pingRpcResponse(PingResponse* response, cPolymorphic* context,
00506                          int rpcId, simtime_t rtt);
00507     void pingRpcTimeout(PingCall* pingCall, const TransportAddress& dest,
00508                         cPolymorphic* context, int rpcId);
00509 
00510     class RpcState
00511     {
00512     public:
00513         int id;
00514         int retries;
00515         TransportType transportType;
00516         RoutingType routingType;
00517         CompType destComp;
00518         CompType srcComp;
00519         RpcListener* listener;
00520         const TransportAddress* dest;
00521         OverlayKey destKey;
00522         BaseCallMessage* callMsg;
00523         RpcTimeoutMessage* timeoutMsg;
00524         simtime_t timeSent;
00525         simtime_t rto;
00526         cPolymorphic* context;
00527     };
00528 
00529     typedef UNORDERED_MAP<int,RpcState> RpcStates;
00530 
00531     int rpcsPending;
00532     RpcListener* defaultRpcListener;
00533     RpcStates rpcStates;
00534     double rpcUdpTimeout, rpcKeyTimeout;
00535     bool rpcExponentialBackoff;
00536 };
00537 
00538 #endif

Generated on Wed Mar 25 16:32:48 2009 for OverSim by  doxygen 1.5.5