Chord's finger table module. More...
#include <ChordFingerTable.h>
Public Member Functions | |
virtual int | numInitStages () const |
virtual void | initialize (int stage) |
virtual void | handleMessage (cMessage *msg) |
virtual void | initializeTable (uint32_t size, const NodeHandle &owner, Chord *overlay) |
Sets up the finger table. | |
virtual void | setFinger (uint32_t pos, const NodeHandle &node, Successors const *sucNodes=NULL) |
Sets a particular finger to point to node. | |
virtual void | setFinger (uint32_t pos, const Successors &nodes) |
virtual bool | updateFinger (uint32_t pos, const NodeHandle &node, simtime_t rtt) |
virtual const NodeHandle & | getFinger (uint32_t pos) |
Returns the NodeVector of a particular finger. | |
virtual NodeVector * | getFinger (uint32_t pos, const OverlayKey &key) |
bool | handleFailedNode (const TransportAddress &failed) |
void | removeFinger (uint32_t pos) |
Deletes a particular finger. | |
virtual uint32_t | getSize () |
Returns the size of the finger table. | |
Private Attributes | |
uint32_t | maxSize |
maximum size of the finger table | |
std::deque< FingerEntry > | fingerTable |
the finger table vector | |
Chord * | overlay |
pointer to the main chord module |
Chord's finger table module.
This modul contains the finger table of the Chord implementation.
Definition at line 52 of file ChordFingerTable.h.
NodeVector * oversim::ChordFingerTable::getFinger | ( | uint32_t | pos, | |
const OverlayKey & | key | |||
) | [virtual] |
Definition at line 194 of file ChordFingerTable.cc.
00196 { 00197 if (pos >= maxSize) { 00198 throw new cRuntimeError("ChordFingerTable::getFinger(): " 00199 "Index out of bound"); 00200 } 00201 00202 NodeVector* nextHop = new NodeVector(); 00203 uint32_t p = maxSize - pos - 1; 00204 00205 if (p < fingerTable.size()) { 00206 for (Successors::const_iterator it = fingerTable[p].second.begin(); 00207 it != fingerTable[p].second.end(); it++) { 00208 00209 if(!key.isBetweenLR(fingerTable[p].first.getKey(), it->second.getKey())) { 00210 nextHop->push_back(it->second); 00211 } 00212 } 00213 } else { 00214 nextHop->push_back(overlay->successorList->getSuccessor()); 00215 return nextHop; 00216 } 00217 00218 if (nextHop->size() == 0) { 00219 if (fingerTable[p].first.isUnspecified()) { 00220 //TODO use other finger 00221 nextHop->push_back(overlay->successorList->getSuccessor()); 00222 } else { 00223 nextHop->push_back(fingerTable[p].first); 00224 } 00225 } 00226 00227 return nextHop;
const NodeHandle & oversim::ChordFingerTable::getFinger | ( | uint32_t | pos | ) | [virtual] |
Returns the NodeVector of a particular finger.
pos | number of the finger to get |
Definition at line 173 of file ChordFingerTable.cc.
Referenced by oversim::Chord::closestPreceedingNode(), and oversim::Chord::handleStabilizeTimerExpired().
00175 { 00176 if (pos >= maxSize) { 00177 throw new cRuntimeError("ChordFingerTable::getFinger(): " 00178 "Index out of bound"); 00179 } 00180 00181 uint32_t p = maxSize - pos - 1; 00182 00183 if (p >= fingerTable.size()) { 00184 return overlay->successorList->getSuccessor(); 00185 } 00186 while (fingerTable[p].first.isUnspecified() && 00187 (p < (fingerTable.size() - 1))) { 00188 ++p; 00189 } 00190 if (fingerTable[p].first.isUnspecified()) 00191 return overlay->successorList->getSuccessor(); 00192 return fingerTable[p].first;
uint32_t oversim::ChordFingerTable::getSize | ( | ) | [virtual] |
Returns the size of the finger table.
Definition at line 60 of file ChordFingerTable.cc.
Referenced by oversim::Chord::closestPreceedingNode().
00062 { 00063 return maxSize;
bool oversim::ChordFingerTable::handleFailedNode | ( | const TransportAddress & | failed | ) |
Definition at line 131 of file ChordFingerTable.cc.
Referenced by oversim::Chord::handleFailedNode().
00133 { 00134 bool ret = false; 00135 for (int p = fingerTable.size() - 1; p >= 0; p--) { 00136 if (!fingerTable[p].first.isUnspecified() && 00137 failed == fingerTable[p].first) { 00138 fingerTable[p].first = NodeHandle::UNSPECIFIED_NODE; 00139 ret = true; 00140 } 00141 for (std::multimap<simtime_t, NodeHandle>::iterator it = 00142 fingerTable[p].second.begin(); it != fingerTable[p].second.end(); 00143 ++it) { 00144 if (failed == it->second) { 00145 fingerTable[p].second.erase(it); 00146 break; 00147 } 00148 } 00149 } 00150 00151 return ret;
void oversim::ChordFingerTable::handleMessage | ( | cMessage * | msg | ) | [virtual] |
Definition at line 47 of file ChordFingerTable.cc.
00049 { 00050 error("this module doesn't handle messages, it runs only in initialize()");
void oversim::ChordFingerTable::initialize | ( | int | stage | ) | [virtual] |
Definition at line 35 of file ChordFingerTable.cc.
00037 { 00038 // because of IPAddressResolver, we need to wait until interfaces 00039 // are registered, address auto-assignment takes place etc. 00040 if(stage != MIN_STAGE_OVERLAY) 00041 return; 00042 00043 maxSize = 0; 00044 00045 WATCH_DEQUE(fingerTable);
void oversim::ChordFingerTable::initializeTable | ( | uint32_t | size, | |
const NodeHandle & | owner, | |||
Chord * | overlay | |||
) | [virtual] |
Sets up the finger table.
Sets up the finger table and makes all fingers pointing to the node itself. Should be called on startup to initialize the finger table.
size | number of fingers | |
owner | set all fingers to the key of node handle owner | |
overlay | pointer to the main chord module |
Definition at line 52 of file ChordFingerTable.cc.
Referenced by oversim::Chord::initializeFriendModules().
00055 { 00056 maxSize = size; 00057 this->overlay = overlay; 00058 fingerTable.clear();
virtual int oversim::ChordFingerTable::numInitStages | ( | ) | const [inline, virtual] |
Definition at line 56 of file ChordFingerTable.h.
00057 { 00058 return MAX_STAGE_OVERLAY + 1; 00059 }
void oversim::ChordFingerTable::removeFinger | ( | uint32_t | pos | ) |
Deletes a particular finger.
pos | number of the finger to get |
Definition at line 153 of file ChordFingerTable.cc.
Referenced by oversim::Chord::handleFixFingersTimerExpired(), and oversim::Chord::handleRpcFixfingersResponse().
00155 { 00156 if (pos >= maxSize) { 00157 throw new cRuntimeError("ChordFingerTable::removeFinger(): " 00158 "Index out of bound"); 00159 } 00160 00161 uint32_t p = maxSize - pos - 1; 00162 00163 if (p >= fingerTable.size()) { 00164 return; 00165 } else if (p == (fingerTable.size() - 1)) { 00166 fingerTable.pop_back(); 00167 } else { 00168 Successors tempSuccessors; 00169 fingerTable[p] = FingerEntry(NodeHandle::UNSPECIFIED_NODE, 00170 tempSuccessors); 00171 }
void oversim::ChordFingerTable::setFinger | ( | uint32_t | pos, | |
const Successors & | nodes | |||
) | [virtual] |
Definition at line 88 of file ChordFingerTable.cc.
00090 { 00091 setFinger(pos, nodes.begin()->second, &nodes);
void oversim::ChordFingerTable::setFinger | ( | uint32_t | pos, | |
const NodeHandle & | node, | |||
Successors const * | sucNodes = NULL | |||
) | [virtual] |
Sets a particular finger to point to node.
pos | number of the finger to set | |
node | set finger to this node | |
sucNodes | optional pointer containing a list of successors of this finger |
Definition at line 65 of file ChordFingerTable.cc.
Referenced by oversim::Chord::handleRpcFixfingersResponse(), and setFinger().
00068 { 00069 if (pos >= maxSize) { 00070 throw new cRuntimeError("ChordFingerTable::setFinger(): " 00071 "Index out of bound"); 00072 } 00073 00074 uint32_t p = maxSize - pos - 1; 00075 Successors tempSuccessors; 00076 00077 while (fingerTable.size() <= p) { 00078 fingerTable.push_back(FingerEntry(NodeHandle::UNSPECIFIED_NODE, 00079 tempSuccessors)); 00080 } 00081 00082 if (sucNodes != NULL) { 00083 fingerTable[p] = FingerEntry(node, *sucNodes); 00084 } else { 00085 fingerTable[p] = FingerEntry(node, tempSuccessors); 00086 }
bool oversim::ChordFingerTable::updateFinger | ( | uint32_t | pos, | |
const NodeHandle & | node, | |||
simtime_t | rtt | |||
) | [virtual] |
Definition at line 93 of file ChordFingerTable.cc.
Referenced by oversim::Chord::handleRpcFixfingersResponse(), oversim::Chord::pingResponse(), and oversim::Chord::proxCallback().
00096 { 00097 if (rtt < 0) 00098 return false; 00099 00100 if (pos >= maxSize) { 00101 throw new cRuntimeError("ChordFingerTable::updateFinger(): " 00102 "Index out of bound"); 00103 } 00104 00105 uint32_t p = maxSize - pos - 1; 00106 00107 while (fingerTable.size() <= p) { 00108 Successors tempSuccessors; 00109 fingerTable.push_back(FingerEntry(NodeHandle::UNSPECIFIED_NODE, 00110 tempSuccessors)); 00111 } 00112 00113 Successors::iterator it; 00114 for (it = fingerTable[p].second.begin(); it != fingerTable[p].second.end(); 00115 it++) { 00116 00117 if (it->second == node) { 00118 break; 00119 } 00120 } 00121 00122 if (it == fingerTable[p].second.end()) { 00123 return false; 00124 } 00125 00126 fingerTable[p].second.erase(it); 00127 fingerTable[p].second.insert(std::make_pair(rtt, node)); 00128 00129 return true;
std::deque<FingerEntry> oversim::ChordFingerTable::fingerTable [private] |
the finger table vector
Definition at line 121 of file ChordFingerTable.h.
Referenced by getFinger(), handleFailedNode(), initialize(), initializeTable(), removeFinger(), setFinger(), and updateFinger().
uint32_t oversim::ChordFingerTable::maxSize [private] |
maximum size of the finger table
Definition at line 120 of file ChordFingerTable.h.
Referenced by getFinger(), getSize(), initialize(), initializeTable(), removeFinger(), setFinger(), and updateFinger().
Chord* oversim::ChordFingerTable::overlay [private] |
pointer to the main chord module
Definition at line 122 of file ChordFingerTable.h.
Referenced by getFinger().