oversim::Koorde Class Reference

#include <Koorde.h>

Inheritance diagram for oversim::Koorde:

oversim::Chord BaseOverlay BaseRpc TopologyVis RpcListener

List of all members.


Detailed Description

Koorde overlay module.

Implementation of the Koorde KBR overlay as described in "Koorde: A simple degree-optimal distributed hash table" by M. Kaashoek and D. Karger

Author:
Jochen Schenk
See also:
Chord, ChordSuccessorList

Definition at line 50 of file Koorde.h.


Public Member Functions

virtual void initializeOverlay (int stage)
 Initializes derived-class-attributes.
virtual void handleTimerEvent (cMessage *msg)
 Processes "timer" self-messages.
virtual void handleUDPMessage (BaseOverlayMessage *msg)
 Processes messages from underlay.
virtual void recordOverlaySentStats (BaseOverlayMessage *msg)
 Collect overlay specific sent messages statistics.
virtual void finishOverlay ()
 collects statistical data in derived class
virtual void updateTooltip ()
 updates information shown in tk-environment

Protected Member Functions

virtual void changeState (int state)
 changes node state
virtual void handleDeBruijnTimerExpired (cMessage *msg)
 handle a expired join timer
virtual void handleFixFingersTimerExpired (cMessage *msg)
 handle a expired fix_fingers timer (dummy function)
virtual bool handleRpc (BaseCallMessage *msg)
 Processes Remote-Procedure-Call invokation messages.
virtual void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 This method is called if an RPC response has been received.
virtual void handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 This method is called if an RPC timeout has been reached.
virtual void handleRpcJoinResponse (JoinResponse *joinResponse)
 handle a received JOIN response
virtual void handleRpcDeBruijnRequest (DeBruijnCall *deBruinCall)
 handle a received DEBRUIJN request
virtual void handleRpcDeBruijnResponse (DeBruijnResponse *deBruijnResponse)
 handle a received DEBRUIJN response
virtual void handleDeBruijnTimeout (DeBruijnCall *deBruijnCall)
 handle a DEBRUIJN timeout
virtual NodeHandle findDeBruijnHop (const OverlayKey &destKey, KoordeFindNodeExtMessage *findNodeExt)
 returns the NodeHandle of the next hop to destination key using the de Bruijn list
NodeVector * findNode (const OverlayKey &key, int numRedundantNodes, int numSiblings, BaseOverlayMessage *msg)
 Implements the find node call.
virtual OverlayKey findStartKey (const OverlayKey &startKey, const OverlayKey &endKey, const OverlayKey &destKey)
 find a "good" routing key to destKey between startingKey and endKey with the longest matching prefix possible
virtual int findLongestMatch (const OverlayKey &srcKey, const OverlayKey &destKey)
 find maximal number of bits in which two keys match using right shifting
virtual const NodeHandle & walkDeBruijnList (const OverlayKey &key)
 Given a key the function checks if the key falls between two nodes in the de Bruijn list.
virtual const NodeHandle & walkSuccessorList (const OverlayKey &key)
 Given a key the function checks if the key falls between two nodes in the de successor list.
virtual void handleRpcStabilizeResponse (StabilizeResponse *stabilizeResponse)
 handles a received Stabilize response
virtual void rpcJoin (JoinCall *call)
 handles a received Join request
virtual void rpcNotify (NotifyCall *call)
 handles a received Notify request
virtual void handleRpcNotifyResponse (NotifyResponse *notifyResponse)
 handles a received Notify response
virtual void findFriendModules ()
 Sets the pointer to the successor list module.
virtual void initializeFriendModules ()
 Intializes the successor list.
virtual void predecessorIsDead ()
 The function is called after the predecessor node is dead and resets the bit indicating the predecessor has a De-Bruijn-Node set.
virtual void successorIsDead ()
 The function is called after the successor node is dead and resets the bit indicating the successor has a De-Bruijn-Node set.

Protected Attributes

int deBruijnDelay
 number of seconds between two de Bruijn algo calls
bool pingProtocol
 enable ping protocol?
int deBruijnNumber
 number of current nodes in de Bruijn list; depend on number of nodes in successor list
int deBruijnListSize
 maximal number of nodes in de Bruijn list
int shiftingBits
 number of bits concurrently shifted in one routing step
bool fastLookup
 enable fast lookup (using successor list)?
bool sucDeBruijnNodeSet
 flag is set if our successor has a de bruijn node
bool preDeBruijnNodeSet
 flag is set if our predecessor has a de bruijn node
bool useOtherLookup
 flag which is indicating that the optimization other lookup is enabled
bool useSucList
 flag which is indicating that the optimization using the successorlist is enabled
bool breakLookup
 flag is used during the recursive step when returning this node
bool firstTimer
 indicates if this is the first de bruijn timer
int deBruijnRetryTime
 time interval when the de bruijn call times out
int failedDBResponses
 number of failed responses to a de bruijn call
bool preOrSuc
 flag which indicates if the predecessor or successor is used as a springboard
int deBruijnCount
 number of de bruijn calls
int deBruijnBytesSent
 number of bytes sent during de bruijn calls
NodeHandle * deBruijnNodes
 List of de Bruijn nodes.
NodeHandle deBruijnNode
 Handle to our de Bruijn node.
cMessage * deBruijn_timer

Member Function Documentation

void oversim::Koorde::initializeOverlay ( int  stage  )  [virtual]

Initializes derived-class-attributes.


Initializes derived-class-attributes, called by BaseOverlay::initialize(). By default this method is called once. If more stages are needed one can overload numInitStages() and add more stages.

Parameters:
stage the init stage

Reimplemented from oversim::Chord.

