oversim::ChordSuccessorList Class Reference

Chord's successor list module. More...

#include <ChordSuccessorList.h>

List of all members.

Public Member Functions

virtual int numInitStages () const
virtual void initialize (int stage)
virtual void handleMessage (cMessage *msg)
virtual void initializeList (uint32_t size, NodeHandle owner, Chord *overlay)
 Initializes the successor list.
virtual uint32_t getSize ()
 Returns number of neighbors in the successor list.
virtual bool isEmpty ()
 Checks if the successor list is empty.
virtual const NodeHandlegetSuccessor (uint32_t pos=0)
 Returns a particular successor.
virtual void addSuccessor (NodeHandle successor, bool resize=true)
 Adds new successor nodes to the successor list.
virtual void updateList (NotifyResponse *notify)
bool handleFailedNode (const TransportAddress &failed)
void display ()

Protected Member Functions

void removeOldSuccessors ()
void updateDisplayString ()
 Displays the current number of successors in the list.
void updateTooltip ()
 Displays the first 4 successor nodes as tooltip.

Protected Attributes

NodeHandle thisNode
 own node handle
std::map< OverlayKey,
SuccessorListEntry
successorMap
 internal representation of the successor list
uint32_t successorListSize
 maximum size of the successor list
Chordoverlay
 pointer to the main chord module

Detailed Description

Chord's successor list module.

This modul contains the successor list of the Chord implementation.

Author:
Markus Mauch, Ingmar Baumgart
See also:
Chord

Definition at line 58 of file ChordSuccessorList.h.


Member Function Documentation

void oversim::ChordSuccessorList::addSuccessor ( NodeHandle  successor,
bool  resize = true 
) [virtual]

Adds new successor nodes to the successor list.

Adds new successor nodes to the successor list and sorts the list using the corresponding chord keys. If the list size exceeds the maximum size nodes at the end of the list will be removed.

Parameters:
successor the node handle of the successor to be added
resize if true, shrink the list to successorListSize

Definition at line 122 of file ChordSuccessorList.cc.

Referenced by handleFailedNode(), oversim::Chord::handleNewSuccessorHint(), oversim::Chord::handleRpcJoinResponse(), oversim::Chord::handleRpcNotifyResponse(), oversim::Chord::handleRpcStabilizeResponse(), initializeList(), removeOldSuccessors(), oversim::Chord::rpcJoin(), oversim::Chord::rpcNotify(), and updateList().

00123 {
00124     OverlayKey sum = successor.getKey() - (thisNode.getKey() + OverlayKey::ONE);
00125 
00126     std::map<OverlayKey, SuccessorListEntry>::iterator it =
00127         successorMap.find(sum);
00128 
00129     // Make a CommonAPI update() upcall to inform application
00130     // about our new neighbor in the successor list
00131 
00132     if (it == successorMap.end()) {
00133         // TODO: first add node and than call update()
00134         overlay->callUpdate(successor, true);
00135     } else {
00136         successorMap.erase(it);
00137     }
00138 
00139     SuccessorListEntry entry;
00140     entry.nodeHandle = successor;
00141     entry.newEntry = true;
00142 
00143     successorMap.insert(make_pair(sum, entry));
00144 
00145     if ((resize == true) && (successorMap.size() > (uint32_t)successorListSize)) {
00146         it = successorMap.end();
00147         it--;
00148         overlay->callUpdate(it->second.nodeHandle, false);
00149         successorMap.erase(it);
00150     }
00151 }

void oversim::ChordSuccessorList::display (  ) 

Definition at line 233 of file ChordSuccessorList.cc.

00234 {
00235     cout << "Content of ChordSuccessorList:" << endl;
00236     for (std::map<OverlayKey,SuccessorListEntry>::iterator it =
00237         successorMap.begin(); it != successorMap.end(); it++)
00238         cout << it->first << " with Node: " << it->second.nodeHandle << endl;
00239 }

uint32_t oversim::ChordSuccessorList::getSize (  )  [virtual]
const NodeHandle & oversim::ChordSuccessorList::getSuccessor ( uint32_t  pos = 0  )  [virtual]

Returns a particular successor.

Parameters:
pos position in the successor list
Returns:
successor at position pos

Definition at line 80 of file ChordSuccessorList.cc.

