#include <Neighbors.h>
Public Member Functions | |
virtual int | numInitStages () const |
Sets init stage. | |
virtual void | initialize (int stage) |
Initializes this class and set some WATCH(variable) for OMNeT++. | |
virtual void | handleMessages (cMessage *msg) |
This module doesn't handle OMNeT++ messages. | |
virtual void | finish () |
Save statistical data. | |
virtual uint | getSize () |
virtual bool | contains (const GiaNode &node) const |
virtual bool | contains (const OverlayKey &key) const |
virtual int | getPosition (const OverlayKey &key) const |
Returns position of node. | |
virtual int | getPosition (const GiaNode &node) const |
Returns position of node. | |
virtual void | add (const GiaNode &node) |
Adds a new neighbor to our neighbor list. | |
virtual void | remove (const GiaNode &node) |
Removes neighbor from our neighbor list. | |
virtual void | remove (int position) |
Removes neighbor from neighbor list at given position. | |
virtual GiaNode * | get (int position) |
Get neighbor at position. | |
virtual GiaNode * | get (const GiaNode &node) |
Get neighbor from neighborlist. | |
virtual GiaNode * | get (const OverlayKey &key) |
Get GiaNode from neighborlist. | |
void | updateTimestamp (const GiaNode &node) |
Update timestamp. | |
void | removeTimedoutNodes () |
Removes timedout nodes. | |
void | setNeighborKeyList (uint pos, const KeyList &keyList) |
Sets the keyList of neighbor at position pos. | |
KeyList * | getNeighborKeyList (uint pos) |
Get keylist from neighbor. | |
Protected Attributes | |
std::vector< NeighborNode > | neighbors |
contains all current neighbors | |
GiaNode | thisNode |
simtime_t | timeout |
this node | |
GiaNode | unspecNode |
timeout for neighbors |
void Neighbors::add | ( | const GiaNode & | node | ) | [virtual] |
Adds a new neighbor to our neighbor list.
node | New neighbor to add |
00083 { 00084 if(!contains(node)) 00085 neighbors.push_back(NeighborNode(node, simulation.simTime())); 00086 }
bool Neighbors::contains | ( | const OverlayKey & | key | ) | const [virtual] |
key | to check |
00055 { 00056 if (getPosition(key) != -1) 00057 return true; 00058 return false; 00059 }
bool Neighbors::contains | ( | const GiaNode & | node | ) | const [virtual] |
node | GiaNode to check |
00062 { 00063 if (getPosition(node) != -1) 00064 return true; 00065 return false; 00066 }
GiaNode * Neighbors::get | ( | const OverlayKey & | key | ) | [virtual] |
Get GiaNode from neighborlist.
key | GiaNode-Key |
00132 { 00133 if(neighbors.size() == 0) 00134 return &unspecNode; 00135 else { 00136 int position = getPosition(key); 00137 if(position == -1) 00138 return &unspecNode; 00139 else 00140 return get 00141 (position); 00142 } 00143 }
Get neighbor from neighborlist.
node | GiaNode |
00117 { 00118 if(neighbors.size() == 0) 00119 return &unspecNode; 00120 else { 00121 int position = getPosition(node); 00122 if(position == -1) 00123 return &unspecNode; 00124 else 00125 return get 00126 (position); 00127 } 00128 }
GiaNode * Neighbors::get | ( | int | position | ) | [virtual] |
Get neighbor at position.
position |
00108 { 00109 if ( neighbors.size() == 0 || position == -1 ) 00110 return &unspecNode; 00111 else 00112 return &neighbors[position].giaNode; 00113 }
KeyList * Neighbors::getNeighborKeyList | ( | uint | pos | ) |
Get keylist from neighbor.
pos | Position of neighbor |
00172 { 00173 return &(neighbors[pos].keyList); 00174 }
int Neighbors::getPosition | ( | const GiaNode & | node | ) | const [virtual] |
Returns position of node.
node | to check |
00069 { 00070 return getPosition(node.getNodeHandle().key); 00071 }
int Neighbors::getPosition | ( | const OverlayKey & | key | ) | const [virtual] |
uint Neighbors::getSize | ( | ) | [virtual] |
void Neighbors::handleMessages | ( | cMessage * | msg | ) | [virtual] |
void Neighbors::initialize | ( | int | stage | ) | [virtual] |
Initializes this class and set some WATCH(variable) for OMNeT++.
stage | Level of initialization (OMNeT++) |
00033 { 00034 // wait until IPAddressResolver finished his initialization 00035 if(stage != MIN_STAGE_OVERLAY) 00036 return; 00037 00038 WATCH_VECTOR(neighbors); 00039 this->timeout = parentModule()->submodule("gia")->par("neighborTimeout"); 00040 unspecNode = GiaNode::UNSPECIFIED_NODE; 00041 }
virtual int Neighbors::numInitStages | ( | ) | const [inline, virtual] |
void Neighbors::remove | ( | int | position | ) | [virtual] |
void Neighbors::remove | ( | const GiaNode & | node | ) | [virtual] |
Removes neighbor from our neighbor list.
node | Node to remove to |
00092 { 00093 int position = getPosition(node); 00094 if ( position != -1 ) 00095 neighbors.erase(neighbors.begin() + position); 00096 }
void Neighbors::removeTimedoutNodes | ( | ) |
Removes timedout nodes.
00155 { 00156 std::vector<NeighborNode>::iterator it = neighbors.begin(); 00157 std::vector<NeighborNode>::iterator it2 = neighbors.begin(); 00158 for ( uint i=0; i<neighbors.size(); i++) { 00159 NeighborNode neighborNode = neighbors[i]; 00160 it2 = it++; 00161 if ( simulation.simTime() > (neighborNode.timestamp + timeout)) 00162 neighbors.erase(it2); 00163 } 00164 }
void Neighbors::setNeighborKeyList | ( | uint | pos, | |
const KeyList & | keyList | |||
) |
void Neighbors::updateTimestamp | ( | const GiaNode & | node | ) |
Update timestamp.
00146 { 00147 int position = getPosition(node); 00148 if(position != -1) { 00149 neighbors[position].timestamp = simulation.simTime(); 00150 } 00151 }
std::vector<NeighborNode> Neighbors::neighbors [protected] |
contains all current neighbors
GiaNode Neighbors::thisNode [protected] |
simtime_t Neighbors::timeout [protected] |
this node
GiaNode Neighbors::unspecNode [protected] |
timeout for neighbors