IterativeLookup Class Reference

This class implements a basic greedy lookup strategy. More...

#include <IterativeLookup.h>

Inheritance diagram for IterativeLookup:
RpcListener AbstractLookup Comparator< OverlayKey >

List of all members.

Classes

class  RpcInfo
class  RpcInfoVector

Public Member Functions

 IterativeLookup (BaseOverlay *overlay, RoutingType routingType, const IterativeLookupConfiguration &config, const cPacket *findNodeExt=NULL, bool appLookup=false)
virtual ~IterativeLookup ()
void lookup (const OverlayKey &key, int numSiblings=1, int hopCountMax=0, int retries=0, LookupListener *listener=NULL)
 Lookup siblings for a key.
const NodeVectorgetResult () const
 Returns the result of the lookup.
bool isValid () const
 Returns true, if the lookup was successful.
void abortLookup ()
 Aborts a running lookup.
uint32_t getAccumulatedHops () const
 Returns the total number of hops for all lookup paths.

Protected Types

typedef std::map< int, int > PendingPings
typedef std::set< NodeHandleMajoritySiblings
typedef UNORDERED_MAP
< TransportAddress,
RpcInfoVector,
TransportAddress::hashFcn
RpcInfoMap

Protected Member Functions

virtual IterativePathLookupcreatePathLookup ()
 This method creates a new path lookup.
virtual FindNodeCall * createFindNodeCall (cPacket *findNodeExt=NULL)
 Creates a find node call message.
int compare (const OverlayKey &lhs, const OverlayKey &rhs) const
 compares two OverlayKeys and indicates which one is closer to the key to look up
bool addSibling (const NodeHandle &handle, bool assured=false)
 adds a node to the siblings NodeVector
void setVisited (const TransportAddress &addr, bool visitedFlag=true)
 adds/deletes visited nodes to/from the visited TransportAddress::Set
bool getVisited (const TransportAddress &addr)
 indicates if the specified node has been visited before
void setPinged (const TransportAddress &addr)
 marks a node as already pinged for authentication
bool getPinged (const TransportAddress &addr)
 verify if this node has already been pinged for authentication
void setDead (const TransportAddress &addr)
 add a dead node to the dead node list
bool getDead (const TransportAddress &addr)
 check if a node seems to be dead
void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 This method is called if an RPC response has been received.
void handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey=OverlayKey::UNSPECIFIED_KEY)
 This method is called if an RPC timeout has been reached.
void sendRpc (const NodeHandle &handle, FindNodeCall *call, IterativePathLookup *listener, int rpcId)
void start ()
void stop ()
void checkStop ()

Protected Attributes

OverlayKey key
 key to lookup
BaseOverlayoverlay
 ptr to overlay
LookupListenerlistener
 lookup listener
std::vector
< IterativePathLookup * > 
paths
 parallel paths
RoutingType routingType
 RoutingType for this lookup.
IterativeLookupConfiguration config
 lookup configuration
cPacket * firstCallExt
 additional info for first findNode()
uint32_t finishedPaths
 number of finished paths
uint32_t successfulPaths
 number of successful paths
uint32_t accumulatedHops
 total number of hops (for all paths)
bool finished
 true, if lookup is finished
bool success
 true, if lookup was successful
bool running
 true, if lookup is running
int retries
 number of retries, if lookup fails
bool appLookup
SimTime startTime
 time at which the lookup was started
NodeVector siblings
 closest nodes
TransportAddress::Set visited
 nodes already visited
TransportAddress::Set dead
 nodes which seem to be dead
TransportAddress::Set pinged
 nodes already pinged
MajoritySiblings majoritySiblings
 map for majority decision on correct siblings
int numSiblings
 number of siblings
int hopCountMax
 maximum hop count
PendingPings pendingPings
 number of pending ping calls
RpcInfoMap rpcs

Friends

class IterativePathLookup
class BaseOverlay

Detailed Description

This class implements a basic greedy lookup strategy.

It uses the standard metric for greedy behaviour. If another metric is needed, the distance function can be replaced by overriding the distance method.

Author:
Sebastian Mies

Definition at line 81 of file IterativeLookup.h.


Member Typedef Documentation

typedef std::set<NodeHandle> IterativeLookup::MajoritySiblings [protected]

Definition at line 152 of file IterativeLookup.h.

typedef std::map<int,int> IterativeLookup::PendingPings [protected]

Definition at line 151 of file IterativeLookup.h.

Definition at line 232 of file IterativeLookup.h.


