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, SuccessorListEntrysuccessorMap
 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]

00060     {
00061         return MAX_STAGE_OVERLAY + 1;
00062     }

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

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

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

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

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
00057 {
00058     successorMap.clear();
00059     successorListSize = size;
00060     thisNode = owner;
00061     this->overlay = overlay;
00062     addSuccessor(thisNode);
00063 }

uint ChordSuccessorList::getSize (  )  [virtual]

Returns number of neighbors in the successor list.

Returns:
number of neighbors
00072 {
00073     return successorMap.size();
00074 }

void ChordSuccessorList::clear (  )  [virtual]

Clears the successor list.

00066 {
00067     successorMap.clear();
00068 }

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.
00077 {
00078     if (successorMap.size() == 1 && getSuccessor() == thisNode)
00079         return true;
00080     else
00081         return false;
00082 }

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

Returns a particular successor.

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

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
00125 {
00126     OverlayKey sum = successor.key - (thisNode.key + OverlayKey::ONE);
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
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
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]

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

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]

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

NodeHandle ChordSuccessorList::thisNode [protected]

own node handle

std::map<OverlayKey, SuccessorListEntry> ChordSuccessorList::successorMap [protected]

internal representation of the successor list

uint ChordSuccessorList::successorListSize [protected]

maximum size of the successor list

Chord* ChordSuccessorList::overlay [protected]

pointer to the main chord module


The documentation for this class was generated from the following files:
Generated on Tue Jul 24 16:51:18 2007 for ITM OverSim by  doxygen 1.5.1