ChordSuccessorList Class Reference

#include <ChordSuccessorList.h>

List of all members.


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

Public Member Functions

virtual int numInitStages () const
virtual void initialize (int stage)
virtual void handleMessage (cMessage *msg)
virtual void initializeList (uint size, NodeHandle owner, Chord *overlay)
 Initializes the successor list.
virtual uint getSize ()
 Returns number of neighbors in the successor list.
virtual void clear ()
 Clears the successor list.
virtual bool isEmpty ()
 Checks if the successor list is empty.
virtual const NodeHandlegetSuccessor (uint pos=0)
 Returns a particular successor.
virtual void addSuccessor (NodeHandle successor, bool resize=true)
 Adds new successor nodes to the successor list.
virtual NodeHandle popSuccessor ()
 Removes all occurrences of the first successor node from the list.
virtual void removeSuccessor (NodeHandle successor)
 Removes a certain successor from the successor list.
virtual void updateList (NotifyResponse *notify)
void display ()

Protected Member Functions

void removeOldSuccessors ()
void buildSuccessorList ()
 Derives a new successor list from the internal successor set.
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
uint successorListSize
 maximum size of the successor list
Chordoverlay
 pointer to the main chord module

Member Function Documentation

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

00059     {
00060         return MAX_STAGE_OVERLAY + 1;
00061     }

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

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

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

00049 {
00050     error("this module doesn't handle messages, it runs only in initialize()");
00051 }

void ChordSuccessorList::initializeList ( uint  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

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

00055 {
00056     successorMap.clear();
00057     successorListSize = size;
00058     thisNode = owner;
00059     this->overlay = overlay;
00060     addSuccessor(thisNode);
00061 }

uint ChordSuccessorList::getSize (  )  [virtual]

void ChordSuccessorList::clear (  )  [virtual]

Clears the successor list.

00064 {
00065     successorMap.clear();
00066 }

bool 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.

Referenced by Koorde::handleDeBruijnTimerExpired(), Chord::handleFixFingersTimerExpired(), Koorde::handleRpcStabilizeResponse(), Chord::handleRpcStabilizeResponse(), Chord::handleStabilizeTimerExpired(), Chord::isSiblingFor(), and Chord::rpcJoin().

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

const NodeHandle & ChordSuccessorList::getSuccessor ( uint  pos = 0  )  [virtual]

Returns a particular successor.

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

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

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

void 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

Referenced by Chord::handleNewSuccessorHint(), Chord::handleRpcJoinResponse(), Chord::handleRpcNotifyResponse(), Koorde::handleRpcStabilizeResponse(), Chord::handleRpcStabilizeResponse(), initializeList(), popSuccessor(), removeOldSuccessors(), removeSuccessor(), Chord::rpcJoin(), and updateList().

00124 {
00125     OverlayKey sum = successor.key - (thisNode.key + OverlayKey::ONE);
00126 
00127     std::map<OverlayKey, SuccessorListEntry>::iterator it =
00128         successorMap.find(sum);
00129 
00130     // Make a CommonAPI update() upcall to inform application
00131     // about our new neighbor in the successor list
00132 
00133     if (it == successorMap.end()) {
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() > (uint)successorListSize)) {
00146         it = successorMap.end();
00147         it--;
00148         overlay->callUpdate(it->second.nodeHandle, false);
00149         successorMap.erase(it);
00150     }
00151 }

NodeHandle ChordSuccessorList::popSuccessor (  )  [virtual]

Removes all occurrences of the first successor node from the list.

Returns:
the removed successor node

Referenced by Chord::handleStabilizeTimerExpired().

00155 {
00156     OverlayKey succKey = successorMap.begin()->first;
00157     NodeHandle succNode = successorMap.begin()->second.nodeHandle;
00158     successorMap.erase(successorMap.find(succKey));
00159 
00160     overlay->callUpdate(succNode, false);
00161 
00162     // ensure that thisNode is always in the successor list
00163     if (getSize() == 0) {
00164         addSuccessor(thisNode);
00165         succNode = thisNode;
00166     }
00167 
00168     return succNode;
00169 }