Constructor & Destructor Documentation

IterativeLookup::IterativeLookup ( BaseOverlay overlay,
RoutingType  routingType,
const IterativeLookupConfiguration config,
const cPacket *  findNodeExt = NULL,
bool  appLookup = false 
)

Definition at line 69 of file IterativeLookup.cc.

00074                                                  :
00075 overlay(overlay),
00076 routingType(routingType),
00077 config(config),
00078 firstCallExt(NULL),
00079 finished(false),
00080 success(false),
00081 running(false),
00082 appLookup(appLookup)
00083 {
00084     if (findNodeExt) firstCallExt = static_cast<cPacket*>(findNodeExt->dup());
00085 
00086     if ((config.parallelPaths > 1) && (!config.merge)) {
00087         throw cRuntimeError("IterativeLookup::IterativeLookup(): "
00088                                 "config.merge must be enabled for "
00089                                 "using parallel paths!");
00090     }
00091 
00092     if (config.verifySiblings && (!config.merge)) {
00093         throw cRuntimeError("IterativeLookup::IterativeLookup(): "
00094                                 "config.merge must be enabled for "
00095                                 "using secure lookups!");
00096     }
00097 
00098 
00099     if (config.majoritySiblings && (!config.merge)) {
00100         throw cRuntimeError("IterativeLookup::IterativeLookup(): "
00101                                 "config.merge must be enabled for "
00102                                 "using majority decision for sibling selection!");
00103     }
00104 
00105     if (config.useAllParallelResponses && (!config.merge)) {
00106         throw cRuntimeError("IterativeLookup::IterativeLookup(): "
00107                                 "config.merge must be enabled if "
00108                                 "config.useAllParallelResponses is true!");
00109     }
}

IterativeLookup::~IterativeLookup (  )  [virtual]

Definition at line 111 of file IterativeLookup.cc.

00112 {
00113     stop();
00114     delete firstCallExt;
00115     overlay->removeLookup(this);
00116 
00117 //    std::cout << "time: " << simTime() << "deleting " << this << endl;
00118 }


Member Function Documentation

void IterativeLookup::abortLookup (  )  [virtual]

Aborts a running lookup.

This method aborts a running lookup without calling the listener and delete the lookup object.

Implements AbstractLookup.

Definition at line 120 of file IterativeLookup.cc.

00121 {
00122     if (listener != NULL) {
00123         delete listener;
00124         listener = NULL;
00125     }
00126     delete this;
00127 }

bool IterativeLookup::addSibling ( const NodeHandle handle,
bool  assured = false 
) [protected]

adds a node to the siblings NodeVector

Parameters:
handle NodeHandle of the node to add
assured true, if this node was already authenticated
Returns:
true if operation was succesful, false otherwise

Definition at line 400 of file IterativeLookup.cc.

Referenced by IterativePathLookup::handleResponse(), handleRpcResponse(), IterativePathLookup::sendRpc(), and start().

00401 {
00402     bool result = false;
00403 
00404     EV << "[IterativeLookup::addSibling() @ " << overlay->getThisNode().getAddress()
00405                    << " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
00406                    << "    Adding potential sibling " << handle
00407                    << endl;
00408 
00409     majoritySiblings.insert(handle);
00410 
00411     if (config.verifySiblings && !assured && !getVisited(handle)) {
00412         // ping potential sibling for authentication
00413         if (siblings.isAddable(handle) && !getPinged(handle)) {
00414             int id = intuniform(1, 2147483647);
00415             int nonce = overlay->pingNode(handle, -1, 0, NULL, NULL, this, id);
00416             pendingPings.insert(make_pair(id, nonce));
00417             setPinged(handle);
00418         }
00419 
00420         return false;
00421     }
00422 
00423     if (numSiblings == 0) {
00424         if (handle.getKey() == key) {
00425             siblings.clear();
00426             siblings.push_back( handle );
00427             result = true;
00428         }
00429     } else {
00430         if (config.parallelPaths == 1 && !config.verifySiblings) {
00431             result = true;
00432             if (!siblings.isFull()) {
00433                 siblings.push_back(handle);
00434             }
00435         } else {
00436             if (siblings.add(handle) >= 0) {
00437                 result = true;
00438             }
00439         }
00440     }
00441 
00442     return result;
00443 }

void IterativeLookup::checkStop (  )  [inline, protected]

Definition at line 289 of file IterativeLookup.cc.

Referenced by handleRpcResponse(), handleRpcTimeout(), and start().