Referenced by oversim::Chord::closestPreceedingNode(), oversim::Koorde::findDeBruijnHop(), oversim::Koorde::findNode(), oversim::Chord::findNode(), oversim::ChordFingerTable::getFinger(), oversim::Koorde::handleDeBruijnTimerExpired(), oversim::Chord::handleFailedNode(), oversim::Chord::handleFixFingersTimerExpired(), oversim::Chord::handleNewSuccessorHint(), oversim::Koorde::handleRpcDeBruijnRequest(), oversim::Chord::handleRpcNotifyResponse(), oversim::Chord::handleRpcStabilizeResponse(), oversim::Chord::handleStabilizeTimerExpired(), isEmpty(), oversim::Chord::isSiblingFor(), oversim::Chord::rpcFixfingers(), oversim::Koorde::rpcJoin(), oversim::Chord::rpcJoin(), oversim::Chord::rpcNotify(), oversim::Koorde::updateTooltip(), updateTooltip(), oversim::Chord::updateTooltip(), and oversim::Koorde::walkSuccessorList().

00081 {
00082     // check boundaries
00083     if (pos == 0 && successorMap.size() == 0)
00084         return NodeHandle::UNSPECIFIED_NODE;
00085 
00086     if (pos >= successorMap.size()) {
00087         error("Index out of bound (ChordSuccessorList, getSuccessor())");
00088     }
00089 
00090     std::map<OverlayKey, SuccessorListEntry>::iterator it =
00091         successorMap.begin();
00092 
00093     for (uint32_t i= 0; i < pos; i++) {
00094         it++;
00095         if (i == (pos-1))
00096             return it->second.nodeHandle;
00097     }
00098     return it->second.nodeHandle;
00099 }

bool oversim::ChordSuccessorList::handleFailedNode ( const TransportAddress failed  ) 

Definition at line 153 of file ChordSuccessorList.cc.

Referenced by oversim::Chord::handleFailedNode().

00154 {
00155     assert(failed != thisNode);
00156     for (std::map<OverlayKey, SuccessorListEntry>::iterator iter =
00157          successorMap.begin(); iter != successorMap.end(); ++iter) {
00158         if (failed == iter->second.nodeHandle) {
00159             successorMap.erase(iter);
00160             overlay->callUpdate(failed, false);
00161             // ensure that thisNode is always in the successor list
00162             if (getSize() == 0)
00163                 addSuccessor(thisNode);
00164             return true;
00165         }
00166     }
00167     return false;
00168 }

void oversim::ChordSuccessorList::handleMessage ( cMessage *  msg  )  [virtual]

Definition at line 52 of file ChordSuccessorList.cc.

00053 {
00054     error("this module doesn't handle messages, it runs only in initialize()");
00055 }

void oversim::ChordSuccessorList::initialize ( int  stage  )  [virtual]

Definition at line 42 of file ChordSuccessorList.cc.

00043 {
00044     // because of IPAddressResolver, we need to wait until interfaces
00045     // are registered, address auto-assignment takes place etc.
00046     if (stage != MIN_STAGE_OVERLAY)
00047         return;
00048 
00049     WATCH_MAP(successorMap);
00050 }

void oversim::ChordSuccessorList::initializeList ( uint32_t  size,
NodeHandle  owner,
Chord overlay 
) [virtual]

Initializes the successor list.

This should be called on startup

Parameters:
size maximum number of neighbors in the successor list
owner the node owner is added to the successor list
overlay pointer to the main chord module

Definition at line 57 of file ChordSuccessorList.cc.

Referenced by oversim::Koorde::initializeFriendModules(), and oversim::Chord::initializeFriendModules().

00059 {
00060     successorMap.clear();
00061     successorListSize = size;
00062     thisNode = owner;
00063     this->overlay = overlay;
00064     addSuccessor(thisNode);
00065 }

bool oversim::ChordSuccessorList::isEmpty (  )  [virtual]

Checks if the successor list is empty.

Returns:
returns false if the successor list contains other nodes than this node, true otherwise.

Definition at line 72 of file ChordSuccessorList.cc.

Referenced by oversim::Chord::findNode(), oversim::Koorde::handleDeBruijnTimerExpired(), oversim::Chord::handleFailedNode(), oversim::Chord::handleFixFingersTimerExpired(), oversim::Koorde::handleRpcDeBruijnRequest(), oversim::Chord::handleRpcStabilizeResponse(), oversim::Chord::handleStabilizeTimerExpired(), oversim::Chord::isSiblingFor(), oversim::Chord::rpcJoin(), oversim::Chord::rpcNotify(), and updateList().

