oversim::Chord Class Reference

#include <Chord.h>

Inheritance diagram for oversim::Chord:

BaseOverlay BaseRpc TopologyVis RpcListener oversim::Koorde

List of all members.


Detailed Description

Chord overlay module.

Implementation of the Chord KBR overlay as described in "Chord: A Scalable Peer-to-Peer Lookup Protocol for Inetnet Applications" by I. Stoica et al. published in Transactions on Networking.

Author:
Markus Mauch, Ingmar Baumgart
See also:
BaseOverlay, ChordFingerTable, ChordSuccessorList

Definition at line 46 of file Chord.h.


Public Member Functions

 Chord ()
virtual ~Chord ()
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
OverlayKey distance (const OverlayKey &x, const OverlayKey &y) const
 This method should implement the distance between two keys.
virtual void updateTooltip ()
 updates information shown in tk-environment

Protected Member Functions

virtual void changeState (int toState)
 changes node state
virtual void handleJoinTimerExpired (cMessage *msg)
 handle a expired join timer
virtual void handleStabilizeTimerExpired (cMessage *msg)
 handle a expired stabilize timer
virtual void handleFixFingersTimerExpired (cMessage *msg)
 handle a expired fix_fingers timer
virtual void handleNewSuccessorHint (ChordMessage *chordMsg)
 handle a received NEWSUCCESSORHINT message
virtual NodeVector * closestPreceedingNode (const OverlayKey &key)
 looks up the finger table and returns the closest preceeding node.
virtual void findFriendModules ()
 Assigns the finger table and succesesor list module to our reference.
virtual void initializeFriendModules ()
 initializes finger table and successor list
virtual bool handleRpc (BaseCallMessage *msg)
 Processes Remote-Procedure-Call invokation messages.
NodeVector * findNode (const OverlayKey &key, int numRedundantNodes, int numSiblings, BaseOverlayMessage *msg)
 Implements the find node call.
virtual void joinOverlay ()
 Join the overlay with a given nodeID in thisNode.key.
virtual void joinForeignPartition (const NodeHandle &node)
 Join another overlay partition with the given node as bootstrap node.
virtual bool isSiblingFor (const NodeHandle &node, const OverlayKey &key, int numSiblings, bool *err)
 Query if a node is among the siblings for a given key.
int getMaxNumSiblings ()
 Query the maximum number of siblings (nodes close to a key) that are maintained by this overlay protocol.
int getMaxNumRedundantNodes ()
 Query the maximum number of redundant next hop nodes that are returned by findNode().
void rpcFixfingers (FixfingersCall *call)
 Fixfingers Remote-Procedure-Call.
virtual void rpcJoin (JoinCall *call)
 Join Remote-Procedure-Call.
virtual void rpcNotify (NotifyCall *call)
 NOTIFY Remote-Procedure-Call.
void rpcStabilize (StabilizeCall *call)
 STABILIZE Remote-Procedure-Call.
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 pingResponse (PingResponse *pingResponse, cPolymorphic *context, int rpcId, simtime_t rtt)
virtual void pingTimeout (PingCall *pingCall, const TransportAddress &dest, cPolymorphic *context, int rpcId)
virtual void handleRpcJoinResponse (JoinResponse *joinResponse)
virtual void handleRpcNotifyResponse (NotifyResponse *notifyResponse)
virtual void handleRpcStabilizeResponse (StabilizeResponse *stabilizeResponse)
virtual void handleRpcFixfingersResponse (FixfingersResponse *fixfingersResponse, double rtt=-1)
bool handleFailedNode (const TransportAddress &failed)
 Handles a failed node.
virtual void predecessorIsDead ()
virtual void successorIsDead ()

Protected Attributes

int joinRetry
int stabilizeRetry
 // retries before neighbor considered failed
double joinDelay
double stabilizeDelay
 stabilize interval (secs)
double fixfingersDelay
double checkPredecessorDelay
int successorListSize
bool aggressiveJoinMode
 use modified (faster) JOIN protocol
bool extendedFingerTable
unsigned int numFingerCandidates
bool proximityRouting
bool memorizeFailedSuccessor
bool newChordFingerTable
bool mergeOptimizationL1
bool mergeOptimizationL2
bool mergeOptimizationL3
bool mergeOptimizationL4
cMessage * join_timer
cMessage * stabilize_timer
cMessage * fixfingers_timer
cMessage * checkPredecessor_timer
int joinCount
int stabilizeCount
int fixfingersCount
int notifyCount
int newsuccessorhintCount
int joinBytesSent
int stabilizeBytesSent
int notifyBytesSent
int fixfingersBytesSent
int newsuccessorhintBytesSent
int keyLength
 length of an overlay key in bits
int missingPredecessorStabRequests
 missing StabilizeCall msgs
NodeHandle predecessorNode
 predecessor of this node
TransportAddress bootstrapNode
 node used to bootstrap
ChordFingerTable * fingerTable
 pointer to this node's finger table
ChordSuccessorList * successorList
 pointer to this node's successor list

Private Attributes

TransportAddress failedSuccessor

Friends

class ChordSuccessorList
class ChordFingerTable

Constructor & Destructor Documentation

oversim::Chord::Chord (  ) 

Definition at line 41 of file Chord.cc.

00042 {
00043     stabilize_timer = fixfingers_timer = join_timer = NULL;
00044     fingerTable = NULL;
00045 }

oversim::Chord::~Chord (  )  [virtual]

Definition at line 119 of file Chord.cc.

00120 {
00121     // destroy self timer messages
00122     cancelAndDelete(join_timer);
00123     cancelAndDelete(stabilize_timer);
00124     cancelAndDelete(fixfingers_timer);
00125     cancelAndDelete(checkPredecessor_timer);
00126 }


Member Function Documentation

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

Reimplemented in oversim::Koorde.

Definition at line 48 of file Chord.cc.

Referenced by oversim::Koorde::initializeOverlay().

00049 {
00050     // because of IPAddressResolver, we need to wait until interfaces
00051     // are registered, address auto-assignment takes place etc.
00052     if (stage != MIN_STAGE_OVERLAY)
00053         return;
00054 
00055     if (iterativeLookupConfig.merge == true) {
00056         throw cRuntimeError("Chord::initializeOverlay(): "
00057               "Chord doesn't work with iterativeLookupConfig.merge = true!");
00058     }
00059 
00060     // Chord provides KBR services
00061     kbr = true;
00062 
00063     // fetch some parameters
00064     useCommonAPIforward = par("useCommonAPIforward");
00065     successorListSize = par("successorListSize");
00066     joinRetry = par("joinRetry");
00067     stabilizeRetry = par("stabilizeRetry");
00068     joinDelay = par("joinDelay");
00069     stabilizeDelay = par("stabilizeDelay");
00070     fixfingersDelay = par("fixfingersDelay");
00071     checkPredecessorDelay = par("checkPredecessorDelay");
00072     aggressiveJoinMode = par("aggressiveJoinMode");
00073     extendedFingerTable = par("extendedFingerTable");
00074     numFingerCandidates = par("numFingerCandidates");
00075     proximityRouting = par("proximityRouting");
00076     memorizeFailedSuccessor = par("memorizeFailedSuccessor");
00077 
00078     // merging optimizations
00079     mergeOptimizationL1 = par("mergeOptimizationL1");
00080     mergeOptimizationL2 = par("mergeOptimizationL2");
00081     mergeOptimizationL3 = par("mergeOptimizationL3");
00082     mergeOptimizationL4 = par("mergeOptimizationL4");
00083 
00084     keyLength = OverlayKey::getLength();
00085     missingPredecessorStabRequests = 0;
00086 
00087     // statistics
00088     joinCount = 0;
00089     stabilizeCount = 0;
00090     fixfingersCount = 0;
00091     notifyCount = 0;
00092     newsuccessorhintCount = 0;
00093     joinBytesSent = 0;
00094     stabilizeBytesSent = 0;
00095     notifyBytesSent = 0;
00096     fixfingersBytesSent = 0;
00097     newsuccessorhintBytesSent = 0;
00098 
00099     failedSuccessor = TransportAddress::UNSPECIFIED_NODE;
00100 
00101     // find friend modules
00102     findFriendModules();
00103 
00104     // add some watches
00105     WATCH(predecessorNode);
00106     WATCH(thisNode);
00107     WATCH(bootstrapNode);
00108     WATCH(joinRetry);
00109     WATCH(missingPredecessorStabRequests);
00110 
00111     // self-messages
00112     join_timer = new cMessage("join_timer");
00113     stabilize_timer = new cMessage("stabilize_timer");
00114     fixfingers_timer = new cMessage("fixfingers_timer");
00115     checkPredecessor_timer = new cMessage("checkPredecessor_timer");
00116 }

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