00290 {
00291     bool finishLookup = false;
00292 
00293     if (config.majoritySiblings && (numSiblings > 0) &&
00294             finishedPaths == (uint32_t)config.parallelPaths) {
00295         if (majoritySiblings.size() <= (uint)numSiblings) {
00296             // TODO: better check that all nodes have sent the same siblings
00297             MajoritySiblings::iterator it;
00298             for (it = majoritySiblings.begin(); it != majoritySiblings.end(); it++) {
00299                 siblings.add(*it);
00300             }
00301             success = true;
00302             finishLookup = true;
00303         }
00304     }
00305 
00306     // check if there are rpcs pending or lookup finished
00307     if (((successfulPaths >= 1) && (numSiblings == 0) && (siblings.size() >= 1)) ||
00308         ((finishedPaths == (uint32_t)config.parallelPaths) &&
00309                 (numSiblings > 0) && (pendingPings.size() == 0))) {
00310 
00311         for (uint32_t i=0; i<paths.size(); i++) {
00312             success |= paths[i]->success;
00313         }
00314         finishLookup = true;
00315 
00316     } else if ((rpcs.size() == 0) && (pendingPings.size() == 0)) {
00317         finishLookup = true;
00318     }
00319 
00320     if (finishLookup == true) {
00321         // TODO: should not be needed, but sometimes finishedPaths seems
00322         //       to be smaller than config.parallelPaths
00323         if (successfulPaths >= 1) {
00324             success = true;
00325         }
00326 
00327         if (success == false) {
00328             //cout << "failed: hops :" << accumulatedHops << endl;
00329         }
00330 
00331         if (success == false && retries > 0) {
00332             //      std::cout << "IterativeLookup::checkStop(): Retry..." << endl;
00333             retries--;
00334             LookupListener* oldListener = listener;
00335             listener = NULL;
00336             stop();
00337             listener = oldListener;
00338             start();
00339         } else {
00340             delete this;
00341         }
00342     }
00343 }

int IterativeLookup::compare ( const OverlayKey lhs,
const OverlayKey rhs 
) const [protected, virtual]

compares two OverlayKeys and indicates which one is closer to the key to look up

Parameters:
lhs the first OverlayKey
rhs the second OverlayKey
Returns:
-1 if rhs is closer, 0 if lhs and rhs are equal and 1 if rhs is farther away to the key to lookup

Reimplemented from Comparator< OverlayKey >.

Definition at line 391 of file IterativeLookup.cc.

00392 {
00393     return overlay->distance(lhs, key).compareTo(overlay->distance(rhs, key));
00394 }

FindNodeCall * IterativeLookup::createFindNodeCall ( cPacket *  findNodeExt = NULL  )  [protected, virtual]

Creates a find node call message.

This method can be overridden to add some additional state information to the FindNodeCall message.

Parameters:
findNodeExt Pointer to a optional cMessage, that may contain overlay specific data to be attached to FindNode RPCs and BaseRouteMessages
Returns:
pointer to a new FindNodeCall message.

Definition at line 353 of file IterativeLookup.cc.

Referenced by IterativePathLookup::sendRpc(), and start().

00354 {
00355     FindNodeCall* call = new FindNodeCall("FindNodeCall");
00356     if (appLookup) {
00357         call->setStatType(APP_LOOKUP_STAT);
00358     } else {
00359         call->setStatType(MAINTENANCE_STAT);
00360     }
00361 
00362     if (routingType == EXHAUSTIVE_ITERATIVE_ROUTING) {
00363         call->setExhaustiveIterative(true);
00364     } else {
00365         call->setExhaustiveIterative(false);
00366     }
00367 
00368     call->setLookupKey(key);
00369     call->setNumRedundantNodes(config.redundantNodes);
00370     call->setNumSiblings(numSiblings);
00371     if (routingType == EXHAUSTIVE_ITERATIVE_ROUTING) {
00372         call->setExhaustiveIterative(true);
00373     } else {
00374         call->setExhaustiveIterative(false);
00375     }
00376     call->setBitLength(FINDNODECALL_L(call));
00377 
00378     // duplicate extension object
00379     if (findNodeExt) {
00380         call->addObject(static_cast<cObject*>(findNodeExt->dup()));
00381         call->addBitLength(findNodeExt->getBitLength());
00382     }
00383 
00384     return call;
00385 }

IterativePathLookup * IterativeLookup::createPathLookup (  )  [protected, virtual]

This method creates a new path lookup.

