BasePathLookup Class Reference

#include <BaseLookup.h>

List of all members.


Detailed Description

This class implements a path lookup.

Author:
Sebastian Mies


Protected Member Functions

bool accepts (int rpcId)
void handleResponse (FindNodeResponse *msg)
void handleTimeout (int rpcId)
 BasePathLookup (BaseLookup *lookup)
virtual ~BasePathLookup ()
virtual FindNodeCall * createRpcMessage (cMessage *findNodeExt=NULL)
 Creates a find node call message.
void add (const NodeHandle &handle)
 Adds a NodeHandle to next hops.

Protected Attributes

BaseLookuplookup
int hops
int step
int pendingRpcs
bool finished
bool success
NodeVector nextHops

Private Member Functions

void sendRpc (int num, cMessage *FindNodeExt=NULL)

Friends

class BaseLookup


Constructor & Destructor Documentation

BasePathLookup::BasePathLookup ( BaseLookup lookup  )  [protected]

00407 {
00408     this->lookup = lookup;
00409     this->hops = 0;
00410     this->step = 0;
00411     this->pendingRpcs = 0;
00412     this->finished = false;
00413     this->success = false;
00414     this->nextHops = NodeVector( lookup->config.numNextHops, lookup );
00415 }

BasePathLookup::~BasePathLookup (  )  [protected, virtual]

00418 {}


Member Function Documentation

bool BasePathLookup::accepts ( int  rpcId  )  [protected]

00421 {
00422     bool accept = ( rpcId == step ) && !finished;
00423     return accept;
00424 }

void BasePathLookup::add ( const NodeHandle handle  )  [protected]

Adds a NodeHandle to next hops.

00561 {
00562     if ( lookup->config.merge )
00563         nextHops.add(handle);
00564     else
00565         nextHops.push_back(handle);
00566 }

FindNodeCall * BasePathLookup::createRpcMessage ( cMessage *  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.
00545 {
00546     // create default find node call message
00547     FindNodeCall* call = new FindNodeCall( "FindNodeCall" );
00548     call->setLookupKey( lookup->key );
00549     call->setLength( FINDNODECALL_L(call) );
00550 
00551     // duplicate extension object
00552     if ( findNodeExt != NULL ) {
00553         call->addObject( (cObject*)findNodeExt->dup() );
00554         call->addLength( findNodeExt->length() );
00555     }
00556 
00557     return call;
00558 }

void BasePathLookup::handleResponse ( FindNodeResponse *  msg  )  [protected]

00427 {
00428     if (finished)
00429         return;
00430 
00431     // increase hops: FIXME don't count local hops
00432     if (lookup->overlay->getThisNode() != msg->getSrcNode())
00433         hops++;
00434     step++;
00435 
00436     // decrease pending rpcs
00437     pendingRpcs--;
00438 
00439     // mode: merge or replace
00440     if (!lookup->config.merge) {
00441         nextHops.clear();
00442     }
00443 
00444     // add new next hops
00445     for ( uint i=0; i < msg->getClosestNodesArraySize(); i++ ) {
00446         const NodeHandle& handle = msg->getClosestNodes(i);
00447 
00448         // add node handles to next hops and neighborhood
00449         add( handle );
00450 
00451         // check if node was found
00452         if ( handle.key == lookup->key && !lookup->config.secure ) {
00453             lookup->addNeighbor( handle );
00454 
00455             finished = true;
00456             success = true;
00457             return;
00458         } else
00459         if (lookup->numNeighbors != 0 && !lookup->config.secure && msg->getNeighbors() )
00460             lookup->addNeighbor( handle );
00461 
00462     }
00463 
00464     // check if neighborlookup is finished
00465     if ( msg->getNeighbors() && msg->getClosestNodesArraySize() != 0 &&
00466             lookup->numNeighbors != 0 && !lookup->config.secure ) {
00467 
00468         finished = true;
00469         success = true;
00470         return;
00471     }
00472 
00473     // extract find node extension object
00474     cMessage* findNodeExt = NULL;
00475     if (msg->hasObject("findNodeExt"))
00476         findNodeExt = (cMessage*)msg->removeObject("findNodeExt");
00477 
00478     // send next rpcs
00479     sendRpc( lookup->config.parallelRpcs, findNodeExt );
00480 
00481     // ...
00482     delete findNodeExt;
00483 }

void BasePathLookup::handleTimeout ( int  rpcId  )  [protected]

00487 {
00488     if (finished)
00489         return;
00490 
00491     EV << "BasePathLookup: Timeout of RPC " << rpcId << endl;
00492 
00493     // decrease pending rpcs
00494     pendingRpcs--;
00495 
00496     // last rpc? yes-> send next rpc
00497     if ( pendingRpcs == 0 )
00498         sendRpc( 1 );
00499 }

void BasePathLookup::sendRpc ( int  num,
cMessage *  FindNodeExt = NULL 
) [private]

00503 {
00504     // path finished? yes -> quit
00505     if (finished)
00506         return;
00507 
00508     // check for maximum hop count
00509     if (lookup->hopCountMax && (hops >= lookup->hopCountMax)) {
00510         EV << "BasePathLookup::sendRpc(): Max hop count exceeded - "
00511            << "lookup failed!" << endl;
00512         finished = true;
00513         success = false;
00514         return;
00515     }
00516 
00517     // send rpc messages
00518     while ( num >= 0 && nextHops.size() != 0 ) {
00519 
00520         // get top node handle
00521         const NodeHandle& handle = nextHops.front();
00522 
00523         // check if node has already been visited? no ->
00524         if ( !lookup->getVisited( handle ) ) {
00525 
00526             // send rpc to node increase pending rpcs
00527             pendingRpcs++;
00528             num--;
00529             lookup->sendRpc( handle, createRpcMessage( findNodeExt ),
00530                              this, step );
00531         }
00532 
00533         // delete first element and continue
00534         nextHops.erase( nextHops.begin() );
00535     }
00536 
00537     // no rpc sent and no pending rpcs? -> failed
00538     if ( pendingRpcs == 0 ) {
00539         finished = true;
00540         success = false;
00541     }
00542 }


Friends And Related Function Documentation

friend class BaseLookup [friend]


Member Data Documentation

bool BasePathLookup::finished [protected]

int BasePathLookup::hops [protected]

BaseLookup* BasePathLookup::lookup [protected]

NodeVector BasePathLookup::nextHops [protected]

int BasePathLookup::pendingRpcs [protected]

int BasePathLookup::step [protected]

bool BasePathLookup::success [protected]


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:37:06 2007 for ITM OverSim by  doxygen 1.4.7