Definition at line 37 of file Koorde.cc.

00038 {
00039     // because of IPAddressResolver, we need to wait until interfaces
00040     // are registered, address auto-assignment takes place etc.
00041     if(stage != MIN_STAGE_OVERLAY)
00042         return;
00043 
00044     // fetch some parameters
00045     deBruijnDelay = par("deBruijnDelay");
00046     deBruijnListSize = par("deBruijnListSize");
00047     shiftingBits = par("shiftingBits");
00048     useOtherLookup = par("useOtherLookup");
00049     useSucList = par("useSucList");
00050 
00051     // init flags
00052     sucDeBruijnNodeSet = false;
00053     preDeBruijnNodeSet = false;
00054     breakLookup = false;
00055     firstTimer = true;
00056     preOrSuc = false;
00057 
00058     // some local variables
00059     failedDBResponses = 0;
00060     deBruijnRetryTime = 20;
00061     deBruijnNumber = 0;
00062     deBruijnNodes = new NodeHandle[deBruijnListSize];
00063 
00064     // statistics
00065     deBruijnCount = 0;
00066     deBruijnBytesSent = 0;
00067 
00068     // add some watches
00069     WATCH(sucDeBruijnNodeSet);
00070     WATCH(deBruijnNumber);
00071     WATCH(deBruijnNode);
00072 
00073     //timer Messages
00074     deBruijn_timer = new cMessage("deBruijn_timer");
00075 
00076     Chord::initializeOverlay(stage);
00077 }

void oversim::Koorde::handleTimerEvent ( cMessage *  msg  )  [virtual]

Processes "timer" self-messages.

Parameters:
msg A self-message

Reimplemented from oversim::Chord.

Definition at line 105 of file Koorde.cc.

00106 {
00107     // catch DeBruijn timer
00108     if (msg->isName("deBruijn_timer"))
00109         handleDeBruijnTimerExpired(msg);
00110     else if (msg->isName("fixfingers_timer"))
00111         handleFixFingersTimerExpired(msg);
00112     else
00113         Chord::handleTimerEvent(msg);
00114 }

void oversim::Koorde::handleUDPMessage ( BaseOverlayMessage *  msg  )  [virtual]

Processes messages from underlay.

Parameters:
msg Message from UDP

Reimplemented from oversim::Chord.

Definition at line 186 of file Koorde.cc.

00187 {
00188     Chord::handleUDPMessage(msg);
00189 }

void oversim::Koorde::recordOverlaySentStats ( BaseOverlayMessage *  msg  )  [virtual]

Collect overlay specific sent messages statistics.

This method is called from BaseOverlay::sendMessageToUDP() for every overlay message that is sent by a node. Use this to collect statistical data for overlay protocol specific message types.

Parameters:
msg The overlay message to be sent to the UDP layer

Reimplemented from oversim::Chord.

Definition at line 674 of file Koorde.cc.

00675 {
00676     Chord::recordOverlaySentStats(msg);
00677 
00678     BaseOverlayMessage* innerMsg;
00679 
00680     if (msg->getType() == OVERLAYROUTE)
00681         innerMsg = dynamic_cast<BaseOverlayMessage*>(msg->getEncapsulatedMsg());
00682     else
00683         innerMsg = msg;
00684 
00685     switch (innerMsg->getType()) {
00686         case RPC: {
00687             if ((dynamic_cast<DeBruijnCall*>(innerMsg) != NULL) ||
00688                 (dynamic_cast<DeBruijnResponse*>(innerMsg) != NULL)) {
00689                 RECORD_STATS(deBruijnCount++; deBruijnBytesSent +=
00690                                  msg->getByteLength());
00691             }
00692         break;
00693         }
00694     }
00695 }

void oversim::Koorde::finishOverlay (  )  [virtual]

collects statistical data in derived class

Reimplemented from oversim::Chord.

Definition at line 654 of file Koorde.cc.

00655 {
00656     // destroy self timer messages
00657     cancelEvent(deBruijn_timer);
00658 
00659     delete deBruijn_timer;
00660 
00661     // statistics
00662     simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime);
00663 
00664     if(time != 0) {
00665         globalStatistics->addStdDev("Koorde: Sent DEBRUIJN Messages/s",
00666                                     deBruijnCount / time);
00667         globalStatistics->addStdDev("Koorde: Sent DEBRUIJN Bytes/s",
00668                                     deBruijnBytesSent / time);
00669     }
00670 
00671     Chord::finishOverlay();
00672 }

void oversim::Koorde::updateTooltip (  )  [virtual]

updates information shown in tk-environment

Reimplemented from oversim::Chord.

Definition at line 612 of file Koorde.cc.

Referenced by changeState(), handleDeBruijnTimeout(), handleDeBruijnTimerExpired(), handleRpcDeBruijnResponse(), handleRpcNotifyResponse(), handleRpcStabilizeResponse(), and rpcNotify().