00073 {
00074     if (successorMap.size() == 1 && getSuccessor() == thisNode)
00075         return true;
00076     else
00077         return false;
00078 }

virtual int oversim::ChordSuccessorList::numInitStages (  )  const [inline, virtual]

Definition at line 61 of file ChordSuccessorList.h.

00062     {
00063         return MAX_STAGE_OVERLAY + 1;
00064     }

void oversim::ChordSuccessorList::removeOldSuccessors (  )  [protected]

Definition at line 170 of file ChordSuccessorList.cc.

Referenced by updateList().

00171 {
00172     std::map<OverlayKey,SuccessorListEntry>::iterator it;
00173 
00174     for (it = successorMap.begin(); it != successorMap.end();) {
00175 
00176         if (it->second.newEntry == false) {
00177             overlay->callUpdate(it->second.nodeHandle, false);
00178             successorMap.erase(it++);
00179         } else {
00180             it->second.newEntry = false;
00181             it++;
00182         }
00183     }
00184 
00185     it = successorMap.end();
00186     it--;
00187 
00188     while (successorMap.size() > successorListSize) {
00189         successorMap.erase(it--);
00190     }
00191 
00192     if (getSize() == 0)
00193         addSuccessor(thisNode);
00194 }

void oversim::ChordSuccessorList::updateDisplayString (  )  [protected]

Displays the current number of successors in the list.

Definition at line 197 of file ChordSuccessorList.cc.

00198 {
00199     // FIXME: doesn't work without tcl/tk
00200     //          if (ev.isGUI()) {
00201     if (1) {
00202         char buf[80];
00203 
00204         if (successorMap.size() == 1) {
00205             sprintf(buf, "1 successor");
00206         } else {
00207             sprintf(buf, "%zi successors", successorMap.size());
00208         }
00209 
00210         getDisplayString().setTagArg("t", 0, buf);
00211         getDisplayString().setTagArg("t", 2, "blue");
00212     }
00213 
00214 }

void oversim::ChordSuccessorList::updateList ( NotifyResponse *  notify  )  [virtual]

Definition at line 101 of file ChordSuccessorList.cc.

Referenced by oversim::Chord::handleRpcNotifyResponse().

00102 {
00103     addSuccessor(notifyResponse->getSrcNode(), false);
00104 
00105     for (uint32_t k = 0; ((k < static_cast<uint32_t>(notifyResponse->getSucNum()))
00106                      && (k < (successorListSize - 1))); k++) {
00107         NodeHandle successor = notifyResponse->getSucNode(k);
00108 
00109         // don't add nodes, if this would change our successor
00110         if (successor.getKey().isBetweenLR(thisNode.getKey(),
00111                                       notifyResponse->getSrcNode().getKey()))
00112             continue;
00113 
00114         addSuccessor(successor, false);
00115     }
00116 
00117     removeOldSuccessors();
00118     assert(!isEmpty());
00119 }

void oversim::ChordSuccessorList::updateTooltip (  )  [protected]

Displays the first 4 successor nodes as tooltip.

Definition at line 216 of file ChordSuccessorList.cc.

00217 {
00218     if (ev.isGUI()) {
00219         std::stringstream str;
00220         for (uint32_t i = 0; i < successorMap.size(); i++)      {
00221             str << getSuccessor(i);
00222             if ( i != successorMap.size() - 1 )
00223                 str << endl;
00224         }
00225 
00226 
00227         char buf[1024];
00228         sprintf(buf, "%s", str.str().c_str());
00229         getDisplayString().setTagArg("tt", 0, buf);
00230     }
00231 }


Member Data Documentation

pointer to the main chord module

Definition at line 126 of file ChordSuccessorList.h.

Referenced by addSuccessor(), handleFailedNode(), and removeOldSuccessors().

maximum size of the successor list

Definition at line 124 of file ChordSuccessorList.h.

Referenced by addSuccessor(), initializeList(), removeOldSuccessors(), and updateList().

own node handle

Definition at line 121 of file ChordSuccessorList.h.

Referenced by addSuccessor(), handleFailedNode(), initializeList(), isEmpty(), removeOldSuccessors(), and updateList().


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