Processes "timer" self-messages.

Parameters:
msg A self-message

Reimplemented from BaseOverlay.

Reimplemented in oversim::Koorde.

Definition at line 256 of file Chord.cc.

Referenced by oversim::Koorde::handleTimerEvent().

00257 {
00258     // catch JOIN timer
00259     if (msg == join_timer) {
00260         handleJoinTimerExpired(msg);
00261     }
00262     // catch STABILIZE timer
00263     else if (msg == stabilize_timer) {
00264         handleStabilizeTimerExpired(msg);
00265     }
00266     // catch FIX_FINGERS timer
00267     else if (msg == fixfingers_timer) {
00268         handleFixFingersTimerExpired(msg);
00269     }
00270     // catch CHECK_PREDECESSOR timer
00271     else if (msg == checkPredecessor_timer) {
00272         cancelEvent(checkPredecessor_timer);
00273         scheduleAt(simTime() + checkPredecessorDelay,
00274                    checkPredecessor_timer);
00275         if (!predecessorNode.isUnspecified()) pingNode(predecessorNode);
00276     }
00277     // unknown self message
00278     else {
00279         error("Chord::handleTimerEvent(): received self message of "
00280               "unknown type!");
00281     }
00282 }

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

Processes messages from underlay.

Parameters:
msg Message from UDP

Reimplemented from BaseOverlay.

Reimplemented in oversim::Koorde.

Definition at line 285 of file Chord.cc.

Referenced by oversim::Koorde::handleUDPMessage().

00286 {
00287     ChordMessage* chordMsg = check_and_cast<ChordMessage*>(msg);
00288     switch(chordMsg->getCommand()) {
00289     case NEWSUCCESSORHINT:
00290         handleNewSuccessorHint(chordMsg);
00291         break;
00292     default:
00293         error("handleUDPMessage(): Unknown message type!");
00294         break;
00295     }
00296 
00297     delete chordMsg;
00298 }

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

Reimplemented in oversim::Koorde.

Definition at line 681 of file Chord.cc.

Referenced by oversim::Koorde::recordOverlaySentStats().

00682 {
00683     BaseOverlayMessage* innerMsg;
00684 
00685     if (msg->getType() == OVERLAYROUTE)
00686         innerMsg = dynamic_cast<BaseOverlayMessage*>(msg->getEncapsulatedMsg());
00687     else
00688         innerMsg = msg;
00689 
00690     switch (innerMsg->getType()) {
00691 
00692     case OVERLAYSIGNALING: {
00693         ChordMessage* chordMsg = dynamic_cast<ChordMessage*>(innerMsg);
00694         switch(chordMsg->getCommand()) {
00695         case NEWSUCCESSORHINT:
00696             RECORD_STATS(newsuccessorhintCount++; newsuccessorhintBytesSent +=
00697                              msg->getByteLength());
00698             break;
00699         }
00700         break;
00701     }
00702 
00703     case RPC: {
00704         if ((dynamic_cast<StabilizeCall*>(innerMsg) != NULL) ||
00705             (dynamic_cast<StabilizeResponse*>(innerMsg) != NULL)) {
00706             RECORD_STATS(stabilizeCount++; stabilizeBytesSent +=
00707                              msg->getByteLength());
00708         } else if ((dynamic_cast<NotifyCall*>(innerMsg) != NULL) ||
00709                    (dynamic_cast<NotifyResponse*>(innerMsg) != NULL)) {
00710             RECORD_STATS(notifyCount++; notifyBytesSent +=
00711                              msg->getByteLength());
00712         } else if ((dynamic_cast<FixfingersCall*>(innerMsg) != NULL) ||
00713                    (dynamic_cast<FixfingersResponse*>(innerMsg) != NULL)) {
00714             RECORD_STATS(fixfingersCount++; fixfingersBytesSent +=
00715                              msg->getByteLength());
00716         } else if ((dynamic_cast<JoinCall*>(innerMsg) != NULL) ||
00717                    (dynamic_cast<JoinResponse*>(innerMsg) != NULL)) {
00718             RECORD_STATS(joinCount++; joinBytesSent += msg->getByteLength());
00719         }
00720         break;
00721     }
00722     }
00723 }

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

collects statistical data in derived class

Reimplemented from BaseOverlay.

Reimplemented in oversim::Koorde.

Definition at line 726 of file Chord.cc.

Referenced by oversim::Koorde::finishOverlay().

00727 {
00728     // remove this node from the bootstrap list
00729     bootstrapList->removeBootstrapNode(thisNode);
00730 
00731     simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime);
00732     if(time == 0) return;
00733 
00734     globalStatistics->addStdDev("Chord: Sent JOIN Messages/s",
00735                                 joinCount / time);
00736     globalStatistics->addStdDev("Chord: Sent NEWSUCCESSORHINT Messages/s",
00737                                 newsuccessorhintCount / time);
00738     globalStatistics->addStdDev("Chord: Sent STABILIZE Messages/s",
00739                                 stabilizeCount / time);
00740     globalStatistics->addStdDev("Chord: Sent NOTIFY Messages/s",
00741                                 notifyCount / time);
00742     globalStatistics->addStdDev("Chord: Sent FIX_FINGERS Messages/s",
00743                                 fixfingersCount / time);
00744     globalStatistics->addStdDev("Chord: Sent JOIN Bytes/s",
00745                                 joinBytesSent / time);
00746     globalStatistics->addStdDev("Chord: Sent NEWSUCCESSORHINT Bytes/s",
00747                                 newsuccessorhintBytesSent / time);
00748     globalStatistics->addStdDev("Chord: Sent STABILIZE Bytes/s",
00749                                 stabilizeBytesSent / time);
00750     globalStatistics->addStdDev("Chord: Sent NOTIFY Bytes/s",
00751                                 notifyBytesSent / time);
00752     globalStatistics->addStdDev("Chord: Sent FIX_FINGERS Bytes/s",
00753                                 fixfingersBytesSent / time);
00754 }

OverlayKey oversim::Chord::distance ( const OverlayKey &  x,
const OverlayKey &  y 
) const [virtual]

This method should implement the distance between two keys.

It may be overloaded to implement a new metric. The default implementation uses the standard-metric d = abs(x-y).

Parameters:
x Left-hand-side Key
y Right-hand-side key
Returns:
OverlayKey Distance between x and y

Reimplemented from BaseOverlay.

Definition at line 1363 of file Chord.cc.

01364 {
01365     return KeyUniRingMetric().distance(x, y);
01366 }

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

updates information shown in tk-environment

Reimplemented in oversim::Koorde.

Definition at line 1340 of file Chord.cc.

Referenced by changeState(), handleFailedNode(), handleNewSuccessorHint(), handleRpcJoinResponse(), handleRpcNotifyResponse(), handleRpcStabilizeResponse(), handleStabilizeTimerExpired(), pingTimeout(), rpcJoin(), and rpcNotify().

01341 {
01342     if (ev.isGUI()) {
01343         std::stringstream ttString;
01344 
01345         // show our predecessor and successor in tooltip
01346         ttString << predecessorNode << endl << thisNode << endl
01347                  << successorList->getSuccessor();
01348 
01349         getParentModule()->getParentModule()->getDisplayString().
01350         setTagArg("tt", 0, ttString.str().c_str());
01351         getParentModule()->getDisplayString().
01352         setTagArg("tt", 0, ttString.str().c_str());
01353         getDisplayString().setTagArg("tt", 0, ttString.str().c_str());
01354 
01355         // draw an arrow to our current successor
01356         showOverlayNeighborArrow(successorList->getSuccessor(), true,
01357                                  "m=m,50,0,50,0;ls=red,1");
01358         showOverlayNeighborArrow(predecessorNode, false,
01359                                  "m=m,50,100,50,100;ls=green,1");
01360     }
01361 }

void oversim::Chord::changeState ( int  toState  )  [protected, virtual]

changes node state

Parameters:
toState state to change to

Reimplemented in oversim::Koorde.

Definition at line 154 of file Chord.cc.

Referenced by oversim::Koorde::changeState(), handleJoinTimerExpired(), handleRpcJoinResponse(), and joinOverlay().

