#include <GiaTokenFactory.h>
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.
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 (uint 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 | |
Gia * | gia |
TokenQueue | tokenQueue |
prioriry queue of all current neighbors | |
GiaNeighbors * | neighbors |
pointer to our current neighbors | |
std::vector< GiaNode > | tokenQueueVector |
uint | maxHopCount |
a vector of the priority queue (to visualize current priority state) | |
uint | stat_sentTokens |
number of sent tokens | |
Classes | |
class | tokenCompareGiaNode |
typedef std::priority_queue<FullGiaNodeInfo, std::vector<FullGiaNodeInfo>, tokenCompareGiaNode> GiaTokenFactory::TokenQueue [protected] |
virtual int GiaTokenFactory::numInitStages | ( | ) | const [inline, virtual] |
void GiaTokenFactory::initialize | ( | int | stage | ) | [virtual] |
Initializes this class and set some WATCH(variable) for OMNeT++.
stage | Level of initialization (OMNeT++) |
00032 { 00033 // wait until IPAddressResolver finished his initialization 00034 if(stage != MIN_STAGE_OVERLAY) 00035 return; 00036 00037 gia = check_and_cast<Gia*>(parentModule()->submodule("gia")); 00038 00039 stat_sentTokens = 0; 00040 00041 WATCH(stat_sentTokens); 00042 WATCH_VECTOR(tokenQueueVector); 00043 }
void GiaTokenFactory::handleMessages | ( | cMessage * | msg | ) | [virtual] |
void GiaTokenFactory::setNeighbors | ( | GiaNeighbors * | neighbors | ) | [virtual] |
void GiaTokenFactory::setMaxHopCount | ( | uint | maxHopCount | ) |
Set maximum hop count.
maxHopCount |
00056 { 00057 this->maxHopCount = maxHopCount; 00058 }
void GiaTokenFactory::grantToken | ( | ) | [virtual] |
Sends a token to a GiaNode.
00061 { 00062 if (neighbors->getSize() == 0) return; 00063 00064 // create priority queue 00065 createPriorityQueue(); 00066 00067 // update sentTokenCount at node on top of priority queue 00068 updateSentTokens(); 00069 00070 // send token to top of queue 00071 assert( tokenQueue.size() ); 00072 assert( !tokenQueue.top().node.isUnspecified() ); 00073 gia->sendToken(tokenQueue.top().node); 00074 00075 // increse statistic variable 00076 stat_sentTokens++; 00077 00078 updateQueueVector(); 00079 }
void GiaTokenFactory::createPriorityQueue | ( | ) | [protected] |
Creates priority queue.
00082 { 00083 clearTokenQueue(); 00084 for (uint i = 0; i < neighbors->getSize(); i++ ) { 00085 FullGiaNodeInfo temp; 00086 temp.node= neighbors->get(i); 00087 temp.info = neighbors->get(temp.node); 00088 //temp.setCapacity(tempInfo->capacity); 00089 //temp.setSentTokens(tempInfo->sentTokens); 00090 00091 tokenQueue.push(temp); 00092 } 00093 }
void GiaTokenFactory::clearTokenQueue | ( | ) | [protected] |
void GiaTokenFactory::updateQueueVector | ( | ) | [protected] |
Update TokenQueue-Vector (for OMNeT++ WATCH).
00102 { 00103 // fill tokenQueueVector 00104 tokenQueueVector.clear(); 00105 while (!tokenQueue.empty()) { 00106 tokenQueueVector.push_back(tokenQueue.top().node); 00107 tokenQueue.pop(); 00108 } 00109 }
void GiaTokenFactory::updateSentTokens | ( | ) | [protected] |
Increase sentTokens at neighbor-node which is on top of priority queue.
00112 { 00113 if (tokenQueue.empty()) return; 00114 00115 tokenQueue.top().info->sentTokens++; 00116 }
void GiaTokenFactory::sendToken | ( | ) | [protected] |
Sends token to node on top of priority queue.
Gia* GiaTokenFactory::gia [protected] |
TokenQueue GiaTokenFactory::tokenQueue [protected] |
prioriry queue of all current neighbors
GiaNeighbors* GiaTokenFactory::neighbors [protected] |
pointer to our current neighbors
std::vector<GiaNode> GiaTokenFactory::tokenQueueVector [protected] |
uint GiaTokenFactory::maxHopCount [protected] |
a vector of the priority queue (to visualize current priority state)
maximum hop count
uint GiaTokenFactory::stat_sentTokens [protected] |
number of sent tokens