00613 {
00614     //
00615     // Updates the tooltip display strings.
00616     //
00617 
00618     if (ev.isGUI()) {
00619         std::stringstream ttString;
00620 
00621         // show our predecessor, successor and de Bruijn node in tooltip
00622         ttString << "Pred "<< predecessorNode << endl << "This  "
00623                  << thisNode << endl
00624                  << "Suc   " << successorList->getSuccessor() << endl
00625                  << "DeBr " << deBruijnNode << endl;
00626         ttString << "List ";
00627 
00628         for (unsigned int i = 0; i < successorList->getSize(); i++) {
00629             ttString << successorList->getSuccessor(i).ip << " ";
00630         }
00631 
00632         ttString << endl;
00633         ttString << "DList ";
00634 
00635         for (int i = 0; i < deBruijnNumber; i++) {
00636             ttString << deBruijnNodes[i].ip << " ";
00637         }
00638 
00639         ttString << endl;
00640 
00641         getParentModule()->getParentModule()->
00642             getDisplayString().setTagArg("tt", 0, ttString.str().c_str());
00643         getParentModule()->getDisplayString().setTagArg("tt", 0,
00644                                                   ttString.str().c_str());
00645         getDisplayString().setTagArg("tt", 0, ttString.str().c_str());
00646 
00647         // draw an arrow to our current successor
00648         showOverlayNeighborArrow(successorList->getSuccessor(), true,
00649                                  "m=m,50,0,50,0;ls=red,1");
00650     }
00651 }

void oversim::Koorde::changeState ( int  state  )  [protected, virtual]

changes node state

Parameters:
state state to change to

Reimplemented from oversim::Chord.

Definition at line 79 of file Koorde.cc.

00080 {
00081     Chord::changeState(toState);
00082 
00083     switch(state) {
00084     case INIT:
00085         // init de Bruijn nodes
00086         deBruijnNode = NodeHandle::UNSPECIFIED_NODE;
00087         for (int i=0; i < deBruijnListSize; i++)
00088             deBruijnNodes[i] = NodeHandle::UNSPECIFIED_NODE;
00089         updateTooltip();
00090         break;
00091     case READY:
00092         // init de Bruijn Protocol
00093         cancelEvent(deBruijn_timer);
00094         scheduleAt(simTime() + deBruijnDelay, deBruijn_timer);
00095 
00096         // since we don't need the fixfingers protocol in Koorde cancel timer
00097         cancelEvent(fixfingers_timer);
00098         break;
00099     default:
00100         break;
00101     }
00102 
00103 }

void oversim::Koorde::handleDeBruijnTimerExpired ( cMessage *  msg  )  [protected, virtual]

handle a expired join timer

Parameters:
msg the timer self-message

Definition at line 117 of file Koorde.cc.

Referenced by handleTimerEvent().

00118 {
00119     if (state == READY) {
00120         OverlayKey lookup = thisNode.key << shiftingBits;
00121 
00122         if (lookup.isBetweenR(thisNode.key, successorList->getSuccessor().key)
00123                 || successorList->isEmpty()) {
00124 
00125             int sucNum = successorList->getSize();
00126             if (sucNum > deBruijnListSize)
00127                 sucNum = deBruijnListSize;
00128 
00129             deBruijnNode = thisNode;
00130             for (int i = 0; i < sucNum; i++) {
00131                 deBruijnNodes[i] = successorList->getSuccessor(i);
00132                 deBruijnNumber = i+1;
00133             }
00134 
00135             updateTooltip();
00136         } else {
00137             DeBruijnCall* call = new DeBruijnCall("DeBruijnCall");
00138             call->setDestKey(lookup);
00139             call->setBitLength(DEBRUIJNCALL_L(call));
00140 
00141             // if we don't have a de Bruijn node we use our successor
00142             // or our predecessor as a springboard if they have their
00143             // flags set or we didn't have a chance to get it
00144             if (deBruijnNode.isUnspecified()) {
00145                 if (firstTimer || (sucDeBruijnNodeSet && !preOrSuc)) {
00146                     sendRouteRpcCall(OVERLAY_COMP,
00147                                      successorList->getSuccessor(),
00148                                      call->getDestKey(), call, NULL,
00149                                      DEFAULT_ROUTING, deBruijnRetryTime);
00150                     firstTimer = false;
00151                 } else if (preOrSuc && preDeBruijnNodeSet) {
00152                     sendRouteRpcCall(OVERLAY_COMP,
00153                                      predecessorNode,
00154                                      call->getDestKey(), call, NULL,
00155                                      DEFAULT_ROUTING, deBruijnRetryTime);
00156                 } else {
00157                     sendRouteRpcCall(OVERLAY_COMP, call->getDestKey(),
00158                                      call, NULL, DEFAULT_ROUTING,
00159                                      deBruijnRetryTime);
00160 
00161                     EV << "[Koorde::handleDeBruijnTimerExpired() @ " << thisNode.ip
00162                        << " (" << thisNode.key.toString(16) << ")]\n"
00163                        << "    Have to route DeBruijnCall to destination key"
00164                        << endl;
00165                 }
00166             } else {
00167                 sendRouteRpcCall(OVERLAY_COMP, deBruijnNode,
00168                                  call->getDestKey(), call, NULL,
00169                                  DEFAULT_ROUTING, deBruijnRetryTime);
00170             }
00171 
00172         }
00173 
00174         cancelEvent(deBruijn_timer);
00175         scheduleAt(simTime() + deBruijnDelay, deBruijn_timer);
00176     }
00177 }

void oversim::Koorde::handleFixFingersTimerExpired ( cMessage *  msg  )  [protected, virtual]

handle a expired fix_fingers timer (dummy function)

Parameters:
msg the timer self-message

Reimplemented from oversim::Chord.

Definition at line 180 of file Koorde.cc.

Referenced by handleTimerEvent().

00181 {
00182     // just in case not all timers from Chord code could be canceled
00183 }

bool oversim::Koorde::handleRpc ( BaseCallMessage *  msg  )  [protected, virtual]

Processes Remote-Procedure-Call invokation messages.


This method should be overloaded when the overlay provides RPC functionality.

Returns:
true, if rpc has been handled

Reimplemented from oversim::Chord.

Definition at line 192 of file Koorde.cc.

