#include <GiaNeighbors.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 unsigned int | getSize () const |
virtual bool | contains (const NodeHandle &node) const |
virtual bool | contains (const OverlayKey &key) const |
virtual void | add (const GiaNode &node) |
Adds a new neighbor to our neighbor list. | |
virtual void | remove (const NodeHandle &node) |
Removes neighbor from our neighbor list. | |
virtual const NodeHandle & | get (unsigned int position) |
Get neighbor at position. | |
virtual const NodeHandle & | get (const OverlayKey &key) |
Get node from neighborlist. | |
GiaNeighborInfo * | get (const NodeHandle &node) |
void | updateTimestamp (const NodeHandle &node) |
Update timestamp. | |
void | removeTimedoutNodes () |
Removes timedout nodes. | |
void | setNeighborKeyList (const NodeHandle &node, const GiaKeyList &keyList) |
Sets the keyList of neighbor at position pos. | |
GiaKeyList * | getNeighborKeyList (const NodeHandle &node) |
double | getCapacity (const NodeHandle &node) const |
void | setCapacity (const NodeHandle &node, double capacity) |
void | setConnectionDegree (const NodeHandle &node, unsigned int degree) |
unsigned int | getConnectionDegree (const NodeHandle &node) const |
void | setReceivedTokens (const NodeHandle &node, unsigned int tokens) |
unsigned int | getReceivedTokens (const NodeHandle &node) const |
void | setSentTokens (const NodeHandle &node, unsigned int tokens) |
void | decreaseSentTokens (const NodeHandle &node) |
unsigned int | getSentTokens (const NodeHandle &node) const |
const NodeHandle & | getDropCandidate (double capacity, unsigned int degree) const |
Protected Types | |
typedef std::map< NodeHandle, GiaNeighborInfo >::iterator | NeighborsIterator |
typedef std::map< NodeHandle, GiaNeighborInfo >::const_iterator | NeighborsConstIterator |
Protected Attributes | |
std::map< NodeHandle, GiaNeighborInfo > | neighbors |
contains all current neighbors | |
GiaNode | thisNode |
simtime_t | timeout |
this node | |
GiaNode | unspecNode |
timeout for neighbors |
typedef std::map<NodeHandle, GiaNeighborInfo>::const_iterator GiaNeighbors::NeighborsConstIterator [protected] |
typedef std::map<NodeHandle, GiaNeighborInfo>::iterator GiaNeighbors::NeighborsIterator [protected] |
void GiaNeighbors::add | ( | const GiaNode & | node | ) | [virtual] |
Adds a new neighbor to our neighbor list.
node | New neighbor to add |
00076 { 00077 GiaNeighborInfo info = {node.getCapacity(), 00078 node.getConnectionDegree(), 00079 node.getReceivedTokens(), 00080 node.getSentTokens(), 00081 simulation.simTime(), 00082 GiaKeyList()}; 00083 00084 neighbors.insert(std::make_pair(node.getNodeHandle(), info)); 00085 }
bool GiaNeighbors::contains | ( | const OverlayKey & | key | ) | const [virtual] |
key | to check |
00054 { 00055 NeighborsConstIterator it = neighbors.begin(); 00056 00057 for(it = neighbors.begin(); it != neighbors.end(); it++) 00058 if(it->first.key == key) 00059 break; 00060 00061 if (it != neighbors.end()) 00062 return true; 00063 return false; 00064 }
bool GiaNeighbors::contains | ( | const NodeHandle & | node | ) | const [virtual] |
node | GiaNode to check |
00067 { 00068 NeighborsConstIterator it = neighbors.find(node); 00069 00070 if(it != neighbors.end()) 00071 return true; 00072 return false; 00073 }
void GiaNeighbors::decreaseSentTokens | ( | const NodeHandle & | node | ) |
00237 { 00238 NeighborsIterator it = neighbors.find(node); 00239 00240 if(it != neighbors.end() && it->second.sentTokens >= 0) 00241 it->second.sentTokens--; 00242 }
GiaNeighborInfo * GiaNeighbors::get | ( | const NodeHandle & | node | ) |
00112 { 00113 NeighborsIterator it = neighbors.find(node); 00114 00115 if(it != neighbors.end()) 00116 return &(it->second); 00117 return NULL; 00118 }
const NodeHandle & GiaNeighbors::get | ( | const OverlayKey & | key | ) | [virtual] |
Get node from neighborlist.
key | the node's key |
00121 { 00122 NeighborsIterator it; 00123 00124 for(it = neighbors.begin(); it != neighbors.end(); it++) 00125 if(it->first.key == key) 00126 break; 00127 00128 if(it != neighbors.end()) 00129 return it->first; 00130 return NodeHandle::UNSPECIFIED_NODE; 00131 }
const NodeHandle & GiaNeighbors::get | ( | unsigned int | position | ) | [virtual] |
Get neighbor at position.
position |
00102 { 00103 NeighborsIterator it = neighbors.begin(); 00104 00105 for(unsigned int j = 0; j < i; j++) 00106 it++; 00107 00108 return it->first; 00109 }
double GiaNeighbors::getCapacity | ( | const NodeHandle & | node | ) | const |
00176 { 00177 NeighborsConstIterator it = neighbors.find(node); 00178 00179 if(it != neighbors.end()) 00180 return it->second.capacity; 00181 return 0; 00182 }
unsigned int GiaNeighbors::getConnectionDegree | ( | const NodeHandle & | node | ) | const |
00193 { 00194 NeighborsConstIterator it = neighbors.find(node); 00195 00196 if(it != neighbors.end()) 00197 return it->second.connectionDegree; 00198 return 0; 00199 }
const NodeHandle & GiaNeighbors::getDropCandidate | ( | double | capacity, | |
unsigned int | degree | |||
) | const |
00255 { 00256 // determine node with highest capacity 00257 unsigned int subset = 0; 00258 double maxCapacity = 0; 00259 unsigned int dropDegree; 00260 NodeHandle dropCandidate; 00261 00262 NeighborsConstIterator it, candIt; 00263 for(it = neighbors.begin(); it != neighbors.end(); it++) { 00264 if(it->second.capacity <= capacity) { 00265 subset++; 00266 if(it->second.capacity > maxCapacity) { 00267 candIt = it; 00268 dropDegree = it->second.connectionDegree; 00269 maxCapacity = it->second.capacity; 00270 } 00271 } 00272 } 00273 00274 if(subset > 0 && 00275 (/*subset == neighbors->getSize() || */dropDegree > degree) && 00276 dropDegree > 1) { 00277 return candIt->first; 00278 } 00279 00280 return NodeHandle::UNSPECIFIED_NODE; 00281 }
GiaKeyList * GiaNeighbors::getNeighborKeyList | ( | const NodeHandle & | node | ) |
00167 { 00168 NeighborsIterator it = neighbors.find(node); 00169 00170 if(it != neighbors.end()) 00171 return &(it->second.keyList); 00172 return NULL; 00173 }
unsigned int GiaNeighbors::getReceivedTokens | ( | const NodeHandle & | node | ) | const |
00220 { 00221 NeighborsConstIterator it = neighbors.find(node); 00222 00223 if(it != neighbors.end()) 00224 return it->second.receivedTokens; 00225 return 0; 00226 }
unsigned int GiaNeighbors::getSentTokens | ( | const NodeHandle & | node | ) | const |
00245 { 00246 NeighborsConstIterator it = neighbors.find(node); 00247 00248 if(it != neighbors.end()) 00249 return it->second.sentTokens; 00250 return 0; 00251 }
uint GiaNeighbors::getSize | ( | ) | const [virtual] |
void GiaNeighbors::handleMessages | ( | cMessage * | msg | ) | [virtual] |
void GiaNeighbors::initialize | ( | int | stage | ) | [virtual] |
Initializes this class and set some WATCH(variable) for OMNeT++.
stage | Level of initialization (OMNeT++) |
00032 { 00033 // wait until IPAddressResolver finished his initialization 00034 if(stage != MIN_STAGE_OVERLAY) 00035 return; 00036 00037 WATCH_MAP(neighbors); 00038 this->timeout = parentModule()->submodule("gia")->par("neighborTimeout"); 00039 unspecNode = GiaNode::UNSPECIFIED_NODE; 00040 }
virtual int GiaNeighbors::numInitStages | ( | ) | const [inline, virtual] |
void GiaNeighbors::remove | ( | const NodeHandle & | node | ) | [virtual] |
Removes neighbor from our neighbor list.
node | Node to remove to |
00097 { 00098 neighbors.erase(node); 00099 }
void GiaNeighbors::removeTimedoutNodes | ( | ) |
Removes timedout nodes.
00142 { 00143 NeighborsIterator it = neighbors.begin(); 00144 00145 while(it != neighbors.end()) { 00146 if(simulation.simTime() > (it->second.timestamp + timeout)) { 00147 neighbors.erase(it); 00148 it = neighbors.begin();//not efficient 00149 } 00150 else 00151 it++; 00152 } 00153 00154 }
void GiaNeighbors::setCapacity | ( | const NodeHandle & | node, | |
double | capacity | |||
) |
00185 { 00186 NeighborsIterator it = neighbors.find(node); 00187 00188 if(it != neighbors.end()) 00189 it->second.capacity = capacity; 00190 }
void GiaNeighbors::setConnectionDegree | ( | const NodeHandle & | node, | |
unsigned int | degree | |||
) |
00203 { 00204 NeighborsIterator it = neighbors.find(node); 00205 00206 if(it != neighbors.end()) 00207 it->second.connectionDegree = degree; 00208 }
void GiaNeighbors::setNeighborKeyList | ( | const NodeHandle & | node, | |
const GiaKeyList & | keyList | |||
) |
Sets the keyList of neighbor at position pos.
node | the node the keylist belongs to | |
keyList | KeyList to set |
00159 { 00160 NeighborsIterator it = neighbors.find(node); 00161 00162 if(it != neighbors.end()) 00163 it->second.keyList = keyList; 00164 }
void GiaNeighbors::setReceivedTokens | ( | const NodeHandle & | node, | |
unsigned int | tokens | |||
) |
00212 { 00213 NeighborsIterator it = neighbors.find(node); 00214 00215 if(it != neighbors.end()) 00216 it->second.receivedTokens = tokens; 00217 }
void GiaNeighbors::setSentTokens | ( | const NodeHandle & | node, | |
unsigned int | tokens | |||
) |
00229 { 00230 NeighborsIterator it = neighbors.find(node); 00231 00232 if(it != neighbors.end()) 00233 it->second.sentTokens = tokens; 00234 }
void GiaNeighbors::updateTimestamp | ( | const NodeHandle & | node | ) |
Update timestamp.
00134 { 00135 NeighborsIterator it = neighbors.find(node); 00136 00137 if(it != neighbors.end()) 00138 it->second.timestamp = simulation.simTime(); 00139 }
std::map<NodeHandle, GiaNeighborInfo> GiaNeighbors::neighbors [protected] |
contains all current neighbors
GiaNode GiaNeighbors::thisNode [protected] |
simtime_t GiaNeighbors::timeout [protected] |
this node
GiaNode GiaNeighbors::unspecNode [protected] |
timeout for neighbors