GiaNeighbors Class Reference

#include <GiaNeighbors.h>

List of all members.


Detailed Description

This class is for managing all neighbor nodes.

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

Member Typedef Documentation

typedef std::map<GiaNode, GiaNeighborInfo>::iterator GiaNeighbors::NeighborsIterator [protected]

typedef std::map<GiaNode, GiaNeighborInfo>::const_iterator GiaNeighbors::NeighborsConstIterator [protected]


Member Function Documentation

virtual int GiaNeighbors::numInitStages (  )  const [inline, virtual]

Sets init stage.

00067     {
00068         return MAX_STAGE_OVERLAY + 1;
00069     }

void GiaNeighbors::initialize ( int  stage  )  [virtual]

Initializes this class and set some WATCH(variable) for OMNeT++.

Parameters:
stage Level of initialization (OMNeT++)
00034 {
00035     // wait until IPAddressResolver finished his initialization
00036     if(stage != MIN_STAGE_OVERLAY)
00037         return;
00038 
00039     WATCH_MAP(neighbors);
00040     this->timeout = parentModule()->submodule("gia")->par("neighborTimeout");
00041     //unspecNode = GiaNode::UNSPECIFIED_NODE;
00042 }

void GiaNeighbors::handleMessages ( cMessage *  msg  )  [virtual]

This module doesn't handle OMNeT++ messages.

Parameters:
msg OMNeT++ message
00046 {
00047     error("this module doesn't handle messages, it runs only in initialize()");
00048 }

uint GiaNeighbors::getSize (  )  const [virtual]

bool GiaNeighbors::contains ( const GiaNode node  )  const [virtual]

Parameters:
node GiaNode to check
Returns:
true if node is our neighbor

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

00069 {
00070     NeighborsConstIterator it = neighbors.find(node);
00071 
00072     if(it != neighbors.end())
00073         return true;
00074     return false;
00075 }

bool GiaNeighbors::contains ( const OverlayKey key  )  const [virtual]

Parameters:
key to check
Returns:
true if node with corresponding key is our neighbor
00056 {
00057     NeighborsConstIterator it = neighbors.begin();
00058 
00059     for(it = neighbors.begin(); it != neighbors.end(); it++)
00060         if(it->first.key == key)
00061             break;
00062 
00063     if (it != neighbors.end())
00064         return true;
00065     return false;
00066 }

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

Adds a new neighbor to our neighbor list.

Parameters:
node New neighbor to add
degree The new neighbor's connection degree

Referenced by Gia::addNeighbor().

00078 {
00079     GiaNeighborInfo info = {degree,
00080                             5,
00081                             5,
00082                             simulation.simTime(),
00083                             GiaKeyList()};
00084 
00085     neighbors.insert(std::make_pair(node, info));
00086     //neighbors.insert(node);
00087 }

void GiaNeighbors::remove ( const GiaNode node  )  [virtual]

Removes neighbor from our neighbor list.

Parameters:
node Node to remove to

Referenced by Gia::acceptNode(), and Gia::removeNeighbor().

00099 {
00100     neighbors.erase(node);
00101 }

const GiaNode & GiaNeighbors::get ( unsigned int  position  )  [virtual]

Get neighbor at position.

Parameters:
position 
Returns:
GiaNode

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

00104 {
00105     assert( getSize() && i <= getSize() );
00106     NeighborsIterator it = neighbors.begin();
00107 
00108     for(unsigned int j = 0; j < i; j++)
00109         it++;
00110 
00111     if (it != neighbors.end()) return it->first;
00112     return GiaNode::UNSPECIFIED_NODE;
00113 }

const GiaNode & GiaNeighbors::get ( const OverlayKey key  )  [virtual]

Get node from neighborlist.

Parameters:
key the node's key
Returns:
the node
00127 {
00128     NeighborsIterator it;
00129 
00130     for(it = neighbors.begin(); it != neighbors.end(); it++)
00131         if(it->first.key == key)
00132             break;
00133 
00134     if(it != neighbors.end())
00135         return it->first;
00136     return GiaNode::UNSPECIFIED_NODE;
00137 }

GiaNeighborInfo * GiaNeighbors::get ( const GiaNode node  ) 

00116 {
00117     if (node.isUnspecified()) return NULL;
00118 
00119     NeighborsIterator it = neighbors.find(node);
00120 
00121     if(it != neighbors.end())
00122         return &(it->second);
00123     return NULL;
00124 }

void GiaNeighbors::updateTimestamp ( const GiaNode node  ) 

Update timestamp.

Referenced by Gia::updateNeighborList().

00140 {
00141     NeighborsIterator it = neighbors.find(node);
00142 
00143     if(it != neighbors.end())
00144         it->second.timestamp = simulation.simTime();
00145 }

void GiaNeighbors::removeTimedoutNodes (  ) 

Removes timedout nodes.

Referenced by Gia::handleTimerEvent().

00148 {
00149     NeighborsIterator it = neighbors.begin();
00150 
00151     while(it != neighbors.end()) {
00152         if(simulation.simTime() > (it->second.timestamp + timeout)) {
00153             neighbors.erase(it);
00154             it = neighbors.begin();//not efficient
00155         }
00156         else
00157             it++;
00158     }
00159 
00160 }