00193 {
00194     if (state == READY) {
00195         // delegate messages
00196         RPC_SWITCH_START( msg )
00197         RPC_DELEGATE( DeBruijn, handleRpcDeBruijnRequest );
00198         RPC_SWITCH_END( )
00199 
00200         if (RPC_HANDLED) return true;
00201     } else {
00202         EV << "[Koorde::handleRpc() @ " << thisNode.ip
00203            << " (" << thisNode.key.toString(16) << ")]\n"
00204            << "    Received RPC call and state != READY!"
00205            << endl;
00206     }
00207 
00208     return Chord::handleRpc(msg);
00209 }

void oversim::Koorde::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 oversim::Chord.

Definition at line 211 of file Koorde.cc.

00214 {
00215     Chord::handleRpcResponse(msg, context, rpcId, rtt);
00216 
00217     RPC_SWITCH_START( msg )
00218     RPC_ON_RESPONSE( DeBruijn ) {
00219         handleRpcDeBruijnResponse(_DeBruijnResponse);
00220         EV << "[Koorde::handleRpcResponse() @ " << thisNode.ip
00221            << " (" << thisNode.key.toString(16) << ")]\n"
00222            << "    DeBruijn RPC Response received: id=" << rpcId
00223            << "\n    msg=" << *_DeBruijnResponse << " rtt=" << rtt
00224            << endl;
00225         break;
00226     }
00227     RPC_SWITCH_END( )
00228 }

