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 #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 IterativePathLookup;
00068 friend class RecursiveLookup;
00069 friend class BootstrapList;
00070 friend class SendToKeyListener;
00071
00072
00073
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
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 class BaseOverlayContext : public cObject
00104 {
00105 public:
00106 BaseOverlayContext(const OverlayKey& key, bool malicious) : key(key), malicious(malicious) {};
00107 OverlayKey key;
00108 bool malicious;
00109 };
00110
00111
00112
00113
00114
00115
00116 private:
00117
00118 int numAppDataSent;
00119 int bytesAppDataSent;
00120 int numAppLookupSent;
00121 int bytesAppLookupSent;
00122 int numMaintenanceSent;
00123 int bytesMaintenanceSent;
00125 int numAppDataReceived;
00126 int bytesAppDataReceived;
00127 int numAppLookupReceived;
00128 int bytesAppLookupReceived;
00129 int numMaintenanceReceived;
00130 int bytesMaintenanceReceived;
00132 int numInternalSent;
00133 int bytesInternalSent;
00134 int numInternalReceived;
00135 int bytesInternalReceived;
00137 int bytesAuthBlockSent;
00139 int joinRetries;
00141 protected:
00142
00146 struct HopDelayRecord
00147 {
00148 int count;
00149 simtime_t val;
00150 HopDelayRecord() : count(0), val(0) {};
00151 };
00152
00153 int numAppDataForwarded;
00154 int bytesAppDataForwarded;
00155 int numAppLookupForwarded;
00156 int bytesAppLookupForwarded;
00157 int numMaintenanceForwarded;
00158 int bytesMaintenanceForwarded;
00160 int numFindNodeSent;
00161 int bytesFindNodeSent;
00162 int numFindNodeResponseSent;
00163 int bytesFindNodeResponseSent;
00164 int numFailedNodeSent;
00165 int bytesFailedNodeSent;
00166 int numFailedNodeResponseSent;
00167 int bytesFailedNodeResponseSent;
00168 std::vector<HopDelayRecord*> singleHopDelays;
00170 simtime_t creationTime;
00173
00174
00175
00176
00177 protected:
00178
00179
00180
00181
00182 GlobalNodeList* globalNodeList;
00183 NotificationBoard* notificationBoard;
00184 UnderlayConfigurator* underlayConfigurator;
00185 BootstrapList* bootstrapList;
00186 GlobalParameters* globalParameters;
00188
00189 bool debugOutput;
00190 RoutingType defaultRoutingType;
00191 bool useCommonAPIforward;
00192 bool collectPerHopDelay;
00193 bool routeMsgAcks;
00194 uint32_t recNumRedundantNodes;
00195 bool recordRoute;
00196 bool drawOverlayTopology;
00197 bool rejoinOnFailure;
00198 bool dropFindNodeAttack;
00199 bool isSiblingAttack;
00200 bool invalidNodesAttack;
00201 bool dropRouteMessageAttack;
00202 int localPort;
00203 int hopCountMax;
00204 bool measureAuthBlock;
00205 bool restoreContext;
00207 int numDropped;
00208 int bytesDropped;
00210 cOutVector delayVector;
00211 cOutVector hopCountVector;
00213 States state;
00214
00215
00216
00217
00218
00219 private:
00220
00226 void initialize(int stage);
00227
00231 void finish();
00232
00233 protected:
00234
00240 int numInitStages() const;
00241
00252 virtual void initializeOverlay( int stage );
00253
00257 virtual void finishOverlay();
00258
00259 private:
00265 virtual void setOwnNodeID();
00266
00267
00268
00269
00270
00271 public:
00272
00278 bool isMalicious();
00279
00285 bool isInSimpleMultiOverlayHost();
00286
00287 const simtime_t& getCreationTime() { return creationTime; };
00288
00289
00290
00291
00292
00293
00294 protected:
00298 void bindToPort(int port);
00299
00300
00301
00302
00303
00304
00305 protected:
00306
00323 virtual void route(const OverlayKey& key, CompType destComp,
00324 CompType srcComp, cPacket* msg,
00325 const std::vector<TransportAddress>& sourceRoute
00326 = TransportAddress::UNSPECIFIED_NODES,
00327 RoutingType routingType = DEFAULT_ROUTING);
00328
00338 void callDeliver( BaseOverlayMessage* msg,
00339 const OverlayKey& destKey);
00340
00352 void callForward( const OverlayKey& key, BaseRouteMessage* msg,
00353 const NodeHandle& nextHopNode);
00354
00363 void callUpdate(const NodeHandle& node, bool joined);
00364
00365 public:
00366
00376 void join(const OverlayKey& nodeID = OverlayKey::UNSPECIFIED_KEY);
00377
00389 virtual NodeVector* local_lookup(const OverlayKey& key, int num, bool safe);
00390
00391
00394 virtual NodeVector* neighborSet(int num);
00395
00411 virtual bool isSiblingFor(const NodeHandle& node,
00412 const OverlayKey& key, int numSiblings, bool* err);
00413
00420 virtual int getMaxNumSiblings();
00421
00428 virtual int getMaxNumRedundantNodes();
00429
00430
00431
00432
00433
00434 private:
00435
00446 void handleMessage(cMessage* msg);
00447
00448
00458 void handleBaseOverlayMessage(BaseOverlayMessage* msg,
00459 const OverlayKey& destKey =
00460 OverlayKey::UNSPECIFIED_KEY);
00461
00462 protected:
00463
00469 virtual void handleUDPMessage(BaseOverlayMessage* msg);
00470
00476
00477
00483 virtual void handleAppMessage(cMessage* msg);
00484
00491 virtual void receiveChangeNotification(int category,
00492 const cPolymorphic* details);
00493
00498 virtual void handleTransportAddressChangedNotification();
00499
00503 virtual void handleNodeLeaveNotification();
00504
00509 virtual void handleNodeGracefulLeaveNotification();
00510
00511
00522 virtual void recordOverlaySentStats(BaseOverlayMessage* msg);
00523
00524 protected:
00525
00531 void setOverlayReady( bool ready );
00532
00533
00534
00535
00536
00537 private:
00538
00539 void sendRouteMessage(const TransportAddress& dest,
00540 BaseRouteMessage* msg,
00541 bool ack);
00542
00543 bool checkFindNode(BaseRouteMessage* routeMsg);
00544
00545 public:
00552 void sendMessageToUDP(const TransportAddress& dest, cPacket* msg);
00553
00554
00555
00556
00557
00558 protected:
00559 IterativeLookupConfiguration iterativeLookupConfig;
00560 RecursiveLookupConfiguration recursiveLookupConfig;
00561
00562 class lookupHashFcn
00563 {
00564 public:
00565 size_t operator()( const AbstractLookup* l1 ) const
00566 {
00567 return (size_t)l1;
00568 }
00569 bool operator()(const AbstractLookup* l1,
00570 const AbstractLookup* l2) const
00571 {
00572 return (l1 == l2);
00573 }
00574 };
00575
00576 typedef UNORDERED_SET<AbstractLookup*, lookupHashFcn, lookupHashFcn> LookupSet;
00577
00578 LookupSet lookups;
00579
00580 private:
00581
00585 void initLookups();
00586
00590 void finishLookups();
00591
00607 virtual bool recursiveRoutingHook(const TransportAddress& dest,
00608 BaseRouteMessage* msg);
00609
00610 public:
00611
00625 void sendToKey(const OverlayKey& key, BaseOverlayMessage* message,
00626 int numSiblings = 1,
00627 const std::vector<TransportAddress>& sourceRoute
00628 = TransportAddress::UNSPECIFIED_NODES,
00629 RoutingType routingType = DEFAULT_ROUTING);
00630
00641 virtual OverlayKey distance(const OverlayKey& x,
00642 const OverlayKey& y,
00643 bool useAlternative = false) const;
00644
00645 protected:
00646
00659 virtual AbstractLookup* createLookup(RoutingType routingType = DEFAULT_ROUTING,
00660 const BaseOverlayMessage* msg = NULL,
00661 const cPacket* findNodeExt = NULL,
00662 bool appLookup = false);
00663
00669 virtual void removeLookup( AbstractLookup* lookup );
00670
00687 virtual NodeVector* findNode( const OverlayKey& key,
00688 int numRedundantNodes,
00689 int numSiblings,
00690 BaseOverlayMessage* msg = NULL);
00691
00692
00702 virtual void joinOverlay();
00703
00713 virtual void joinForeignPartition(const NodeHandle& node);
00714
00724 virtual bool handleFailedNode(const TransportAddress& failed);
00725
00726 virtual void lookupRpc(LookupCall* call);
00727
00728 virtual void nextHopRpc(NextHopCall* call);
00729
00730 protected:
00731
00732 void countFindNodeCall(const FindNodeCall* call);
00733 void countFailedNodeCall(const FailedNodeCall* call);
00734
00735
00736 bool internalHandleRpcCall( BaseCallMessage* msg );
00737 void internalHandleRpcResponse(BaseResponseMessage* msg,
00738 cPolymorphic* context, int rpcId,
00739 simtime_t rtt);
00740 void internalHandleRpcTimeout(BaseCallMessage* msg,
00741 const TransportAddress& dest,
00742 cPolymorphic* context,
00743 int rpcId, const OverlayKey& destKey);
00744
00745
00746 void internalSendRouteRpc(BaseRpcMessage* message,
00747 const OverlayKey& destKey,
00748 const std::vector<TransportAddress>&
00749 sourceRoute,
00750 RoutingType routingType);
00751
00752
00753
00754
00755
00756
00757 CompType getThisCompType();
00758
00759 bool kbr;
00761 private:
00762 void internalSendRpcResponse(BaseCallMessage* call,
00763 BaseResponseMessage* response);
00764
00765 const cGate* udpGate;
00766 const cGate* appGate;
00767
00768 public:
00769
00770
00771
00772
00773
00774
00775 void registerComp(CompType compType, cModule *module);
00776
00777
00778
00779
00780
00781
00782
00783 cModule* getCompModule(CompType compType);
00784
00785
00786
00787
00788
00789
00790
00791 cGate* getCompRpcGate(CompType compType);
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801 void sendMessageToAllComp(cMessage* msg, CompType srcComp);
00802
00803
00804
00805
00806
00807 bool providesKbr() { return kbr; };
00808
00809 virtual uint8_t getBitsPerDigit() { return 1; };
00810
00811 bool getMeasureAuthBlock() { return measureAuthBlock; }
00812
00813 private:
00814 void findNodeRpc( FindNodeCall* call );
00815 void failedNodeRpc( FailedNodeCall* call );
00816
00817 typedef std::map<CompType, std::pair<cModule*, cGate*> > CompModuleList;
00818 CompModuleList compModuleList;
00819 bool internalReadyState;
00820 };
00821
00822 #endif