It may be overloaded to enhance IterativePathLookup with some new information/features.

Returns:
The new path lookup

Definition at line 348 of file IterativeLookup.cc.

00349 {
00350     return new IterativePathLookup(this);
00351 }

uint32_t IterativeLookup::getAccumulatedHops (  )  const [virtual]

Returns the total number of hops for all lookup paths.

Returns:
The accumulated number of hops.

Implements AbstractLookup.

Definition at line 714 of file IterativeLookup.cc.

00715 {
00716     return accumulatedHops;
00717 }

bool IterativeLookup::getDead ( const TransportAddress addr  )  [protected]

check if a node seems to be dead

Parameters:
addr TransportAddress of the node
Returns:
true, if the node seems to be dead

Definition at line 463 of file IterativeLookup.cc.

Referenced by IterativePathLookup::handleTimeout(), and IterativePathLookup::sendRpc().

00464 {
00465     return (dead.count(addr) != 0);
00466 }

bool IterativeLookup::getPinged ( const TransportAddress addr  )  [protected]

verify if this node has already been pinged for authentication

Parameters:
addr TransportAddress of the node
Returns:
false if addr was not already pinged, true otherwise

Definition at line 473 of file IterativeLookup.cc.

Referenced by addSibling().

00474 {
00475     return (pinged.count(addr) != 0);
00476 }

const NodeVector & IterativeLookup::getResult (  )  const [virtual]

Returns the result of the lookup.

Returns:
The result node vector.

Implements AbstractLookup.

Definition at line 703 of file IterativeLookup.cc.

00704 {
00705     // return sibling vector
00706     return siblings;
00707 }

bool IterativeLookup::getVisited ( const TransportAddress addr  )  [protected]

indicates if the specified node has been visited before

Parameters:
addr TransportAddress of the node
Returns:
false if addr is not in visited, true otherwise

Definition at line 453 of file IterativeLookup.cc.

Referenced by addSibling(), and IterativePathLookup::sendRpc().

00454 {
00455     return (visited.count(addr) != 0);
00456 }

void IterativeLookup::handleRpcResponse ( BaseResponseMessage *  msg,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
) [protected, virtual]

This method is called if an RPC response has been received.

Parameters:
msg The response message.
context Pointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code
rpcId The RPC id.
rtt The Round-Trip-Time of this RPC

Reimplemented from RpcListener.

Definition at line 482 of file IterativeLookup.cc.

00485 {
00486     // check flags
00487     if (finished || !running)
00488         return;
00489 
00490     // get source, cast messages and mark node as visited
00491     const TransportAddress& src = msg->getSrcNode();
00492     FindNodeResponse* findNodeResponse = dynamic_cast<FindNodeResponse*>(msg);
00493     PingResponse* pingResponse = dynamic_cast<PingResponse*>(msg);
00494     FailedNodeResponse* failedNodeResponse =
00495     dynamic_cast<FailedNodeResponse*>(msg);
00496 
00497     if (pingResponse != NULL) {
00498         pendingPings.erase(rpcId);
00499         // add authenticated sibling
00500         addSibling(pingResponse->getSrcNode(), true);
00501     }
00502 
00503     // handle find node response
00504     if (findNodeResponse != NULL) {
00505 //      std::cout << "time: " << simTime() << " node: " << overlay->thisNode << " this: " << this << " received rpc with nonce: " << findNodeResponse->getNonce() << " from: " << findNodeResponse->getSrcNode() << endl;
00506 
00507         // check if rpc info is available, no -> exit
00508         if (rpcs.count(src) == 0)
00509             return;
00510 
00511         // get info
00512         RpcInfoVector infos = rpcs[src];
00513         rpcs.erase(src);
00514 
00515         // iterate
00516         bool rpcHandled = false;
00517 
00518         for (uint32_t i=0; i<infos.size(); i++) {
00519             // get info
00520             const RpcInfo& info = infos[i];
00521 
00522             // do not handle finished paths
00523             if (info.path->finished)
00524                 continue;
00525 
00526             // check if path accepts the message
00527             // make an exception for responses with siblings==true
00528             if (!rpcHandled &&
00529                     (info.path->accepts(info.vrpcId) ||
00530                     ((routingType == EXHAUSTIVE_ITERATIVE_ROUTING)
00531                             || (findNodeResponse->getSiblings() &&
00532                                 config.acceptLateSiblings)))) {
00533                 info.path->handleResponse(findNodeResponse);
00534                 rpcHandled = true;
00535             } else {
00536                 EV << "[IterativeLookup::handleRpcResponse()]\n"
00537                    << "    Path does not accept message with id " << info.vrpcId
00538                    << endl;
00539 
00540                 info.path->handleTimeout(NULL, findNodeResponse->getSrcNode(),
00541                                          info.vrpcId);
00542             }
00543 
00544             // count finished and successful paths
00545             if (info.path->finished) {
00546                 finishedPaths++;
00547 
00548                 // count total number of hops
00549                 accumulatedHops += info.path->hops;
00550 
00551                 if (info.path->success)
00552                     successfulPaths++;
00553             }
00554 
00555         }
00556     }
00557 
00558 
00559     // handle failed node response
00560     if (failedNodeResponse != NULL) {
00561         cPacket* findNodeExt = NULL;
00562         if (failedNodeResponse->hasObject("findNodeExt")) {
00563             findNodeExt =
00564                 (cPacket*)failedNodeResponse->removeObject("findNodeExt");
00565         }
00566 
00567         for (std::vector<IterativePathLookup*>::iterator i = paths.begin();
00568             i != paths.end(); i++) {
00569 
00570             (*i)->handleFailedNodeResponse(failedNodeResponse->getSrcNode(),
00571                                            findNodeExt,
00572                                            failedNodeResponse->getTryAgain());
00573         }
00574     }
00575 
00576     checkStop();
00577 }

