#include <ChordSuccessorList.h>
This modul contains the successor list of the Chord implementation.
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 | |
Chord * | overlay |
pointer to the main chord module |
virtual int ChordSuccessorList::numInitStages | ( | ) | const [inline, virtual] |
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] |
void ChordSuccessorList::initializeList | ( | uint | 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 |
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] |
Returns number of neighbors in the successor list.
Referenced by Chord::closestPreceedingNode(), Koorde::findNode(), Chord::findNode(), Koorde::handleDeBruijnTimerExpired(), Koorde::handleRpcDeBruijnRequest(), Chord::isSiblingFor(), popSuccessor(), removeOldSuccessors(), removeSuccessor(), Chord::rpcFixfingers(), Chord::rpcJoin(), Koorde::rpcNotify(), Chord::rpcNotify(), Koorde::updateTooltip(), and Koorde::walkSuccessorList().
00070 { 00071 return successorMap.size(); 00072 }
void ChordSuccessorList::clear | ( | ) | [virtual] |
bool ChordSuccessorList::isEmpty | ( | ) | [virtual] |
Checks if the successor list is empty.
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.
pos | position in the successor list |
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.
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.
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.
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 }
NodeHandle ChordSuccessorList::thisNode [protected] |
own node handle
Referenced by addSuccessor(), initializeList(), isEmpty(), popSuccessor(), removeOldSuccessors(), removeSuccessor(), and updateList().
std::map<OverlayKey, SuccessorListEntry> ChordSuccessorList::successorMap [protected] |
internal representation of the successor list
Referenced by addSuccessor(), clear(), display(), getSize(), getSuccessor(), initialize(), initializeList(), isEmpty(), popSuccessor(), removeOldSuccessors(), removeSuccessor(), updateDisplayString(), and updateTooltip().
uint ChordSuccessorList::successorListSize [protected] |
maximum size of the successor list
Referenced by addSuccessor(), initializeList(), removeOldSuccessors(), and updateList().
Chord* ChordSuccessorList::overlay [protected] |
pointer to the main chord module
Referenced by addSuccessor(), popSuccessor(), removeOldSuccessors(), and removeSuccessor().