00155 {
00156     //
00157     // Defines tasks to be executed when a state change occurs.
00158     //
00159 
00160     switch (toState) {
00161     case INIT:
00162         state = INIT;
00163 
00164         setOverlayReady(false);
00165 
00166         if (thisNode.key.isUnspecified()) {
00167             thisNode.key = OverlayKey::random();
00168             callUpdate(thisNode, true);
00169         }
00170 
00171         // initialize predecessor pointer
00172         predecessorNode = NodeHandle::UNSPECIFIED_NODE;
00173 
00174         // initialize finger table and successor list
00175         initializeFriendModules();
00176 
00177         updateTooltip();
00178 
00179         // debug message
00180         if (debugOutput) {
00181             EV << "[Chord::changeState() @ " << thisNode.ip
00182             << " (" << thisNode.key.toString(16) << ")]\n"
00183             << "    Entered INIT stage"
00184             << endl;
00185         }
00186 
00187         getParentModule()->getParentModule()->bubble("Enter INIT state.");
00188         break;
00189 
00190     case BOOTSTRAP:
00191         state = BOOTSTRAP;
00192 
00193         // initiate bootstrap process
00194         cancelEvent(join_timer);
00195         // workaround: prevent notificationBoard from taking
00196         // ownership of join_timer message
00197         take(join_timer);
00198         scheduleAt(simTime(), join_timer);
00199 
00200         // debug message
00201         if (debugOutput) {
00202             EV << "[Chord::changeState() @ " << thisNode.ip
00203             << " (" << thisNode.key.toString(16) << ")]\n"
00204             << "    Entered BOOTSTRAP stage"
00205             << endl;
00206         }
00207         getParentModule()->getParentModule()->bubble("Enter BOOTSTRAP state.");
00208 
00209         // find a new bootstrap node and enroll to the bootstrap list
00210         bootstrapNode = bootstrapList->getBootstrapNode();
00211 
00212         // is this the first node?
00213         if (bootstrapNode.isUnspecified()) {
00214             // create new cord ring
00215             assert(predecessorNode.isUnspecified());
00216             bootstrapNode = thisNode;
00217             changeState(READY);
00218             updateTooltip();
00219         }
00220         break;
00221 
00222     case READY:
00223         state = READY;
00224 
00225         setOverlayReady(true);
00226 
00227         // initiate stabilization protocol
00228         cancelEvent(stabilize_timer);
00229         scheduleAt(simTime() + stabilizeDelay, stabilize_timer);
00230 
00231         // initiate finger repair protocol
00232         cancelEvent(fixfingers_timer);
00233         scheduleAt(simTime() + fixfingersDelay,
00234                    fixfingers_timer);
00235 
00236         // initiate predecessor check
00237         cancelEvent(checkPredecessor_timer);
00238         if (checkPredecessorDelay > 0) {
00239             scheduleAt(simTime() + checkPredecessorDelay,
00240                        checkPredecessor_timer);
00241         }
00242 
00243         // debug message
00244         if (debugOutput) {
00245             EV << "[Chord::changeState() @ " << thisNode.ip
00246             << " (" << thisNode.key.toString(16) << ")]\n"
00247             << "    Entered READY stage"
00248             << endl;
00249         }
00250         getParentModule()->getParentModule()->bubble("Enter READY state.");
00251         break;
00252     }
00253 }

void oversim::Chord::handleJoinTimerExpired ( cMessage *  msg  )  [protected, virtual]

handle a expired join timer

Parameters:
msg the timer self-message

Definition at line 758 of file Chord.cc.

Referenced by handleTimerEvent().

00759 {
00760     // only process timer, if node is not bootstrapped yet
00761     if (state == READY)
00762         return;
00763 
00764     // enter state BOOTSTRAP
00765     if (state != BOOTSTRAP)
00766         changeState(BOOTSTRAP);
00767 
00768     // change bootstrap node from time to time
00769     joinRetry--;
00770     if (joinRetry == 0) {
00771         joinRetry = par("joinRetry");
00772         changeState(BOOTSTRAP);
00773         return;
00774     }
00775 
00776     // call JOIN RPC
00777     JoinCall* call = new JoinCall("JoinCall");
00778     call->setBitLength(JOINCALL_L(call));
00779 
00780     RoutingType routingType = (defaultRoutingType == FULL_RECURSIVE_ROUTING ||
00781                                defaultRoutingType == RECURSIVE_SOURCE_ROUTING) ?
00782                               SEMI_RECURSIVE_ROUTING : defaultRoutingType;
00783 
00784     sendRouteRpcCall(OVERLAY_COMP, bootstrapNode, thisNode.key,
00785                      call, NULL, routingType, joinDelay);
00786 
00787     // schedule next bootstrap process in the case this one fails
00788     cancelEvent(join_timer);
00789     scheduleAt(simTime() + joinDelay, msg);
00790 }

void oversim::Chord::handleStabilizeTimerExpired ( cMessage *  msg  )  [protected, virtual]

handle a expired stabilize timer

Parameters:
msg the timer self-message

Definition at line 793 of file Chord.cc.

Referenced by handleTimerEvent().

00794 {
00795     if (state != READY)
00796         return;
00797 
00798     // alternative predecessor check
00799     if ((checkPredecessorDelay == 0) &&
00800         (missingPredecessorStabRequests >= stabilizeRetry)) {
00801         // predecessor node seems to be dead
00802         // remove it from the predecessor / successor lists
00803         //successorList->removeSuccessor(predecessorNode);
00804         predecessorIsDead();
00805         callUpdate(predecessorNode, false);
00806         predecessorNode = NodeHandle::UNSPECIFIED_NODE;
00807         missingPredecessorStabRequests = 0;
00808         updateTooltip();
00809     }
00810 
00811     if (!successorList->isEmpty()) {
00812         // call STABILIZE RPC
00813         StabilizeCall* call = new StabilizeCall("StabilizeCall");
00814         call->setBitLength(STABILIZECALL_L(call));
00815 
00816         sendUdpRpcCall(successorList->getSuccessor(), call);
00817 
00818         missingPredecessorStabRequests++;
00819     }
00820 
00821     // check if fingers are still alive and remove unreachable finger nodes
00822     if (mergeOptimizationL4) {
00823         OverlayKey offset;
00824         for (uint32_t nextFinger = 0; nextFinger < thisNode.key.getLength();
00825              nextFinger++) {
00826             offset = OverlayKey::pow2(nextFinger);
00827 
00828             // send message only for non-trivial fingers
00829             if (offset > successorList->getSuccessor().key - thisNode.key) {
00830                 if ((fingerTable->getFinger(nextFinger)).isUnspecified()) {
00831                     continue;
00832                 } else {
00833                     pingNode(fingerTable->getFinger(nextFinger), -1, 0, NULL,
00834                              NULL, NULL, nextFinger);
00835                 }
00836             }
00837         }
00838     }
00839 
00840     // schedule next stabilization process
00841     cancelEvent(stabilize_timer);
00842     scheduleAt(simTime() + stabilizeDelay, msg);
00843 }

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

handle a expired fix_fingers timer

Parameters:
msg the timer self-message

Reimplemented in oversim::Koorde.

Definition at line 846 of file Chord.cc.

Referenced by handleTimerEvent().

00847 {
00848     if ((state != READY) || successorList->isEmpty())
00849         return;
00850 
00851     OverlayKey offset, lookupKey;
00852     for (uint32_t nextFinger = 0; nextFinger < thisNode.key.getLength();
00853          nextFinger++) {
00854         // calculate "n + 2^(i - 1)"
00855         offset = OverlayKey::pow2(nextFinger);
00856         lookupKey = thisNode.key + offset;
00857 
00858         // send message only for non-trivial fingers
00859         if (offset > successorList->getSuccessor().key - thisNode.key) {
00860             // call FIXFINGER RPC
00861             FixfingersCall* call = new FixfingersCall("FixfingersCall");
00862             call->setFinger(nextFinger);
00863             call->setBitLength(FIXFINGERSCALL_L(call));
00864 
00865             sendRouteRpcCall(OVERLAY_COMP, lookupKey, call, NULL,
00866                              DEFAULT_ROUTING, fixfingersDelay);
00867         } else {
00868             // delete trivial fingers (points to the successor node)
00869 #if 0
00870             // memory optimized finger table
00871             // still seems to contain a bug (slightly different simulation results) => disabled for now
00872             fingerTable->removeFinger(nextFinger);
00873 #else                
00874             fingerTable->setFinger(nextFinger, successorList->getSuccessor());
00875 #endif
00876         }
00877     }
00878 
00879     // schedule next finger repair process
00880     cancelEvent(fixfingers_timer);
00881     scheduleAt(simTime() + fixfingersDelay, msg);
00882 }

