OverSim
GiaNeighbors Class Reference

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 GiaNodeget (unsigned int position)
 Get neighbor at position.
virtual const GiaNodeget (const OverlayKey &key)
 Get node from neighborlist.
GiaNeighborInfoget (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.
GiaKeyListgetNeighborKeyList (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 GiaNodegetDropCandidate (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

Detailed Description

This class is for managing all neighbor nodes.

Definition at line 59 of file GiaNeighbors.h.

Member Typedef Documentation

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.

Member Function Documentation

void GiaNeighbors::add ( const GiaNode node,
unsigned int  degree 
)
virtual

Adds a new neighbor to our neighbor list.

Parameters
nodeNew neighbor to add
degreeThe new neighbor's connection degree

Definition at line 77 of file GiaNeighbors.cc.

Referenced by Gia::addNeighbor().

{
GiaNeighborInfo info = {degree,
5,
5,
simTime(),
neighbors.insert(std::make_pair(node, info));
//neighbors.insert(node);
}
bool GiaNeighbors::contains ( const GiaNode node) const
virtual
Parameters
nodeGiaNode to check
Returns
true if node is our neighbor

Definition at line 68 of file GiaNeighbors.cc.

Referenced by Gia::acceptNode(), Gia::forwardMessage(), Gia::handleTimerEvent(), and Gia::updateNeighborList().

{
if(it != neighbors.end())
return true;
return false;
}
bool GiaNeighbors::contains ( const OverlayKey key) const
virtual
Parameters
keyto check
Returns
true if node with corresponding key is our neighbor

Definition at line 55 of file GiaNeighbors.cc.

{
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
const GiaNode & GiaNeighbors::get ( const OverlayKey key)
virtual

Get node from neighborlist.

Parameters
keythe node's key
Returns
the node

Definition at line 126 of file GiaNeighbors.cc.

{
for(it = neighbors.begin(); it != neighbors.end(); it++)
if(it->first.getKey() == key)
break;
if(it != neighbors.end())
return it->first;
}
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.

{
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.

{
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;
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;
}
}
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.

{
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.

{
if(it != neighbors.end())
return it->second.sentTokens;
return 0;
}
void GiaNeighbors::handleMessages ( cMessage *  msg)
virtual

This module doesn't handle OMNeT++ messages.

Parameters
msgOMNeT++ 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++.

Parameters
stageLevel 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
inlinevirtual

Sets init stage.

Definition at line 66 of file GiaNeighbors.h.

{
return MAX_STAGE_OVERLAY + 1;
}
void GiaNeighbors::remove ( const GiaNode node)
virtual

Removes neighbor from our neighbor list.

Parameters
nodeNode 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().

{
while(it != neighbors.end()) {
if(simTime() > (it->second.timestamp + timeout)) {
neighbors.erase(it);
it = neighbors.begin();//not efficient
}
else
it++;
}
}
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.

Parameters
nodethe node the keylist belongs to
keyListKeyList 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();
}

Member Data Documentation

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().


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