#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 GiaNode &node) const | |||
| ||||
virtual bool | contains (const OverlayKey &key) const | |||
| ||||
virtual void | add (const GiaNode &node, unsigned int degree) | |||
Adds a new neighbor to our neighbor list. | ||||
virtual void | remove (const GiaNode &node) | |||
Removes neighbor from our neighbor list. | ||||
virtual const GiaNode & | get (unsigned int position) | |||
Get neighbor at position. | ||||
virtual const GiaNode & | get (const OverlayKey &key) | |||
Get node from neighborlist. | ||||
GiaNeighborInfo * | get (const GiaNode &node) | |||
void | updateTimestamp (const GiaNode &node) | |||
Update timestamp. | ||||
void | removeTimedoutNodes () | |||
Removes timedout nodes. | ||||
void | setNeighborKeyList (const GiaNode &node, const GiaKeyList &keyList) | |||
Sets the keyList of neighbor at position pos. | ||||
GiaKeyList * | getNeighborKeyList (const GiaNode &node) | |||
double | getCapacity (const GiaNode &node) const | |||
void | setConnectionDegree (const GiaNode &node, unsigned int degree) | |||
unsigned int | getConnectionDegree (const GiaNode &node) const | |||
void | setReceivedTokens (const GiaNode &node, unsigned int tokens) | |||
void | increaseReceivedTokens (const GiaNode &node) | |||
void | decreaseReceivedTokens (const GiaNode &node) | |||
unsigned int | getReceivedTokens (const GiaNode &node) const | |||
void | setSentTokens (const GiaNode &node, unsigned int tokens) | |||
void | increaseSentTokens (const GiaNode &node) | |||
unsigned int | getSentTokens (const GiaNode &node) const | |||
const GiaNode & | getDropCandidate (double capacity, unsigned int degree) const | |||
Protected Types | ||||
typedef std::map < GiaNode, GiaNeighborInfo > ::iterator | NeighborsIterator | |||
typedef std::map < GiaNode, GiaNeighborInfo > ::const_iterator | NeighborsConstIterator | |||
Protected Attributes | ||||
std::map< GiaNode, GiaNeighborInfo > | neighbors | |||
contains all current neighbors | ||||
GiaNode | thisNode | |||
simtime_t | timeout | |||
this node |
typedef std::map<GiaNode, GiaNeighborInfo>::iterator GiaNeighbors::NeighborsIterator [protected] |
typedef std::map<GiaNode, GiaNeighborInfo>::const_iterator GiaNeighbors::NeighborsConstIterator [protected] |
virtual int GiaNeighbors::numInitStages | ( | ) | const [inline, 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 }
void GiaNeighbors::handleMessages | ( | cMessage * | msg | ) | [virtual] |
uint GiaNeighbors::getSize | ( | ) | const [virtual] |
bool GiaNeighbors::contains | ( | const GiaNode & | 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 }
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 }
void GiaNeighbors::add | ( | const GiaNode & | node, | |
unsigned int | degree | |||
) | [virtual] |
Adds a new neighbor to our neighbor list.
node | New neighbor to add | |
degree | The new neighbor's connection degree |
00076 { 00077 GiaNeighborInfo info = {degree, 00078 5, 00079 5, 00080 simulation.simTime(), 00081 GiaKeyList()}; 00082 00083 neighbors.insert(std::make_pair(node, info)); 00084 //neighbors.insert(node); 00085 }
void GiaNeighbors::remove | ( | const GiaNode & | node | ) | [virtual] |
Removes neighbor from our neighbor list.
node | Node to remove to |
00097 { 00098 neighbors.erase(node); 00099 }
const GiaNode & GiaNeighbors::get | ( | unsigned int | position | ) | [virtual] |
Get neighbor at position.
position |
00102 { 00103 assert( getSize() && i <= getSize() ); 00104 NeighborsIterator it = neighbors.begin(); 00105 00106 for(unsigned int j = 0; j < i; j++) 00107 it++; 00108 00109 if (it != neighbors.end()) return it->first; 00110 return GiaNode::UNSPECIFIED_NODE; 00111 }
const GiaNode & GiaNeighbors::get | ( | const OverlayKey & | key | ) | [virtual] |
Get node from neighborlist.
key | the node's key |
00125 { 00126 NeighborsIterator it; 00127 00128 for(it = neighbors.begin(); it != neighbors.end(); it++) 00129 if(it->first.key == key) 00130 break; 00131 00132 if(it != neighbors.end()) 00133 return it->first; 00134 return GiaNode::UNSPECIFIED_NODE; 00135 }
GiaNeighborInfo * GiaNeighbors::get | ( | const GiaNode & | node | ) |
00114 { 00115 if (node.isUnspecified()) return NULL; 00116 00117 NeighborsIterator it = neighbors.find(node); 00118 00119 if(it != neighbors.end()) 00120 return &(it->second); 00121 return NULL; 00122 }
void GiaNeighbors::updateTimestamp | ( | const GiaNode & | node | ) |
Update timestamp.
00138 { 00139 NeighborsIterator it = neighbors.find(node); 00140 00141 if(it != neighbors.end()) 00142 it->second.timestamp = simulation.simTime(); 00143 }
void GiaNeighbors::removeTimedoutNodes | ( | ) |
Removes timedout nodes.
00146 { 00147 NeighborsIterator it = neighbors.begin(); 00148 00149 while(it != neighbors.end()) { 00150 if(simulation.simTime() > (it->second.timestamp + timeout)) { 00151 neighbors.erase(it); 00152 it = neighbors.begin();//not efficient 00153 } 00154 else 00155 it++; 00156 } 00157 00158 }
void GiaNeighbors::setNeighborKeyList | ( | const GiaNode & | node, | |
const GiaKeyList & | keyList | |||
) |
Sets the keyList of neighbor at position pos.
node | the node the keylist belongs to | |
keyList | KeyList to set |
00163 { 00164 NeighborsIterator it = neighbors.find(node); 00165 00166 if(it != neighbors.end()) 00167 it->second.keyList = keyList; 00168 }
GiaKeyList * GiaNeighbors::getNeighborKeyList | ( | const GiaNode & | node | ) |
00171 { 00172 NeighborsIterator it = neighbors.find(node); 00173 00174 if(it != neighbors.end()) 00175 return &(it->second.keyList); 00176 return NULL; 00177 }
double GiaNeighbors::getCapacity | ( | const GiaNode & | node | ) | const |
00180 { 00181 NeighborsConstIterator it = neighbors.find(node); 00182 00183 if(it != neighbors.end()) 00184 return it->first.getCapacity(); 00185 return 0; 00186 }
void GiaNeighbors::setConnectionDegree | ( | const GiaNode & | node, | |
unsigned int | degree | |||
) |
00207 { 00208 NeighborsIterator it = neighbors.find(node); 00209 00210 if(it != neighbors.end()) 00211 it->second.connectionDegree = degree; 00212 }
unsigned int GiaNeighbors::getConnectionDegree | ( | const GiaNode & | node | ) | const |
00197 { 00198 NeighborsConstIterator it = neighbors.find(node); 00199 00200 if(it != neighbors.end()) 00201 return it->second.connectionDegree; 00202 return 0; 00203 }
void GiaNeighbors::setReceivedTokens | ( | const GiaNode & | node, | |
unsigned int | tokens | |||
) |
00216 { 00217 NeighborsIterator it = neighbors.find(node); 00218 00219 if(it != neighbors.end()) { 00220 std::cout << "recieved: " << it->second.receivedTokens << " -> " << tokens << std::endl; 00221 it->second.receivedTokens = tokens; 00222 } 00223 }
void GiaNeighbors::increaseReceivedTokens | ( | const GiaNode & | node | ) |
00226 { 00227 NeighborsIterator it = neighbors.find(node); 00228 00229 if(it != neighbors.end()) 00230 it->second.receivedTokens++; 00231 }
void GiaNeighbors::decreaseReceivedTokens | ( | const GiaNode & | node | ) |
00234 { 00235 NeighborsIterator it = neighbors.find(node); 00236 00237 if(it != neighbors.end()) 00238 it->second.receivedTokens--; 00239 }
unsigned int GiaNeighbors::getReceivedTokens | ( | const GiaNode & | node | ) | const |
00242 { 00243 NeighborsConstIterator it = neighbors.find(node); 00244 00245 if(it != neighbors.end()) 00246 return it->second.receivedTokens; 00247 return 0; 00248 }
void GiaNeighbors::setSentTokens | ( | const GiaNode & | node, | |
unsigned int | tokens | |||
) |
00252 { 00253 NeighborsIterator it = neighbors.find(node); 00254 00255 if(it != neighbors.end()) { 00256 std::cout << "sent: " << it->second.sentTokens << " -> " << tokens << std::endl; 00257 it->second.sentTokens = tokens; 00258 } 00259 }
void GiaNeighbors::increaseSentTokens | ( | const GiaNode & | node | ) |
00262 { 00263 NeighborsIterator it = neighbors.find(node); 00264 00265 if(it != neighbors.end() && it->second.sentTokens >= 0) 00266 it->second.sentTokens++; 00267 }
unsigned int GiaNeighbors::getSentTokens | ( | const GiaNode & | node | ) | const |
00270 { 00271 NeighborsConstIterator it = neighbors.find(node); 00272 00273 if(it != neighbors.end()) 00274 return it->second.sentTokens; 00275 return 0; 00276 }
const GiaNode & GiaNeighbors::getDropCandidate | ( | double | capacity, | |
unsigned int | degree | |||
) | const |
00280 { 00281 // determine node with highest capacity 00282 unsigned int subset = 0; 00283 double maxCapacity = 0; 00284 unsigned int dropDegree; 00285 GiaNode dropCandidate; 00286 00287 NeighborsConstIterator it, candIt; 00288 for(it = neighbors.begin(); it != neighbors.end(); it++) { 00289 if(it->first.getCapacity() <= capacity) { 00290 subset++; 00291 if(it->first.getCapacity() > maxCapacity) { 00292 candIt = it; 00293 dropDegree = it->second.connectionDegree; 00294 maxCapacity = it->first.getCapacity(); 00295 } 00296 } 00297 } 00298 00299 if(subset > 0 && 00300 (/*subset == neighbors->getSize() || */dropDegree > degree) && 00301 dropDegree > 1) { 00302 return candIt->first; 00303 } 00304 00305 return GiaNode::UNSPECIFIED_NODE; 00306 }
std::map<GiaNode, GiaNeighborInfo> GiaNeighbors::neighbors [protected] |
contains all current neighbors
GiaNode GiaNeighbors::thisNode [protected] |
simtime_t GiaNeighbors::timeout [protected] |
this node