void oversim::Chord::handleNewSuccessorHint ( ChordMessage *  chordMsg  )  [protected, virtual]

handle a received NEWSUCCESSORHINT message

Parameters:
chordMsg the message to process

Definition at line 885 of file Chord.cc.

Referenced by handleUDPMessage().

00886 {
00887     NewSuccessorHintMessage* newSuccessorHintMsg =
00888         check_and_cast<NewSuccessorHintMessage*>(chordMsg);
00889 
00890     // fetch the successor's predecessor
00891     NodeHandle predecessor = newSuccessorHintMsg->getPreNode();
00892 
00893     // is the successor's predecessor a new successor for this node?
00894     if (predecessor.key.isBetween(thisNode.key,
00895                                   successorList->getSuccessor().key)
00896         || (thisNode.key == successorList->getSuccessor().key)) {
00897         // add the successor's predecessor to the successor list
00898         successorList->addSuccessor(predecessor);
00899         updateTooltip();
00900     }
00901 
00902     // if the successor node reports a new successor, put it into the
00903     // successor list and start stabilizing
00904     if (mergeOptimizationL3) {
00905         if (successorList->getSuccessor() == predecessor) {
00906             StabilizeCall *call = new StabilizeCall("StabilizeCall");
00907             call->setBitLength(STABILIZECALL_L(call));
00908 
00909             sendUdpRpcCall(predecessor, call);
00910         } else {
00911             if (successorList->getSuccessor() == newSuccessorHintMsg->
00912                                                                getSrcNode()) {
00913 
00914                 StabilizeCall *call = new StabilizeCall("StabilizeCall");
00915                 call->setBitLength(STABILIZECALL_L(call));
00916 
00917                 sendUdpRpcCall(predecessor, call);
00918             }
00919         }
00920     }
00921 }

NodeVector * oversim::Chord::closestPreceedingNode ( const OverlayKey &  key  )  [protected, virtual]

looks up the finger table and returns the closest preceeding node.

Parameters:
key key to find the closest preceeding node for
Returns:
node vector of the closest preceeding nodes to key

Definition at line 602 of file Chord.cc.

Referenced by findNode().

00603 {
00604     NodeHandle tempHandle = NodeHandle::UNSPECIFIED_NODE;
00605 
00606     // find the closest preceding node in the successor list
00607     for (int j = successorList->getSize() - 1; j >= 0; j--) {
00608         if(successorList->getSuccessor(j).key.isBetweenR(thisNode.key, key)) {
00609             tempHandle = successorList->getSuccessor(j);
00610             break;
00611         }
00612     }
00613 
00614     if(tempHandle.isUnspecified()) {
00615         std::stringstream temp;
00616         temp << "Chord::closestPreceedingNode(): Successor list broken "
00617              << thisNode.key << " " << key;
00618         throw cRuntimeError(temp.str().c_str());
00619     }
00620 
00621     NodeVector* nextHop;
00622 
00623     /*if(tempHandle.isUnspecified()) {
00624         nextHop = new NodeVector();
00625         return nextHop;
00626     }*/
00627 
00628     for (int i = fingerTable->getSize() - 1; i >= 0; i--) {
00629         if (fingerTable->getFinger(i).key.isBetweenLR(tempHandle.key, key)) {
00630             if(!extendedFingerTable) {
00631                 nextHop = new NodeVector();
00632                 nextHop->push_back(fingerTable->getFinger(i));
00633 
00634                 EV << "[Chord::closestPreceedingNode() @ " << thisNode.ip
00635                    << " (" << thisNode.key.toString(16) << ")]\n"
00636                    << "    ClosestPreceedingNode: node " << thisNode
00637                    << " for key " << key << "\n"
00638                    << "    finger " << fingerTable->getFinger(i).key
00639                    << " better than \n"
00640                    << "    " << tempHandle.key
00641                    << endl;
00642                 return nextHop;
00643             } else {
00644                 return fingerTable->getFinger(i, key);
00645             }
00646         }
00647     }
00648 
00649     nextHop = new NodeVector();
00650     EV << "[Chord::closestPreceedingNode() @ " << thisNode.ip
00651        << " (" << thisNode.key.toString(16) << ")]\n"
00652        << "    No finger found"
00653        << endl;
00654 
00655     // if no finger is found lookup the rest of the successor list
00656     for(int i = successorList->getSize() - 1; i >= 0
00657         && nextHop->size() <= numFingerCandidates ; i--) {
00658         if(successorList->getSuccessor(i).key.isBetween(thisNode.key, key)) {
00659             nextHop->push_back(successorList->getSuccessor(i));
00660         }
00661     }
00662 
00663     if(nextHop->size() != 0)
00664         return nextHop;
00665 
00666     // if this is the first and only node on the ring, it is responsible
00667     if ((predecessorNode.isUnspecified()) &&
00668         (successorList->getSuccessor() == thisNode)) {
00669         nextHop->push_back(thisNode);
00670         return nextHop;
00671     }
00672 
00673     // if there is still no node found return NodeHandle::UNSPECIFIED_NODE
00674     std::stringstream temp("Error in Chord::closestPreceedingNode()!\n");
00675     temp << thisNode.key << " " << key;
00676     error(temp.str().c_str());
00677     nextHop->push_back(NodeHandle::UNSPECIFIED_NODE);
00678     return nextHop;
00679 }

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

Assigns the finger table and succesesor list module to our reference.

Reimplemented in oversim::Koorde.

Definition at line 1320 of file Chord.cc.

Referenced by initializeOverlay().

01321 {
01322     fingerTable = check_and_cast<ChordFingerTable*>
01323                   (getParentModule()->getSubmodule("fingerTable"));
01324 
01325     successorList = check_and_cast<ChordSuccessorList*>
01326                     (getParentModule()->getSubmodule("successorList"));
01327 }

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

initializes finger table and successor list

Reimplemented in oversim::Koorde.

Definition at line 1330 of file Chord.cc.

Referenced by changeState().

01331 {
01332     // initialize finger table
01333     fingerTable->initializeTable(thisNode.key.getLength(), thisNode, this);
01334 
01335     // initialize successor list
01336     successorList->initializeList(par("successorListSize"), thisNode, this);
01337 }

bool oversim::Chord::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 BaseRpc.

Reimplemented in oversim::Koorde.

Definition at line 301 of file Chord.cc.

Referenced by oversim::Koorde::handleRpc().

00302 {
00303     if (state != READY) {
00304         EV << "[Chord::handleRpc() @ " << thisNode.ip
00305            << " (" << thisNode.key.toString(16) << ")]\n"
00306            << "    Received RPC call and state != READY"
00307            << endl;
00308         return false;
00309     }
00310 
00311     // delegate messages
00312     RPC_SWITCH_START( msg )
00313     // RPC_DELEGATE( <messageName>[Call|Response], <methodToCall> )
00314     RPC_DELEGATE( Join, rpcJoin );
00315     RPC_DELEGATE( Notify, rpcNotify );
00316     RPC_DELEGATE( Stabilize, rpcStabilize );
00317     RPC_DELEGATE( Fixfingers, rpcFixfingers );
00318     RPC_SWITCH_END( )
00319 
00320     return RPC_HANDLED;
00321 }

NodeVector * oversim::Chord::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 BaseOverlay.

Reimplemented in oversim::Koorde.

Definition at line 548 of file Chord.cc.

00552 {
00553     bool err;
00554     NodeVector* nextHop;
00555 
00556     if (state != READY)
00557         return new NodeVector();
00558 
00559     if (successorList->isEmpty() && !predecessorNode.isUnspecified()) {
00560         throw new cRuntimeError("Chord: Node is READY, has a "
00561                                 "predecessor but no successor!");
00562         joinOverlay();
00563         return new NodeVector();
00564     }
00565 
00566     // if key is unspecified, the message is for this node
00567     if (key.isUnspecified()) {
00568         nextHop = new NodeVector();
00569         nextHop->push_back(thisNode);
00570     }
00571 
00572     // the message is destined for this node
00573     else if (isSiblingFor(thisNode, key, 1, &err)) {
00574         nextHop = new NodeVector();
00575         nextHop->push_back(thisNode);
00576         for (uint32_t i = 0; i < successorList->getSize(); i++) {
00577             nextHop->push_back(successorList->getSuccessor(i));
00578         }
00579         nextHop->downsizeTo(numSiblings);
00580     }
00581 
00582     // the message destined for our successor
00583     else if (key.isBetweenR(thisNode.key,
00584                             successorList->getSuccessor().key)) {
00585         nextHop = new NodeVector();
00586         for (uint32_t i = 0; i < successorList->getSize(); i++) {
00587             nextHop->push_back(successorList->getSuccessor(i));
00588         }
00589         nextHop->downsizeTo(numRedundantNodes);
00590     }
00591 
00592     // find next hop with finger table and/or successor list
00593     else {
00594         nextHop = closestPreceedingNode(key);
00595         nextHop->downsizeTo(numRedundantNodes);
00596     }
00597 
00598     return nextHop;
00599 }

