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 
00038 class GlobalNodeList;
00039 class UnderlayConfigurator;
00040 class BaseApp;
00041 class NodeHandle;
00042 class OverlayKey;
00043 class NotificationBoard;
00044 class AbstractLookup;
00045 class BootstrapList;
00046 
00060 class BaseOverlay : public INotifiable,
00061                     public BaseRpc,
00062                     public TopologyVis
00063 {
00064 
00065     friend class IterativeLookup;
00066     friend class RecursiveLookup;
00067     friend class IterativePathLookup;
00068     friend class BootstrapList;
00069     friend class SendToKeyListener;
00070 
00071     //------------------------------------------------------------------------
00072     //--- Construction / Destruction -----------------------------------------
00073     //------------------------------------------------------------------------
00074 
00075 public:
00076 
00077     BaseOverlay();
00078 
00080     virtual ~BaseOverlay();
00081 
00082     enum States {
00083         INIT = 0,
00084         JOINING_1 = 1,
00085         JOINING_2 = 2,
00086         JOINING_3 = 3,
00087         READY = 4,
00088         REFRESH = 5,
00089         SHUTDOWN = 6,
00090 
00091         //some aliases for compatibility
00092         JOINING = JOINING_1,
00093         JOIN = JOINING_1,
00094         BOOTSTRAP = JOINING_1,
00095         RSET = JOINING_2,
00096         BSET = JOINING_3
00097     };
00098 
00099     States getState() { return state; };
00100 
00101 
00102     //------------------------------------------------------------------------
00103     //--- Statistics ---------------------------------------------------------
00104     //------------------------------------------------------------------------
00105 
00106 private://fields: statistics
00107 
00108     int numAppDataSent;   //*< number of sent app data packets (incl.\ forwarded packets) */
00109     int bytesAppDataSent; //*< number of sent app data bytes (incl.\ forwarded bytes) */
00110     int numAppLookupSent;   //*< number of sent app loookup packets (incl.\ forwarded packets) */
00111     int bytesAppLookupSent; //*< number of sent app lookup bytes (incl.\ forwarded bytes) */
00112     int numMaintenanceSent;   //*< number of sent maintenance packets (incl.\ forwarded packets) */
00113     int bytesMaintenanceSent; //*< number of sent maintenance bytes (incl.\ forwarded bytes) */
00114 
00115     int numAppDataReceived;   //*< number of received app data packets (incl.\ packets to be forwarded ) */
00116     int bytesAppDataReceived; //*< number of received app data bytes (incl.\ bytes to be forwarded) */
00117     int numAppLookupReceived;   //*< number of received app lookup packets (incl.\ packets to be forwarded) */
00118     int bytesAppLookupReceived; //*< number of received app lookup bytes (incl.\ bytes to be forwarded) */
00119     int numMaintenanceReceived;   //*< number of received maintenance packets (incl.\ packets to be forwarded) */
00120     int bytesMaintenanceReceived; //*< number of received maintenance bytes (incl.\ bytes to be forwarded) */
00121 
00122     int numInternalSent;  // number of packets sent to same host but different port (SimpleMultiOverlayHost)
00123     int bytesInternalSent;  // number of bytes sent to same host but different port (SimpleMultiOverlayHost)
00124     int numInternalReceived;  // number of packets received from same host but different port (SimpleMultiOverlayHost)
00125     int bytesInternalReceived;  // number of bytes received from same host but different port (SimpleMultiOverlayHost)
00126 
00127 protected:
00128 
00132     struct HopDelayRecord
00133     {
00134         int count;
00135         simtime_t val;
00136         HopDelayRecord() : count(0), val(0) {};
00137     };
00138 
00139     int numAppDataForwarded;   //*< number of forwarded app data packets */
00140     int bytesAppDataForwarded; //*< number of forwarded app data bytes at out-gate */
00141     int numAppLookupForwarded;   //*< number of forwarded app lookup packets */
00142     int bytesAppLookupForwarded; //*< number of forwarded app lookup bytes at out-gate */
00143     int numMaintenanceForwarded;   //*< number of forwarded maintenance packets */
00144     int bytesMaintenanceForwarded; //*< number of forwarded maintenance bytes at out-gate */
00145 
00146     int numFindNodeSent; 
00147     int bytesFindNodeSent; 
00148     int numFindNodeResponseSent; 
00149     int bytesFindNodeResponseSent; 
00150     int numFailedNodeSent; 
00151     int bytesFailedNodeSent; 
00152     int numFailedNodeResponseSent; 
00153     int bytesFailedNodeResponseSent; 
00154     std::vector<HopDelayRecord*> singleHopDelays; 
00156     simtime_t creationTime; //*< simtime when the node has been created */
00157 
00158 
00159     //------------------------------------------------------------------------
00160     //--- Common Overlay Attributes & Global Module References ---------------
00161     //------------------------------------------------------------------------
00162 
00163 protected://fields: overlay attributes
00164 
00165 
00166 
00167     // references to global modules
00168     GlobalNodeList* globalNodeList;           
00169     NotificationBoard* notificationBoard;       
00170     UnderlayConfigurator* underlayConfigurator; 
00171     BootstrapList* bootstrapList; 
00172     GlobalParameters* globalParameters; 
00174     // overlay common parameters
00175     bool debugOutput;           
00176     RoutingType defaultRoutingType;
00177     bool useCommonAPIforward;   
00178     bool collectPerHopDelay;    
00179     bool routeMsgAcks;          
00180     uint32_t recNumRedundantNodes;  
00181     bool recursivePathRecord;   
00182     bool drawOverlayTopology;
00183     int localPort;              
00184     int hopCountMax;            
00185     int numDropped;             
00186     int bytesDropped;           
00188     cOutVector delayVector;     
00189     cOutVector hopCountVector;  
00191     States state;
00192 
00193     //------------------------------------------------------------------------
00194     //--- Initialization & finishing -----------------------------------------
00195     //------------------------------------------------------------------------
00196 
00197 private://methods: cSimpleModule initialization
00198 
00204     void initialize(int stage);
00205 
00209     void finish();
00210 
00211 protected://methods: overlay initialization
00212 
00218     int numInitStages() const;
00219 
00230     virtual void initializeOverlay( int stage );
00231 
00235     virtual void finishOverlay();
00236 
00237 private:
00243     virtual void setOwnNodeID();
00244 
00245     //------------------------------------------------------------------------
00246     //--- General Overlay Parameters (getter and setters) --------------------
00247     //------------------------------------------------------------------------
00248 
00249 public://methods: getters and setters
00250 
00256     bool isMalicious();
00257 
00263     bool isInSimpleMultiOverlayHost();
00264 
00265 
00266     //------------------------------------------------------------------------
00267     //--- UDP functions copied from the INET framework .----------------------
00268     //------------------------------------------------------------------------
00269 
00270 protected:
00274     void bindToPort(int port);
00275 
00276 
00277     //------------------------------------------------------------------------
00278     //--- Overlay Common API: Key-based Routing ------------------------------
00279     //------------------------------------------------------------------------
00280 
00281 protected://methods: KBR
00282 
00299     virtual void route(const OverlayKey& key, CompType destComp,
00300                        CompType srcComp, cPacket* msg,
00301                        const std::vector<TransportAddress>& sourceRoute
00302                            = TransportAddress::UNSPECIFIED_NODES,
00303                        RoutingType routingType = DEFAULT_ROUTING);
00304 
00314     void callDeliver( BaseOverlayMessage* msg,
00315                       const OverlayKey& destKey);
00316 
00328     void callForward( const OverlayKey& key, BaseRouteMessage* msg,
00329                       const NodeHandle& nextHopNode);
00330 
00339     void callUpdate(const NodeHandle& node, bool joined);
00340 
00341 public:
00342 
00352     void join(const OverlayKey& nodeID = OverlayKey::UNSPECIFIED_KEY);
00353 
00365     virtual NodeVector* local_lookup(const OverlayKey& key, int num, bool safe);
00366 
00367 
00370     virtual NodeVector* neighborSet(int num);
00371 
00387     virtual bool isSiblingFor(const NodeHandle& node,
00388                               const OverlayKey& key, int numSiblings, bool* err);
00389 
00396     virtual int getMaxNumSiblings();
00397 
00404     virtual int getMaxNumRedundantNodes();
00405 
00406     //------------------------------------------------------------------------
00407     //--- Message Handlers ---------------------------------------------------
00408     //------------------------------------------------------------------------
00409 
00410 private://methods: message handling
00411 
00422     void handleMessage(cMessage* msg);
00423 
00424 
00434     void handleBaseOverlayMessage(BaseOverlayMessage* msg,
00435                                   const OverlayKey& destKey =
00436                                       OverlayKey::UNSPECIFIED_KEY);
00437 
00438 protected://methods: message handling
00439 
00445     virtual void handleUDPMessage(BaseOverlayMessage* msg);
00446 
00452     virtual void handleTimerEvent(cMessage* msg);
00453 
00459     virtual void handleAppMessage(cMessage* msg);
00460 
00467     virtual void receiveChangeNotification(int category,
00468                                            const cPolymorphic* details);
00469 
00474     virtual void handleTransportAddressChangedNotification();
00475 
00479     virtual void handleNodeLeaveNotification();
00480 
00485     virtual void handleNodeGracefulLeaveNotification();
00486 
00487 
00498     virtual void recordOverlaySentStats(BaseOverlayMessage* msg);
00499 
00500 protected://methods: icons and ui support
00501 
00507     void setOverlayReady( bool ready );
00508 
00509     //------------------------------------------------------------------------
00510     //--- Messages -----------------------------------------------------------
00511     //------------------------------------------------------------------------
00512 
00513 private://methods: sending packets over udp
00514 
00515     void sendRouteMessage(const TransportAddress& dest,
00516                           BaseRouteMessage* msg,
00517                           bool ack);
00518 
00519     bool checkFindNode(BaseRouteMessage* routeMsg);
00520 
00521 public:
00528     void sendMessageToUDP(const TransportAddress& dest, cPacket* msg);
00529 
00530     //------------------------------------------------------------------------
00531     //--- Basic Routing ------------------------------------------------------
00532     //------------------------------------------------------------------------
00533 
00534 protected://fields: config
00535     IterativeLookupConfiguration iterativeLookupConfig;
00536     RecursiveLookupConfiguration recursiveLookupConfig;
00537 
00538     class lookupHashFcn
00539     {
00540     public:
00541         size_t operator()( const AbstractLookup* l1 ) const
00542         {
00543             return (size_t)l1;
00544         }
00545         bool operator()(const AbstractLookup* l1,
00546                         const AbstractLookup* l2) const
00547         {
00548             return (l1 == l2);
00549         }
00550     };
00551 
00552     typedef UNORDERED_SET<AbstractLookup*, lookupHashFcn, lookupHashFcn> LookupSet;
00553 
00554     LookupSet lookups;
00555 
00556 private://methods: internal routing
00557 
00561     void initLookups();
00562 
00566     void finishLookups();
00567 
00583     virtual bool recursiveRoutingHook(const TransportAddress& dest,
00584                                       BaseRouteMessage* msg);
00585 
00586 public://methods: basic message routing
00587 
00601     void sendToKey(const OverlayKey& key, BaseOverlayMessage* message,
00602                    int numSiblings = 1,
00603                    const std::vector<TransportAddress>& sourceRoute
00604                              = TransportAddress::UNSPECIFIED_NODES,
00605                    RoutingType routingType = DEFAULT_ROUTING);
00606 
00607 protected://methods: routing class factory
00608 
00621     virtual AbstractLookup* createLookup(RoutingType routingType = DEFAULT_ROUTING,
00622                                          const BaseOverlayMessage* msg = NULL,
00623                                          const cObject* findNodeExt = NULL,
00624                                          bool appLookup = false);
00625 
00631     virtual void removeLookup( AbstractLookup* lookup );
00632 
00642     virtual OverlayKey distance( const OverlayKey& x,
00643                                  const OverlayKey& y ) const;
00644 
00661     virtual NodeVector* findNode( const OverlayKey& key,
00662                                   int numRedundantNodes,
00663                                   int numSiblings,
00664                                   BaseOverlayMessage* msg = NULL);
00665 
00666 
00676     virtual void joinOverlay();
00677 
00687     virtual void joinForeignPartition(const NodeHandle& node);
00688 
00698     virtual bool handleFailedNode(const TransportAddress& failed);
00699 
00700     virtual void lookupRpc(LookupCall* call);
00701 
00702     virtual void nextHopRpc(NextHopCall* call);
00703 
00704 protected://methods: statistic helpers for IterativeLookup
00705 
00706     void countFindNodeCall( const FindNodeCall* call );
00707     void countFailedNodeCall( const FailedNodeCall* call );
00708 
00709 
00710     bool internalHandleRpc( BaseCallMessage* msg );
00711     bool internalHandleRpcResponse(BaseResponseMessage* msg,
00712                                    cPolymorphic* context, int rpcId,
00713                                    simtime_t rtt);
00714     void internalHandleRpcTimeout(BaseCallMessage* msg,
00715                                   const TransportAddress& dest,
00716                                   cPolymorphic* context,
00717                                   int rpcId, const OverlayKey& destKey);
00718 
00719     // TODO rename to internalSendRouteRpcMessage()
00720     void internalSendRouteRpc(BaseRpcMessage* message,
00721                               const OverlayKey& destKey,
00722                               const std::vector<TransportAddress>&
00723                               sourceRoute,
00724                               RoutingType routingType);
00725 
00726     /*
00727      * Returns the component type of this module
00728      *
00729      * @return the component type
00730      */
00731     CompType getThisCompType();
00732 
00733     bool kbr; 
00735 private:
00736     void internalSendRpcResponse(BaseCallMessage* call,
00737                                  BaseResponseMessage* response);
00738 
00739 public:
00740     /*
00741      * Register a new component at the overlay
00742      *
00743      * @param compType The compoment type (defined in CommonMessages.msg)
00744      * @param module The module pointer of the component
00745      */
00746     void registerComp(CompType compType, cModule *module);
00747 
00748     /*
00749      * Get the module pointer of a registered component
00750      *
00751      * @param compType The compoment type (defined in CommonMessages.msg)
00752      * @return The module pointer of the component
00753      */
00754     cModule* getCompModule(CompType compType);
00755 
00756     /*
00757      * Get the direct_in gate of a registered component
00758      *
00759      * @param compType The compoment type (defined in CommonMessages.msg)
00760      * @return The pointer to the direct_in gate of the component
00761      */
00762     cGate* getCompRpcGate(CompType compType);
00763 
00764     /*
00765      * Sends a message to all currently registered components, but the
00766      * source component
00767      *
00768      * @param msg The pointer to the message to send
00769      * @param srcComp The type of the originating component
00770      *
00771      */
00772     void sendMessageToAllComp(cMessage* msg, CompType srcComp);
00773 
00774     /*
00775      * Returns true, if the overlay is a structured overlay and
00776      * provides KBR services (e.g. route, lookup, ...).
00777      */
00778     bool providesKbr() { return kbr; };
00779 
00780 private:
00781     void findNodeRpc( FindNodeCall* call );
00782     void failedNodeRpc( FailedNodeCall* call );
00783 
00784     typedef std::map<CompType, std::pair<cModule*, cGate*> > CompModuleList;
00785     CompModuleList compModuleList;
00786 
00787 };
00788 
00789 #endif

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