void oversim::Koorde::handleRpcTimeout ( BaseCallMessage *  msg,
const TransportAddress &  dest,
cPolymorphic *  context,
int  rpcId,
const OverlayKey &  destKey 
) [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 oversim::Chord.

Definition at line 230 of file Koorde.cc.

00233 {
00234     Chord::handleRpcTimeout(msg, dest, context, rpcId, destKey);
00235 
00236     RPC_SWITCH_START( msg )
00237     RPC_ON_CALL( DeBruijn ) {
00238         handleDeBruijnTimeout(_DeBruijnCall);
00239         EV << "[Koorde::handleRpcTimeout() @ " << thisNode.ip
00240            << " (" << thisNode.key.toString(16) << ")]\n"
00241            << "    DeBruijn RPC Call timed out: id=" << rpcId
00242            << "\n    msg=" << *_DeBruijnCall
00243            << endl;
00244         break;
00245     }
00246     RPC_SWITCH_END( )
00247 }

void oversim::Koorde::handleRpcJoinResponse ( JoinResponse *  joinResponse  )  [protected, virtual]

handle a received JOIN response

Parameters:
joinResponse the message to process

Reimplemented from oversim::Chord.

Definition at line 262 of file Koorde.cc.

00263 {
00264     Chord::handleRpcJoinResponse(joinResponse);
00265 
00266     // has to be canceled in Koorde
00267     cancelEvent(fixfingers_timer);
00268 
00269     // immediate deBruijn protocol
00270     cancelEvent(deBruijn_timer);
00271     scheduleAt(simTime(), deBruijn_timer);
00272 }

void oversim::Koorde::handleRpcDeBruijnRequest ( DeBruijnCall *  deBruinCall  )  [protected, virtual]

handle a received DEBRUIJN request

Parameters:
deBruinCall the message to process

Definition at line 379 of file Koorde.cc.

Referenced by handleRpc().

00380 {
00381     // The key lies between thisNode and its predecessor and
00382     // because routing the message to the predecessor of a key
00383     // is near to impossible we set the deBruijnNodes here
00384     // and the information is as actual as the predecessor pointer
00385     if (deBruijnCall->getDestKey().isBetweenR(predecessorNode.key,
00386                                               thisNode.key)) {
00387         DeBruijnResponse* deBruijnResponse =
00388             new DeBruijnResponse("DeBruijnResponse");
00389 
00390         deBruijnResponse->setDBNode(predecessorNode);
00391 
00392         int sucNum = successorList->getSize() + 1;
00393         deBruijnResponse->setSucNum(sucNum);
00394         deBruijnResponse->setSucNodeArraySize(sucNum);
00395 
00396         deBruijnResponse->setSucNode(0, thisNode);
00397         for (int k = 1; k < sucNum; k++) {
00398             deBruijnResponse->setSucNode(k, successorList->getSuccessor(k-1));
00399         }
00400         deBruijnResponse->setBitLength(DEBRUIJNRESPONSE_L(deBruijnResponse));
00401 
00402         sendRpcResponse(deBruijnCall, deBruijnResponse);
00403     } else if (deBruijnCall->getDestKey().isBetweenR(thisNode.key,
00404                successorList->getSuccessor().key)) {
00405         error("Koorde::handleRpcDeBruijnRequest() - unknown error.");
00406     } else {
00407         error("Koorde::handleRpcDeBruijnRequest() - "
00408               "Request couldn't be delivered!");
00409     }
00410 }

void oversim::Koorde::handleRpcDeBruijnResponse ( DeBruijnResponse *  deBruijnResponse  )  [protected, virtual]

handle a received DEBRUIJN response

Parameters:
deBruijnResponse the message to process

Definition at line 412 of file Koorde.cc.

Referenced by handleRpcResponse().

00413 {
00414     int sucNum = deBruijnResponse->getSucNum();
00415     if (sucNum > deBruijnListSize)
00416         sucNum = deBruijnListSize;
00417 
00418     for (int i = 0; i < sucNum; i++) {
00419         deBruijnNodes[i] = deBruijnResponse->getSucNode(i);
00420         deBruijnNumber = i+1;
00421     }
00422 
00423     deBruijnNode = deBruijnResponse->getDBNode();
00424 
00425     updateTooltip();
00426 }

void oversim::Koorde::handleDeBruijnTimeout ( DeBruijnCall *  deBruijnCall  )  [protected, virtual]

handle a DEBRUIJN timeout

Parameters:
deBruijnCall the message which timed out

Definition at line 428 of file Koorde.cc.

Referenced by handleRpcTimeout().

00429 {
00430     if (failedDBResponses == stabilizeRetry) {
00431         failedDBResponses = 0;
00432         deBruijnNode = NodeHandle::UNSPECIFIED_NODE;
00433         preOrSuc = !preOrSuc;
00434     } else {
00435         failedDBResponses++;
00436     }
00437 
00438     updateTooltip();
00439     cancelEvent(deBruijn_timer);
00440     scheduleAt(simTime(), deBruijn_timer);
00441 }

NodeHandle oversim::Koorde::findDeBruijnHop ( const OverlayKey &  destKey,
KoordeFindNodeExtMessage *  findNodeExt 
) [protected, virtual]

returns the NodeHandle of the next hop to destination key using the de Bruijn list

Parameters:
destKey The destination key
findNodeExt The FindNodeExtensionMessage
Returns:
next hop to destination key

Definition at line 515 of file Koorde.cc.

Referenced by findNode().

00517 {
00518     // check if the route key falls in our responsibility or
00519     // else forward the message to our successor
00520     if (findNodeExt->getRouteKey().isBetweenR(thisNode.key,
00521         successorList->getSuccessor().key)) {
00522         if ((unsigned int)findNodeExt->getStep() > destKey.getLength())
00523             error("Broose::findDeBruijnHop - Bounding error: "
00524                   "trying to get non existing bit out of overlay key!");
00525 
00526         // updating the route key
00527         OverlayKey add = OverlayKey(destKey.getBit(destKey.getLength() -
00528                                                    findNodeExt->getStep()));
00529         for (int i = 1; i < shiftingBits; i++) {
00530             add = (add << 1) + OverlayKey(destKey.getBit(destKey.getLength() - findNodeExt->getStep() - i));
00531         }
00532 
00533         OverlayKey routeKey = (findNodeExt->getRouteKey()<<shiftingBits) + add;
00534         findNodeExt->setRouteKey(routeKey);
00535         findNodeExt->setStep(findNodeExt->getStep() + shiftingBits);
00536 
00537         if(deBruijnNode.isUnspecified()) {
00538             breakLookup = true;
00539             if (useSucList)
00540                 return walkSuccessorList(findNodeExt->getRouteKey());
00541             else
00542                 return successorList->getSuccessor();
00543         }
00544 
00545         // check if the new route key falls between our
00546         // de Bruijn node and its successor
00547         if (deBruijnNumber > 0) {
00548             if (findNodeExt->getRouteKey().isBetweenR(deBruijnNode.key,
00549                                                       deBruijnNodes[0].key)) {
00550                 return deBruijnNode;
00551             } else {
00552                 // otherwise check if the route key falls between
00553                 // our de Bruijn successors
00554                 NodeHandle nextHop = walkDeBruijnList(findNodeExt->
00555                                                       getRouteKey());
00556                 return nextHop;
00557             }
00558         } else {
00559             return deBruijnNode;
00560         }
00561     } else {
00562         breakLookup = true;
00563         // if optimization is set search the successor list and
00564         // de bruijn node to find "good" next hop
00565         if (useSucList) {
00566             if (!deBruijnNode.isUnspecified()) {
00567                 return walkSuccessorList(findNodeExt->getRouteKey());
00568             } else {
00569                 NodeHandle tmpHandle =
00570                     walkSuccessorList(findNodeExt->getRouteKey());
00571 
00572                 //todo: optimization - check complete deBruijnList
00573                 if (deBruijnNode.key.isBetween(tmpHandle.key,
00574                                                findNodeExt->getRouteKey())) {
00575                     return deBruijnNode;
00576                 } else {
00577                     return tmpHandle;
00578                 }
00579             }
00580         } else
00581             return successorList->getSuccessor();
00582     }
00583 }

NodeVector * oversim::Koorde::findNode ( const OverlayKey &  key,
int  numRedundantNodes,
int  numSiblings,
BaseOverlayMessage *  msg 
) [protected, virtual]

Implements the find node call.

This method simply returns the closest nodes known in the corresponding routing topology. If the node is a sibling for this key (isSiblingFor(key) = true), this method returns all numSiblings siblings, with the closest neighbor to the key first.

Parameters:
key The lookup key.
numRedundantNodes Maximum number of next hop nodes to return.
numSiblings number of siblings to return
msg A pointer to the BaseRouteMessage or FindNodeCall message of this lookup.
Returns:
NodeVector with closest nodes.

Reimplemented from oversim::Chord.

Definition at line 443 of file Koorde.cc.

00447 {
00448     NodeVector* nextHop = new NodeVector();
00449     KoordeFindNodeExtMessage *findNodeExt = NULL;
00450 
00451     if (state != READY)
00452         return nextHop;
00453 
00454     if (msg != NULL) {
00455         if (!msg->hasObject("findNodeExt")) {
00456             findNodeExt = new KoordeFindNodeExtMessage("findNodeExt");
00457 
00458             OverlayKey routeKey =
00459                 findStartKey(thisNode.key, successorList->getSuccessor().key,
00460                              key);
00461             int matchingBits = findLongestMatch(routeKey, key);
00462             findNodeExt->setRouteKey(routeKey);
00463             findNodeExt->setStep(matchingBits + 1);
00464             findNodeExt->setOtherLookup(false);
00465             findNodeExt->setBitLength(KOORDEFINDNODEEXTMESSAGE_L);
00466             findNodeExt->setSrcNode(thisNode);
00467             msg->addObject( findNodeExt );
00468         }
00469         findNodeExt = (KoordeFindNodeExtMessage*) msg->getObject("findNodeExt");
00470     }
00471 
00472     if (key.isUnspecified()) {
00473         error("Koorde::findNode() - direct Messaging is no longer in use.");
00474     } else if (key.isBetweenR(predecessorNode.key, thisNode.key)) {
00475         // the message is destined for this node
00476         nextHop->push_back(thisNode);
00477     } else if (key.isBetweenR(thisNode.key, successorList->getSuccessor().key)){
00478         // the message destined for our successor
00479         nextHop->push_back(successorList->getSuccessor());
00480     } else {
00481         // if useOtherLookup is enabled we try to use
00482         // our successor list to get to the key
00483         if (useOtherLookup) {
00484             NodeHandle tmpNode = walkSuccessorList(key);
00485             if (tmpNode !=
00486                   successorList->getSuccessor(successorList->getSize() - 1)) {
00487                 findNodeExt->setOtherLookup(true);
00488                 nextHop->push_back(tmpNode);
00489             } else if (findNodeExt->getOtherLookup() == true) {
00490                 nextHop->push_back(tmpNode);
00491             } else {
00492                 NodeHandle tmpHandle = findDeBruijnHop(key, findNodeExt);
00493                 if (tmpHandle != thisNode || breakLookup) {
00494                     nextHop->push_back(tmpHandle);
00495                     breakLookup = false;
00496                 } else {
00497                     return findNode(key, numRedundantNodes, numSiblings, msg);
00498                 }
00499             }
00500         } else {
00501             // find next hop using either the de Bruijn node and
00502             // its successors or our own successors
00503             NodeHandle tmpHandle = findDeBruijnHop(key, findNodeExt);
00504             if (tmpHandle != thisNode || breakLookup) {
00505                 nextHop->push_back(tmpHandle);
00506                 breakLookup = false;
00507             } else {
00508                 return findNode(key, numRedundantNodes, numSiblings, msg);
00509             }
00510         }
00511     }
00512     return nextHop;
00513 }

OverlayKey oversim::Koorde::findStartKey ( const OverlayKey &  startKey,
const OverlayKey &  endKey,
const OverlayKey &  destKey 
) [protected, virtual]

find a "good" routing key to destKey between startingKey and endKey with the longest matching prefix possible

Parameters:
startKey begin of the (key) interval
endKey end of the (key) interval
destKey destination key - should be matched as good as possible
Returns:
a "good" routing key to start from

Definition at line 697 of file Koorde.cc.

Referenced by findNode().

00700 {
00701     OverlayKey diffKey, newStart, tmpDest, newKey, powKey;
00702     int nBits;
00703 
00704     if (startKey == endKey)
00705         return startKey;
00706 
00707     diffKey = endKey - startKey;
00708     nBits = diffKey.log_2();
00709 
00710     while ((startKey.getLength() - nBits) % shiftingBits != 0) {
00711         nBits--;
00712     }
00713 
00714     newStart = startKey >> nBits;
00715     newStart = newStart << nBits;
00716 
00717     tmpDest = destKey >> (destKey.getLength() - nBits);
00718     newKey = tmpDest + newStart;
00719 
00720     // is the new constructed route key bigger than our start key return it
00721     if (newKey.isBetweenR(startKey, endKey)) {
00722         return newKey;
00723     }
00724 
00725     // If the part of the destination key smaller than the one of
00726     // the orginal key add pow(nBits) (this is the first bit where
00727     // the start key and end key differ) to the new constructed key
00728     // and check if it's beetween start and end key.
00729 
00730     newKey += powKey.pow2(nBits);
00731     if(newKey.isBetweenR(startKey, endKey)) {
00732         return newKey;
00733     }
00734 
00735     // this part should not be called
00736     error("Koorde::findStartKey()");
00737     return OverlayKey::UNSPECIFIED_KEY;
00738 }

int oversim::Koorde::findLongestMatch ( const OverlayKey &  srcKey,
const OverlayKey &  destKey 
) [protected, virtual]

find maximal number of bits in which two keys match using right shifting

Parameters:
srcKey the source key
destKey the destination key
Returns:
number of matching bits

Definition at line 740 of file Koorde.cc.

Referenced by findNode().

00742 {
00743     int keyLength = srcKey.getLength();
00744     bool equal = true;
00745 
00746     for (int i = keyLength; i>0; i--) {
00747         equal = true;
00748         for(int j = 1; j <= i; j++) {
00749             if (srcKey.getBit(i - j) != destKey.getBit(destKey.getLength() - j)) {
00750                 equal = false;
00751                 break;
00752             }
00753         }
00754 
00755         if (equal)
00756             return i;
00757 
00758     }
00759     return 0;
00760 }

const NodeHandle & oversim::Koorde::walkDeBruijnList ( const OverlayKey &  key  )  [protected, virtual]

Given a key the function checks if the key falls between two nodes in the de Bruijn list.

If no match is found the last node in the de Bruijn list is returned.

Parameters:
key the key to check
Returns:
either the node directly preceding key or the node which has the shortest distance to the key

Definition at line 586 of file Koorde.cc.

Referenced by findDeBruijnHop().

00587 {
00588     if (deBruijnNumber == 0)
00589         return NodeHandle::UNSPECIFIED_NODE;
00590 
00591     for (int i = 0; i < deBruijnNumber-1; i++) {
00592         if (key.isBetweenR(deBruijnNodes[i].key,deBruijnNodes[i+1].key)) {
00593             return deBruijnNodes[i];
00594         }
00595     }
00596 
00597     return deBruijnNodes[deBruijnNumber-1];
00598 }

const NodeHandle & oversim::Koorde::walkSuccessorList ( const OverlayKey &  key  )  [protected, virtual]

Given a key the function checks if the key falls between two nodes in the de successor list.

If no match is found the last node in the de successor list is returned.

Parameters:
key the key to check
Returns:
either the node directly preceding key or the node which has the shortest distance to the key

Definition at line 600 of file Koorde.cc.

Referenced by findDeBruijnHop(), and findNode().

00601 {
00602     for (unsigned int i = 0; i < successorList->getSize()-1; i++) {
00603         if (key.isBetweenR(successorList->getSuccessor(i).key,
00604                            successorList->getSuccessor(i+1).key)) {
00605             return successorList->getSuccessor(i);
00606         }
00607     }
00608 
00609     return successorList->getSuccessor(successorList->getSize()-1);
00610 }

void oversim::Koorde::handleRpcStabilizeResponse ( StabilizeResponse *  stabilizeResponse  )  [protected, virtual]

handles a received Stabilize response

Parameters:
stabilizeResponse the message to process

Reimplemented from oversim::Chord.

Definition at line 274 of file Koorde.cc.

00275 {
00276     // fetch the successor's predecessor
00277     NodeHandle predecessor = stabilizeResponse->getPreNode();
00278 
00279     // is the successor's predecessor a new successor for this node?
00280     if (successorList->isEmpty() ||
00281             predecessor.key.isBetween(thisNode.key,
00282                                       successorList->getSuccessor().key)) {
00283         // add the successor's predecessor to the successor list
00284         successorList->addSuccessor(predecessor);
00285         updateTooltip();
00286     }
00287 
00288     // compile NOTIFY RPC
00289     NotifyCall* notifyCall = new NotifyCall("NotifyCall");
00290 
00291     if (!deBruijnNode.isUnspecified()) {
00292         notifyCall->setPreDBNodeSet(true);
00293     } else {
00294         notifyCall->setPreDBNodeSet(false);
00295     }
00296 
00297     notifyCall->setBitLength(NOTIFYCALL_L(notifyCall));
00298     sendUdpRpcCall(successorList->getSuccessor(), notifyCall);
00299 }

void oversim::Koorde::rpcJoin ( JoinCall *  call  )  [protected, virtual]

handles a received Join request

Parameters:
call RPC Parameter Message

Reimplemented from oversim::Chord.

Definition at line 249 of file Koorde.cc.

00250 {
00251 //    std::cout << "rpcJoin" << std::endl;
00252 
00253     if (deBruijnNode.isUnspecified()) {
00254         delete joinCall;
00255 //        std::cout << "rpcJoin: no deBruijnNode!" << std::endl;
00256         return;
00257     }
00258 
00259     Chord::rpcJoin(joinCall);
00260 }

void oversim::Koorde::rpcNotify ( NotifyCall *  call  )  [protected, virtual]

handles a received Notify request

Parameters:
call the message to process

Reimplemented from oversim::Chord.

Definition at line 302 of file Koorde.cc.

00303 {
00304     // our predecessor seems to be alive
00305     missingPredecessorStabRequests = 0;
00306 
00307     NodeHandle newPredecessor = call->getSrcNode();
00308 
00309     // is the new predecessor closer than the current one?
00310     if (predecessorNode.isUnspecified() ||
00311             newPredecessor.key.isBetween(predecessorNode.key, thisNode.key)) {
00312 
00313         if ((predecessorNode.isUnspecified()) ||
00314             (newPredecessor != predecessorNode)) {
00315             // send update to application if we've got a new predecessor
00316             if (!predecessorNode.isUnspecified()) {
00317                 callUpdate(predecessorNode, false);
00318             }
00319             callUpdate(newPredecessor, true);
00320 
00321             // set up new predecessor
00322             predecessorNode = newPredecessor;
00323         }
00324 
00325         preDeBruijnNodeSet = call->getPreDBNodeSet();
00326         firstTimer = false;
00327         updateTooltip();
00328     }
00329 
00330     // needed if the predecessor doesn't change
00331     if (newPredecessor == predecessorNode)
00332         preDeBruijnNodeSet = call->getPreDBNodeSet();
00333 
00334     // compile NOTIFY response
00335     NotifyResponse* notifyResponse = new NotifyResponse("NotifyResponse");
00336 
00337     int sucNum = successorList->getSize();
00338 
00339     if (deBruijnNode.isUnspecified()) {
00340         notifyResponse->setSucDBNodeSet(false);
00341     } else {
00342         notifyResponse->setSucDBNodeSet(true);
00343     }
00344 
00345     notifyResponse->setSucNum(sucNum);
00346     notifyResponse->setSucNodeArraySize(sucNum);
00347 
00348     for (int k = 0; k < sucNum; k++) {
00349         notifyResponse->setSucNode(k, successorList->getSuccessor(k));
00350     }
00351 
00352     notifyResponse->setBitLength(NOTIFYRESPONSE_L(notifyResponse));
00353 
00354     sendRpcResponse(call, notifyResponse);
00355 }

void oversim::Koorde::handleRpcNotifyResponse ( NotifyResponse *  notifyResponse  )  [protected, virtual]

handles a received Notify response

Parameters:
notifyResponse the message to process

Reimplemented from oversim::Chord.

Definition at line 358 of file Koorde.cc.

00359 {
00360     if (successorList->getSuccessor() != notifyResponse->getSrcNode()) {
00361         EV << "[Koorde::handleRpcNotifyResponse() @ " << thisNode.ip
00362            << " (" << thisNode.key.toString(16) << ")]\n"
00363            << "    The srcNode of the received NotifyResponse is not our current successor"
00364            << endl;
00365         return;
00366     }
00367 
00368     // replace our successor list by our successor's successor list
00369     successorList->updateList(notifyResponse);
00370 
00371     // store if the de bruijn node of my successor is set, also
00372     // reset firstTimer flag
00373     sucDeBruijnNodeSet = notifyResponse->getSucDBNodeSet();
00374     firstTimer = false;
00375 
00376     updateTooltip();
00377 }

void oversim::Koorde::findFriendModules (  )  [protected, virtual]

Sets the pointer to the successor list module.

Reimplemented from oversim::Chord.

Definition at line 762 of file Koorde.cc.

00763 {
00764     successorList = check_and_cast<ChordSuccessorList*>
00765                     (getParentModule()->getSubmodule("successorList"));
00766 }

void oversim::Koorde::initializeFriendModules (  )  [protected, virtual]

Intializes the successor list.

Reimplemented from oversim::Chord.

Definition at line 768 of file Koorde.cc.

00769 {
00770     // initialize successor list
00771     successorList->initializeList(par("successorListSize"), thisNode, this);
00772 }

void oversim::Koorde::predecessorIsDead (  )  [protected, virtual]

The function is called after the predecessor node is dead and resets the bit indicating the predecessor has a De-Bruijn-Node set.

Reimplemented from oversim::Chord.

Definition at line 774 of file Koorde.cc.

00775 {
00776     preDeBruijnNodeSet = false;
00777     //todo: this info could be used to remove predecessor node
00778     //      from de bruijn successor list or even as our de bruijn node
00779 }

void oversim::Koorde::successorIsDead (  )  [protected, virtual]

The function is called after the successor node is dead and resets the bit indicating the successor has a De-Bruijn-Node set.

Reimplemented from oversim::Chord.

Definition at line 781 of file Koorde.cc.

00782 {
00783     sucDeBruijnNodeSet = false;
00784     //todo: this info could be used to remove successor node
00785     //      from de bruijn successor list or even as our de bruijn node
00786 }


Member Data Documentation

number of seconds between two de Bruijn algo calls

Definition at line 75 of file Koorde.h.

Referenced by changeState(), handleDeBruijnTimerExpired(), and initializeOverlay().

enable ping protocol?

Definition at line 76 of file Koorde.h.

number of current nodes in de Bruijn list; depend on number of nodes in successor list

Definition at line 77 of file Koorde.h.

Referenced by findDeBruijnHop(), handleDeBruijnTimerExpired(), handleRpcDeBruijnResponse(), initializeOverlay(), updateTooltip(), and walkDeBruijnList().

maximal number of nodes in de Bruijn list

Definition at line 78 of file Koorde.h.

Referenced by changeState(), handleDeBruijnTimerExpired(), handleRpcDeBruijnResponse(), and initializeOverlay().

number of bits concurrently shifted in one routing step

Definition at line 79 of file Koorde.h.

Referenced by findDeBruijnHop(), findStartKey(), handleDeBruijnTimerExpired(), and initializeOverlay().

bool oversim::Koorde::fastLookup [protected]

enable fast lookup (using successor list)?

Definition at line 80 of file Koorde.h.

flag is set if our successor has a de bruijn node

Definition at line 81 of file Koorde.h.

Referenced by handleDeBruijnTimerExpired(), handleRpcNotifyResponse(), initializeOverlay(), and successorIsDead().

flag is set if our predecessor has a de bruijn node

Definition at line 82 of file Koorde.h.

Referenced by handleDeBruijnTimerExpired(), initializeOverlay(), predecessorIsDead(), and rpcNotify().

flag which is indicating that the optimization other lookup is enabled

Definition at line 83 of file Koorde.h.

Referenced by findNode(), and initializeOverlay().

bool oversim::Koorde::useSucList [protected]

flag which is indicating that the optimization using the successorlist is enabled

Definition at line 84 of file Koorde.h.

Referenced by findDeBruijnHop(), and initializeOverlay().

bool oversim::Koorde::breakLookup [protected]

flag is used during the recursive step when returning this node

Definition at line 85 of file Koorde.h.

Referenced by findDeBruijnHop(), findNode(), and initializeOverlay().

bool oversim::Koorde::firstTimer [protected]

indicates if this is the first de bruijn timer

Definition at line 86 of file Koorde.h.

Referenced by handleDeBruijnTimerExpired(), handleRpcNotifyResponse(), initializeOverlay(), and rpcNotify().

time interval when the de bruijn call times out

Definition at line 87 of file Koorde.h.

Referenced by handleDeBruijnTimerExpired(), and initializeOverlay().

number of failed responses to a de bruijn call

Definition at line 88 of file Koorde.h.

Referenced by handleDeBruijnTimeout(), and initializeOverlay().

bool oversim::Koorde::preOrSuc [protected]

flag which indicates if the predecessor or successor is used as a springboard

Definition at line 89 of file Koorde.h.

Referenced by handleDeBruijnTimeout(), handleDeBruijnTimerExpired(), and initializeOverlay().

number of de bruijn calls

Definition at line 92 of file Koorde.h.

Referenced by finishOverlay(), initializeOverlay(), and recordOverlaySentStats().

number of bytes sent during de bruijn calls

Definition at line 93 of file Koorde.h.

Referenced by finishOverlay(), initializeOverlay(), and recordOverlaySentStats().

cMessage* oversim::Koorde::deBruijn_timer [protected]


The documentation for this class was generated from the following files:

Generated on Wed Mar 25 16:32:55 2009 for OverSim by  doxygen 1.5.5