void oversim::Chord::joinOverlay (  )  [protected, virtual]

Join the overlay with a given nodeID in thisNode.key.

Join the overlay with a given nodeID in thisNode.key. This method may be called by an application to join the overlay with a specific nodeID. It is also called if the node's IP address changes.

Reimplemented from BaseOverlay.

Definition at line 130 of file Chord.cc.

Referenced by findNode(), and handleRpcTimeout().

00131 {
00132     changeState(INIT);
00133     changeState(BOOTSTRAP);
00134 }

void oversim::Chord::joinForeignPartition ( const NodeHandle &  node  )  [protected, virtual]

Join another overlay partition with the given node as bootstrap node.

Join another overlay partition with the given node as bootstrap node. This method is called to join a foreign overlay partition and start the merging process.

Parameters:
node The foreign bootstrap node

Reimplemented from BaseOverlay.

Definition at line 137 of file Chord.cc.

00138 {
00139     Enter_Method_Silent();
00140 
00141     // create a join call and sent to the bootstrap node.
00142     JoinCall *call = new JoinCall("JoinCall");
00143     call->setBitLength(JOINCALL_L(call));
00144 
00145     RoutingType routingType = (defaultRoutingType == FULL_RECURSIVE_ROUTING ||
00146                                defaultRoutingType == RECURSIVE_SOURCE_ROUTING) ?
00147                               SEMI_RECURSIVE_ROUTING : defaultRoutingType;
00148 
00149     sendRouteRpcCall(OVERLAY_COMP, node, thisNode.key,
00150                      call, NULL, routingType, joinDelay);
00151 }

bool oversim::Chord::isSiblingFor ( const NodeHandle &  node,
const OverlayKey &  key,
int  numSiblings,
bool *  err 
) [protected, virtual]

Query if a node is among the siblings for a given key.

Query if a node is among the siblings for a given key. This means, that the nodeId of this node is among the closest numSiblings nodes to the key and that by a local findNode() call all other siblings to this key can be retrieved.

Parameters:
node the NodeHandle
key destination key
numSiblings The nodes knows all numSiblings nodes close to this key
err return false if the range could not be determined
Returns:
bool true, if the node is responsible for the key.

Reimplemented from BaseOverlay.

Definition at line 429 of file Chord.cc.

Referenced by findNode().

00433 {
00434     if (key.isUnspecified())
00435         error("Chord::isSiblingFor(): key is unspecified!");
00436 
00437     if (state != READY) {
00438         *err = true;
00439         return false;
00440     }
00441 
00442     if (numSiblings > getMaxNumSiblings()) {
00443         opp_error("Chord::isSiblingFor(): numSiblings too big!");
00444     }
00445     // set default number of siblings to consider
00446     if (numSiblings == -1) numSiblings = getMaxNumSiblings();
00447 
00448     // if this is the first and only node on the ring, it is responsible
00449     if ((predecessorNode.isUnspecified()) && (node == thisNode)) {
00450         if(successorList->isEmpty() || (node.key == key)) {
00451             *err = false;
00452             return true;
00453         } else {
00454             *err = true;
00455             return false;
00456         }
00457     }
00458 
00459     if ((node == thisNode)
00460          && (key.isBetweenR(predecessorNode.key, thisNode.key))) {
00461 
00462         *err = false;
00463         return true;
00464     }
00465 
00466     NodeHandle prevNode = predecessorNode;
00467     NodeHandle curNode;
00468 
00469     for (int i = -1; i < (int)successorList->getSize();
00470          i++, prevNode = curNode) {
00471 
00472         if (i < 0) {
00473             curNode = thisNode;
00474         } else {
00475             curNode = successorList->getSuccessor(i);
00476         }
00477 
00478         if (node == curNode) {
00479             // is the message destined for curNode?
00480             if (key.isBetweenR(prevNode.key, curNode.key)) {
00481                 if (numSiblings <= ((int)successorList->getSize() - i)) {
00482                     *err = false;
00483                     return true;
00484                 } else {
00485                     *err = true;
00486                     return false;
00487                 }
00488             } else {
00489                 // the key doesn't directly belong to this node, but
00490                 // the node could be a sibling for this key
00491                 if (numSiblings <= 1) {
00492                     *err = false;
00493                     return false;
00494                 } else {
00495                     // In Chord we don't know if we belong to the
00496                     // replicaSet of one of our predecessors
00497                     *err = true;
00498                     return false;
00499                 }
00500             }
00501         }
00502     }
00503 
00504     // node is not in our neighborSet
00505     *err = true;
00506     return false;
00507 }

int oversim::Chord::getMaxNumSiblings (  )  [protected, virtual]

Query the maximum number of siblings (nodes close to a key) that are maintained by this overlay protocol.

Returns:
int number of siblings.

Reimplemented from BaseOverlay.

Definition at line 418 of file Chord.cc.

Referenced by isSiblingFor().

00419 {
00420     return successorListSize;
00421 }

int oversim::Chord::getMaxNumRedundantNodes (  )  [protected, virtual]

Query the maximum number of redundant next hop nodes that are returned by findNode().

Returns:
int number of redundant nodes returned by findNode().

Reimplemented from BaseOverlay.

Definition at line 423 of file Chord.cc.

00424 {
00425     return extendedFingerTable ? numFingerCandidates : 1;
00426 }

void oversim::Chord::rpcFixfingers ( FixfingersCall *  call  )  [protected]

Fixfingers Remote-Procedure-Call.

Parameters:
call RPC Parameter Message

Definition at line 1214 of file Chord.cc.

Referenced by handleRpc().

01215 {
01216     FixfingersResponse* fixfingersResponse =
01217         new FixfingersResponse("FixfingersResponse");
01218 
01219     fixfingersResponse->setSucNodeArraySize(1);
01220     fixfingersResponse->setSucNode(0, thisNode);
01221 
01222     if (extendedFingerTable) {
01223         fixfingersResponse->setSucNodeArraySize(((successorList->getSize() + 1
01224                                                 < numFingerCandidates + 1)
01225                                                 ? successorList->getSize() + 1
01226                                                 : numFingerCandidates + 1));
01227         for (unsigned int i = 0;
01228             i < (((successorList->getSize()) < numFingerCandidates)
01229                  ? (successorList->getSize()) : numFingerCandidates); i++) {
01230 
01231             assert(!successorList->getSuccessor(i).isUnspecified());
01232             fixfingersResponse->setSucNode(i + 1,
01233                                            successorList->getSuccessor(i));
01234         }
01235     }
01236     fixfingersResponse->setFinger(call->getFinger());
01237     fixfingersResponse->setBitLength(FIXFINGERSRESPONSE_L(fixfingersResponse));
01238 
01239     sendRpcResponse(call, fixfingersResponse);
01240 }

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

Join Remote-Procedure-Call.

Parameters:
call RPC Parameter Message

Reimplemented in oversim::Koorde.

Definition at line 924 of file Chord.cc.

Referenced by handleRpc(), and oversim::Koorde::rpcJoin().