void ChordSuccessorList::removeSuccessor ( NodeHandle  successor  )  [virtual]

Removes a certain successor from the successor list.

Parameters:
successor the successor to be removed

Referenced by Chord::handleStabilizeTimerExpired().

00172 {
00173     OverlayKey tmp = successor.key - (thisNode.key + OverlayKey::ONE);
00174     std::map<OverlayKey, SuccessorListEntry>::iterator iter =
00175         successorMap.find(tmp);
00176     if (iter != successorMap.end()) {
00177         if (iter->second.nodeHandle != successor)
00178             cout << "wrong mapping" << endl;
00179         successorMap.erase(iter);
00180         overlay->callUpdate(successor, false);
00181     }
00182 
00183     // ensure that thisNode is always in the successor list
00184     if (getSize() == 0)
00185         addSuccessor(thisNode);
00186 }

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

Referenced by Koorde::handleRpcNotifyResponse(), and Chord::handleRpcNotifyResponse().

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

void ChordSuccessorList::display (  ) 

00252 {
00253     cout << "Content of ChordSuccessorList:" << endl;
00254     for (std::map<OverlayKey,SuccessorListEntry>::iterator it =
00255         successorMap.begin(); it != successorMap.end(); it++)
00256         cout << it->first << " with Node: " << it->second.nodeHandle << endl;
00257 }

void ChordSuccessorList::removeOldSuccessors (  )  [protected]

Referenced by updateList().

00189 {
00190     std::map<OverlayKey,SuccessorListEntry>::iterator it;
00191 
00192     for (it = successorMap.begin(); it != successorMap.end();) {
00193 
00194         if (it->second.newEntry == false) {
00195             overlay->callUpdate(it->second.nodeHandle, false);
00196             successorMap.erase(it++);
00197         } else {
00198             it->second.newEntry = false;
00199             it++;
00200         }
00201     }
00202 
00203     it = successorMap.end();
00204     it--;
00205 
00206     while (successorMap.size() > successorListSize) {
00207         successorMap.erase(it--);
00208     }
00209 
00210     if (getSize() == 0)
00211         addSuccessor(thisNode);
00212 }

void ChordSuccessorList::buildSuccessorList (  )  [protected]

Derives a new successor list from the internal successor set.

Derives a new successor list from the internal successor set. This method is called whenever nodes are added or removed from the set.

void ChordSuccessorList::updateDisplayString (  )  [protected]

Displays the current number of successors in the list.

00216 {
00217     // FIXME: doesn't work without tcl/tk
00218     //          if (ev.isGUI()) {
00219     if (1) {
00220         char buf[80];
00221 
00222         if (successorMap.size() == 1) {
00223             sprintf(buf, "1 successor");
00224         } else {
00225             sprintf(buf, "%zi successors", successorMap.size());
00226         }
00227 
00228         displayString().setTagArg("t", 0, buf);
00229         displayString().setTagArg("t", 2, "blue");
00230     }
00231 
00232 }

void ChordSuccessorList::updateTooltip (  )  [protected]

Displays the first 4 successor nodes as tooltip.

00235 {
00236     if (ev.isGUI()) {
00237         std::stringstream str;
00238         for (uint i = 0; i < successorMap.size(); i++)  {
00239             str << getSuccessor(i);
00240             if ( i != successorMap.size() - 1 )
00241                 str << endl;
00242         }
00243 
00244 
00245         char buf[1024];
00246         sprintf(buf, "%s", str.str().c_str());
00247         displayString().setTagArg("tt", 0, buf);
00248     }
00249 }


Member Data Documentation

maximum size of the successor list

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

pointer to the main chord module

Referenced by addSuccessor(), popSuccessor(), removeOldSuccessors(), and removeSuccessor().


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

Generated on Fri Sep 19 13:05:06 2008 for ITM OverSim by  doxygen 1.5.5