00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #include <sstream>
00025
00026 #include <IPAddressResolver.h>
00027 #include <IPvXAddress.h>
00028 #include <IInterfaceTable.h>
00029 #include <IPv4InterfaceData.h>
00030 #include <RpcMacros.h>
00031 #include <InitStages.h>
00032 #include <NeighborCache.h>
00033 #include <GlobalStatistics.h>
00034 #include <BootstrapList.h>
00035 #include <assert.h>
00036
00037 #include "BasePastry.h"
00038
00039
00040 void BasePastry::purgeVectors(void)
00041 {
00042
00043 if (!stReceived.empty()) {
00044 for (std::vector<PastryStateMsgHandle>::iterator it =
00045 stReceived.begin(); it != stReceived.end(); it++) {
00046
00047 if (it->msg == stateCache.msg) {
00048 stateCache.msg = NULL;
00049 stateCache.prox = NULL;
00050 }
00051 delete it->msg;
00052 delete it->prox;
00053 }
00054 stReceived.clear();
00055 stReceivedPos = stReceived.end();
00056 }
00057
00058
00059 notifyList.clear();
00060
00061
00062 for (std::map<TransportAddress, BaseRouteMessage*>::iterator i =
00063 recFwdQueue.begin(); i != recFwdQueue.end(); i++) {
00064 delete i->second;
00065 }
00066 recFwdQueue.clear();
00067
00068
00069 while (! stateCacheQueue.empty()) {
00070 delete stateCacheQueue.front().msg;
00071 stateCacheQueue.pop();
00072 }
00073
00074
00075 if (stateCache.msg) {
00076 delete stateCache.msg;
00077 stateCache.msg = NULL;
00078 delete stateCache.prox;
00079 stateCache.prox = NULL;
00080 }
00081
00082
00083 if (! sendStateWait.empty()) {
00084 for (std::vector<PastrySendState*>::iterator it =
00085 sendStateWait.begin(); it != sendStateWait.end(); it++) {
00086 if ( (*it)->isScheduled() ) cancelEvent(*it);
00087 delete *it;
00088 }
00089 sendStateWait.clear();
00090 }
00091 }
00092
00093 void BasePastry::baseInit()
00094 {
00095 bitsPerDigit = par("bitsPerDigit");
00096 numberOfLeaves = par("numberOfLeaves");
00097 numberOfNeighbors = par("numberOfNeighbors");
00098 joinTimeoutAmount = par("joinTimeout");
00099 repairTimeout = par("repairTimeout");
00100 enableNewLeafs = par("enableNewLeafs");
00101 optimizeLookup = par("optimizeLookup");
00102 optimisticForward = par("optimisticForward");
00103 avoidDuplicates = par("avoidDuplicates");
00104 sendStateWaitAmount = par("sendStateWaitAmount");
00105 timeoutPing = par("pingTimeout");
00106 pingRetries = par("pingRetries");
00107 useRegularNextHop = par("useRegularNextHop");
00108 alwaysSendUpdate = par("alwaysSendUpdate");
00109
00110 useDiscovery = false;
00111
00112 if (!neighborCache->isEnabled()) {
00113 throw cRuntimeError("NeighborCache is disabled, which is mandatory "
00114 "for Pastry/Bamboo. Activate it by setting "
00115 "\"**.neighborCache.enableNeighborCache "
00116 "= true\" in your omnetpp.ini!");
00117 }
00118
00119 if (numberOfLeaves % 2) {
00120 EV << "[BasePastry::baseInit() @ " << thisNode.ip
00121 << " (" << thisNode.key.toString(16) << ")]\n"
00122 << " Warning: numberOfLeaves must be even - adding 1."
00123 << endl;
00124 numberOfLeaves++;
00125 }
00126
00127 routingTable = check_and_cast<PastryRoutingTable*>
00128 (getParentModule()->getSubmodule("pastryRoutingTable"));
00129 leafSet = check_and_cast<PastryLeafSet*>
00130 (getParentModule()->getSubmodule("pastryLeafSet"));
00131 neighborhoodSet = check_and_cast<PastryNeighborhoodSet*>
00132 (getParentModule()->getSubmodule("pastryNeighborhoodSet"));
00133
00134 stateCache.msg = NULL;
00135 stateCache.prox = NULL;
00136
00137 rowToAsk = 0;
00138
00139
00140 joins = 0;
00141 joinTries = 0;
00142 joinPartial = 0;
00143 joinSeen = 0;
00144 joinReceived = 0;
00145 joinSent = 0;
00146 stateSent = 0;
00147 stateReceived = 0;
00148 repairReqSent = 0;
00149 repairReqReceived = 0;
00150 stateReqSent = 0;
00151 stateReqReceived = 0;
00152
00153 joinBytesSeen = 0;
00154 joinBytesReceived = 0;
00155 joinBytesSent = 0;
00156 stateBytesSent = 0;
00157 stateBytesReceived = 0;
00158 repairReqBytesSent = 0;
00159 repairReqBytesReceived = 0;
00160 stateReqBytesSent = 0;
00161 stateReqBytesReceived = 0;
00162
00163 totalLookups = 0;
00164 responsibleLookups = 0;
00165 routingTableLookups = 0;
00166 closerNodeLookups = 0;
00167 closerNodeLookupsFromNeighborhood = 0;
00168
00169 leafsetReqSent = 0;
00170 leafsetReqBytesSent = 0;
00171 leafsetReqReceived = 0;
00172 leafsetReqBytesReceived = 0;
00173 leafsetSent = 0;
00174 leafsetBytesSent = 0;
00175 leafsetReceived = 0;
00176 leafsetBytesReceived = 0;
00177
00178 routingTableReqSent = 0;
00179 routingTableReqBytesSent = 0;
00180 routingTableReqReceived = 0;
00181 routingTableReqBytesReceived = 0;
00182 routingTableSent = 0;
00183 routingTableBytesSent = 0;
00184 routingTableReceived = 0;
00185 routingTableBytesReceived = 0;
00186
00187 WATCH(joins);
00188 WATCH(joinTries);
00189 WATCH(joinSeen);
00190 WATCH(joinBytesSeen);
00191 WATCH(joinReceived);
00192 WATCH(joinBytesReceived);
00193 WATCH(joinSent);
00194 WATCH(joinBytesSent);
00195 WATCH(stateSent);
00196 WATCH(stateBytesSent);
00197 WATCH(stateReceived);
00198 WATCH(stateBytesReceived);
00199 WATCH(repairReqSent);
00200 WATCH(repairReqBytesSent);
00201 WATCH(repairReqReceived);
00202 WATCH(repairReqBytesReceived);
00203 WATCH(stateReqSent);
00204 WATCH(stateReqBytesSent);
00205 WATCH(stateReqReceived);
00206 WATCH(stateReqBytesReceived);
00207 WATCH(lastStateChange);
00208
00209 WATCH(leafsetReqSent);
00210 WATCH(leafsetReqBytesSent);
00211 WATCH(leafsetReqReceived);
00212 WATCH(leafsetReqBytesReceived);
00213 WATCH(leafsetSent);
00214 WATCH(leafsetBytesSent);
00215 WATCH(leafsetReceived);
00216 WATCH(leafsetBytesReceived);
00217
00218 WATCH(routingTableReqSent);
00219 WATCH(routingTableReqBytesSent);
00220 WATCH(routingTableReqReceived);
00221 WATCH(routingTableReqBytesReceived);
00222 WATCH(routingTableSent);
00223 WATCH(routingTableBytesSent);
00224 WATCH(routingTableReceived);
00225 WATCH(routingTableBytesReceived);
00226
00227 }
00228
00229 void BasePastry::baseChangeState(int toState)
00230 {
00231 switch (toState) {
00232 case INIT:
00233
00234 state = INIT;
00235
00236 if (!thisNode.key.isUnspecified())
00237 bootstrapList->removeBootstrapNode(thisNode);
00238
00239 if (joinTimeout->isScheduled()) cancelEvent(joinTimeout);
00240
00241 purgeVectors();
00242
00243 bootstrapNode = bootstrapList->getBootstrapNode();
00244
00245 routingTable->initializeTable(bitsPerDigit, repairTimeout,
00246 thisNode);
00247 leafSet->initializeSet(numberOfLeaves, bitsPerDigit,
00248 repairTimeout, thisNode,
00249 this);
00250 neighborhoodSet->initializeSet(numberOfNeighbors, bitsPerDigit,
00251 thisNode);
00252
00253 updateTooltip();
00254 lastStateChange = simTime();
00255
00256 getParentModule()->getParentModule()->bubble("entering INIT state");
00257
00258 break;
00259
00260
00261 case DISCOVERY:
00262
00263 break;
00264
00265 case JOINING_2:
00266 state = JOINING_2;
00267
00268
00269
00270
00271 if (bootstrapNode.isUnspecified()) {
00272
00273 changeState(READY);
00274 return;
00275 }
00276
00277 cancelEvent(joinTimeout);
00278 scheduleAt(simTime() + joinTimeoutAmount, joinTimeout);
00279
00280 updateTooltip();
00281 getParentModule()->getParentModule()->bubble("entering JOIN state");
00282
00283 RECORD_STATS(joinTries++);
00284
00285 break;
00286
00287 case READY:
00288 assert(state != READY);
00289 state = READY;
00290
00291
00292
00293
00294
00295 if (bootstrapNode.isUnspecified()) {
00296 RECORD_STATS(joinTries++);
00297 RECORD_STATS(joins++);
00298 setOverlayReady(true);
00299 return;
00300 }
00301
00302 getParentModule()->getParentModule()->bubble("entering READY state");
00303 updateTooltip();
00304 RECORD_STATS(joins++);
00305
00306 break;
00307 }
00308 setOverlayReady(state == READY);
00309 }
00310
00311
00312 void BasePastry::newLeafs(void)
00313 {
00314 if (! enableNewLeafs) return;
00315
00316 PastryNewLeafsMessage* msg = leafSet->getNewLeafsMessage();
00317 if (msg) {
00318 send(msg, "appOut");
00319 EV << "[BasePastry::newLeafs() @ " << thisNode.ip
00320 << " (" << thisNode.key.toString(16) << ")]\n"
00321 << " newLeafs() called."
00322 << endl;
00323 }
00324 }
00325
00326
00327 void BasePastry::changeState(int toState)
00328 {
00329
00330 }
00331
00332
00333 bool BasePastry::recursiveRoutingHook(const TransportAddress& dest,
00334 BaseRouteMessage* msg)
00335 {
00336 if (dest == thisNode) {
00337 return true;
00338 }
00339
00340 PastryMessage* pmsg =
00341 dynamic_cast<PastryMessage*>(msg->getEncapsulatedMsg());
00342
00343 if (pmsg && pmsg->getPastryMsgType() == PASTRY_MSG_JOIN) {
00344 PastryJoinMessage* jmsg = static_cast<PastryJoinMessage*>(pmsg);
00345 if (jmsg->getSendStateTo() != thisNode) {
00346 RECORD_STATS(joinSeen++; joinBytesSeen += jmsg->getByteLength());
00347
00348 handleFailedNode(jmsg->getSendStateTo());
00349
00350 sendStateTables(jmsg->getSendStateTo(), PASTRY_STATE_JOIN,
00351 check_and_cast<OverlayCtrlInfo*>(msg->getControlInfo())
00352 ->getHopCount(), false);
00353 }
00354 }
00355
00356 if (recFwdQueue.find(dest) != recFwdQueue.end()) {
00357
00358
00359 return true;
00360 }
00361
00362 assert(msg->getControlInfo());
00363
00364 if (optimisticForward) {
00365
00366 return true;
00367 } else {
00368 if (routeMsgAcks) throw cRuntimeError("!optimisticForward && "
00369 "routeMsgAcks");
00370
00371 recFwdQueue[dest] = msg;
00372 pingNode(dest, timeoutPing, pingRetries, NULL,
00373 "PING next hop", NULL, PING_NEXT_HOP);
00374
00375 return false;
00376 }
00377 }
00378
00379 void BasePastry::doRoutingTableMaintenance()
00380 {
00381
00382 if (sendPullFlag) {
00383
00384 uint32_t rrows = routingTable->getLastRow();
00385 if (++rowToAsk >= rrows) rowToAsk = 0;
00386 const TransportAddress& ask4row = routingTable->getRandomNode(rowToAsk);
00387
00388 if ((!ask4row.isUnspecified()) && (ask4row != thisNode)) {
00389
00390 PastryRoutingRowRequestMessage* msg = new PastryRoutingRowRequestMessage("ROWREQ");
00391
00392 msg->setPastryMsgType(PASTRY_MSG_ROWREQ);
00393 msg->setStatType(MAINTENANCE_STAT);
00394 msg->setSendStateTo(thisNode);
00395 msg->setRow(rowToAsk+1);
00396 msg->setBitLength(PASTRYRTREQ_L(msg));
00397 RECORD_STATS(routingTableReqSent++; routingTableReqBytesSent += msg->getByteLength());
00398 EV << "[BasePastry::doRoutingTableMaintenance() @ " << thisNode.ip
00399 << " (" << thisNode.key.toString(16) << ")]\n"
00400 << " Sending Message to Node in Row" << rowToAsk
00401 << endl;
00402 sendMessageToUDP(ask4row, msg);
00403 }
00404 } else {
00405
00406
00407 for (int i = 0; i < routingTable->getLastRow(); i++) {
00408 const TransportAddress& ask4row = routingTable->getRandomNode(i);
00409
00410 if ((!ask4row.isUnspecified()) && (ask4row != thisNode)) {
00411
00412 PastryRoutingRowRequestMessage* msg = new PastryRoutingRowRequestMessage("ROWREQ");
00413
00414 msg->setPastryMsgType(PASTRY_MSG_ROWREQ);
00415 msg->setStatType(MAINTENANCE_STAT);
00416 msg->setSendStateTo(thisNode);
00417 msg->setRow(i+1);
00418 msg->setBitLength(PASTRYRTREQ_L(msg));
00419 RECORD_STATS(routingTableReqSent++; routingTableReqBytesSent += msg->getByteLength());
00420 sendMessageToUDP(ask4row, msg);
00421 } else EV << "[BasePastry::doRoutingTableMaintenance() @ " << thisNode.ip
00422 << " (" << thisNode.key.toString(16) << ")]\n"
00423 << " could not send Message to Node in Row" << i
00424 << endl;
00425
00426 }
00427 }
00428 }
00429
00430 void BasePastry::pingResponse(PingResponse* msg, cPolymorphic* context,
00431 int rpcId, simtime_t rtt)
00432 {
00433 EV << "[BasePastry::pingResponse() @ " << thisNode.ip
00434 << " (" << thisNode.key.toString(16) << ")]\n"
00435 << " Pong (or Ping-context from NeighborCache) received (from "
00436 << msg->getSrcNode().ip << ")"
00437 << endl;
00438
00439 const NodeHandle& src = msg->getSrcNode();
00440 assert(!src.isUnspecified());
00441
00442
00443 if ((src.key == thisNode.key) && (src.ip != thisNode.ip)) {
00444 EV << "[BasePastry::pingResponse() @ " << thisNode.ip
00445 << " (" << thisNode.key.toString(16) << ")]\n"
00446 << " a node with the an equal ID has responded, rejoining" << endl;
00447
00448 delete context;
00449 joinOverlay();
00450 return;
00451 }
00452
00453 if (state == DISCOVERY) {
00454 if (nearNodeRtt > rtt) {
00455 nearNode = src;
00456 nearNodeRtt = rtt;
00457 nearNodeImproved = true;
00458 }
00459 }
00460
00461
00462 if (context != NULL && stateCache.msg && stateCache.prox) {
00463 PingContext* pingContext = check_and_cast<PingContext*>(context);
00464 if (pingContext->nonce != stateCache.nonce) {
00465 throw cRuntimeError("response doesn't fit stateCache");
00466 }
00467 switch (pingContext->stateObject) {
00468 case ROUTINGTABLE: {
00469
00470
00471
00472
00473
00474
00475
00476 *(stateCache.prox->pr_rt.begin() + pingContext->index) = rtt;
00477 break;
00478 }
00479 case LEAFSET: {
00480
00481
00482
00483
00484
00485
00486
00487 *(stateCache.prox->pr_ls.begin() + pingContext->index) = rtt;
00488 break;
00489 }
00490 case NEIGHBORHOODSET: {
00491
00492
00493
00494
00495
00496
00497
00498 *(stateCache.prox->pr_ns.begin() + pingContext->index) = rtt;
00499 break;
00500 }
00501 default: {
00502 throw cRuntimeError("wrong state object type!");
00503 }
00504 }
00505 checkProxCache();
00506 }
00507 delete context;
00508
00509 std::map<TransportAddress, BaseRouteMessage*>::iterator pos;
00510 if ((pos = recFwdQueue.find(src)) != recFwdQueue.end()) {
00511
00512 if (!optimisticForward) {
00513 sendMessageToUDP(pos->first, pos->second);
00514 } else if (!avoidDuplicates) {
00515 delete pos->second;
00516 }
00517 recFwdQueue.erase(pos);
00518 }
00519 }
00520
00521 void BasePastry::prePing(const PastryStateMessage* stateMsg)
00522 {
00523 uint32_t rt_size = stateMsg->getRoutingTableArraySize();
00524 uint32_t ls_size = stateMsg->getLeafSetArraySize();
00525 uint32_t ns_size = stateMsg->getNeighborhoodSetArraySize();
00526
00527 for (uint32_t i = 0; i < rt_size + ls_size + ns_size; i++) {
00528 const NodeHandle* node;
00529 if (i < rt_size) {
00530 node = &(stateMsg->getRoutingTable(i));
00531 }
00532 else if (i < (rt_size + ls_size) ) {
00533 node = &(stateMsg->getLeafSet(i - rt_size));
00534 }
00535 else {
00536 node = &(stateMsg->getNeighborhoodSet(i - rt_size - ls_size));
00537 }
00538 if ((node->isUnspecified()) || (*node == thisNode)) {
00539 continue;
00540 }
00541 if (node->key == thisNode.key) {
00542
00543
00544
00545
00546
00547
00548
00549 continue;
00550 }
00551 pingNode(*node, timeoutPing, pingRetries, NULL,
00552 "PING received state", NULL, PING_RECEIVED_STATE,
00553 UDP_TRANSPORT, false);
00554 }
00555 }
00556
00557 void BasePastry::pingNodes(void)
00558 {
00559 if (stateCache.msg == NULL) throw cRuntimeError("no state msg");
00560
00561 assert(stateCache.prox == NULL);
00562 stateCache.prox = new PastryStateMsgProximity();
00563
00564 uint32_t rt_size = stateCache.msg->getRoutingTableArraySize();
00565
00566 stateCache.prox->pr_rt.resize(rt_size, PASTRY_PROX_UNDEF);
00567
00568 uint32_t ls_size = stateCache.msg->getLeafSetArraySize();
00569
00570 stateCache.prox->pr_ls.resize(ls_size, PASTRY_PROX_UNDEF);
00571
00572 uint32_t ns_size = stateCache.msg->getNeighborhoodSetArraySize();
00573
00574 stateCache.prox->pr_ns.resize(ns_size, PASTRY_PROX_UNDEF);
00575
00576 std::vector< std::pair<const NodeHandle*, PingContext*> > nodesToPing;
00577
00578 for (uint32_t i = 0; i < rt_size + ls_size + ns_size; i++) {
00579 const NodeHandle* node;
00580 std::vector<simtime_t>::iterator proxPos;
00581 PingContext* pingContext = NULL;
00582 StateObject stateObject;
00583 uint32_t index;
00584 if (stateCache.msg == NULL) break;
00585 if (i < rt_size) {
00586 node = &(stateCache.msg->getRoutingTable(i));
00587 proxPos = stateCache.prox->pr_rt.begin() + i;
00588 stateObject = ROUTINGTABLE;
00589 index = i;
00590 } else if ( i < (rt_size + ls_size) ) {
00591 node = &(stateCache.msg->getLeafSet(i - rt_size));
00592 proxPos = stateCache.prox->pr_ls.begin() + (i - rt_size);
00593 stateObject = LEAFSET;
00594 index = i - rt_size;
00595 } else {
00596 node = &(stateCache.msg->getNeighborhoodSet(i - rt_size - ls_size));
00597 proxPos = stateCache.prox->pr_ns.begin() + (i - rt_size - ls_size);
00598 stateObject = NEIGHBORHOODSET;
00599 index = i - rt_size - ls_size;
00600 }
00601
00602 if (!node->isUnspecified()) {
00603 if (*node == thisNode) {
00604 *proxPos = 0;
00605 } else {
00606 *proxPos = PASTRY_PROX_PENDING;
00607 pingContext = new PingContext(stateObject, index,
00608 stateCache.nonce);
00609 nodesToPing.push_back(std::make_pair(node, pingContext));
00610 }
00611 }
00612 }
00613 assert(nodesToPing.size() != 0);
00614
00615 for (uint32_t i = 0; i < nodesToPing.size(); ++i) {
00616 pingNode(*nodesToPing[i].first, timeoutPing, pingRetries,
00617 nodesToPing[i].second, "PING received state", NULL,
00618 PING_RECEIVED_STATE, UDP_TRANSPORT, false);
00619 }
00620
00621 }
00622
00623 void BasePastry::determineAliveTable(const PastryStateMessage* stateMsg)
00624 {
00625 uint32_t rt_size = stateMsg->getRoutingTableArraySize();
00626 aliveTable.pr_rt.clear();
00627 aliveTable.pr_rt.resize(rt_size, 1);
00628
00629 uint32_t ls_size = stateMsg->getLeafSetArraySize();
00630 aliveTable.pr_ls.clear();
00631 aliveTable.pr_ls.resize(ls_size, 1);
00632
00633 uint32_t ns_size = stateMsg->getNeighborhoodSetArraySize();
00634 aliveTable.pr_ns.clear();
00635 aliveTable.pr_ns.resize(ns_size, 1);
00636
00637 for (uint32_t i = 0; i < rt_size + ls_size + ns_size; i++) {
00638 const TransportAddress* node;
00639 std::vector<simtime_t>::iterator tblPos;
00640 if (i < rt_size) {
00641 node = &(stateMsg->getRoutingTable(i));
00642 tblPos = aliveTable.pr_rt.begin() + i;
00643 } else if ( i < (rt_size + ls_size) ) {
00644 node = &(stateMsg->getLeafSet(i - rt_size));
00645 tblPos = aliveTable.pr_ls.begin() + (i - rt_size);
00646 } else {
00647 node = &(stateMsg->getNeighborhoodSet(i - rt_size - ls_size));
00648 tblPos = aliveTable.pr_ns.begin() + (i - rt_size - ls_size);
00649 }
00650 if (neighborCache->getNodeRtt(*node) == NEIGHBORSTATE_TIMEOUT) {
00651 *tblPos = PASTRY_PROX_INFINITE;
00652 }
00653 }
00654 }
00655
00656 void BasePastry::sendStateTables(const TransportAddress& destination, int type, ...)
00657 {
00658 if (destination.ip == thisNode.ip)
00659 opp_error("Pastry: trying to send state to self!");
00660
00661 int hops = 0;
00662 bool last = false;
00663 simtime_t timestamp = 0;
00664
00665 if ((type == PASTRY_STATE_JOIN) || (type == PASTRY_STATE_UPDATE)) {
00666
00667 va_list ap;
00668 va_start(ap, type);
00669 if (type == PASTRY_STATE_JOIN) {
00670 hops = va_arg(ap, int);
00671 last = static_cast<bool>(va_arg(ap, int));
00672 } else {
00673 timestamp = *va_arg(ap, simtime_t*);
00674 }
00675 va_end(ap);
00676 }
00677
00678
00679 PastryStateMessage* stateMsg;
00680 if (type == PASTRY_STATE_JOIN) {
00681 stateMsg = new PastryStateMessage("STATE (Join)");
00682 stateMsg->setJoinHopCount(hops);
00683 stateMsg->setLastHop(last);
00684 stateMsg->setTimestamp(simTime());
00685 } else if (type == PASTRY_STATE_UPDATE) {
00686 stateMsg = new PastryStateMessage("STATE (Update)");
00687 EV << "[BasePastry::sendStateTables() @ " << thisNode.ip
00688 << " (" << thisNode.key.toString(16) << ")]\n"
00689 << " sending state (update) to " << destination
00690 << endl;
00691 stateMsg->setTimestamp(timestamp);
00692 } else if (type == PASTRY_STATE_REPAIR) {
00693 stateMsg = new PastryStateMessage("STATE (Repair)");
00694 stateMsg->setTimestamp(timestamp);
00695 EV << "[BasePastry::sendStateTables() @ " << thisNode.ip
00696 << " (" << thisNode.key.toString(16) << ")]\n"
00697 << " sending state (repair) to " << destination
00698 << endl;
00699 } else {
00700 stateMsg = new PastryStateMessage("STATE");
00701 EV << "[BasePastry::sendStateTables() @ " << thisNode.ip
00702 << " (" << thisNode.key.toString(16) << ")]\n"
00703 << " sending state (standard) to " << destination
00704 << endl;
00705 }
00706
00707
00708 stateMsg->setPastryMsgType(PASTRY_MSG_STATE);
00709 stateMsg->setStatType(MAINTENANCE_STAT);
00710 stateMsg->setPastryStateMsgType(type);
00711 stateMsg->setSender(thisNode);
00712
00713
00714
00715
00716 if ((type == PASTRY_STATE_JOIN) && (useDiscovery)) {
00717 routingTable->dumpRowToMessage(stateMsg, hops);
00718 if (last) leafSet->dumpToStateMessage(stateMsg);
00719 else stateMsg->setLeafSetArraySize(0);
00720 if (hops == 1) neighborhoodSet->dumpToStateMessage(stateMsg);
00721 else stateMsg->setNeighborhoodSetArraySize(0);
00722 }
00723 else {
00724 routingTable->dumpToStateMessage(stateMsg);
00725 leafSet->dumpToStateMessage(stateMsg);
00726 neighborhoodSet->dumpToStateMessage(stateMsg);
00727 }
00728
00729
00730 stateMsg->setBitLength(PASTRYSTATE_L(stateMsg));
00731 RECORD_STATS(stateSent++; stateBytesSent += stateMsg->getByteLength());
00732 sendMessageToUDP(destination, stateMsg);
00733 }
00734
00735 void BasePastry::sendStateDelayed(const TransportAddress& destination)
00736 {
00737 PastrySendState* selfMsg = new PastrySendState("sendStateWait");
00738 selfMsg->setDest(destination);
00739 sendStateWait.push_back(selfMsg);
00740 scheduleAt(simTime() + sendStateWaitAmount, selfMsg);
00741 }
00742
00743 void BasePastry::pingTimeout(PingCall* msg,
00744 const TransportAddress& dest,
00745 cPolymorphic* context,
00746 int rpcId)
00747 {
00748 EV << "[BasePastry::sendStateDelayed() @ " << thisNode.ip
00749 << " (" << thisNode.key.toString(16) << ")]\n"
00750 << " Ping timeout occurred (" << dest.ip << ")"
00751 << endl;
00752
00753
00754 if (state == READY) {
00755 handleFailedNode(dest);
00756 updateTooltip();
00757
00758
00759
00760 if (state != READY) {
00761 delete context;
00762 return;
00763 }
00764 }
00765
00766 if (context && stateCache.msg && stateCache.prox &&
00767 rpcId == PING_RECEIVED_STATE) {
00768 PingContext* pingContext = check_and_cast<PingContext*>(context);
00769 if (pingContext->nonce != stateCache.nonce) {
00770 std::stringstream temp;
00771 temp << thisNode << " timeout/call doesn't fit stateCache";
00772 throw cRuntimeError(temp.str().c_str());
00773 }
00774
00775 switch (pingContext->stateObject) {
00776 case ROUTINGTABLE: {
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789 *(stateCache.prox->pr_rt.begin() + pingContext->index) =
00790 PASTRY_PROX_INFINITE;
00791 break;
00792 }
00793 case LEAFSET: {
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806 *(stateCache.prox->pr_ls.begin() + pingContext->index) =
00807 PASTRY_PROX_INFINITE;
00808 break;
00809 }
00810 case NEIGHBORHOODSET: {
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823 *(stateCache.prox->pr_ns.begin() + pingContext->index) =
00824 PASTRY_PROX_INFINITE;
00825 break;
00826 }
00827 }
00828 checkProxCache();
00829 }
00830
00831 delete context;
00832
00833 if (rpcId == PING_NEXT_HOP) {
00834
00835 std::map<TransportAddress, BaseRouteMessage*>::iterator pos;
00836 if ((pos = recFwdQueue.find(dest)) == recFwdQueue.end()) return;
00837 BaseRouteMessage* rmsg = pos->second;
00838 recFwdQueue.erase(pos);
00839 if (dynamic_cast<PastryJoinMessage*>(rmsg->getEncapsulatedMsg()) &&
00840 rmsg->getDestKey() == thisNode.key) {
00841
00842 changeState(INIT);
00843 return;
00844 }
00845 assert(rmsg->getControlInfo());
00846 sendToKey(rmsg->getDestKey(), rmsg);
00847 }
00848 }
00849
00850 void BasePastry::sendRequest(const TransportAddress& ask, int type)
00851 {
00852 std::string msgName("Req: ");
00853 switch (type) {
00854 case PASTRY_REQ_REPAIR:
00855 if (ask.isUnspecified())
00856 opp_error("Pastry::sendRequest(): asked for repair from "
00857 "unspecified node!");
00858 msgName += "Repair";
00859 break;
00860
00861 case PASTRY_REQ_STATE:
00862 if (ask.isUnspecified())
00863 opp_error("Pastry::sendRequest(): asked for state from "
00864 "unspecified node!");
00865 msgName += "State";
00866 break;
00867
00868 case PASTRY_REQ_LEAFSET:
00869 if (ask.isUnspecified())
00870 opp_error("Pastry::sendRequest(): asked for leafset from "
00871 "unspecified node!");
00872 msgName += "Leafset";
00873 break;
00874 }
00875 PastryRequestMessage* msg = new PastryRequestMessage(msgName.c_str());
00876 msg->setPastryMsgType(PASTRY_MSG_REQ);
00877 msg->setPastryReqType(type);
00878 msg->setStatType(MAINTENANCE_STAT);
00879 msg->setSendStateTo(thisNode);
00880 msg->setBitLength(PASTRYREQ_L(msg));
00881 sendMessageToUDP(ask, msg);
00882
00883 switch (type) {
00884 case PASTRY_REQ_REPAIR:
00885 RECORD_STATS(repairReqSent++; repairReqBytesSent += msg->getByteLength());
00886 break;
00887
00888 case PASTRY_REQ_STATE:
00889 RECORD_STATS(stateReqSent++; stateReqBytesSent += msg->getByteLength());
00890 break;
00891
00892 case PASTRY_REQ_LEAFSET:
00893 RECORD_STATS(leafsetReqSent++; leafsetReqBytesSent += msg->getByteLength());
00894 break;
00895 }
00896 }
00897
00898
00899 void BasePastry::sendLeafset(const TransportAddress& tell, bool pull)
00900 {
00901 if (tell.isUnspecified())
00902 opp_error("Pastry::sendLeafset(): send leafset to "
00903 "unspecified node!");
00904
00905 PastryLeafsetMessage* msg = new PastryLeafsetMessage("Leafset");
00906 if (pull) msg->setPastryMsgType(PASTRY_MSG_LEAFSET_PULL);
00907 else msg->setPastryMsgType(PASTRY_MSG_LEAFSET);
00908 msg->setTimestamp(simTime());
00909 msg->setStatType(MAINTENANCE_STAT);
00910 msg->setSender(thisNode);
00911 msg->setSendStateTo(thisNode);
00912 leafSet->dumpToStateMessage(msg);
00913 msg->setBitLength(PASTRYLEAFSET_L(msg));
00914 RECORD_STATS(leafsetSent++; leafsetBytesSent += msg->getByteLength());
00915 sendMessageToUDP(tell, msg);
00916
00917
00918 }
00919
00920 void BasePastry::sendRoutingRow(const TransportAddress& tell, int row)
00921 {
00922 if (tell.isUnspecified())
00923 opp_error("Pastry::sendRoutingTable(): asked for routing Table from "
00924 "unspecified node!");
00925
00926 PastryRoutingRowMessage* msg = new PastryRoutingRowMessage("Routing Row");
00927 msg->setPastryMsgType(PASTRY_MSG_RROW);
00928 msg->setStatType(MAINTENANCE_STAT);
00929
00930 msg->setSender(thisNode);
00931 msg->setRow(row);
00932 routingTable->dumpRowToMessage(msg, row);
00933 msg->setBitLength(PASTRYRTABLE_L(msg));
00934 RECORD_STATS(routingTableSent++; routingTableBytesSent += msg->getByteLength());
00935 sendMessageToUDP(tell, msg);
00936 }
00937
00938 void BasePastry::handleRequestMessage(PastryRequestMessage* msg)
00939 {
00940 uint32_t reqtype = msg->getPastryReqType();
00941 if (reqtype == PASTRY_REQ_REPAIR) {
00942 RECORD_STATS(repairReqReceived++; repairReqBytesReceived +=
00943 msg->getByteLength());
00944 if (state == READY)
00945 sendStateTables(msg->getSendStateTo(),
00946 PASTRY_STATE_REPAIR);
00947 else
00948 EV << "[BasePastry::handleRequestMessage() @ " << thisNode.ip
00949 << " (" << thisNode.key.toString(16) << ")]\n"
00950 << " received repair request before reaching"
00951 << " READY state, dropping message!"
00952 << endl;
00953 delete msg;
00954 }
00955 else if (reqtype == PASTRY_REQ_STATE) {
00956 RECORD_STATS(stateReqReceived++; stateReqBytesReceived +=
00957 msg->getByteLength());
00958 if (state == READY)
00959 sendStateTables(msg->getSendStateTo());
00960 else
00961 EV << "[BasePastry::handleRequestMessage() @ " << thisNode.ip
00962 << " (" << thisNode.key.toString(16) << ")]\n"
00963 << " received state request before reaching"
00964 << " READY state, dropping message!"
00965 << endl;
00966 delete msg;
00967 }
00968 else if (PASTRY_REQ_LEAFSET) {
00969 RECORD_STATS(leafsetReqReceived++; leafsetReqBytesReceived +=
00970 msg->getByteLength());
00971 if (state == READY) {
00972 sendLeafset(msg->getSendStateTo());
00973 }
00974 else
00975 EV << "[BasePastry::handleRequestMessage() @ " << thisNode.ip
00976 << " (" << thisNode.key.toString(16) << ")]\n"
00977 << " received leafset request before reaching"
00978 << " READY state, dropping message!"
00979 << endl;
00980 delete msg;
00981 }
00982
00983 }
00984
00985 void BasePastry::handleLeafsetMessage(PastryLeafsetMessage* msg, bool mergeSender)
00986 {
00987 uint32_t lsSize = msg->getLeafSetArraySize();
00988 PastryStateMessage* stateMsg;
00989
00990 stateMsg = new PastryStateMessage("STATE");
00991 stateMsg->setTimestamp(msg->getTimestamp());
00992 stateMsg->setPastryMsgType(PASTRY_MSG_STATE);
00993 stateMsg->setStatType(MAINTENANCE_STAT);
00994 stateMsg->setSender(msg->getSender());
00995 stateMsg->setLeafSetArraySize(lsSize);
00996 stateMsg->setNeighborhoodSetArraySize(0);
00997 stateMsg->setRoutingTableArraySize(0);
00998
00999 for (uint32_t i = 0; i < lsSize; i++) {
01000 stateMsg->setLeafSet(i, msg->getLeafSet(i));
01001 }
01002
01003 if (mergeSender) {
01004 stateMsg->setLeafSetArraySize(lsSize+1);
01005 stateMsg->setLeafSet(lsSize, msg->getSender());
01006 }
01007
01008 handleStateMessage(stateMsg);
01009 delete msg;
01010 }
01011
01012 bool BasePastry::isSiblingFor(const NodeHandle& node,
01013 const OverlayKey& key,
01014 int numSiblings,
01015 bool* err)
01016 {
01017 if (key.isUnspecified())
01018 error("Pastry::isSiblingFor(): key is unspecified!");
01019
01020 if ((numSiblings == 1) && (node == thisNode)) {
01021 if (leafSet->isClosestNode(key)) {
01022 *err = false;
01023 return true;
01024 } else {
01025 *err = false;
01026 return false;
01027 }
01028 }
01029
01030 NodeVector* result = leafSet->createSiblingVector(key, numSiblings);
01031
01032 if (result == NULL) {
01033 *err = true;
01034 return false;
01035 }
01036
01037 if (result->contains(node.key)) {
01038 delete result;
01039 *err = false;
01040 return true;
01041 } else {
01042 delete result;
01043 *err = true;
01044 return false;
01045 }
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058 }
01059
01060
01061 void BasePastry::handleAppMessage(BaseOverlayMessage* msg)
01062 {
01063 delete msg;
01064 }
01065
01066 void BasePastry::updateTooltip()
01067 {
01068 if (ev.isGUI()) {
01069 std::stringstream ttString;
01070
01071
01072 ttString << leafSet->getPredecessor() << endl << thisNode << endl
01073 << leafSet->getSuccessor();
01074
01075 getParentModule()->getParentModule()->getDisplayString().
01076 setTagArg("tt", 0, ttString.str().c_str());
01077 getParentModule()->getDisplayString().
01078 setTagArg("tt", 0, ttString.str().c_str());
01079 getDisplayString().setTagArg("tt", 0, ttString.str().c_str());
01080
01081
01082 showOverlayNeighborArrow(leafSet->getSuccessor(), true,
01083 "m=m,50,0,50,0;ls=red,1");
01084 showOverlayNeighborArrow(leafSet->getPredecessor(), false,
01085 "m=m,50,100,50,100;ls=green,1");
01086
01087 }
01088 }
01089
01090 BasePastry::~BasePastry()
01091 {
01092 cancelAndDelete(joinTimeout);
01093
01094 purgeVectors();
01095 }
01096
01097 void BasePastry::finishOverlay()
01098 {
01099
01100 if (!thisNode.key.isUnspecified()) bootstrapList->removeBootstrapNode(thisNode);
01101
01102
01103 simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime);
01104 if(time == 0) return;
01105
01106
01107
01108
01109
01110
01111
01112 if (joinTries > 0 && joinTimeout->isScheduled()) joinTries--;
01113 if (joinTries > 0) {
01114 globalStatistics->addStdDev("Pastry: join success ratio", (double)joins / (double)joinTries);
01115 globalStatistics->addStdDev("Pastry: join tries", joinTries);
01116 } else if (state == READY) {
01117
01118 globalStatistics->addStdDev("Pastry: join success ratio", 1);
01119 globalStatistics->addStdDev("Pastry: join tries", 1);
01120 } else {
01121 globalStatistics->addStdDev("Pastry: join success ratio", 0);
01122 globalStatistics->addStdDev("Pastry: join tries", 1);
01123 }
01124
01125 globalStatistics->addStdDev("Pastry: joins with missing replies from routing path/s",
01126 joinPartial / time);
01127 globalStatistics->addStdDev("Pastry: JOIN Messages seen/s", joinSeen / time);
01128 globalStatistics->addStdDev("Pastry: bytes of JOIN Messages seen/s", joinBytesSeen / time);
01129 globalStatistics->addStdDev("Pastry: JOIN Messages received/s", joinReceived / time);
01130 globalStatistics->addStdDev("Pastry: bytes of JOIN Messages received/s",
01131 joinBytesReceived / time);
01132 globalStatistics->addStdDev("Pastry: JOIN Messages sent/s", joinSent / time);
01133 globalStatistics->addStdDev("Pastry: bytes of JOIN Messages sent/s", joinBytesSent / time);
01134 globalStatistics->addStdDev("Pastry: STATE Messages sent/s", stateSent / time);
01135 globalStatistics->addStdDev("Pastry: bytes of STATE Messages sent/s", stateBytesSent / time);
01136 globalStatistics->addStdDev("Pastry: STATE Messages received/s", stateReceived / time);
01137 globalStatistics->addStdDev("Pastry: bytes of STATE Messages received/s",
01138 stateBytesReceived / time);
01139 globalStatistics->addStdDev("Pastry: REPAIR Requests sent/s", repairReqSent / time);
01140 globalStatistics->addStdDev("Pastry: bytes of REPAIR Requests sent/s",
01141 repairReqBytesSent / time);
01142 globalStatistics->addStdDev("Pastry: REPAIR Requests received/s", repairReqReceived / time);
01143 globalStatistics->addStdDev("Pastry: bytes of REPAIR Requests received/s",
01144 repairReqBytesReceived / time);
01145 globalStatistics->addStdDev("Pastry: STATE Requests sent/s", stateReqSent / time);
01146 globalStatistics->addStdDev("Pastry: bytes of STATE Requests sent/s", stateReqBytesSent / time);
01147 globalStatistics->addStdDev("Pastry: STATE Requests received/s", stateReqReceived / time);
01148 globalStatistics->addStdDev("Pastry: bytes of STATE Requests received/s",
01149 stateReqBytesReceived / time);
01150
01151 globalStatistics->addStdDev("Pastry: bytes of STATE Requests received/s",
01152 stateReqBytesReceived / time);
01153
01154 globalStatistics->addStdDev("Pastry: total number of lookups", totalLookups);
01155 globalStatistics->addStdDev("Pastry: responsible lookups", responsibleLookups);
01156 globalStatistics->addStdDev("Pastry: lookups in routing table", routingTableLookups);
01157 globalStatistics->addStdDev("Pastry: lookups using closerNode()", closerNodeLookups);
01158 globalStatistics->addStdDev("Pastry: lookups using closerNode() with result from "
01159 "neighborhood set", closerNodeLookupsFromNeighborhood);
01160 globalStatistics->addStdDev("Pastry: LEAFSET Requests sent/s", leafsetReqSent / time);
01161 globalStatistics->addStdDev("Pastry: bytes of LEAFSET Requests sent/s", leafsetReqBytesSent / time);
01162 globalStatistics->addStdDev("Pastry: LEAFSET Requests received/s", leafsetReqReceived / time);
01163 globalStatistics->addStdDev("Pastry: bytes of LEAFSET Requests received/s",
01164 leafsetReqBytesReceived / time);
01165 globalStatistics->addStdDev("Pastry: LEAFSET Messages sent/s", leafsetSent / time);
01166 globalStatistics->addStdDev("Pastry: bytes of LEAFSET Messages sent/s", leafsetBytesSent / time);
01167 globalStatistics->addStdDev("Pastry: LEAFSET Messages received/s", leafsetReceived / time);
01168 globalStatistics->addStdDev("Pastry: bytes of LEAFSET Messages received/s",
01169 leafsetBytesReceived / time);
01170 globalStatistics->addStdDev("Pastry: ROUTING TABLE Requests sent/s", routingTableReqSent / time);
01171 globalStatistics->addStdDev("Pastry: bytes of ROUTING TABLE Requests sent/s", routingTableReqBytesSent / time);
01172 globalStatistics->addStdDev("Pastry: ROUTING TABLE Requests received/s", routingTableReqReceived / time);
01173 globalStatistics->addStdDev("Pastry: bytes of ROUTING TABLE Requests received/s",
01174 routingTableReqBytesReceived / time);
01175 globalStatistics->addStdDev("Pastry: ROUTING TABLE Messages sent/s", routingTableSent / time);
01176 globalStatistics->addStdDev("Pastry: bytes of ROUTING TABLE Messages sent/s", routingTableBytesSent / time);
01177 globalStatistics->addStdDev("Pastry: ROUTING TABLE Messages received/s", routingTableReceived / time);
01178 globalStatistics->addStdDev("Pastry: bytes of ROUTING TABLE Messages received/s",
01179 routingTableBytesReceived / time);
01180
01181 }
01182
01183 int BasePastry::getMaxNumSiblings()
01184 {
01185 return (int) floor(numberOfLeaves/4.0);
01186 }
01187
01188 int BasePastry::getMaxNumRedundantNodes()
01189 {
01190 return 10;
01191 }
01192
01193 NodeVector* BasePastry::findNode(const OverlayKey& key,
01194 int numRedundantNodes,
01195 int numSiblings,
01196 BaseOverlayMessage* msg)
01197 {
01198 if ((numRedundantNodes > getMaxNumRedundantNodes()) ||
01199 (numSiblings > getMaxNumSiblings())) {
01200
01201 opp_error("(Pastry::findNode()) numRedundantNodes or numSiblings "
01202 "too big!");
01203 }
01204 RECORD_STATS(totalLookups++);
01205
01206 NodeVector* nextHops = new NodeVector(numRedundantNodes);
01207
01208 const NodeHandle* next;
01209 PastryFindNodeExtData* findNodeExt = NULL;
01210 if (msg && msg->hasObject("findNodeExt")) {
01211 findNodeExt =
01212 check_and_cast<PastryFindNodeExtData*>(msg->
01213 getObject("findNodeExt"));
01214 }
01215
01216 if (state != READY) {
01217 return nextHops;
01218 } else if (key.isUnspecified() || leafSet->isClosestNode(key)) {
01219 RECORD_STATS(responsibleLookups++);
01220 nextHops->add(thisNode);
01221 } else {
01222
01223 if (findNodeExt) {
01224 const TransportAddress& stateRecipient =
01225 findNodeExt->getSendStateTo();
01226 if (!stateRecipient.isUnspecified()) {
01227 RECORD_STATS(joinSeen++);
01228 sendStateTables(stateRecipient, PASTRY_STATE_JOIN,
01229 findNodeExt->getJoinHopCount(), false);
01230 }
01231 }
01232
01233 next = &(leafSet->getDestinationNode(key));
01234
01235 if (next->isUnspecified()) {
01236 next = &(routingTable->lookupNextHop(key));
01237 if (!next->isUnspecified()) {
01238 RECORD_STATS(routingTableLookups++);
01239 }
01240 } else {
01241 RECORD_STATS(responsibleLookups++);
01242 }
01243
01244 if (next->isUnspecified()) {
01245 RECORD_STATS(closerNodeLookups++);
01246
01247 if (optimizeLookup) {
01248 const NodeHandle* tmp;
01249 next = &(routingTable->findCloserNode(key, true));
01250 tmp = &(neighborhoodSet->findCloserNode(key, true));
01251
01252 if ((! tmp->isUnspecified()) &&
01253 (leafSet->isCloser(*tmp, key, *next))) {
01254 RECORD_STATS(closerNodeLookupsFromNeighborhood++);
01255 next = tmp;
01256 }
01257
01258 tmp = &(leafSet->findCloserNode(key, true));
01259 if ((! tmp->isUnspecified()) &&
01260 (leafSet->isCloser(*tmp, key, *next))) {
01261 RECORD_STATS(closerNodeLookupsFromNeighborhood--);
01262 next = tmp;
01263 }
01264 } else {
01265 next = &(routingTable->findCloserNode(key));
01266
01267 if (next->isUnspecified()) {
01268 RECORD_STATS(closerNodeLookupsFromNeighborhood++);
01269 next = &(neighborhoodSet->findCloserNode(key));
01270 }
01271
01272 if (next->isUnspecified()) {
01273 RECORD_STATS(closerNodeLookupsFromNeighborhood--);
01274 next = &(leafSet->findCloserNode(key));
01275 }
01276 }
01277 }
01278
01279 if (!next->isUnspecified()) {
01280 if (findNodeExt) {
01281 findNodeExt->setJoinHopCount(findNodeExt->getJoinHopCount() + 1);
01282 }
01283 nextHops->add(*next);
01284 }
01285 }
01286
01287 bool err;
01288
01289
01290 if (isSiblingFor(thisNode, key, numSiblings, &err)) {
01291 if (err == false) {
01292 delete nextHops;
01293 return leafSet->createSiblingVector(key, numSiblings);
01294 }
01295 }
01296
01297
01298 if ( (numRedundantNodes > 1)) {
01299
01300 KeyDistanceComparator<KeyRingMetric> comp(key);
01301
01302
01303 NodeVector* additionalHops = new NodeVector( numRedundantNodes, &comp );
01304
01305 routingTable->findCloserNodes(key, additionalHops);
01306 leafSet->findCloserNodes(key, additionalHops);
01307 neighborhoodSet->findCloserNodes(key, additionalHops);
01308
01309 if (useRegularNextHop && (*additionalHops)[0] != (*nextHops)[0]) {
01310 for (uint32_t i = 0; i < additionalHops->size(); i++) {
01311 if ((*additionalHops)[i] != (*nextHops)[0])
01312 nextHops->push_back((*additionalHops)[i]);
01313 }
01314 delete additionalHops;
01315 } else {
01316 delete nextHops;
01317 return additionalHops;
01318 }
01319 }
01320 return nextHops;
01321 }
01322 AbstractLookup* BasePastry::createLookup(RoutingType routingType,
01323 const BaseOverlayMessage* msg,
01324 const cObject* dummy,
01325 bool appLookup)
01326 {
01327 assert(dummy == NULL);
01328 PastryFindNodeExtData* findNodeExt =
01329 new PastryFindNodeExtData("findNodeExt");
01330
01331 if (msg) {
01332 const PastryMessage* pmsg =
01333 dynamic_cast<const PastryMessage*>(msg->getEncapsulatedMsg());
01334 if ((pmsg) && (pmsg->getPastryMsgType() == PASTRY_MSG_JOIN)) {
01335 const PastryJoinMessage* jmsg =
01336 check_and_cast<const PastryJoinMessage*>(pmsg);
01337 findNodeExt->setSendStateTo(jmsg->getSendStateTo());
01338 findNodeExt->setJoinHopCount(1);
01339 }
01340 }
01341 findNodeExt->setBitLength(PASTRYFINDNODEEXTDATA_L);
01342
01343 AbstractLookup* newLookup = BaseOverlay::createLookup(routingType,
01344 msg, findNodeExt,
01345 appLookup);
01346
01347 delete findNodeExt;
01348 return newLookup;
01349 }
01350
01351 bool stateMsgIsSmaller(const PastryStateMsgHandle& hnd1,
01352 const PastryStateMsgHandle& hnd2)
01353 {
01354 return (hnd1.msg->getJoinHopCount() < hnd2.msg->getJoinHopCount());
01355 }
01356
01357 std::ostream& operator<<(std::ostream& os, const PastryStateMsgProximity pr)
01358 {
01359 os << "PastryStateMsgProximity {" << endl;
01360 os << " pr_rt {" << endl;
01361 for (std::vector<simtime_t>::const_iterator i = pr.pr_rt.begin();
01362 i != pr.pr_rt.end(); ++i) {
01363 os << " " << *i << endl;
01364 }
01365 os << " }" << endl;
01366 os << " pr_ls {" << endl;
01367 for (std::vector<simtime_t>::const_iterator i = pr.pr_ls.begin();
01368 i != pr.pr_ls.end(); ++i) {
01369 os << " " << *i << endl;
01370 }
01371 os << " }" << endl;
01372 os << " pr_ns {" << endl;
01373 for (std::vector<simtime_t>::const_iterator i = pr.pr_ns.begin();
01374 i != pr.pr_ns.end(); ++i) {
01375 os << " " << *i << endl;
01376 }
01377 os << " }" << endl;
01378 os << "}" << endl;
01379 return os;
01380 }