00925 {
00926     NodeHandle requestor = joinCall->getSrcNode();
00927 
00928     // compile successor list
00929     JoinResponse* joinResponse =
00930         new JoinResponse("JoinResponse");
00931 
00932     int sucNum = successorList->getSize();
00933     joinResponse->setSucNum(sucNum);
00934     joinResponse->setSucNodeArraySize(sucNum);
00935 
00936     for (int k = 0; k < sucNum; k++) {
00937         joinResponse->setSucNode(k, successorList->getSuccessor(k));
00938     }
00939 
00940     // sent our predecessor as hint to the joining node
00941     if (predecessorNode.isUnspecified() && successorList->isEmpty()) {
00942         // we are the only node in the ring
00943         joinResponse->setPreNode(thisNode);
00944     } else {
00945         joinResponse->setPreNode(predecessorNode);
00946     }
00947 
00948     joinResponse->setBitLength(JOINRESPONSE_L(joinResponse));
00949 
00950     sendRpcResponse(joinCall, joinResponse);
00951 
00952     if (aggressiveJoinMode) {
00953         // aggressiveJoinMode differs from standard join operations:
00954         // 1. set our predecessor pointer to the joining node
00955         // 2. send our old predecessor as hint in JoinResponse msgs
00956         // 3. send a NEWSUCCESSORHINT to our old predecessor to update
00957         //    its successor pointer
00958 
00959         // send NEWSUCCESSORHINT to our old predecessor
00960 
00961         if (!predecessorNode.isUnspecified()) {
00962             NewSuccessorHintMessage* newSuccessorHintMsg =
00963                 new NewSuccessorHintMessage("NEWSUCCESSORHINT");
00964             newSuccessorHintMsg->setCommand(NEWSUCCESSORHINT);
00965 
00966             newSuccessorHintMsg->setSrcNode(thisNode);
00967             newSuccessorHintMsg->setPreNode(requestor);
00968             newSuccessorHintMsg->
00969             setBitLength(NEWSUCCESSORHINT_L(newSuccessorHintMsg));
00970 
00971             sendMessageToUDP(predecessorNode, newSuccessorHintMsg);
00972         }
00973 
00974         if (predecessorNode.isUnspecified() || (predecessorNode != requestor)) {
00975             // send update to application if we've got a new predecessor
00976             if (!predecessorNode.isUnspecified()) {
00977                 callUpdate(predecessorNode, false);
00978             }
00979             callUpdate(requestor, true);
00980 
00981             // the requestor is our new predecessor
00982             predecessorNode = requestor;
00983         }
00984     }
00985 
00986     // if we don't have a successor, the requestor is also our new successor
00987     if (successorList->isEmpty())
00988         successorList->addSuccessor(requestor);
00989 
00990     updateTooltip();
00991 }

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

NOTIFY Remote-Procedure-Call.

Parameters:
call RPC Parameter Message

Reimplemented in oversim::Koorde.

Definition at line 1102 of file Chord.cc.

Referenced by handleRpc().

01103 {
01104     // our predecessor seems to be alive
01105     if (!predecessorNode.isUnspecified() &&
01106         call->getSrcNode() == predecessorNode) {
01107         missingPredecessorStabRequests = 0;
01108     }
01109 
01110     bool newPredecessorSet = false;
01111 
01112     NodeHandle newPredecessor = call->getSrcNode();
01113 
01114     // is the new predecessor closer than the current one?
01115     if (predecessorNode.isUnspecified() ||
01116         newPredecessor.key.isBetween(predecessorNode.key, thisNode.key) ||
01117         (!call->getFailed().isUnspecified() &&
01118          call->getFailed() == predecessorNode)) {
01119 
01120         if ((predecessorNode.isUnspecified()) ||
01121             (newPredecessor != predecessorNode)) {
01122             // send update to application if we've got a new predecessor
01123             if (!predecessorNode.isUnspecified()) {
01124                 callUpdate(predecessorNode, false);
01125             }
01126             callUpdate(newPredecessor, true);
01127 
01128             // inform the original predecessor about the new predecessor
01129             if (mergeOptimizationL1) {
01130                 if (!predecessorNode.isUnspecified()) {
01131                     NewSuccessorHintMessage *newSuccessorHintMsg =
01132                         new NewSuccessorHintMessage("NEWSUCCESSORHINT");
01133                     newSuccessorHintMsg->setCommand(NEWSUCCESSORHINT);
01134 
01135                     newSuccessorHintMsg->setSrcNode(thisNode);
01136                     newSuccessorHintMsg->setPreNode(newPredecessor);
01137                     newSuccessorHintMsg->
01138                         setBitLength(NEWSUCCESSORHINT_L(newSuccessorHintMsg));
01139                     sendMessageToUDP(predecessorNode, newSuccessorHintMsg);
01140                 }
01141             }
01142             // set up new predecessor
01143             predecessorNode = newPredecessor;
01144             if (successorList->isEmpty()) {
01145                 successorList->addSuccessor(newPredecessor);
01146             }
01147             updateTooltip();
01148 
01149             newPredecessorSet = true;
01150         }
01151     }
01152 
01153     // compile NOTIFY response
01154     NotifyResponse* notifyResponse = new NotifyResponse("NotifyResponse");
01155 
01156     int sucNum = successorList->getSize();
01157     notifyResponse->setSucNum(sucNum);
01158     notifyResponse->setSucNodeArraySize(sucNum);
01159 
01160     // can't accept the notify sender as predecessor,
01161     // tell it about my correct predecessor
01162     if (mergeOptimizationL3) {
01163         if (!newPredecessorSet && (predecessorNode != newPredecessor)) {
01164 
01165             notifyResponse->setPreNode(predecessorNode);
01166             notifyResponse->setPreNodeSet(false);
01167         } else {
01168             notifyResponse->setPreNodeSet(true);
01169         }
01170     }
01171 
01172     for (int k = 0; k < sucNum; k++) {
01173         notifyResponse->setSucNode(k, successorList->getSuccessor(k));
01174     }
01175 
01176     notifyResponse->setBitLength(NOTIFYRESPONSE_L(notifyResponse));
01177 
01178     sendRpcResponse(call, notifyResponse);
01179 }

void oversim::Chord::rpcStabilize ( StabilizeCall *  call  )  [protected]

STABILIZE Remote-Procedure-Call.

Parameters:
call RPC Parameter Message

Definition at line 1061 of file Chord.cc.

Referenced by handleRpc().

01062 {
01063     // our predecessor seems to be alive
01064     if (!predecessorNode.isUnspecified() &&
01065         call->getSrcNode() == predecessorNode) {
01066         missingPredecessorStabRequests = 0;
01067     }
01068 
01069     // reply with StabilizeResponse message
01070     StabilizeResponse* stabilizeResponse =
01071         new StabilizeResponse("StabilizeResponse");
01072     stabilizeResponse->setPreNode(predecessorNode);
01073     stabilizeResponse->setBitLength(STABILIZERESPONSE_L(stabilizeResponse));
01074 
01075     sendRpcResponse(call, stabilizeResponse);
01076 }

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

Reimplemented in oversim::Koorde.

Definition at line 323 of file Chord.cc.

Referenced by oversim::Koorde::handleRpcResponse().

00326 {
00327     RPC_SWITCH_START(msg)
00328     RPC_ON_RESPONSE( Join ) {
00329         handleRpcJoinResponse(_JoinResponse);
00330         EV << "[Chord::handleRpcResponse() @ " << thisNode.ip
00331         << " (" << thisNode.key.toString(16) << ")]\n"
00332         << "    Received a Join RPC Response: id=" << rpcId << "\n"
00333         << "    msg=" << *_JoinResponse << " rtt=" << rtt
00334         << endl;
00335         break;
00336     }
00337     RPC_ON_RESPONSE( Notify ) {
00338         handleRpcNotifyResponse(_NotifyResponse);
00339         EV << "[Chord::handleRpcResponse() @ " << thisNode.ip
00340         << " (" << thisNode.key.toString(16) << ")]\n"
00341         << "    Received a Notify RPC Response: id=" << rpcId << "\n"
00342         << "    msg=" << *_NotifyResponse << " rtt=" << rtt
00343         << endl;
00344         break;
00345     }
00346     RPC_ON_RESPONSE( Stabilize ) {
00347         handleRpcStabilizeResponse(_StabilizeResponse);
00348         EV << "[Chord::handleRpcResponse() @ " << thisNode.ip
00349         << " (" << thisNode.key.toString(16) << ")]\n"
00350         << "    Received a Stabilize RPC Response: id=" << rpcId << "\n"
00351         << "    msg=" << *_StabilizeResponse << " rtt=" << rtt
00352         << endl;
00353         break;
00354     }
00355     RPC_ON_RESPONSE( Fixfingers ) {
00356         handleRpcFixfingersResponse(_FixfingersResponse, SIMTIME_DBL(rtt));
00357         EV << "[Chord::handleRpcResponse() @ " << thisNode.ip
00358         << " (" << thisNode.key.toString(16) << ")]\n"
00359         << "    Received a Fixfingers RPC Response: id=" << rpcId << "\n"
00360         << "    msg=" << *_FixfingersResponse << " rtt=" << rtt
00361         << endl;
00362         break;
00363     }
00364     RPC_SWITCH_END( )
00365 }

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