void IterativeLookup::handleRpcTimeout ( BaseCallMessage *  msg,
const TransportAddress dest,
cPolymorphic *  context,
int  rpcId,
const OverlayKey destKey = OverlayKey::UNSPECIFIED_KEY 
) [protected, virtual]

This method is called if an RPC timeout has been reached.

Parameters:
msg The original RPC message.
dest The destination node
context Pointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code
rpcId The RPC id.
destKey the destination OverlayKey

Reimplemented from RpcListener.

Definition at line 580 of file IterativeLookup.cc.

00584 {
00585     // check flags
00586     if (finished || !running)
00587         return;
00588 
00589     if (dynamic_cast<PingCall*>(msg) != NULL) {
00590         pendingPings.erase(rpcId);
00591         checkStop();
00592         return;
00593     }
00594 
00595     // check if rpc info is available
00596     if (rpcs.count(dest)==0) {
00597         cout << "IterativeLookup::handleRpcTimeout(): RPC Timeout, but node"
00598                  << " is not in rpcs structure!" << endl;
00599         return;
00600     }
00601 
00602     // mark the node as dead
00603     setDead(dest);
00604 
00605     RpcInfoVector infos = rpcs[dest];
00606     rpcs.erase(dest);
00607 
00608     // iterate
00609     for (uint32_t i=0; i < infos.size(); i++) {
00610 
00611         const RpcInfo& info = infos[i];
00612 
00613         // do not handle finished paths
00614         if (info.path->finished)
00615             continue;
00616 
00617         // delegate timeout
00618         info.path->handleTimeout(msg, dest, info.vrpcId);
00619 
00620         // count finished and successful paths
00621         if (info.path->finished) {
00622             finishedPaths++;
00623 
00624             // count total number of hops
00625             accumulatedHops += info.path->hops;
00626 
00627             if (info.path->success)
00628                 successfulPaths++;
00629         }
00630     }
00631     checkStop();
00632 }

bool IterativeLookup::isValid (  )  const [virtual]

Returns true, if the lookup was successful.

Returns:
true, if the lookup was successful.

Implements AbstractLookup.

Definition at line 709 of file IterativeLookup.cc.

Referenced by stop().

00710 {
00711     return success && finished;
00712 }

void IterativeLookup::lookup ( const OverlayKey key,
int  numSiblings = 1,
int  hopCountMax = 0,
int  retries = 0,
LookupListener listener = NULL 
) [virtual]

Lookup siblings for a key.

Parameters:
key The key to lookup
numSiblings Number of siblings to lookup
hopCountMax Maximum hop count
retries Number of retries if lookup fails
listener Listener to inform, when the lookup is done

Implements AbstractLookup.

Definition at line 673 of file IterativeLookup.cc.

