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
NodeHandle
getSuccessor (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]

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

NodeHandle ChordSuccessorList::popSuccessor (  )  [virtual]

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

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

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

Removes a certain successor from the successor list.

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

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

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

void ChordSuccessorList::display (  ) 

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

void ChordSuccessorList::removeOldSuccessors (  )  [protected]

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

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.

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

void ChordSuccessorList::updateTooltip (  )  [protected]

Displays the first 4 successor nodes as tooltip.

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


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 Thu Apr 17 13:19:28 2008 for ITM OverSim by  doxygen 1.5.3