Reimplemented in oversim::Koorde.

Definition at line 367 of file Chord.cc.

Referenced by oversim::Koorde::handleRpcTimeout().

00371 {
00372     RPC_SWITCH_START(msg)
00373     RPC_ON_CALL( FindNode ) {
00374         EV << "[Chord::handleRpcTimeout() @ " << thisNode.ip
00375         << " (" << thisNode.key.toString(16) << ")]\n"
00376         << "    FindNode RPC Call timed out: id=" << rpcId << "\n"
00377         << "    msg=" << *_FindNodeCall
00378         << endl;
00379         break;
00380     }
00381     RPC_ON_CALL( Join ) {
00382         EV << "[Chord::handleRpcTimeout() @ " << thisNode.ip
00383         << " (" << thisNode.key.toString(16) << ")]\n"
00384         << "    Join RPC Call timed out: id=" << rpcId << "\n"
00385         << "    msg=" << *_JoinCall
00386         << endl;
00387         break;
00388     }
00389     RPC_ON_CALL( Notify ) {
00390         EV << "[Chord::handleRpcTimeout() @ " << thisNode.ip
00391         << " (" << thisNode.key.toString(16) << ")]\n"
00392         << "    Notify RPC Call timed out: id=" << rpcId << "\n"
00393         << "    msg=" << *_NotifyCall
00394         << endl;
00395         if (!handleFailedNode(dest)) joinOverlay();
00396         break;
00397     }
00398     RPC_ON_CALL( Stabilize ) {
00399         EV << "[Chord::handleRpcTimeout() @ " << thisNode.ip
00400         << " (" << thisNode.key.toString(16) << ")]\n"
00401         << "    Stabilize RPC Call timed out: id=" << rpcId << "\n"
00402         << "    msg=" << *_StabilizeCall
00403         << endl;
00404         if (!handleFailedNode(dest)) joinOverlay();
00405         break;
00406     }
00407     RPC_ON_CALL( Fixfingers ) {
00408         EV << "[Chord::handleRpcTimeout() @ " << thisNode.ip
00409         << " (" << thisNode.key.toString(16) << ")]\n"
00410         << "    Fixfingers RPC Call timed out: id=" << rpcId << "\n"
00411         << "    msg=" << *_FixfingersCall
00412         << endl;
00413         break;
00414     }
00415     RPC_SWITCH_END( )
00416 }

void oversim::Chord::pingResponse ( PingResponse *  pingResponse,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
) [protected, virtual]

Reimplemented from BaseRpc.

Definition at line 1289 of file Chord.cc.

01291 {
01292     EV << "[Chord::pingResponse() @ " << thisNode.ip
01293        << " (" << thisNode.key.toString(16) << ")]\n"
01294        << "    Received a Ping RPC Response: id=" << rpcId << "\n"
01295        << "    msg=" << *pingResponse << " rtt=" << rtt
01296        << endl;
01297 
01298     if (rpcId != -1)
01299         fingerTable->updateFinger(rpcId, pingResponse->getSrcNode(), rtt);
01300 }

void oversim::Chord::pingTimeout ( PingCall *  pingCall,
const TransportAddress &  dest,
cPolymorphic *  context,
int  rpcId 
) [protected, virtual]

Reimplemented from BaseRpc.

Definition at line 1302 of file Chord.cc.

01305 {
01306     EV << "[Chord::pingTimeout() @ " << thisNode.ip
01307        << " (" << thisNode.key.toString(16) << ")]\n"
01308        << "    Ping RPC timeout: id=" << rpcId << endl;
01309 
01310     if (!predecessorNode.isUnspecified() && dest == predecessorNode) {
01311         predecessorIsDead();
01312         callUpdate(predecessorNode, false);
01313         predecessorNode = NodeHandle::UNSPECIFIED_NODE;
01314         updateTooltip();
01315     }
01316     if (rpcId != -1 && dest == fingerTable->getFinger(rpcId))
01317         fingerTable->removeFinger(rpcId);
01318 }

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

Todo:
check commented out addSuccessor (Schenk)

Reimplemented in oversim::Koorde.

Definition at line 993 of file Chord.cc.

Referenced by oversim::Koorde::handleRpcJoinResponse(), and handleRpcResponse().

00994 {
00995     // determine the numer of successor nodes to add
00996     int sucNum = successorListSize - 1;
00997 
00998     if (joinResponse->getSucNum() < successorListSize - 1) {
00999         sucNum = joinResponse->getSucNum();
01000     }
01001 
01002     // add successor getNode(s)
01003     for (int k = 0; k < sucNum; k++) {
01004         NodeHandle successor = joinResponse->getSucNode(k);
01005         successorList->addSuccessor(successor);
01006     }
01007 
01008     // \todo {check commented out addSuccessor (Schenk)}
01009     //successorList->addSuccessor(joinResponse->getSrcNode());
01010 
01011     // the sender of this message is our new successor
01012     successorList->addSuccessor(joinResponse->getSrcNode());
01013 
01014     // in aggressiveJoinMode: use hint in JoinResponse
01015     // to set our new predecessor
01016     if (aggressiveJoinMode) {
01017         // it is possible that the joinResponse doesn't contain a valid
01018         // predecessor especially when merging two partitions
01019         if (!joinResponse->getPreNode().isUnspecified()) {
01020             if (!predecessorNode.isUnspecified()) {
01021 
01022 
01023                 // inform the original predecessor about the new predecessor
01024                 if (mergeOptimizationL2) {
01025                     NewSuccessorHintMessage* newSuccessorHintMsg =
01026                         new NewSuccessorHintMessage("NEWSUCCESSORHINT");
01027                     newSuccessorHintMsg->setCommand(NEWSUCCESSORHINT);
01028                     newSuccessorHintMsg->setSrcNode(thisNode);
01029                     newSuccessorHintMsg->setPreNode(joinResponse->getPreNode());
01030                     newSuccessorHintMsg->
01031                         setBitLength(NEWSUCCESSORHINT_L(newSuccessorHintMsg));
01032 
01033                     sendMessageToUDP(predecessorNode, newSuccessorHintMsg);
01034                 }
01035             }
01036 
01037             if (!predecessorNode.isUnspecified()
01038                 && !joinResponse->getPreNode().isUnspecified()
01039                 && predecessorNode != joinResponse->getPreNode()) {
01040                 callUpdate(predecessorNode, false);
01041             }
01042             predecessorNode = joinResponse->getPreNode();
01043             callUpdate(predecessorNode, true);
01044         }
01045     }
01046 
01047     updateTooltip();
01048 
01049     changeState(READY);
01050 
01051     // immediate stabilization protocol
01052     cancelEvent(stabilize_timer);
01053     scheduleAt(simTime(), stabilize_timer);
01054 
01055     // immediate finger repair protocol
01056     cancelEvent(fixfingers_timer);
01057     scheduleAt(simTime(), fixfingers_timer);
01058 }

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

Reimplemented in oversim::Koorde.

Definition at line 1182 of file Chord.cc.

Referenced by handleRpcResponse().

01183 {
01184     if (successorList->getSuccessor() != notifyResponse->getSrcNode()) {
01185         EV << "[Chord::handleRpcNotifyResponse() @ " << thisNode.ip
01186            << " (" << thisNode.key.toString(16) << ")]\n"
01187            << "    The srcNode of the received NotifyResponse is not our "
01188            << " current successor"
01189            << endl;
01190         return;
01191     }
01192 
01193     // if the NotifyResponse sender couldn't accept me as predecessor,
01194     // put its predecessor into the successor list and starts stabilizing
01195     if (mergeOptimizationL3) {
01196         if (!notifyResponse->getPreNodeSet()) {
01197             StabilizeCall *call = new StabilizeCall("StabilizeCall");
01198             call->setBitLength(STABILIZECALL_L(call));
01199 
01200             successorList->addSuccessor(notifyResponse->getPreNode());
01201             if (successorList->getSuccessor() == notifyResponse->getPreNode())
01202                 sendUdpRpcCall(notifyResponse->getPreNode(), call);
01203             return;
01204         }
01205     }
01206 
01207     // replace our successor list by our successor's successor list
01208     successorList->updateList(notifyResponse);
01209 
01210     updateTooltip();
01211 }

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

Reimplemented in oversim::Koorde.

Definition at line 1078 of file Chord.cc.

Referenced by handleRpcResponse().

