Neighbors Class Reference

#include <Neighbors.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 void finish ()
 Save statistical data.
virtual uint getSize ()
virtual bool contains (const GiaNode &node) const
virtual bool contains (const OverlayKey &key) const
virtual int getPosition (const OverlayKey &key) const
 Returns position of node.
virtual int getPosition (const GiaNode &node) const
 Returns position of node.
virtual void add (const GiaNode &node)
 Adds a new neighbor to our neighbor list.
virtual void remove (const GiaNode &node)
 Removes neighbor from our neighbor list.
virtual void remove (int position)
 Removes neighbor from neighbor list at given position.
virtual GiaNodeget (int position)
 Get neighbor at position.
virtual GiaNodeget (const GiaNode &node)
 Get neighbor from neighborlist.
virtual GiaNodeget (const OverlayKey &key)
 Get GiaNode from neighborlist.
void updateTimestamp (const GiaNode &node)
 Update timestamp.
void removeTimedoutNodes ()
 Removes timedout nodes.
void setNeighborKeyList (uint pos, const KeyList &keyList)
 Sets the keyList of neighbor at position pos.
KeyListgetNeighborKeyList (uint pos)
 Get keylist from neighbor.

Protected Attributes

std::vector< NeighborNodeneighbors
 contains all current neighbors
GiaNode thisNode
simtime_t timeout
 this node
GiaNode unspecNode
 timeout for neighbors


Member Function Documentation

void Neighbors::add ( const GiaNode node  )  [virtual]

Adds a new neighbor to our neighbor list.

Parameters:
node New neighbor to add
00083 {
00084     if(!contains(node))
00085         neighbors.push_back(NeighborNode(node, simulation.simTime()));
00086 }

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

Parameters:
key to check
Returns:
true if node with corresponding key is our neighbor
00055 {
00056     if (getPosition(key) != -1)
00057         return true;
00058     return false;
00059 }

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

Parameters:
node GiaNode to check
Returns:
true if node is our neighbor
00062 {
00063     if (getPosition(node) != -1)
00064         return true;
00065     return false;
00066 }

void Neighbors::finish (  )  [virtual]

Save statistical data.

00177 {}

GiaNode * Neighbors::get ( const OverlayKey key  )  [virtual]

Get GiaNode from neighborlist.

Parameters:
key GiaNode-Key
Returns:
GiaNode
00132 {
00133     if(neighbors.size() == 0)
00134         return &unspecNode;
00135     else {
00136         int position = getPosition(key);
00137         if(position == -1)
00138             return &unspecNode;
00139         else
00140             return get
00141                        (position);
00142     }
00143 }

GiaNode * Neighbors::get ( const GiaNode node  )  [virtual]

Get neighbor from neighborlist.

Parameters:
node GiaNode
Returns:
GiaNode
00117 {
00118     if(neighbors.size() == 0)
00119         return &unspecNode;
00120     else {
00121         int position = getPosition(node);
00122         if(position == -1)
00123             return &unspecNode;
00124         else
00125             return get
00126                        (position);
00127     }
00128 }

GiaNode * Neighbors::get ( int  position  )  [virtual]

Get neighbor at position.

Parameters:
position 
Returns:
GiaNode
00108 {
00109     if ( neighbors.size() == 0 || position == -1 )
00110         return &unspecNode;
00111     else
00112         return &neighbors[position].giaNode;
00113 }

KeyList * Neighbors::getNeighborKeyList ( uint  pos  ) 

Get keylist from neighbor.

Parameters:
pos Position of neighbor
Returns:
keylist of neighbor
00172 {
00173     return &(neighbors[pos].keyList);
00174 }

int Neighbors::getPosition ( const GiaNode node  )  const [virtual]

Returns position of node.

Parameters:
node to check
Returns:
-1 if neighbor-list doesn't contain node, else position is returned
00069 {
00070     return getPosition(node.getNodeHandle().key);
00071 }

int Neighbors::getPosition ( const OverlayKey key  )  const [virtual]

Returns position of node.

Parameters:
key to check
Returns:
-1 if neighbor-list doesn't contain node, else position is returned
00074 {
00075     for ( uint i=0; i<neighbors.size(); i++ )
00076         if ( neighbors[i].giaNode.getNodeHandle().key == key )
00077             return i;
00078     return -1;
00079 }

uint Neighbors::getSize (  )  [virtual]

Returns:
Number of neighbors
00050 {
00051     return neighbors.size();
00052 }

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

This module doesn't handle OMNeT++ messages.

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

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

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

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

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

Sets init stage.

00049     {
00050         return MAX_STAGE_OVERLAY + 1;
00051     }

void Neighbors::remove ( int  position  )  [virtual]

Removes neighbor from neighbor list at given position.

Parameters:
position 
00101 {
00102     if (position != -1)
00103         neighbors.erase( neighbors.begin() + position);
00104 }

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

Removes neighbor from our neighbor list.

Parameters:
node Node to remove to
00092 {
00093     int position = getPosition(node);
00094     if ( position != -1 )
00095         neighbors.erase(neighbors.begin() + position);
00096 }

void Neighbors::removeTimedoutNodes (  ) 

Removes timedout nodes.

00155 {
00156     std::vector<NeighborNode>::iterator it = neighbors.begin();
00157     std::vector<NeighborNode>::iterator it2 = neighbors.begin();
00158     for ( uint i=0; i<neighbors.size(); i++) {
00159         NeighborNode neighborNode = neighbors[i];
00160         it2 = it++;
00161         if ( simulation.simTime() > (neighborNode.timestamp + timeout))
00162             neighbors.erase(it2);
00163     }
00164 }

void Neighbors::setNeighborKeyList ( uint  pos,
const KeyList keyList 
)

Sets the keyList of neighbor at position pos.

Parameters:
pos Position in vector
keyList KeyList to set
00167 {
00168     neighbors[pos].keyList = keyList;
00169 }

void Neighbors::updateTimestamp ( const GiaNode node  ) 

Update timestamp.

00146 {
00147     int position  = getPosition(node);
00148     if(position != -1) {
00149         neighbors[position].timestamp = simulation.simTime();
00150     }
00151 }


Member Data Documentation

std::vector<NeighborNode> Neighbors::neighbors [protected]

contains all current neighbors

GiaNode Neighbors::thisNode [protected]

simtime_t Neighbors::timeout [protected]

this node

GiaNode Neighbors::unspecNode [protected]

timeout for neighbors


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:37:06 2007 for ITM OverSim by  doxygen 1.4.7