00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef __BASEPASTRY_H_
00025 #define __BASEPASTRY_H_
00026
00027 #include <vector>
00028 #include <map>
00029 #include <queue>
00030 #include <algorithm>
00031
00032 #include <omnetpp.h>
00033 #include <IPvXAddress.h>
00034
00035 #include <OverlayKey.h>
00036 #include <NodeHandle.h>
00037 #include <BaseOverlay.h>
00038
00039 #include "PastryTypes.h"
00040 #include "PastryMessage_m.h"
00041 #include "PastryRoutingTable.h"
00042 #include "PastryLeafSet.h"
00043 #include "PastryNeighborhoodSet.h"
00044
00045 class PastryLeafSet;
00046
00047 #define DISCOVERY JOINING_1
00048
00049 class BasePastry : public BaseOverlay
00050 {
00051 public:
00052
00053 virtual ~BasePastry();
00054
00055 virtual void pingResponse(PingResponse* pingResponse,
00056 cPolymorphic* context, int rpcId,
00057 simtime_t rtt);
00058
00059 void pingTimeout(PingCall* call, const TransportAddress& dest,
00060 cPolymorphic* context, int rpcId);
00061
00062
00063 int getMaxNumSiblings();
00064
00065
00066 int getMaxNumRedundantNodes();
00067
00073 virtual void handleAppMessage(BaseOverlayMessage* msg);
00074
00078 virtual void updateTooltip();
00079
00080
00081 virtual NodeVector* findNode(const OverlayKey& key,
00082 int numRedundantNodes,
00083 int numSiblings,
00084 BaseOverlayMessage* msg);
00085
00091 virtual void handleStateMessage(PastryStateMessage* msg) = 0;
00092
00093
00094 virtual void finishOverlay();
00095
00109
00110 void sendStateTables(const TransportAddress& destination,
00111 int type = PASTRY_STATE_STD, ...);
00112
00118 void sendStateDelayed(const TransportAddress& destination);
00119
00120
00121
00122 virtual bool isSiblingFor(const NodeHandle& node,
00123 const OverlayKey& key,
00124 int numSiblings,
00125 bool* err);
00126
00127
00128 virtual AbstractLookup* createLookup(RoutingType routingType = DEFAULT_ROUTING,
00129 const BaseOverlayMessage* msg = NULL,
00130 const cObject* dummy = NULL,
00131 bool appLookup = false);
00132
00133
00134 int joins;
00135 int joinTries;
00136 int joinPartial;
00137 int joinSeen;
00138 int joinBytesSeen;
00139 int joinReceived;
00140 int joinBytesReceived;
00141 int joinSent;
00142 int joinBytesSent;
00143 int stateSent;
00144 int stateBytesSent;
00145 int stateReceived;
00146 int stateBytesReceived;
00147 int repairReqSent;
00148 int repairReqBytesSent;
00149 int repairReqReceived;
00150 int repairReqBytesReceived;
00151 int stateReqSent;
00152 int stateReqBytesSent;
00153 int stateReqReceived;
00154 int stateReqBytesReceived;
00155 int totalLookups;
00156 int responsibleLookups;
00157 int routingTableLookups;
00158 int closerNodeLookups;
00159 int closerNodeLookupsFromNeighborhood;
00160
00161 int leafsetReqSent;
00162 int leafsetReqBytesSent;
00163 int leafsetReqReceived;
00164 int leafsetReqBytesReceived;
00165 int leafsetSent;
00166 int leafsetBytesSent;
00167 int leafsetReceived;
00168 int leafsetBytesReceived;
00169
00170 int routingTableReqSent;
00171 int routingTableReqBytesSent;
00172 int routingTableReqReceived;
00173 int routingTableReqBytesReceived;
00174 int routingTableSent;
00175 int routingTableBytesSent;
00176 int routingTableReceived;
00177 int routingTableBytesReceived;
00178 uint32_t rowToAsk;
00179 protected:
00180
00186 virtual void changeState(int toState);
00187
00188
00189 uint32_t bitsPerDigit;
00190 uint32_t numberOfLeaves;
00191 uint32_t numberOfNeighbors;
00192 uint32_t pingRetries;
00193 double timeoutPing;
00194 double readyWaitAmount;
00195 double joinTimeoutAmount;
00196 double pingCacheExpireTime;
00197 double repairTimeout;
00198 double sendStateWaitAmount;
00199 bool enableNewLeafs;
00200 bool useRegularNextHop;
00201 bool alwaysSendUpdate;
00202 bool optimizeLookup;
00203 bool optimisticForward;
00204 bool avoidDuplicates;
00205
00206 simtime_t nearNodeRtt;
00207 double repairTaskTimeoutAmount;
00208
00209 uint32_t unspecNodes;
00210 uint32_t pingedNodes;
00211 bool nearNodeImproved;
00212 bool sendPullFlag;
00213
00214 bool useDiscovery;
00215 bool periodicMaintenance;
00216
00217 TransportAddress* leaf2ask;
00218
00219 TransportAddress bootstrapNode;
00220 NodeHandle nearNode;
00221
00222 simtime_t lastStateChange;
00223
00227 std::vector<PastryStateMsgHandle> stReceived;
00228 std::vector<PastryStateMsgHandle>::iterator stReceivedPos;
00229
00233 std::vector<TransportAddress> notifyList;
00234
00238 PastryStateMsgHandle stateCache;
00239
00243 std::queue<PastryStateMsgHandle> stateCacheQueue;
00244
00248 PastryStateMsgProximity aliveTable;
00249
00254 virtual void checkProxCache(void) = 0;
00255
00259 std::map<TransportAddress, BaseRouteMessage*> recFwdQueue;
00260
00261 uint32_t joinHopCount;
00262 cMessage* joinTimeout;
00263 cMessage* readyWait;
00264 cMessage* joinUpdateWait;
00265 std::vector<PastrySendState*> sendStateWait;
00266
00267 cMessage* repairTaskTimeout;
00268
00269 PastryRoutingTable* routingTable;
00270 PastryLeafSet* leafSet;
00271 PastryNeighborhoodSet* neighborhoodSet;
00272
00273 virtual bool recursiveRoutingHook(const TransportAddress& dest,
00274 BaseRouteMessage* msg);
00275
00280 void purgeVectors(void);
00281
00285 void baseInit(void);
00286
00291 void baseChangeState(int);
00292
00293
00294
00300 void doRoutingTableMaintenance();
00301
00302 enum StateObject
00303 {
00304 ROUTINGTABLE,
00305 LEAFSET,
00306 NEIGHBORHOODSET
00307 };
00308
00309 struct PingContext : public cPolymorphic
00310 {
00311 PingContext(StateObject stateObject, uint32_t index, uint32_t nonce)
00312 : stateObject(stateObject), index(index), nonce(nonce)
00313 {};
00314 virtual ~PingContext() {};
00315 StateObject stateObject;
00316 uint32_t index;
00317 uint32_t nonce;
00318 };
00319
00320 enum
00321 {
00322 PING_RECEIVED_STATE = 1,
00323 PING_NEXT_HOP = 2
00324 };
00325
00330 void prePing(const PastryStateMessage* stateMsg);
00331
00336 void pingNodes(void);
00337
00345 void determineAliveTable(const PastryStateMessage* stateMsg);
00346
00352 void sendRequest(const TransportAddress& ask, int type);
00353
00359 void sendLeafset(const TransportAddress& tell, bool pull = false);
00360
00366 void sendRoutingRow(const TransportAddress& tell, int row);
00367
00368
00374 void handleRequestMessage(PastryRequestMessage* msg);
00375
00382 void handleLeafsetMessage(PastryLeafsetMessage* msg, bool mergeSender = false);
00383
00387 void newLeafs(void);
00388
00389
00390 friend class PastryLeafSet;
00391
00392 };
00393
00398 bool stateMsgIsSmaller(const PastryStateMsgHandle& hnd1,
00399 const PastryStateMsgHandle& hnd2);
00400
00401 std::ostream& operator<<(std::ostream& os, const PastryStateMsgProximity pr);
00402
00403 #endif
00404