01079 {
01080     // fetch the successor's predecessor
01081     const NodeHandle& predecessor = stabilizeResponse->getPreNode();
01082 
01083     // is the successor's predecessor a new successor for this node?
01084     if ((successorList->isEmpty() ||
01085          predecessor.key.isBetween(thisNode.key,
01086                                   successorList->getSuccessor().key)) &&
01087         (failedSuccessor.isUnspecified() || failedSuccessor != predecessor)) {
01088         // add the successor's predecessor to the successor list
01089         successorList->addSuccessor(predecessor);
01090         updateTooltip();
01091     }
01092 
01093     // compile NOTIFY RPC
01094     NotifyCall* notifyCall = new NotifyCall("NotifyCall");
01095     notifyCall->setBitLength(NOTIFYCALL_L(notifyCall));
01096     notifyCall->setFailed(failedSuccessor);
01097     failedSuccessor = TransportAddress::UNSPECIFIED_NODE;
01098 
01099     sendUdpRpcCall(successorList->getSuccessor(), notifyCall);
01100 }

void oversim::Chord::handleRpcFixfingersResponse ( FixfingersResponse *  fixfingersResponse,
double  rtt = -1 
) [protected, virtual]

Definition at line 1243 of file Chord.cc.

Referenced by handleRpcResponse().

01245 {
01246     // set new finger pointer#
01247     if (!extendedFingerTable) {
01248         fingerTable->setFinger(fixfingersResponse->getFinger(),
01249                                fixfingersResponse->getSucNode(0));
01250     } else {
01251         Successors successors;
01252         for (unsigned int i = 0; i < fixfingersResponse->getSucNodeArraySize();
01253              i++) {
01254             if (fixfingersResponse->getSucNode(i).isUnspecified())
01255                 continue;
01256             if (fixfingersResponse->getSucNode(i) == thisNode)
01257                 break;
01258             successors.insert(std::make_pair(MAXTIME,
01259                                              fixfingersResponse->getSucNode(i)));
01260         }
01261 
01262         if (successors.size() == 0) {
01263             return;
01264         }
01265 
01266         fingerTable->setFinger(fixfingersResponse->getFinger(), successors);
01267 
01268 #if 0
01269         if (proximityRouting || globalParameters->getTopologyAdaptation()) {
01270 #else
01271         if (proximityRouting) {
01272 #endif
01273             for (unsigned int i = 0;
01274                  i < fixfingersResponse->getSucNodeArraySize();
01275                  i++) {
01276                 if (fixfingersResponse->getSucNode(i).isUnspecified())
01277                     continue;
01278                 if (fixfingersResponse->getSucNode(i) == thisNode)
01279                     break;
01280                 pingNode(fixfingersResponse->getSucNode(i), -1, 0, NULL,
01281                          NULL, NULL, fixfingersResponse->getFinger(),
01282                          INVALID_TRANSPORT, false);
01283             }
01284         }
01285     }
01286 }

bool oversim::Chord::handleFailedNode ( const TransportAddress &  failed  )  [protected, virtual]

Handles a failed node.

This method is called whenever a node given by findNode() was unreachable. The default implementation does nothing at all.

Parameters:
failed the failed node
Returns:
true if lookup should retry here

Reimplemented from BaseOverlay.

Definition at line 509 of file Chord.cc.

Referenced by handleRpcTimeout().

00510 {
00511     if (!predecessorNode.isUnspecified() && failed == predecessorNode)
00512         predecessorNode = NodeHandle::UNSPECIFIED_NODE;
00513 
00514     //TODO const reference -> trying to compare unspec NH
00515     TransportAddress oldSuccessor = successorList->getSuccessor();
00516 
00517     if (successorList->handleFailedNode(failed))
00518         updateTooltip();
00519     // check pointer for koorde
00520     if (fingerTable != NULL)
00521         fingerTable->handleFailedNode(failed);
00522 
00523     // if we had a ring consisting of 2 nodes and our successor seems
00524     // to be dead. Remove also predecessor because the successor
00525     // and predecessor are the same node
00526     if ((!predecessorNode.isUnspecified()) &&
00527         oldSuccessor == predecessorNode) {
00528         predecessorIsDead();
00529         callUpdate(predecessorNode, false);
00530         predecessorNode = NodeHandle::UNSPECIFIED_NODE;
00531     }
00532 
00533     if (failed == oldSuccessor) {
00534         successorIsDead();
00535         // schedule next stabilization process
00536         if (memorizeFailedSuccessor) {
00537             failedSuccessor = oldSuccessor;
00538         }
00539         cancelEvent(stabilize_timer);
00540         scheduleAt(simTime(), stabilize_timer);
00541     }
00542 
00543     if (state != READY) return true;
00544 
00545     return !(successorList->isEmpty());
00546 }

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

Reimplemented in oversim::Koorde.

Definition at line 1368 of file Chord.cc.

Referenced by handleFailedNode(), handleStabilizeTimerExpired(), and pingTimeout().

01369 {}

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

Reimplemented in oversim::Koorde.

Definition at line 1371 of file Chord.cc.

Referenced by handleFailedNode().

01372 {}


Friends And Related Function Documentation

friend class ChordSuccessorList [friend]

Definition at line 271 of file Chord.h.

friend class ChordFingerTable [friend]

Definition at line 272 of file Chord.h.


Member Data Documentation

int oversim::Chord::joinRetry [protected]

Definition at line 76 of file Chord.h.

Referenced by handleJoinTimerExpired(), and initializeOverlay().

// retries before neighbor considered failed

Definition at line 77 of file Chord.h.

Referenced by oversim::Koorde::handleDeBruijnTimeout(), handleStabilizeTimerExpired(), and initializeOverlay().

double oversim::Chord::joinDelay [protected]

Definition at line 78 of file Chord.h.

Referenced by handleJoinTimerExpired(), initializeOverlay(), and joinForeignPartition().

double oversim::Chord::stabilizeDelay [protected]

stabilize interval (secs)

Definition at line 79 of file Chord.h.

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

double oversim::Chord::fixfingersDelay [protected]

Definition at line 80 of file Chord.h.

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

Definition at line 82 of file Chord.h.

Referenced by getMaxNumSiblings(), handleRpcJoinResponse(), and initializeOverlay().

use modified (faster) JOIN protocol

Definition at line 83 of file Chord.h.

Referenced by handleRpcJoinResponse(), initializeOverlay(), and rpcJoin().

unsigned int oversim::Chord::numFingerCandidates [protected]

Definition at line 86 of file Chord.h.

Referenced by handleRpcFixfingersResponse(), and initializeOverlay().

Definition at line 87 of file Chord.h.

Referenced by handleFailedNode(), and initializeOverlay().

Definition at line 88 of file Chord.h.

Definition at line 89 of file Chord.h.

Referenced by initializeOverlay(), and rpcNotify().

Definition at line 90 of file Chord.h.

Referenced by handleRpcJoinResponse(), and initializeOverlay().

Definition at line 92 of file Chord.h.

Referenced by handleStabilizeTimerExpired(), and initializeOverlay().

cMessage* oversim::Chord::join_timer [protected]

cMessage* oversim::Chord::stabilize_timer [protected]

cMessage* oversim::Chord::fixfingers_timer [protected]

Definition at line 99 of file Chord.h.

Referenced by changeState(), handleTimerEvent(), initializeOverlay(), and ~Chord().

int oversim::Chord::joinCount [protected]

Definition at line 102 of file Chord.h.

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

Definition at line 103 of file Chord.h.

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

Definition at line 104 of file Chord.h.

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

int oversim::Chord::notifyCount [protected]

Definition at line 105 of file Chord.h.

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

Definition at line 106 of file Chord.h.

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

Definition at line 107 of file Chord.h.

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

Definition at line 108 of file Chord.h.

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

Definition at line 109 of file Chord.h.

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

Definition at line 110 of file Chord.h.

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

Definition at line 111 of file Chord.h.

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

int oversim::Chord::keyLength [protected]

length of an overlay key in bits

Definition at line 113 of file Chord.h.

Referenced by oversim::Koorde::findLongestMatch(), and initializeOverlay().

missing StabilizeCall msgs

Definition at line 114 of file Chord.h.

Referenced by handleStabilizeTimerExpired(), initializeOverlay(), oversim::Koorde::rpcNotify(), rpcNotify(), and rpcStabilize().

node used to bootstrap

Definition at line 125 of file Chord.h.

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

Definition at line 275 of file Chord.h.

Referenced by handleFailedNode(), handleRpcStabilizeResponse(), and initializeOverlay().


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