OverSim
oversim::ChordSuccessorList Class Reference

Chord's successor list module. More...

#include <ChordSuccessorList.h>

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
successorthe node handle of the successor to be added
resizeif true, shrink the list to successorListSize

Definition at line 122 of file ChordSuccessorList.cc.

{
OverlayKey sum = successor.getKey() - (thisNode.getKey() + OverlayKey::ONE);
std::map<OverlayKey, SuccessorListEntry>::iterator it =
successorMap.find(sum);
// Make a CommonAPI update() upcall to inform application
// about our new neighbor in the successor list
if (it == successorMap.end()) {
// TODO: first add node and than call update()
overlay->callUpdate(successor, true);
} else {
successorMap.erase(it);
}
SuccessorListEntry entry;
entry.nodeHandle = successor;
entry.newEntry = true;
successorMap.insert(make_pair(sum, entry));
if ((resize == true) && (successorMap.size() > (uint32_t)successorListSize)) {
it = successorMap.end();
it--;
overlay->callUpdate(it->second.nodeHandle, false);
successorMap.erase(it);
}
}
void oversim::ChordSuccessorList::display ( )

Definition at line 233 of file ChordSuccessorList.cc.

{
cout << "Content of ChordSuccessorList:" << endl;
for (std::map<OverlayKey,SuccessorListEntry>::iterator it =
successorMap.begin(); it != successorMap.end(); it++)
cout << it->first << " with Node: " << it->second.nodeHandle << endl;
}
uint32_t oversim::ChordSuccessorList::getSize ( )
virtual

Returns number of neighbors in the successor list.

Returns
number of neighbors

Definition at line 67 of file ChordSuccessorList.cc.

{
return successorMap.size();
}
const NodeHandle & oversim::ChordSuccessorList::getSuccessor ( uint32_t  pos = 0)
virtual

Returns a particular successor.

Parameters
posposition in the successor list
Returns
successor at position pos

Definition at line 80 of file ChordSuccessorList.cc.

{
// check boundaries
if (pos == 0 && successorMap.size() == 0)
if (pos >= successorMap.size()) {
error("Index out of bound (ChordSuccessorList, getSuccessor())");
}
std::map<OverlayKey, SuccessorListEntry>::iterator it =
successorMap.begin();
for (uint32_t i= 0; i < pos; i++) {
it++;
if (i == (pos-1))
return it->second.nodeHandle;
}
return it->second.nodeHandle;
}
bool oversim::ChordSuccessorList::handleFailedNode ( const TransportAddress failed)

Definition at line 153 of file ChordSuccessorList.cc.

{
assert(failed != thisNode);
for (std::map<OverlayKey, SuccessorListEntry>::iterator iter =
successorMap.begin(); iter != successorMap.end(); ++iter) {
if (failed == iter->second.nodeHandle) {
successorMap.erase(iter);
overlay->callUpdate(failed, false);
// ensure that thisNode is always in the successor list
if (getSize() == 0)
return true;
}
}
return false;
}
void oversim::ChordSuccessorList::handleMessage ( cMessage *  msg)
virtual

Definition at line 52 of file ChordSuccessorList.cc.

{
error("this module doesn't handle messages, it runs only in initialize()");
}
void oversim::ChordSuccessorList::initialize ( int  stage)
virtual

Definition at line 42 of file ChordSuccessorList.cc.

{
// because of IPAddressResolver, we need to wait until interfaces
// are registered, address auto-assignment takes place etc.
if (stage != MIN_STAGE_OVERLAY)
return;
WATCH_MAP(successorMap);
}
void oversim::ChordSuccessorList::initializeList ( uint32_t  size,
NodeHandle  owner,
Chord overlay 
)
virtual

Initializes the successor list.

This should be called on startup

Parameters
sizemaximum number of neighbors in the successor list
ownerthe node owner is added to the successor list
overlaypointer to the main chord module

Definition at line 57 of file ChordSuccessorList.cc.

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

{
successorMap.clear();
thisNode = owner;
this->overlay = overlay;
}
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.

{
if (successorMap.size() == 1 && getSuccessor() == thisNode)
return true;
else
return false;
}
virtual int oversim::ChordSuccessorList::numInitStages ( ) const
inlinevirtual

Definition at line 61 of file ChordSuccessorList.h.

{
return MAX_STAGE_OVERLAY + 1;
}
void oversim::ChordSuccessorList::removeOldSuccessors ( )
protected

Definition at line 170 of file ChordSuccessorList.cc.

{
std::map<OverlayKey,SuccessorListEntry>::iterator it;
for (it = successorMap.begin(); it != successorMap.end();) {
if (it->second.newEntry == false) {
overlay->callUpdate(it->second.nodeHandle, false);
successorMap.erase(it++);
} else {
it->second.newEntry = false;
it++;
}
}
it = successorMap.end();
it--;
while (successorMap.size() > successorListSize) {
successorMap.erase(it--);
}
if (getSize() == 0)
}
void oversim::ChordSuccessorList::updateDisplayString ( )
protected

Displays the current number of successors in the list.

Definition at line 197 of file ChordSuccessorList.cc.

{
// FIXME: doesn't work without tcl/tk
// if (ev.isGUI()) {
if (1) {
char buf[80];
if (successorMap.size() == 1) {
sprintf(buf, "1 successor");
} else {
sprintf(buf, "%zi successors", successorMap.size());
}
getDisplayString().setTagArg("t", 0, buf);
getDisplayString().setTagArg("t", 2, "blue");
}
}
void oversim::ChordSuccessorList::updateList ( NotifyResponse notify)
virtual

Definition at line 101 of file ChordSuccessorList.cc.

{
addSuccessor(notifyResponse->getSrcNode(), false);
for (uint32_t k = 0; ((k < static_cast<uint32_t>(notifyResponse->getSucNum()))
&& (k < (successorListSize - 1))); k++) {
NodeHandle successor = notifyResponse->getSucNode(k);
// don't add nodes, if this would change our successor
if (successor.getKey().isBetweenLR(thisNode.getKey(),
notifyResponse->getSrcNode().getKey()))
continue;
addSuccessor(successor, false);
}
assert(!isEmpty());
}
void oversim::ChordSuccessorList::updateTooltip ( )
protected

Displays the first 4 successor nodes as tooltip.

Definition at line 216 of file ChordSuccessorList.cc.

{
if (ev.isGUI()) {
std::stringstream str;
for (uint32_t i = 0; i < successorMap.size(); i++) {
str << getSuccessor(i);
if ( i != successorMap.size() - 1 )
str << endl;
}
char buf[1024];
sprintf(buf, "%s", str.str().c_str());
getDisplayString().setTagArg("tt", 0, buf);
}
}

Member Data Documentation

Chord* oversim::ChordSuccessorList::overlay
protected

pointer to the main chord module

Definition at line 126 of file ChordSuccessorList.h.

uint32_t oversim::ChordSuccessorList::successorListSize
protected

maximum size of the successor list

Definition at line 124 of file ChordSuccessorList.h.

std::map<OverlayKey, SuccessorListEntry> oversim::ChordSuccessorList::successorMap
protected

internal representation of the successor list

Definition at line 122 of file ChordSuccessorList.h.

NodeHandle oversim::ChordSuccessorList::thisNode
protected

own node handle

Definition at line 121 of file ChordSuccessorList.h.


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