OverSim
oversim::ChordFingerTable Class Reference

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 NodeHandlegetFinger (uint32_t pos)
 Returns the NodeVector of a particular finger.
virtual NodeVectorgetFinger (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< FingerEntryfingerTable
 the finger table vector
Chordoverlay
 pointer to the main chord module

Detailed Description

Chord's finger table module.

This modul contains the finger table of the Chord implementation.

Author
Markus Mauch, Ingmar Baumgart
See Also
Chord

Definition at line 52 of file ChordFingerTable.h.

Member Function Documentation

const NodeHandle & oversim::ChordFingerTable::getFinger ( uint32_t  pos)
virtual

Returns the NodeVector of a particular finger.

Parameters
posnumber of the finger to get
Returns
NodeVector of the particular finger(s)

Definition at line 176 of file ChordFingerTable.cc.

{
if (pos >= maxSize) {
throw new cRuntimeError("ChordFingerTable::getFinger(): "
"Index out of bound");
}
uint32_t p = maxSize - pos - 1;
if (p >= fingerTable.size()) {
}
while (fingerTable[p].first.isUnspecified() &&
(p < (fingerTable.size() - 1))) {
++p;
}
if (fingerTable[p].first.isUnspecified())
return fingerTable[p].first;
}
NodeVector * oversim::ChordFingerTable::getFinger ( uint32_t  pos,
const OverlayKey key 
)
virtual

Definition at line 197 of file ChordFingerTable.cc.

{
if (pos >= maxSize) {
throw new cRuntimeError("ChordFingerTable::getFinger(): "
"Index out of bound");
}
NodeVector* nextHop = new NodeVector();
uint32_t p = maxSize - pos - 1;
if (p < fingerTable.size()) {
for (Successors::const_iterator it = fingerTable[p].second.begin();
it != fingerTable[p].second.end(); it++) {
if(!key.isBetweenLR(fingerTable[p].first.getKey(), it->second.getKey())) {
nextHop->push_back(it->second);
}
}
} else {
nextHop->push_back(overlay->successorList->getSuccessor());
return nextHop;
}
if (nextHop->size() == 0) {
if (fingerTable[p].first.isUnspecified()) {
//TODO use other finger
nextHop->push_back(overlay->successorList->getSuccessor());
} else {
nextHop->push_back(fingerTable[p].first);
}
}
return nextHop;
}
uint32_t oversim::ChordFingerTable::getSize ( )
virtual

Returns the size of the finger table.

Returns
number of fingers

Definition at line 63 of file ChordFingerTable.cc.

{
return maxSize;
}
bool oversim::ChordFingerTable::handleFailedNode ( const TransportAddress failed)

Definition at line 134 of file ChordFingerTable.cc.

{
bool ret = false;
for (int p = fingerTable.size() - 1; p >= 0; p--) {
if (!fingerTable[p].first.isUnspecified() &&
failed == fingerTable[p].first) {
ret = true;
}
for (std::multimap<simtime_t, NodeHandle>::iterator it =
fingerTable[p].second.begin(); it != fingerTable[p].second.end();
++it) {
if (failed == it->second) {
fingerTable[p].second.erase(it);
break;
}
}
}
return ret;
}
void oversim::ChordFingerTable::handleMessage ( cMessage *  msg)
virtual

Definition at line 50 of file ChordFingerTable.cc.

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

Definition at line 38 of file ChordFingerTable.cc.

{
// because of IPAddressResolver, we need to wait until interfaces
// are registered, address auto-assignment takes place etc.
if(stage != MIN_STAGE_OVERLAY)
return;
maxSize = 0;
}
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.

Parameters
sizenumber of fingers
ownerset all fingers to the key of node handle owner
overlaypointer to the main chord module

Definition at line 55 of file ChordFingerTable.cc.

{
maxSize = size;
this->overlay = overlay;
fingerTable.clear();
}
virtual int oversim::ChordFingerTable::numInitStages ( ) const
inlinevirtual

Definition at line 56 of file ChordFingerTable.h.

{
return MAX_STAGE_OVERLAY + 1;
}
void oversim::ChordFingerTable::removeFinger ( uint32_t  pos)

Deletes a particular finger.

Parameters
posnumber of the finger to get

Definition at line 156 of file ChordFingerTable.cc.

{
if (pos >= maxSize) {
throw new cRuntimeError("ChordFingerTable::removeFinger(): "
"Index out of bound");
}
uint32_t p = maxSize - pos - 1;
if (p >= fingerTable.size()) {
return;
} else if (p == (fingerTable.size() - 1)) {
fingerTable.pop_back();
} else {
Successors tempSuccessors;
tempSuccessors);
}
}
void oversim::ChordFingerTable::setFinger ( uint32_t  pos,
const NodeHandle node,
Successors const *  sucNodes = NULL 
)
virtual

Sets a particular finger to point to node.

Parameters
posnumber of the finger to set
nodeset finger to this node
sucNodesoptional pointer containing a list of successors of this finger

Definition at line 68 of file ChordFingerTable.cc.

{
if (pos >= maxSize) {
throw new cRuntimeError("ChordFingerTable::setFinger(): "
"Index out of bound");
}
uint32_t p = maxSize - pos - 1;
Successors tempSuccessors;
while (fingerTable.size() <= p) {
tempSuccessors));
}
if (sucNodes != NULL) {
fingerTable[p] = FingerEntry(node, *sucNodes);
} else {
fingerTable[p] = FingerEntry(node, tempSuccessors);
}
}
void oversim::ChordFingerTable::setFinger ( uint32_t  pos,
const Successors nodes 
)
virtual

Definition at line 91 of file ChordFingerTable.cc.

{
setFinger(pos, nodes.begin()->second, &nodes);
}
bool oversim::ChordFingerTable::updateFinger ( uint32_t  pos,
const NodeHandle node,
simtime_t  rtt 
)
virtual

Definition at line 96 of file ChordFingerTable.cc.

{
if (rtt < 0)
return false;
if (pos >= maxSize) {
throw new cRuntimeError("ChordFingerTable::updateFinger(): "
"Index out of bound");
}
uint32_t p = maxSize - pos - 1;
while (fingerTable.size() <= p) {
Successors tempSuccessors;
tempSuccessors));
}
Successors::iterator it;
for (it = fingerTable[p].second.begin(); it != fingerTable[p].second.end();
it++) {
if (it->second == node) {
break;
}
}
if (it == fingerTable[p].second.end()) {
return false;
}
fingerTable[p].second.erase(it);
fingerTable[p].second.insert(std::make_pair(rtt, node));
return true;
}

Member Data Documentation

std::deque<FingerEntry> oversim::ChordFingerTable::fingerTable
private

the finger table vector

Definition at line 121 of file ChordFingerTable.h.

uint32_t oversim::ChordFingerTable::maxSize
private

maximum size of the finger table

Definition at line 120 of file ChordFingerTable.h.

Chord* oversim::ChordFingerTable::overlay
private

pointer to the main chord module

Definition at line 122 of file ChordFingerTable.h.


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