BaseOverlay.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 
00024 #ifndef __BASEOVERLAY_H_
00025 #define __BASEOVERLAY_H_
00026 
00027 #include <oversim_mapset.h>
00028 
00029 #include <omnetpp.h>
00030 
00031 #include <NodeVector.h>
00032 #include <TopologyVis.h>
00033 #include <INotifiable.h>
00034 #include <BaseRpc.h>
00035 #include <IterativeLookupConfiguration.h>
00036 #include <RecursiveLookup.h>
00037 #include <InitStages.h>
00038 
00039 class GlobalNodeList;
00040 class UnderlayConfigurator;
00041 class BaseApp;
00042 class NodeHandle;
00043 class OverlayKey;
00044 class NotificationBoard;
00045 class AbstractLookup;
00046 class BootstrapList;
00047 
00061 class BaseOverlay : public INotifiable,
00062                     public BaseRpc,
00063                     public TopologyVis
00064 {
00065 
00066     friend class IterativeLookup;
00067     friend class RecursiveLookup;
00068     friend class IterativePathLookup;
00069     friend class BootstrapList;
00070     friend class SendToKeyListener;
00071 
00072     //------------------------------------------------------------------------
00073     //--- Construction / Destruction -----------------------------------------
00074     //------------------------------------------------------------------------
00075 
00076 public:
00077 
00078     BaseOverlay();
00079 
00081     virtual ~BaseOverlay();
00082 
00083     enum States {
00084         INIT = 0,
00085         JOINING_1 = 1,
00086         JOINING_2 = 2,
00087         JOINING_3 = 3,
00088         READY = 4,
00089         REFRESH = 5,
00090         SHUTDOWN = 6,
00091         FAILED = 7,
00092 
00093         //some aliases for compatibility
00094         JOINING = JOINING_1,
00095         JOIN = JOINING_1,
00096         BOOTSTRAP = JOINING_1,
00097         RSET = JOINING_2,
00098         BSET = JOINING_3
00099     };
00100 
00101     States getState() { return state; };
00102 
00103 
00104     //------------------------------------------------------------------------
00105     //--- Statistics ---------------------------------------------------------
00106     //------------------------------------------------------------------------
00107 
00108 private://fields: statistics
00109 
00110     int numAppDataSent;   
00111     int bytesAppDataSent; 
00112     int numAppLookupSent;   
00113     int bytesAppLookupSent; 
00114     int numMaintenanceSent;   
00115     int bytesMaintenanceSent; 
00117     int numAppDataReceived;   
00118     int bytesAppDataReceived; 
00119     int numAppLookupReceived;   
00120     int bytesAppLookupReceived; 
00121     int numMaintenanceReceived;   
00122     int bytesMaintenanceReceived; 
00124     int numInternalSent;  
00125     int bytesInternalSent;  
00126     int numInternalReceived;  
00127     int bytesInternalReceived;  
00129     int joinRetries; 
00131 protected:
00132 
00136     struct HopDelayRecord
00137     {
00138         int count;
00139         simtime_t val;
00140         HopDelayRecord() : count(0), val(0) {};
00141     };
00142 
00143     int numAppDataForwarded;   
00144     int bytesAppDataForwarded; 
00145     int numAppLookupForwarded;   
00146     int bytesAppLookupForwarded; 
00147     int numMaintenanceForwarded;   
00148     int bytesMaintenanceForwarded; 
00150     int numFindNodeSent; 
00151     int bytesFindNodeSent; 
00152     int numFindNodeResponseSent; 
00153     int bytesFindNodeResponseSent; 
00154     int numFailedNodeSent; 
00155     int bytesFailedNodeSent; 
00156     int numFailedNodeResponseSent; 
00157     int bytesFailedNodeResponseSent; 
00158     std::vector<HopDelayRecord*> singleHopDelays; 
00160     simtime_t creationTime; 
00163     //------------------------------------------------------------------------
00164     //--- Common Overlay Attributes & Global Module References ---------------
00165     //------------------------------------------------------------------------
00166 
00167 protected://fields: overlay attributes
00168 
00169 
00170 
00171     // references to global modules
00172     GlobalNodeList* globalNodeList;           
00173     NotificationBoard* notificationBoard;       
00174     UnderlayConfigurator* underlayConfigurator; 
00175     BootstrapList* bootstrapList; 
00176     GlobalParameters* globalParameters; 
00178     // overlay common parameters
00179     bool debugOutput;           
00180     RoutingType defaultRoutingType;
00181     bool useCommonAPIforward;   
00182     bool collectPerHopDelay;    
00183     bool routeMsgAcks;          
00184     uint32_t recNumRedundantNodes;  
00185     bool recordRoute;   
00186     bool drawOverlayTopology;
00187     bool rejoinOnFailure;
00188     int localPort;              
00189     int hopCountMax;            
00191     int numDropped;             
00192     int bytesDropped;           
00194     cOutVector delayVector;     
00195     cOutVector hopCountVector;  
00197     States state;
00198 
00199     //------------------------------------------------------------------------
00200     //--- Initialization & finishing -----------------------------------------
00201     //------------------------------------------------------------------------
00202 
00203 private://methods: cSimpleModule initialization
00204 
00210     void initialize(int stage);
00211 
00215     void finish();
00216 
00217 protected://methods: overlay initialization
00218 
00224     int numInitStages() const;
00225 
00236     virtual void initializeOverlay( int stage );
00237 
00241     virtual void finishOverlay();
00242 
00243 private:
00249     virtual void setOwnNodeID();
00250 
00251     //------------------------------------------------------------------------
00252     //--- General Overlay Parameters (getter and setters) --------------------
00253     //------------------------------------------------------------------------
00254 
00255 public://methods: getters and setters
00256 
00262     bool isMalicious();
00263 
00269     bool isInSimpleMultiOverlayHost();
00270 
00271     const simtime_t& getCreationTime() { return creationTime; };
00272 
00273 
00274     //------------------------------------------------------------------------
00275     //--- UDP functions copied from the INET framework .----------------------
00276     //------------------------------------------------------------------------
00277 
00278 protected:
00282     void bindToPort(int port);
00283 
00284 
00285     //------------------------------------------------------------------------
00286     //--- Overlay Common API: Key-based Routing ------------------------------
00287     //------------------------------------------------------------------------
00288 
00289 protected://methods: KBR
00290 
00307     virtual void route(const OverlayKey& key, CompType destComp,
00308                        CompType srcComp, cPacket* msg,
00309                        const std::vector<TransportAddress>& sourceRoute
00310                            = TransportAddress::UNSPECIFIED_NODES,
00311                        RoutingType routingType = DEFAULT_ROUTING);
00312 
00322     void callDeliver( BaseOverlayMessage* msg,
00323                       const OverlayKey& destKey);
00324 
00336     void callForward( const OverlayKey& key, BaseRouteMessage* msg,
00337                       const NodeHandle& nextHopNode);
00338 
00347     void callUpdate(const NodeHandle& node, bool joined);
00348 
00349 public:
00350 
00360     void join(const OverlayKey& nodeID = OverlayKey::UNSPECIFIED_KEY);
00361 
00373     virtual NodeVector* local_lookup(const OverlayKey& key, int num, bool safe);
00374 
00375 
00378     virtual NodeVector* neighborSet(int num);
00379 
00395     virtual bool isSiblingFor(const NodeHandle& node,
00396                               const OverlayKey& key, int numSiblings, bool* err);
00397 
00404     virtual int getMaxNumSiblings();
00405 
00412     virtual int getMaxNumRedundantNodes();
00413 
00414     //------------------------------------------------------------------------
00415     //--- Message Handlers ---------------------------------------------------
00416     //------------------------------------------------------------------------
00417 
00418 private://methods: message handling
00419 
00430     void handleMessage(cMessage* msg);
00431 
00432 
00442     void handleBaseOverlayMessage(BaseOverlayMessage* msg,
00443                                   const OverlayKey& destKey =
00444                                       OverlayKey::UNSPECIFIED_KEY);
00445 
00446 protected://methods: message handling
00447 
00453     virtual void handleUDPMessage(BaseOverlayMessage* msg);
00454 
00460     //virtual void handleTimerEvent(cMessage* msg);
00461 
00467     virtual void handleAppMessage(cMessage* msg);
00468 
00475     virtual void receiveChangeNotification(int category,
00476                                            const cPolymorphic* details);
00477 
00482     virtual void handleTransportAddressChangedNotification();
00483 
00487     virtual void handleNodeLeaveNotification();
00488 
00493     virtual void handleNodeGracefulLeaveNotification();
00494 
00495 
00506     virtual void recordOverlaySentStats(BaseOverlayMessage* msg);
00507 
00508 protected://methods: icons and ui support
00509 
00515     void setOverlayReady( bool ready );
00516 
00517     //------------------------------------------------------------------------
00518     //--- Messages -----------------------------------------------------------
00519     //------------------------------------------------------------------------
00520 
00521 private://methods: sending packets over udp
00522 
00523     void sendRouteMessage(const TransportAddress& dest,
00524                           BaseRouteMessage* msg,
00525                           bool ack);
00526 
00527     bool checkFindNode(BaseRouteMessage* routeMsg);
00528 
00529 public:
00536     void sendMessageToUDP(const TransportAddress& dest, cPacket* msg);
00537 
00538     //------------------------------------------------------------------------
00539     //--- Basic Routing ------------------------------------------------------
00540     //------------------------------------------------------------------------
00541 
00542 protected://fields: config
00543     IterativeLookupConfiguration iterativeLookupConfig;
00544     RecursiveLookupConfiguration recursiveLookupConfig;
00545 
00546     class lookupHashFcn
00547     {
00548     public:
00549         size_t operator()( const AbstractLookup* l1 ) const
00550         {
00551             return (size_t)l1;
00552         }
00553         bool operator()(const AbstractLookup* l1,
00554                         const AbstractLookup* l2) const
00555         {
00556             return (l1 == l2);
00557         }
00558     };
00559 
00560     typedef UNORDERED_SET<AbstractLookup*, lookupHashFcn, lookupHashFcn> LookupSet;
00561 
00562     LookupSet lookups;
00563 
00564 private://methods: internal routing
00565 
00569     void initLookups();
00570 
00574     void finishLookups();
00575 
00591     virtual bool recursiveRoutingHook(const TransportAddress& dest,
00592                                       BaseRouteMessage* msg);
00593 
00594 public://methods: basic message routing
00595 
00609     void sendToKey(const OverlayKey& key, BaseOverlayMessage* message,
00610                    int numSiblings = 1,
00611                    const std::vector<TransportAddress>& sourceRoute
00612                              = TransportAddress::UNSPECIFIED_NODES,
00613                    RoutingType routingType = DEFAULT_ROUTING);
00614 
00615 protected://methods: routing class factory
00616 
00629     virtual AbstractLookup* createLookup(RoutingType routingType = DEFAULT_ROUTING,
00630                                          const BaseOverlayMessage* msg = NULL,
00631                                          const cPacket* findNodeExt = NULL,
00632                                          bool appLookup = false);
00633 
00639     virtual void removeLookup( AbstractLookup* lookup );
00640 
00650     virtual OverlayKey distance( const OverlayKey& x,
00651                                  const OverlayKey& y ) const;
00652 
00669     virtual NodeVector* findNode( const OverlayKey& key,
00670                                   int numRedundantNodes,
00671                                   int numSiblings,
00672                                   BaseOverlayMessage* msg = NULL);
00673 
00674 
00684     virtual void joinOverlay();
00685 
00695     virtual void joinForeignPartition(const NodeHandle& node);
00696 
00706     virtual bool handleFailedNode(const TransportAddress& failed);
00707 
00708     virtual void lookupRpc(LookupCall* call);
00709 
00710     virtual void nextHopRpc(NextHopCall* call);
00711 
00712 protected://methods: statistic helpers for IterativeLookup
00713 
00714     void countFindNodeCall(const FindNodeCall* call);
00715     void countFailedNodeCall(const FailedNodeCall* call);
00716 
00717 
00718     bool internalHandleRpcCall( BaseCallMessage* msg );
00719     void internalHandleRpcResponse(BaseResponseMessage* msg,
00720                                    cPolymorphic* context, int rpcId,
00721                                    simtime_t rtt);
00722     void internalHandleRpcTimeout(BaseCallMessage* msg,
00723                                   const TransportAddress& dest,
00724                                   cPolymorphic* context,
00725                                   int rpcId, const OverlayKey& destKey);
00726 
00727     // TODO rename to internalSendRouteRpcMessage()
00728     void internalSendRouteRpc(BaseRpcMessage* message,
00729                               const OverlayKey& destKey,
00730                               const std::vector<TransportAddress>&
00731                               sourceRoute,
00732                               RoutingType routingType);
00733 
00734     /*
00735      * Returns the component type of this module
00736      *
00737      * @return the component type
00738      */
00739     CompType getThisCompType();
00740 
00741     bool kbr; 
00743 private:
00744     void internalSendRpcResponse(BaseCallMessage* call,
00745                                  BaseResponseMessage* response);
00746 
00747     const cGate* udpGate;
00748     const cGate* appGate;
00749 
00750 public:
00751     /*
00752      * Register a new component at the overlay
00753      *
00754      * @param compType The compoment type (defined in CommonMessages.msg)
00755      * @param module The module pointer of the component
00756      */
00757     void registerComp(CompType compType, cModule *module);
00758 
00759     /*
00760      * Get the module pointer of a registered component
00761      *
00762      * @param compType The compoment type (defined in CommonMessages.msg)
00763      * @return The module pointer of the component
00764      */
00765     cModule* getCompModule(CompType compType);
00766 
00767     /*
00768      * Get the direct_in gate of a registered component
00769      *
00770      * @param compType The compoment type (defined in CommonMessages.msg)
00771      * @return The pointer to the direct_in gate of the component
00772      */
00773     cGate* getCompRpcGate(CompType compType);
00774 
00775     /*
00776      * Sends a message to all currently registered components, but the
00777      * source component
00778      *
00779      * @param msg The pointer to the message to send
00780      * @param srcComp The type of the originating component
00781      *
00782      */
00783     void sendMessageToAllComp(cMessage* msg, CompType srcComp);
00784 
00785     /*
00786      * Returns true, if the overlay is a structured overlay and
00787      * provides KBR services (e.g. route, lookup, ...).
00788      */
00789     bool providesKbr() { return kbr; };
00790 
00791     virtual uint8_t getBitsPerDigit() { return 1; };
00792 
00793 private:
00794     void findNodeRpc( FindNodeCall* call );
00795     void failedNodeRpc( FailedNodeCall* call );
00796 
00797     typedef std::map<CompType, std::pair<cModule*, cGate*> > CompModuleList;
00798     CompModuleList compModuleList;
00799     bool internalReadyState; 
00801 };
00802 
00803 #endif

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