00675 {
00676     EV << "[IterativeLookup::lookup() @ " << overlay->overlay->getThisNode().getAddress()
00677        << " (" << overlay->overlay->getThisNode().getKey().toString(16) << ")]\n"
00678        << "    Lookup of key " << key
00679        << endl;
00680 
00681     // check flags
00682     if (finished || running)
00683         return;
00684 
00685     // set params
00686     this->key = key;
00687     this->numSiblings = numSiblings;
00688     this->hopCountMax = hopCountMax;
00689     this->listener = listener;
00690     this->retries = retries;
00691 
00692     if ((routingType == EXHAUSTIVE_ITERATIVE_ROUTING)
00693         && (numSiblings > config.redundantNodes)) {
00694         throw cRuntimeError("IterativeLookup::lookup(): "
00695                   "With EXHAUSTIVE_ITERATIVE_ROUTING numRedundantNodes "
00696                   "must be >= numSiblings!");
00697     }
00698 
00699     // start lookup
00700     start();
00701 }

void IterativeLookup::sendRpc ( const NodeHandle handle,
FindNodeCall *  call,
IterativePathLookup listener,
int  rpcId 
) [protected]

Definition at line 634 of file IterativeLookup.cc.

Referenced by IterativePathLookup::sendRpc().

00636 {
00637     // check flags
00638     if (finished || !running) {
00639         delete call;
00640         return;
00641     }
00642 
00643     // create rpc info
00644     RpcInfo info;
00645     info.path = listener;
00646     info.vrpcId = rpcId;
00647 
00648     // send new message
00649     if (rpcs.count(handle) == 0) {
00650         RpcInfoVector newVector;
00651 
00652         overlay->countFindNodeCall(call);
00653         newVector.nonce = overlay->sendUdpRpcCall(handle, call, NULL,
00654                                                   -1, 0, -1, this);
00655 
00656         //      std::cout << "time: " << simTime() << " node: " << overlay->thisNode << " new rpc with nonce: " << newVector.nonce << " to: " << handle << endl;
00657         rpcs[handle] = newVector;
00658     } else {
00659         EV << "[IterativeLookup::sendRpc()]\n"
00660            << "    RPC already sent...not sent again"
00661            << endl;
00662         delete call;
00663     }
00664 
00665     // register info
00666     rpcs[handle].push_back(info);
00667 }

void IterativeLookup::setDead ( const TransportAddress addr  )  [protected]

add a dead node to the dead node list

Parameters:
addr TransportAddress of the node to add

Definition at line 458 of file IterativeLookup.cc.

Referenced by handleRpcTimeout().

00459 {
00460     dead.insert(addr);
00461 }

void IterativeLookup::setPinged ( const TransportAddress addr  )  [protected]

marks a node as already pinged for authentication

Parameters:
addr TransportAddress of the node to mark as already pinged

Definition at line 468 of file IterativeLookup.cc.

Referenced by addSibling().

00469 {
00470     pinged.insert(addr);
00471 }

void IterativeLookup::setVisited ( const TransportAddress addr,
bool  visitedFlag = true 
) [protected]

adds/deletes visited nodes to/from the visited TransportAddress::Set

Parameters:
addr TransportAddress of the node to add
visitedFlag if true node is added, else node is erased

Definition at line 445 of file IterativeLookup.cc.

Referenced by IterativePathLookup::handleFailedNodeResponse(), IterativePathLookup::handleResponse(), and start().

00446 {
00447     if (visitedFlag)
00448         this->visited.insert(addr);
00449     else
00450         this->visited.erase(addr);
00451 }

void IterativeLookup::start (  )  [protected]

Definition at line 129 of file IterativeLookup.cc.

Referenced by checkStop(), and lookup().

