This class is for managing all neighbor nodes. More...
#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 |
This class is for managing all neighbor nodes.
Definition at line 59 of file GiaNeighbors.h.
typedef std::map<GiaNode, GiaNeighborInfo>::const_iterator GiaNeighbors::NeighborsConstIterator [protected] |
Definition at line 172 of file GiaNeighbors.h.
typedef std::map<GiaNode, GiaNeighborInfo>::iterator GiaNeighbors::NeighborsIterator [protected] |
Definition at line 171 of file GiaNeighbors.h.
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 |
Definition at line 77 of file GiaNeighbors.cc.
Referenced by Gia::addNeighbor().
{ GiaNeighborInfo info = {degree, 5, 5, simTime(), GiaKeyList()}; neighbors.insert(std::make_pair(node, info)); //neighbors.insert(node); }
bool GiaNeighbors::contains | ( | const GiaNode & | node | ) | const [virtual] |
node | GiaNode to check |
Definition at line 68 of file GiaNeighbors.cc.
Referenced by Gia::acceptNode(), Gia::forwardMessage(), Gia::handleTimerEvent(), and Gia::updateNeighborList().
{ NeighborsConstIterator it = neighbors.find(node); if(it != neighbors.end()) return true; return false; }
bool GiaNeighbors::contains | ( | const OverlayKey & | key | ) | const [virtual] |
key | to check |
Definition at line 55 of file GiaNeighbors.cc.
{ NeighborsConstIterator it = neighbors.begin(); for(it = neighbors.begin(); it != neighbors.end(); it++) if(it->first.getKey() == key) break; if (it != neighbors.end()) return true; return false; }
void GiaNeighbors::decreaseReceivedTokens | ( | const GiaNode & | node | ) |
Definition at line 235 of file GiaNeighbors.cc.
Referenced by Gia::forwardMessage().
{ NeighborsIterator it = neighbors.find(node); if(it != neighbors.end()) it->second.receivedTokens--; }
const GiaNode & GiaNeighbors::get | ( | unsigned int | position | ) | [virtual] |
Get neighbor at position.
position |
Definition at line 103 of file GiaNeighbors.cc.
Referenced by GiaMessageBookkeeping::addMessage(), Gia::calculateLevelOfSatisfaction(), GiaTokenFactory::createPriorityQueue(), Gia::forwardMessage(), Gia::forwardSearchResponseMessage(), GiaMessageBookkeeping::getNextHop(), Gia::handleTimerEvent(), Gia::processSearchMessage(), Gia::sendMessage_JOIN_ACK(), and Gia::sendMessage_JOIN_RSP().
{ assert( getSize() && i <= getSize() ); NeighborsIterator it = neighbors.begin(); for(unsigned int j = 0; j < i; j++) it++; if (it != neighbors.end()) return it->first; return GiaNode::UNSPECIFIED_NODE; }
const GiaNode & GiaNeighbors::get | ( | const OverlayKey & | key | ) | [virtual] |
Get node from neighborlist.
key | the node's key |
Definition at line 126 of file GiaNeighbors.cc.
{ NeighborsIterator it; for(it = neighbors.begin(); it != neighbors.end(); it++) if(it->first.getKey() == key) break; if(it != neighbors.end()) return it->first; return GiaNode::UNSPECIFIED_NODE; }
GiaNeighborInfo * GiaNeighbors::get | ( | const GiaNode & | node | ) |
Definition at line 115 of file GiaNeighbors.cc.
{ if (node.isUnspecified()) return NULL; NeighborsIterator it = neighbors.find(node); if(it != neighbors.end()) return &(it->second); return NULL; }
double GiaNeighbors::getCapacity | ( | const GiaNode & | node | ) | const |
Definition at line 181 of file GiaNeighbors.cc.
{ NeighborsConstIterator it = neighbors.find(node); if(it != neighbors.end()) return it->first.getCapacity(); return 0; }
unsigned int GiaNeighbors::getConnectionDegree | ( | const GiaNode & | node | ) | const |
Definition at line 198 of file GiaNeighbors.cc.
{ NeighborsConstIterator it = neighbors.find(node); if(it != neighbors.end()) return it->second.connectionDegree; return 0; }
const GiaNode & GiaNeighbors::getDropCandidate | ( | double | capacity, | |
unsigned int | degree | |||
) | const |
Definition at line 280 of file GiaNeighbors.cc.
Referenced by Gia::acceptNode().
{ // determine node with highest capacity unsigned int subset = 0; double maxCapacity = 0; unsigned int dropDegree = 0; GiaNode dropCandidate; NeighborsConstIterator it, candIt; for(it = neighbors.begin(); it != neighbors.end(); it++) { if(it->first.getCapacity() <= capacity) { subset++; if(it->first.getCapacity() > maxCapacity) { candIt = it; dropDegree = it->second.connectionDegree; maxCapacity = it->first.getCapacity(); } } } if(subset > 0 && (/*subset == neighbors->getSize() || */dropDegree > degree) && dropDegree > 1) { return candIt->first; } return GiaNode::UNSPECIFIED_NODE; }
GiaKeyList * GiaNeighbors::getNeighborKeyList | ( | const GiaNode & | node | ) |
Definition at line 172 of file GiaNeighbors.cc.
Referenced by Gia::processSearchMessage().
{ NeighborsIterator it = neighbors.find(node); if(it != neighbors.end()) return &(it->second.keyList); return NULL; }
unsigned int GiaNeighbors::getReceivedTokens | ( | const GiaNode & | node | ) | const |
Definition at line 243 of file GiaNeighbors.cc.
{ NeighborsConstIterator it = neighbors.find(node); if(it != neighbors.end()) return it->second.receivedTokens; return 0; }
unsigned int GiaNeighbors::getSentTokens | ( | const GiaNode & | node | ) | const |
Definition at line 271 of file GiaNeighbors.cc.
{ NeighborsConstIterator it = neighbors.find(node); if(it != neighbors.end()) return it->second.sentTokens; return 0; }
uint32_t GiaNeighbors::getSize | ( | ) | const [virtual] |
Definition at line 50 of file GiaNeighbors.cc.
Referenced by Gia::acceptNode(), GiaMessageBookkeeping::addMessage(), Gia::addNeighbor(), Gia::calculateLevelOfSatisfaction(), GiaTokenFactory::createPriorityQueue(), get(), GiaMessageBookkeeping::getNextHop(), GiaTokenFactory::grantToken(), Gia::handleTimerEvent(), Gia::handleUDPMessage(), Gia::processSearchMessage(), Gia::removeNeighbor(), Gia::sendMessage_JOIN_ACK(), Gia::sendMessage_JOIN_RSP(), and Gia::updateTooltip().
{ return neighbors.size(); }
void GiaNeighbors::handleMessages | ( | cMessage * | msg | ) | [virtual] |
This module doesn't handle OMNeT++ messages.
msg | OMNeT++ message |
Definition at line 45 of file GiaNeighbors.cc.
{ error("this module doesn't handle messages, it runs only in initialize()"); }
void GiaNeighbors::increaseReceivedTokens | ( | const GiaNode & | node | ) |
Definition at line 227 of file GiaNeighbors.cc.
Referenced by Gia::handleUDPMessage().
{ NeighborsIterator it = neighbors.find(node); if(it != neighbors.end()) it->second.receivedTokens++; }
void GiaNeighbors::increaseSentTokens | ( | const GiaNode & | node | ) |
Definition at line 263 of file GiaNeighbors.cc.
{ NeighborsIterator it = neighbors.find(node); if(it != neighbors.end() && it->second.sentTokens >= 0) it->second.sentTokens++; }
void GiaNeighbors::initialize | ( | int | stage | ) | [virtual] |
Initializes this class and set some WATCH(variable) for OMNeT++.
stage | Level of initialization (OMNeT++) |
Definition at line 33 of file GiaNeighbors.cc.
{ // wait until IPAddressResolver finished his initialization if(stage != MIN_STAGE_OVERLAY) return; WATCH_MAP(neighbors); timeout = getParentModule()->getSubmodule("gia")->par("neighborTimeout"); //unspecNode = GiaNode::UNSPECIFIED_NODE; }
virtual int GiaNeighbors::numInitStages | ( | ) | const [inline, virtual] |
void GiaNeighbors::remove | ( | const GiaNode & | node | ) | [virtual] |
Removes neighbor from our neighbor list.
node | Node to remove to |
Definition at line 98 of file GiaNeighbors.cc.
Referenced by Gia::acceptNode(), and Gia::removeNeighbor().
{ neighbors.erase(node); }
void GiaNeighbors::removeTimedoutNodes | ( | ) |
Removes timedout nodes.
Definition at line 147 of file GiaNeighbors.cc.
Referenced by Gia::handleTimerEvent().
void GiaNeighbors::setConnectionDegree | ( | const GiaNode & | node, | |
unsigned int | degree | |||
) |
Definition at line 207 of file GiaNeighbors.cc.
Referenced by Gia::handleUDPMessage(), and Gia::updateNeighborList().
{ NeighborsIterator it = neighbors.find(node); if(it != neighbors.end()) it->second.connectionDegree = degree; }
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 |
Definition at line 163 of file GiaNeighbors.cc.
Referenced by Gia::handleUDPMessage().
{ NeighborsIterator it = neighbors.find(node); if(it != neighbors.end()) it->second.keyList = keyList; }
void GiaNeighbors::setReceivedTokens | ( | const GiaNode & | node, | |
unsigned int | tokens | |||
) |
Definition at line 216 of file GiaNeighbors.cc.
{ NeighborsIterator it = neighbors.find(node); if(it != neighbors.end()) { std::cout << "recieved: " << it->second.receivedTokens << " -> " << tokens << std::endl; it->second.receivedTokens = tokens; } }
void GiaNeighbors::setSentTokens | ( | const GiaNode & | node, | |
unsigned int | tokens | |||
) |
Definition at line 253 of file GiaNeighbors.cc.
{ NeighborsIterator it = neighbors.find(node); if(it != neighbors.end()) { std::cout << "sent: " << it->second.sentTokens << " -> " << tokens << std::endl; it->second.sentTokens = tokens; } }
void GiaNeighbors::updateTimestamp | ( | const GiaNode & | node | ) |
Update timestamp.
Definition at line 139 of file GiaNeighbors.cc.
Referenced by Gia::updateNeighborList().
{ NeighborsIterator it = neighbors.find(node); if(it != neighbors.end()) it->second.timestamp = simTime(); }
std::map<GiaNode, GiaNeighborInfo> GiaNeighbors::neighbors [protected] |
contains all current neighbors
Definition at line 170 of file GiaNeighbors.h.
Referenced by add(), contains(), decreaseReceivedTokens(), get(), getCapacity(), getConnectionDegree(), getDropCandidate(), getNeighborKeyList(), getReceivedTokens(), getSentTokens(), getSize(), increaseReceivedTokens(), increaseSentTokens(), initialize(), remove(), removeTimedoutNodes(), setConnectionDegree(), setNeighborKeyList(), setReceivedTokens(), setSentTokens(), and updateTimestamp().
GiaNode GiaNeighbors::thisNode [protected] |
Definition at line 173 of file GiaNeighbors.h.
simtime_t GiaNeighbors::timeout [protected] |
this node
Definition at line 174 of file GiaNeighbors.h.
Referenced by initialize(), and removeTimedoutNodes().