void GiaNeighbors::setNeighborKeyList ( const GiaNode node,
const GiaKeyList keyList 
)

Sets the keyList of neighbor at position pos.

Parameters:
node the node the keylist belongs to
keyList KeyList to set

Referenced by Gia::handleUDPMessage().

00165 {
00166     NeighborsIterator it = neighbors.find(node);
00167 
00168     if(it != neighbors.end())
00169         it->second.keyList = keyList;
00170 }

GiaKeyList * GiaNeighbors::getNeighborKeyList ( const GiaNode node  ) 

Referenced by Gia::processSearchMessage().

00173 {
00174     NeighborsIterator it = neighbors.find(node);
00175 
00176     if(it != neighbors.end())
00177         return &(it->second.keyList);
00178     return NULL;
00179 }

double GiaNeighbors::getCapacity ( const GiaNode node  )  const

00182 {
00183     NeighborsConstIterator it = neighbors.find(node);
00184 
00185     if(it != neighbors.end())
00186         return it->first.getCapacity();
00187     return 0;
00188 }

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

Referenced by Gia::handleUDPMessage(), and Gia::updateNeighborList().

00209 {
00210     NeighborsIterator it = neighbors.find(node);
00211 
00212     if(it != neighbors.end())
00213         it->second.connectionDegree = degree;
00214 }

unsigned int GiaNeighbors::getConnectionDegree ( const GiaNode node  )  const

00199 {
00200     NeighborsConstIterator it = neighbors.find(node);
00201 
00202     if(it != neighbors.end())
00203         return it->second.connectionDegree;
00204     return 0;
00205 }

void GiaNeighbors::setReceivedTokens ( const GiaNode node,
unsigned int  tokens 
)

00218 {
00219     NeighborsIterator it = neighbors.find(node);
00220 
00221     if(it != neighbors.end()) {
00222         std::cout << "recieved: " << it->second.receivedTokens << " -> " << tokens << std::endl;
00223         it->second.receivedTokens = tokens;
00224     }
00225 }

void GiaNeighbors::increaseReceivedTokens ( const GiaNode node  ) 

Referenced by Gia::handleUDPMessage().

00228 {
00229     NeighborsIterator it = neighbors.find(node);
00230 
00231     if(it != neighbors.end())
00232         it->second.receivedTokens++;
00233 }

void GiaNeighbors::decreaseReceivedTokens ( const GiaNode node  ) 

Referenced by Gia::forwardMessage().

00236 {
00237     NeighborsIterator it = neighbors.find(node);
00238 
00239     if(it != neighbors.end())
00240         it->second.receivedTokens--;
00241 }

unsigned int GiaNeighbors::getReceivedTokens ( const GiaNode node  )  const

00244 {
00245     NeighborsConstIterator it = neighbors.find(node);
00246 
00247     if(it != neighbors.end())
00248         return it->second.receivedTokens;
00249     return 0;
00250 }

void GiaNeighbors::setSentTokens ( const GiaNode node,
unsigned int  tokens 
)

00254 {
00255     NeighborsIterator it = neighbors.find(node);
00256 
00257     if(it != neighbors.end()) {
00258         std::cout << "sent: " << it->second.sentTokens << " -> " << tokens << std::endl;
00259         it->second.sentTokens = tokens;
00260     }
00261 }

void GiaNeighbors::increaseSentTokens ( const GiaNode node  ) 

00264 {
00265     NeighborsIterator it = neighbors.find(node);
00266 
00267     if(it != neighbors.end() && it->second.sentTokens >= 0)
00268         it->second.sentTokens++;
00269 }

unsigned int GiaNeighbors::getSentTokens ( const GiaNode node  )  const

00272 {
00273     NeighborsConstIterator it = neighbors.find(node);
00274 
00275     if(it != neighbors.end())
00276         return it->second.sentTokens;
00277     return 0;
00278 }

const GiaNode & GiaNeighbors::getDropCandidate ( double  capacity,
unsigned int  degree 
) const

Referenced by Gia::acceptNode().

00282 {
00283     // determine node with highest capacity
00284     unsigned int subset = 0;
00285     double maxCapacity = 0;
00286     unsigned int dropDegree = 0;
00287     GiaNode dropCandidate;
00288 
00289     NeighborsConstIterator it, candIt;
00290     for(it = neighbors.begin(); it != neighbors.end(); it++) {
00291         if(it->first.getCapacity() <= capacity) {
00292             subset++;
00293             if(it->first.getCapacity() > maxCapacity) {
00294                 candIt = it;
00295                 dropDegree = it->second.connectionDegree;
00296                 maxCapacity = it->first.getCapacity();
00297             }
00298         }
00299     }
00300 
00301     if(subset > 0 &&
00302             (/*subset == neighbors->getSize() || */dropDegree > degree) &&
00303             dropDegree > 1) {
00304         return candIt->first;
00305     }
00306 
00307     return GiaNode::UNSPECIFIED_NODE;
00308                                               }


Member Data Documentation

simtime_t GiaNeighbors::timeout [protected]

this node

Referenced by initialize(), and removeTimedoutNodes().


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

Generated on Fri Sep 19 13:05:06 2008 for ITM OverSim by  doxygen 1.5.5