00130 {
00131 //    std::cout << "time: " << simTime() << " start(): node: " << overlay->getThisNode() << " this: " << this  << " key: " << key << endl;
00132 
00133     // init params
00134     successfulPaths = 0;
00135     finishedPaths   = 0;
00136     accumulatedHops = 0;
00137 
00138     // init flags
00139     finished = false;
00140     success  = false;
00141     running  = true;
00142 
00143     // init siblings vector
00144     siblings = NodeVector(numSiblings == 0 ? 1 : numSiblings, this);
00145     visited.clear();
00146     dead.clear();
00147     pinged.clear();
00148 
00149     startTime = simTime();
00150 
00151     // get local closest nodes
00152     FindNodeCall* call = createFindNodeCall(firstCallExt);
00153     NodeVector* nextHops = overlay->findNode(key, overlay->getMaxNumRedundantNodes(),
00154         (routingType == EXHAUSTIVE_ITERATIVE_ROUTING) ? -1 : numSiblings, call);
00155 
00156     bool err;
00157 
00158     setVisited(overlay->getThisNode());
00159 
00160     // if this node is new and no nodes are known -> stop lookup
00161     if (nextHops->size() == 0) {
00162         //std::cout << "IterativeLookup: No next hops known" << endl;
00163         finished = true;
00164         success = false;
00165     } else if ((numSiblings == 0)
00166             && overlay->isSiblingFor(overlay->getThisNode(),
00167                                      key, numSiblings,
00168                                      &err)) {
00169         if (overlay->getThisNode().getKey() == key) {
00170             addSibling(overlay->getThisNode(), true);
00171             success = true;
00172         } else {
00173             std::cout << "IterativeLookup: numSiblings==0 and no node with this id"
00174                       << endl;
00175             success = false;
00176         }
00177         finished = true;
00178     }
00179     // finish lookup if the key is local and siblings are needed
00180     else if (numSiblings != 0 && routingType != EXHAUSTIVE_ITERATIVE_ROUTING &&
00181              overlay->isSiblingFor(overlay->getThisNode(), key,
00182                                    numSiblings, &err)) {
00183 
00184         for (uint32_t i=0; i<nextHops->size(); i++) {
00185             addSibling(nextHops->at(i), true);
00186         }
00187 
00188         success = finished = true;
00189     }
00190 
00191     // if the key was local or belongs to one of our siblings we are finished
00192     if (finished) {
00193         // calls stop and finishes the lookup
00194         delete nextHops;
00195         delete call;
00196         delete this;
00197         return;
00198     }
00199 
00200     // extract find node extensions
00201     cPacket* findNodeExt = NULL;
00202     if (call->hasObject("findNodeExt"))
00203         findNodeExt = (cPacket*)call->removeObject("findNodeExt");
00204     delete call;
00205 
00206     // not enough nodes for all paths? -> reduce number of parallel paths
00207     if ((uint32_t)config.parallelPaths > nextHops->size()) {
00208         config.parallelPaths = nextHops->size();
00209     }
00210 
00211     // create parallel paths and distribute nodes to paths
00212     for (int i = 0; i < config.parallelPaths; i++) {
00213 
00214         // create state
00215         IterativePathLookup* pathLookup = new IterativePathLookup(this);
00216         paths.push_back(pathLookup);
00217 
00218         // populate next hops
00219         for (uint32_t k=0; (k * config.parallelPaths + i) < nextHops->size(); k++) {
00220             pathLookup->add(nextHops->at(k * config.parallelPaths + i));
00221         }
00222 
00223         // send initial rpcs
00224         pathLookup->sendRpc(config.parallelRpcs, findNodeExt);
00225     }
00226 
00227 
00228     //std::cout << "nextHops size: " << nextHops->size()
00229     //<< " numSiblings: " << numSiblings
00230     //<< " redundantNodes: " << config.redundantNodes
00231     //<< " thisNode " << overlay->getThisNode().ip
00232     //<< " nextHop " << nextHops->at(0).ip << endl;
00233 
00234     delete nextHops;
00235     delete findNodeExt;
00236 
00237     checkStop();
00238 }

void IterativeLookup::stop (  )  [protected]

Definition at line 240 of file IterativeLookup.cc.

Referenced by checkStop(), and ~IterativeLookup().

00241 {
00242     // only stop if running
00243     if (!running)
00244         return;
00245 
00246     for (uint32_t i=0; i<paths.size(); i++) {
00247         success |= paths[i]->success;
00248     }
00249 
00250     // cancel pending rpcs
00251     for (RpcInfoMap::iterator i = rpcs.begin(); i != rpcs.end(); i++) {
00252 //      std::cout << "time: " << simTime()     << " node: " << overlay->thisNode          << " this: " << this << " first: " << i->first  << " nonce: " << i->second.nonce << endl;
00253         overlay->cancelRpcMessage(i->second.nonce);
00254     }
00255     rpcs.clear();
00256 
00257     // cancel pending ping rpcs
00258     for (PendingPings::iterator i = pendingPings.begin(); i != pendingPings.end(); i++) {
00259         overlay->cancelRpcMessage(i->second);
00260     }
00261     pendingPings.clear();
00262 
00263     // delete path lookups
00264     for (uint32_t i=0; i<paths.size(); i++) {
00265         delete paths[i];
00266     }
00267     paths.clear();
00268 
00269     // reset running flag
00270     running  = false;
00271     finished = true;
00272 
00273 #if 0
00274     EV << "[IterativeLookup::stop() @ " << overlay->getThisNode().getAddress()
00275                    << " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
00276                    << "    Lookup " << (isValid() ? "succeeded\n" : "failed\n")
00277                    << "    (" << successfulPaths << " successful paths)\n"
00278                    << "    (" << finishedPaths << " finished paths)"
00279                    << endl;
00280 #endif
00281 
00282     // inform listener
00283     if (listener != NULL) {
00284         listener->lookupFinished(this);
00285         listener = NULL;
00286     }
00287 }


