GiaNeighbors Class Reference

This class is for managing all neighbor nodes. More...

#include <GiaNeighbors.h>

List of all members.

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:
node New neighbor to add
degree The new neighbor's connection degree

Definition at line 77 of file GiaNeighbors.cc.

Referenced by Gia::addNeighbor().

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

bool GiaNeighbors::contains ( const OverlayKey key  )  const [virtual]
Parameters:
key to check
Returns:
true if node with corresponding key is our neighbor

Definition at line 55 of file GiaNeighbors.cc.

00056 {
00057     NeighborsConstIterator it = neighbors.begin();
00058 
00059     for(it = neighbors.begin(); it != neighbors.end(); it++)
00060         if(it->first.getKey() == key)
00061             break;
00062 
00063     if (it != neighbors.end())
00064         return true;
00065     return false;
00066 }

bool GiaNeighbors::contains ( const GiaNode node  )  const [virtual]
Parameters:
node GiaNode 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().

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

void GiaNeighbors::decreaseReceivedTokens ( const GiaNode node  ) 

Definition at line 235 of file GiaNeighbors.cc.

Referenced by Gia::forwardMessage().

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

GiaNeighborInfo * GiaNeighbors::get ( const GiaNode node  ) 

Definition at line 115 of file GiaNeighbors.cc.

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 }

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

Get node from neighborlist.

Parameters:
key the node's key
Returns:
the node

Definition at line 126 of file GiaNeighbors.cc.

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

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

Get neighbor at position.

Parameters:
position 
Returns:
GiaNode

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

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 }

double GiaNeighbors::getCapacity ( const GiaNode node  )  const

Definition at line 181 of file GiaNeighbors.cc.

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

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

Definition at line 198 of file GiaNeighbors.cc.

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

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

Definition at line 280 of file GiaNeighbors.cc.

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                                               }

GiaKeyList * GiaNeighbors::getNeighborKeyList ( const GiaNode node  ) 

Definition at line 172 of file GiaNeighbors.cc.

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 }

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

Definition at line 243 of file GiaNeighbors.cc.

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

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

Definition at line 271 of file GiaNeighbors.cc.

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

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

This module doesn't handle OMNeT++ messages.

Parameters:
msg OMNeT++ message

Definition at line 45 of file GiaNeighbors.cc.

00046 {
00047     error("this module doesn't handle messages, it runs only in initialize()");
00048 }

void GiaNeighbors::increaseReceivedTokens ( const GiaNode node  ) 

Definition at line 227 of file GiaNeighbors.cc.

Referenced by Gia::handleUDPMessage().

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

void GiaNeighbors::increaseSentTokens ( const GiaNode node  ) 

Definition at line 263 of file GiaNeighbors.cc.

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

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

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

Parameters:
stage Level of initialization (OMNeT++)

Definition at line 33 of file GiaNeighbors.cc.

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

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

Sets init stage.

Definition at line 66 of file GiaNeighbors.h.

00067     {
00068         return MAX_STAGE_OVERLAY + 1;
00069     }

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

Removes neighbor from our neighbor list.

Parameters:
node Node to remove to

Definition at line 98 of file GiaNeighbors.cc.

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

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

void GiaNeighbors::removeTimedoutNodes (  ) 

Removes timedout nodes.

Definition at line 147 of file GiaNeighbors.cc.

Referenced by Gia::handleTimerEvent().

00148 {
00149     NeighborsIterator it = neighbors.begin();
00150 
00151     while(it != neighbors.end()) {
00152         if(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::setConnectionDegree ( const GiaNode node,
unsigned int  degree 
)

Definition at line 207 of file GiaNeighbors.cc.

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 }

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

Definition at line 163 of file GiaNeighbors.cc.

Referenced by Gia::handleUDPMessage().

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

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

Definition at line 216 of file GiaNeighbors.cc.

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::setSentTokens ( const GiaNode node,
unsigned int  tokens 
)

Definition at line 253 of file GiaNeighbors.cc.

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::updateTimestamp ( const GiaNode node  ) 

Update timestamp.

Definition at line 139 of file GiaNeighbors.cc.

Referenced by Gia::updateNeighborList().

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


Member Data Documentation

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:
Generated on Wed May 26 16:21:17 2010 for OverSim by  doxygen 1.6.3