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 protected:
00074 
00075     // overlay identity
00076     NodeHandle thisNode;   
00078     BaseOverlay* overlay;
00079 
00080     // overlay common parameters
00081     bool debugOutput;           
00083     // references to global modules
00084     GlobalStatistics* globalStatistics;  
00095     virtual bool internalHandleRpcCall(BaseCallMessage* msg);
00096 
00110     virtual void internalHandleRpcResponse(BaseResponseMessage* msg,
00111                                            cPolymorphic* context, int rpcId,
00112                                            simtime_t rtt);
00113 
00130     virtual void internalHandleRpcTimeout(BaseCallMessage* msg,
00131                                           const TransportAddress& dest,
00132                                           cPolymorphic* context,
00133                                           int rpcId, const OverlayKey& destKey);
00137     void initRpcs();
00138 
00142     void finishRpcs();
00143 
00150     virtual void internalHandleRpcMessage(BaseRpcMessage* msg);
00151 
00152 protected:
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 
00397     void pingNode(const TransportAddress& dest,
00398                   simtime_t timeout = -1,
00399                   int retries = 0,
00400                   cPolymorphic* context = NULL,
00401                   const char* caption = "PING",
00402                   RpcListener* rpcListener = NULL,
00403                   int rpcId = -1,
00404                   TransportType transportType = INVALID_TRANSPORT);
00405 
00414     virtual bool handleRpcCall(BaseCallMessage* msg);
00415 
00424     virtual CompType getThisCompType() = 0;
00425 
00426     CompType thisCompType;
00427 
00428     virtual void sendMessageToUDP(const TransportAddress& addr,
00429                                   cPacket* message)
00430     {
00431         throw cRuntimeError("sendMessageToUDP() not implemented");
00432     }
00433 
00434     virtual void pingResponse(PingResponse* pingResponse,
00435                               cPolymorphic* context, int rpcId,
00436                               simtime_t rtt);
00437 
00438     virtual void pingTimeout(PingCall* pingCall,
00439                              const TransportAddress& dest,
00440                              cPolymorphic* context,
00441                              int rpcId);
00442 
00443     NeighborCache *neighborCache; 
00444     CryptoModule *cryptoModule; 
00446     int numPingSent;
00447     int bytesPingSent;
00448     int numPingResponseSent;
00449     int bytesPingResponseSent;
00450 
00451     bool internalHandleMessage(cMessage* msg);
00452 
00453 
00454 private:
00455 
00456     virtual void handleTimerEvent(cMessage* msg);
00457 
00486     uint32_t sendRpcCall(TransportType transportType,
00487                          CompType destComp,
00488                          const TransportAddress& dest,
00489                          const OverlayKey& destKey,
00490                          BaseCallMessage* msg,
00491                          cPolymorphic* context,
00492                          RoutingType routingType,
00493                          simtime_t timeout, int retries,
00494                          int rpcId, RpcListener* rpcListener);
00495 
00496     void sendRpcMessageWithTransport(TransportType transportType,
00497                                      CompType destComp,
00498                                      RoutingType routingType,
00499                                      const std::vector<TransportAddress>& sourceRoute,
00500                                      const OverlayKey& destKey,
00501                                      BaseRpcMessage* message);
00502 
00503     virtual void internalSendRouteRpc(BaseRpcMessage* message,
00504                                       const OverlayKey& destKey,
00505                                       const std::vector<TransportAddress>&
00506                                       sourceRoute,
00507                                       RoutingType routingType) = 0;
00508 
00509     virtual void internalSendRpcResponse(BaseCallMessage* call,
00510                                          BaseResponseMessage* response) = 0;
00511 
00512 
00513 
00514     void pingRpcCall(PingCall* call);
00515     void pingRpcResponse(PingResponse* response, cPolymorphic* context,
00516                          int rpcId, simtime_t rtt);
00517     void pingRpcTimeout(PingCall* pingCall, const TransportAddress& dest,
00518                         cPolymorphic* context, int rpcId);
00519 
00520     typedef UNORDERED_MAP<int,RpcState> RpcStates;
00521 
00522     int rpcsPending;
00523     RpcListener* defaultRpcListener;
00524     RpcStates rpcStates;
00525     simtime_t rpcUdpTimeout, rpcKeyTimeout;
00526     bool rpcExponentialBackoff;
00527 
00528 public:
00529     // Prox stuff
00530 
00531 
00532     /* Gets the proximity of a node.
00533     @param node The node whose proximity will be requested.
00534     @param type Request type.
00535                 NEIGHBORCACHE_EXACT looks in the cache, and if no value
00536                 is found, sends an RTT query to the node.
00537                 NEIGHBORCACHE_AVAILABLE looks in the cache, and if no value
00538                 is found returns Prox::PROX_UNKNOWN.
00539                 NEIGHBORCACHE_ESTIMATED looks in the cache, and if no value
00540                 is found calculates an estimate based on information collected
00541                 by the overlay.
00542                 NEIGHBORCACHE_QUERY always sends an RTT query to the node and
00543                 returns Prox::PROX_UNKNOWN.
00544     @param rpcId Identifier sent to the RPC to identify the call.
00545     @param listener Module to be called back when an RTT query returns.
00546     @param contextPointer Pointer sent to the RPC to identify the call.
00547     @returns The proximity value of node.
00548     */
00549 //    Prox getProx(const TransportAddress &node,
00550 //                 NeighborCacheQueryType /*int*/ type = NEIGHBORCACHE_AVAILABLE/*0*/,
00551 //                       int rpcId = -1,
00552 //                       ProxListener *listener = NULL,
00553 //                       cPolymorphic *contextPointer = NULL);
00554 
00555 };
00556 
00557 #endif

Generated on Tue Sep 8 17:26:51 2009 for OverSim by  doxygen 1.5.8