Friends And Related Function Documentation

friend class BaseOverlay [friend]

Definition at line 86 of file IterativeLookup.h.

friend class IterativePathLookup [friend]

Definition at line 85 of file IterativeLookup.h.

Referenced by createPathLookup(), and start().


Member Data Documentation

uint32_t IterativeLookup::accumulatedHops [protected]

total number of hops (for all paths)

Definition at line 123 of file IterativeLookup.h.

Referenced by getAccumulatedHops(), handleRpcResponse(), handleRpcTimeout(), and start().

bool IterativeLookup::appLookup [protected]

Definition at line 128 of file IterativeLookup.h.

Referenced by createFindNodeCall().

nodes which seem to be dead

Definition at line 149 of file IterativeLookup.h.

Referenced by getDead(), setDead(), and start().

bool IterativeLookup::finished [protected]

true, if lookup is finished

Definition at line 124 of file IterativeLookup.h.

Referenced by handleRpcResponse(), handleRpcTimeout(), isValid(), lookup(), sendRpc(), start(), and stop().

uint32_t IterativeLookup::finishedPaths [protected]

number of finished paths

Definition at line 121 of file IterativeLookup.h.

Referenced by checkStop(), handleRpcResponse(), handleRpcTimeout(), start(), and stop().

cPacket* IterativeLookup::firstCallExt [protected]

additional info for first findNode()

Definition at line 120 of file IterativeLookup.h.

Referenced by IterativeLookup(), start(), and ~IterativeLookup().

maximum hop count

Definition at line 155 of file IterativeLookup.h.

Referenced by IterativePathLookup::sendRpc().

key to lookup

Definition at line 114 of file IterativeLookup.h.

Referenced by addSibling(), compare(), createFindNodeCall(), IterativePathLookup::handleResponse(), and start().

lookup listener

Definition at line 116 of file IterativeLookup.h.

Referenced by abortLookup(), checkStop(), and stop().

map for majority decision on correct siblings

Definition at line 153 of file IterativeLookup.h.

Referenced by addSibling(), and checkStop().

std::vector<IterativePathLookup*> IterativeLookup::paths [protected]

parallel paths

Definition at line 117 of file IterativeLookup.h.

Referenced by checkStop(), handleRpcResponse(), start(), and stop().

number of pending ping calls

Definition at line 156 of file IterativeLookup.h.

Referenced by addSibling(), checkStop(), handleRpcResponse(), handleRpcTimeout(), and stop().

nodes already pinged

Definition at line 150 of file IterativeLookup.h.

Referenced by getPinged(), setPinged(), and start().

int IterativeLookup::retries [protected]

number of retries, if lookup fails

Definition at line 127 of file IterativeLookup.h.

Referenced by checkStop().

RoutingType IterativeLookup::routingType [protected]

Definition at line 233 of file IterativeLookup.h.

Referenced by checkStop(), handleRpcResponse(), handleRpcTimeout(), sendRpc(), and stop().

bool IterativeLookup::running [protected]

true, if lookup is running

Definition at line 126 of file IterativeLookup.h.

Referenced by handleRpcResponse(), handleRpcTimeout(), lookup(), sendRpc(), start(), and stop().

closest nodes

Definition at line 147 of file IterativeLookup.h.

Referenced by addSibling(), checkStop(), getResult(), and start().

SimTime IterativeLookup::startTime [protected]

time at which the lookup was started

Definition at line 129 of file IterativeLookup.h.

Referenced by IterativePathLookup::handleResponse(), IterativePathLookup::handleTimeout(), and start().

bool IterativeLookup::success [protected]

true, if lookup was successful

Definition at line 125 of file IterativeLookup.h.

Referenced by checkStop(), isValid(), start(), and stop().

uint32_t IterativeLookup::successfulPaths [protected]

number of successful paths

Definition at line 122 of file IterativeLookup.h.

Referenced by checkStop(), handleRpcResponse(), handleRpcTimeout(), start(), and stop().

nodes already visited

Definition at line 148 of file IterativeLookup.h.

Referenced by getVisited(), setVisited(), and start().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:17 2010 for OverSim by  doxygen 1.6.3