00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
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
00104
00105
00106 private:
00107
00108 int numAppDataSent;
00109 int bytesAppDataSent;
00110 int numAppLookupSent;
00111 int bytesAppLookupSent;
00112 int numMaintenanceSent;
00113 int bytesMaintenanceSent;
00114
00115 int numAppDataReceived;
00116 int bytesAppDataReceived;
00117 int numAppLookupReceived;
00118 int bytesAppLookupReceived;
00119 int numMaintenanceReceived;
00120 int bytesMaintenanceReceived;
00121
00122 int numInternalSent;
00123 int bytesInternalSent;
00124 int numInternalReceived;
00125 int bytesInternalReceived;
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;
00140 int bytesAppDataForwarded;
00141 int numAppLookupForwarded;
00142 int bytesAppLookupForwarded;
00143 int numMaintenanceForwarded;
00144 int bytesMaintenanceForwarded;
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;
00157
00158
00159
00160
00161
00162
00163 protected:
00164
00165
00166
00167
00168 GlobalNodeList* globalNodeList;
00169 NotificationBoard* notificationBoard;
00170 UnderlayConfigurator* underlayConfigurator;
00171 BootstrapList* bootstrapList;
00172 GlobalParameters* globalParameters;
00174
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
00195
00196
00197 private:
00198
00204 void initialize(int stage);
00205
00209 void finish();
00210
00211 protected:
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
00247
00248
00249 public:
00250
00256 bool isMalicious();
00257
00263 bool isInSimpleMultiOverlayHost();
00264
00265
00266
00267
00268
00269
00270 protected:
00274 void bindToPort(int port);
00275
00276
00277
00278
00279
00280
00281 protected:
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
00408
00409
00410 private:
00411
00422 void handleMessage(cMessage* msg);
00423
00424
00434 void handleBaseOverlayMessage(BaseOverlayMessage* msg,
00435 const OverlayKey& destKey =
00436 OverlayKey::UNSPECIFIED_KEY);
00437
00438 protected:
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:
00501
00507 void setOverlayReady( bool ready );
00508
00509
00510
00511
00512
00513 private:
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
00532
00533
00534 protected:
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:
00557
00561 void initLookups();
00562
00566 void finishLookups();
00567
00583 virtual bool recursiveRoutingHook(const TransportAddress& dest,
00584 BaseRouteMessage* msg);
00585
00586 public:
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:
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:
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
00720 void internalSendRouteRpc(BaseRpcMessage* message,
00721 const OverlayKey& destKey,
00722 const std::vector<TransportAddress>&
00723 sourceRoute,
00724 RoutingType routingType);
00725
00726
00727
00728
00729
00730
00731 CompType getThisCompType();
00732
00733 bool kbr;
00735 private:
00736 void internalSendRpcResponse(BaseCallMessage* call,
00737 BaseResponseMessage* response);
00738
00739 public:
00740
00741
00742
00743
00744
00745
00746 void registerComp(CompType compType, cModule *module);
00747
00748
00749
00750
00751
00752
00753
00754 cModule* getCompModule(CompType compType);
00755
00756
00757
00758
00759
00760
00761
00762 cGate* getCompRpcGate(CompType compType);
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772 void sendMessageToAllComp(cMessage* msg, CompType srcComp);
00773
00774
00775
00776
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