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 NodeHandle & | getSuccessor (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 | |
Chord * | overlay |
pointer to the main chord module |
Chord's successor list module.
This modul contains the successor list of the Chord implementation.
Definition at line 58 of file ChordSuccessorList.h.
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.
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().
{ 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.
Definition at line 67 of file ChordSuccessorList.cc.
Referenced by oversim::Chord::closestPreceedingNode(), oversim::Koorde::findNode(), oversim::Chord::findNode(), oversim::Koorde::handleDeBruijnTimerExpired(), handleFailedNode(), oversim::Koorde::handleRpcDeBruijnRequest(), oversim::Chord::isSiblingFor(), removeOldSuccessors(), oversim::Chord::rpcFixfingers(), oversim::Chord::rpcJoin(), oversim::Chord::rpcNotify(), oversim::Koorde::updateTooltip(), and oversim::Koorde::walkSuccessorList().
{ return successorMap.size(); }
const NodeHandle & oversim::ChordSuccessorList::getSuccessor | ( | uint32_t | pos = 0 |
) | [virtual] |
Returns a particular successor.
pos | position in the successor list |
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().
{ // check boundaries if (pos == 0 && successorMap.size() == 0) return NodeHandle::UNSPECIFIED_NODE; 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.
Referenced by oversim::Chord::handleFailedNode().
{ 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) addSuccessor(thisNode); 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
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().
{ successorMap.clear(); successorListSize = size; thisNode = owner; this->overlay = overlay; addSuccessor(thisNode); }
bool oversim::ChordSuccessorList::isEmpty | ( | ) | [virtual] |
Checks if the successor list is empty.
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().
{ if (successorMap.size() == 1 && getSuccessor() == thisNode) return true; else return false; }
virtual int oversim::ChordSuccessorList::numInitStages | ( | ) | const [inline, virtual] |
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.
Referenced by updateList().
{ 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) addSuccessor(thisNode); }
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.
Referenced by oversim::Chord::handleRpcNotifyResponse().
{ 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); } removeOldSuccessors(); 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); } }
Chord* oversim::ChordSuccessorList::overlay [protected] |
pointer to the main chord module
Definition at line 126 of file ChordSuccessorList.h.
Referenced by addSuccessor(), handleFailedNode(), and removeOldSuccessors().
uint32_t oversim::ChordSuccessorList::successorListSize [protected] |
maximum size of the successor list
Definition at line 124 of file ChordSuccessorList.h.
Referenced by addSuccessor(), initializeList(), removeOldSuccessors(), and updateList().
std::map<OverlayKey, SuccessorListEntry> oversim::ChordSuccessorList::successorMap [protected] |
internal representation of the successor list
Definition at line 122 of file ChordSuccessorList.h.
Referenced by addSuccessor(), display(), getSize(), getSuccessor(), handleFailedNode(), initialize(), initializeList(), isEmpty(), removeOldSuccessors(), updateDisplayString(), and updateTooltip().
NodeHandle oversim::ChordSuccessorList::thisNode [protected] |
own node handle
Definition at line 121 of file ChordSuccessorList.h.
Referenced by addSuccessor(), handleFailedNode(), initializeList(), isEmpty(), removeOldSuccessors(), and updateList().