OverSim
GiaTokenFactory Class Reference

This class handles the token allocation. More...

#include <GiaTokenFactory.h>

Classes

class  tokenCompareGiaNode

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 setNeighbors (GiaNeighbors *neighbors)
 Set neighbors.
void setMaxHopCount (uint32_t maxHopCount)
 Set maximum hop count.
virtual void grantToken ()
 Sends a token to a GiaNode.

Protected Types

typedef std::priority_queue
< FullGiaNodeInfo, std::vector
< FullGiaNodeInfo >
, tokenCompareGiaNode
TokenQueue

Protected Member Functions

void createPriorityQueue ()
 Creates priority queue.
void clearTokenQueue ()
 Clears tokenQueue.
void updateQueueVector ()
 Update TokenQueue-Vector (for OMNeT++ WATCH)
void updateSentTokens ()
 Increase sentTokens at neighbor-node which is on top of priority queue.
void sendToken ()
 Sends token to node on top of priority queue.

Protected Attributes

Giagia
TokenQueue tokenQueue
 prioriry queue of all current neighbors
GiaNeighborsneighbors
 pointer to our current neighbors
std::vector< GiaNodetokenQueueVector
uint32_t maxHopCount
 a vector of the priority queue (to visualize current priority state)
uint32_t stat_sentTokens
 number of sent tokens

Detailed Description

This class handles the token allocation.

It grants the next token to the node which has fewest tokens. If some nodes have the same amount of granted tokens, the node with the highest capacity will obtain the token.

Definition at line 45 of file GiaTokenFactory.h.

Member Typedef Documentation

typedef std::priority_queue<FullGiaNodeInfo, std::vector<FullGiaNodeInfo>, tokenCompareGiaNode> GiaTokenFactory::TokenQueue
protected

Definition at line 98 of file GiaTokenFactory.h.

Member Function Documentation

void GiaTokenFactory::clearTokenQueue ( )
protected

Clears tokenQueue.

Definition at line 97 of file GiaTokenFactory.cc.

Referenced by createPriorityQueue().

{
while( !tokenQueue.empty() )
tokenQueue.pop();
}
void GiaTokenFactory::createPriorityQueue ( )
protected

Creates priority queue.

Definition at line 83 of file GiaTokenFactory.cc.

Referenced by grantToken().

{
for (uint32_t i = 0; i < neighbors->getSize(); i++ ) {
temp.node= neighbors->get(i);
temp.info = neighbors->get(temp.node);
//temp.setCapacity(tempInfo->capacity);
//temp.setSentTokens(tempInfo->sentTokens);
tokenQueue.push(temp);
}
}
void GiaTokenFactory::grantToken ( )
virtual

Sends a token to a GiaNode.

Definition at line 62 of file GiaTokenFactory.cc.

Referenced by Gia::forwardMessage(), Gia::handleTimerEvent(), and Gia::processSearchMessage().

{
if (neighbors->getSize() == 0) return;
// create priority queue
// update sentTokenCount at node on top of priority queue
// send token to top of queue
assert( tokenQueue.size() );
assert( !tokenQueue.top().node.isUnspecified() );
gia->sendToken(tokenQueue.top().node);
// increse statistic variable
}
void GiaTokenFactory::handleMessages ( cMessage *  msg)
virtual

This module doesn't handle OMNeT++ messages.

Parameters
msgOMNeT++ message

Definition at line 47 of file GiaTokenFactory.cc.

{
error("this module doesn't handle messages, it runs only in initialize()");
}
void GiaTokenFactory::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 GiaTokenFactory.cc.

{
// wait until IPAddressResolver finished his initialization
if(stage != MIN_STAGE_OVERLAY)
return;
gia = check_and_cast<Gia*>(getParentModule()->getSubmodule("gia"));
WATCH(stat_sentTokens);
WATCH_VECTOR(tokenQueueVector);
}
virtual int GiaTokenFactory::numInitStages ( ) const
inlinevirtual

Sets init stage.

Definition at line 52 of file GiaTokenFactory.h.

{
return MAX_STAGE_OVERLAY + 1;
}
void GiaTokenFactory::sendToken ( )
protected

Sends token to node on top of priority queue.

void GiaTokenFactory::setMaxHopCount ( uint32_t  maxHopCount)

Set maximum hop count.

Parameters
maxHopCount

Definition at line 57 of file GiaTokenFactory.cc.

Referenced by Gia::changeState().

{
}
void GiaTokenFactory::setNeighbors ( GiaNeighbors neighbors)
virtual

Set neighbors.

Parameters
neighborspointer to our neighborlist

Definition at line 52 of file GiaTokenFactory.cc.

Referenced by Gia::changeState().

{
neighbors = nghbors;
}
void GiaTokenFactory::updateQueueVector ( )
protected

Update TokenQueue-Vector (for OMNeT++ WATCH)

Definition at line 103 of file GiaTokenFactory.cc.

Referenced by grantToken().

{
// fill tokenQueueVector
while (!tokenQueue.empty()) {
tokenQueueVector.push_back(tokenQueue.top().node);
tokenQueue.pop();
}
}
void GiaTokenFactory::updateSentTokens ( )
protected

Increase sentTokens at neighbor-node which is on top of priority queue.

Definition at line 113 of file GiaTokenFactory.cc.

Referenced by grantToken().

{
if (tokenQueue.empty()) return;
tokenQueue.top().info->sentTokens++;
}

Member Data Documentation

Gia* GiaTokenFactory::gia
protected

Definition at line 89 of file GiaTokenFactory.h.

Referenced by grantToken(), and initialize().

uint32_t GiaTokenFactory::maxHopCount
protected

a vector of the priority queue (to visualize current priority state)

maximum hop count

Definition at line 102 of file GiaTokenFactory.h.

Referenced by setMaxHopCount().

GiaNeighbors* GiaTokenFactory::neighbors
protected

pointer to our current neighbors

Definition at line 100 of file GiaTokenFactory.h.

Referenced by createPriorityQueue(), grantToken(), and setNeighbors().

uint32_t GiaTokenFactory::stat_sentTokens
protected

number of sent tokens

Definition at line 105 of file GiaTokenFactory.h.

Referenced by grantToken(), and initialize().

TokenQueue GiaTokenFactory::tokenQueue
protected

prioriry queue of all current neighbors

Definition at line 99 of file GiaTokenFactory.h.

Referenced by clearTokenQueue(), createPriorityQueue(), grantToken(), updateQueueVector(), and updateSentTokens().

std::vector<GiaNode> GiaTokenFactory::tokenQueueVector
protected

Definition at line 101 of file GiaTokenFactory.h.

Referenced by initialize(), and updateQueueVector().


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