#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 | |
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().
00123 { 00124 OverlayKey sum = successor.getKey() - (thisNode.getKey() + OverlayKey::ONE); 00125 00126 std::map<OverlayKey, SuccessorListEntry>::iterator it = 00127 successorMap.find(sum); 00128 00129 // Make a CommonAPI update() upcall to inform application 00130 // about our new neighbor in the successor list 00131 00132 if (it == successorMap.end()) { 00133 overlay->callUpdate(successor, true); 00134 } else { 00135 successorMap.erase(it); 00136 } 00137 00138 SuccessorListEntry entry; 00139 entry.nodeHandle = successor; 00140 entry.newEntry = true; 00141 00142 successorMap.insert(make_pair(sum, entry)); 00143 00144 if ((resize == true) && (successorMap.size() > (uint32_t)successorListSize)) { 00145 it = successorMap.end(); 00146 it--; 00147 overlay->callUpdate(it->second.nodeHandle, false); 00148 successorMap.erase(it); 00149 } 00150 }
| void oversim::ChordSuccessorList::display | ( | ) |
Definition at line 232 of file ChordSuccessorList.cc.
00233 { 00234 cout << "Content of ChordSuccessorList:" << endl; 00235 for (std::map<OverlayKey,SuccessorListEntry>::iterator it = 00236 successorMap.begin(); it != successorMap.end(); it++) 00237 cout << it->first << " with Node: " << it->second.nodeHandle << endl; 00238 }
| 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().
00068 { 00069 return successorMap.size(); 00070 }
| 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().
00081 { 00082 // check boundaries 00083 if (pos == 0 && successorMap.size() == 0) 00084 return NodeHandle::UNSPECIFIED_NODE; 00085 00086 if (pos >= successorMap.size()) { 00087 error("Index out of bound (ChordSuccessorList, getSuccessor())"); 00088 } 00089 00090 std::map<OverlayKey, SuccessorListEntry>::iterator it = 00091 successorMap.begin(); 00092 00093 for (uint32_t i= 0; i < pos; i++) { 00094 it++; 00095 if (i == (pos-1)) 00096 return it->second.nodeHandle; 00097 } 00098 return it->second.nodeHandle; 00099 }
| bool oversim::ChordSuccessorList::handleFailedNode | ( | const TransportAddress & | failed | ) |
Definition at line 152 of file ChordSuccessorList.cc.
Referenced by oversim::Chord::handleFailedNode().
00153 { 00154 assert(failed != thisNode); 00155 for (std::map<OverlayKey, SuccessorListEntry>::iterator iter = 00156 successorMap.begin(); iter != successorMap.end(); ++iter) { 00157 if (failed == iter->second.nodeHandle) { 00158 successorMap.erase(iter); 00159 overlay->callUpdate(failed, false); 00160 // ensure that thisNode is always in the successor list 00161 if (getSize() == 0) 00162 addSuccessor(thisNode); 00163 return true; 00164 } 00165 } 00166 return false; 00167 }
| void oversim::ChordSuccessorList::handleMessage | ( | cMessage * | msg | ) | [virtual] |
Definition at line 52 of file ChordSuccessorList.cc.
00053 { 00054 error("this module doesn't handle messages, it runs only in initialize()"); 00055 }
| void oversim::ChordSuccessorList::initialize | ( | int | stage | ) | [virtual] |
Definition at line 42 of file ChordSuccessorList.cc.
00043 { 00044 // because of IPAddressResolver, we need to wait until interfaces 00045 // are registered, address auto-assignment takes place etc. 00046 if (stage != MIN_STAGE_OVERLAY) 00047 return; 00048 00049 WATCH_MAP(successorMap); 00050 }
| 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().
00059 { 00060 successorMap.clear(); 00061 successorListSize = size; 00062 thisNode = owner; 00063 this->overlay = overlay; 00064 addSuccessor(thisNode); 00065 }
| 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().
00073 { 00074 if (successorMap.size() == 1 && getSuccessor() == thisNode) 00075 return true; 00076 else 00077 return false; 00078 }
| virtual int oversim::ChordSuccessorList::numInitStages | ( | ) | const [inline, virtual] |
Definition at line 61 of file ChordSuccessorList.h.
00062 { 00063 return MAX_STAGE_OVERLAY + 1; 00064 }
| void oversim::ChordSuccessorList::removeOldSuccessors | ( | ) | [protected] |
Definition at line 169 of file ChordSuccessorList.cc.
Referenced by updateList().
00170 { 00171 std::map<OverlayKey,SuccessorListEntry>::iterator it; 00172 00173 for (it = successorMap.begin(); it != successorMap.end();) { 00174 00175 if (it->second.newEntry == false) { 00176 overlay->callUpdate(it->second.nodeHandle, false); 00177 successorMap.erase(it++); 00178 } else { 00179 it->second.newEntry = false; 00180 it++; 00181 } 00182 } 00183 00184 it = successorMap.end(); 00185 it--; 00186 00187 while (successorMap.size() > successorListSize) { 00188 successorMap.erase(it--); 00189 } 00190 00191 if (getSize() == 0) 00192 addSuccessor(thisNode); 00193 }
| void oversim::ChordSuccessorList::updateDisplayString | ( | ) | [protected] |
Displays the current number of successors in the list.
Definition at line 196 of file ChordSuccessorList.cc.
00197 { 00198 // FIXME: doesn't work without tcl/tk 00199 // if (ev.isGUI()) { 00200 if (1) { 00201 char buf[80]; 00202 00203 if (successorMap.size() == 1) { 00204 sprintf(buf, "1 successor"); 00205 } else { 00206 sprintf(buf, "%zi successors", successorMap.size()); 00207 } 00208 00209 getDisplayString().setTagArg("t", 0, buf); 00210 getDisplayString().setTagArg("t", 2, "blue"); 00211 } 00212 00213 }
| void oversim::ChordSuccessorList::updateList | ( | NotifyResponse * | notify | ) | [virtual] |
Definition at line 101 of file ChordSuccessorList.cc.
Referenced by oversim::Chord::handleRpcNotifyResponse().
00102 { 00103 addSuccessor(notifyResponse->getSrcNode(), false); 00104 00105 for (uint32_t k = 0; ((k < static_cast<uint32_t>(notifyResponse->getSucNum())) 00106 && (k < (successorListSize - 1))); k++) { 00107 NodeHandle successor = notifyResponse->getSucNode(k); 00108 00109 // don't add nodes, if this would change our successor 00110 if (successor.getKey().isBetweenLR(thisNode.getKey(), 00111 notifyResponse->getSrcNode().getKey())) 00112 continue; 00113 00114 addSuccessor(successor, false); 00115 } 00116 00117 removeOldSuccessors(); 00118 assert(!isEmpty()); 00119 }
| void oversim::ChordSuccessorList::updateTooltip | ( | ) | [protected] |
Displays the first 4 successor nodes as tooltip.
Definition at line 215 of file ChordSuccessorList.cc.
00216 { 00217 if (ev.isGUI()) { 00218 std::stringstream str; 00219 for (uint32_t i = 0; i < successorMap.size(); i++) { 00220 str << getSuccessor(i); 00221 if ( i != successorMap.size() - 1 ) 00222 str << endl; 00223 } 00224 00225 00226 char buf[1024]; 00227 sprintf(buf, "%s", str.str().c_str()); 00228 getDisplayString().setTagArg("tt", 0, buf); 00229 } 00230 }
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().
1.5.8