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 | |
Gia * | gia |
TokenQueue | tokenQueue |
prioriry queue of all current neighbors | |
GiaNeighbors * | neighbors |
pointer to our current neighbors | |
std::vector< GiaNode > | tokenQueueVector |
uint32_t | maxHopCount |
a vector of the priority queue (to visualize current priority state) | |
uint32_t | stat_sentTokens |
number of sent tokens |
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.
typedef std::priority_queue<FullGiaNodeInfo, std::vector<FullGiaNodeInfo>, tokenCompareGiaNode> GiaTokenFactory::TokenQueue [protected] |
Definition at line 98 of file GiaTokenFactory.h.
void GiaTokenFactory::clearTokenQueue | ( | ) | [protected] |
Clears tokenQueue.
Definition at line 97 of file GiaTokenFactory.cc.
Referenced by createPriorityQueue().
00098 { 00099 while( !tokenQueue.empty() ) 00100 tokenQueue.pop(); 00101 }
void GiaTokenFactory::createPriorityQueue | ( | ) | [protected] |
Creates priority queue.
Definition at line 83 of file GiaTokenFactory.cc.
Referenced by grantToken().
00084 { 00085 clearTokenQueue(); 00086 for (uint32_t i = 0; i < neighbors->getSize(); i++ ) { 00087 FullGiaNodeInfo temp; 00088 temp.node= neighbors->get(i); 00089 temp.info = neighbors->get(temp.node); 00090 //temp.setCapacity(tempInfo->capacity); 00091 //temp.setSentTokens(tempInfo->sentTokens); 00092 00093 tokenQueue.push(temp); 00094 } 00095 }
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().
00063 { 00064 if (neighbors->getSize() == 0) return; 00065 00066 // create priority queue 00067 createPriorityQueue(); 00068 00069 // update sentTokenCount at node on top of priority queue 00070 updateSentTokens(); 00071 00072 // send token to top of queue 00073 assert( tokenQueue.size() ); 00074 assert( !tokenQueue.top().node.isUnspecified() ); 00075 gia->sendToken(tokenQueue.top().node); 00076 00077 // increse statistic variable 00078 stat_sentTokens++; 00079 00080 updateQueueVector(); 00081 }
void GiaTokenFactory::handleMessages | ( | cMessage * | msg | ) | [virtual] |
This module doesn't handle OMNeT++ messages.
msg | OMNeT++ message |
Definition at line 47 of file GiaTokenFactory.cc.
00048 { 00049 error("this module doesn't handle messages, it runs only in initialize()"); 00050 }
void GiaTokenFactory::initialize | ( | int | stage | ) | [virtual] |
Initializes this class and set some WATCH(variable) for OMNeT++.
stage | Level of initialization (OMNeT++) |
Definition at line 33 of file GiaTokenFactory.cc.
00034 { 00035 // wait until IPAddressResolver finished his initialization 00036 if(stage != MIN_STAGE_OVERLAY) 00037 return; 00038 00039 gia = check_and_cast<Gia*>(getParentModule()->getSubmodule("gia")); 00040 00041 stat_sentTokens = 0; 00042 00043 WATCH(stat_sentTokens); 00044 WATCH_VECTOR(tokenQueueVector); 00045 }
virtual int GiaTokenFactory::numInitStages | ( | ) | const [inline, virtual] |
Sets init stage.
Definition at line 52 of file GiaTokenFactory.h.
00053 { 00054 return MAX_STAGE_OVERLAY + 1; 00055 }
void GiaTokenFactory::sendToken | ( | ) | [protected] |
Sends token to node on top of priority queue.
void GiaTokenFactory::setMaxHopCount | ( | uint32_t | maxHopCount | ) |
Set maximum hop count.
maxHopCount |
Definition at line 57 of file GiaTokenFactory.cc.
Referenced by Gia::changeState().
00058 { 00059 this->maxHopCount = maxHopCount; 00060 }
void GiaTokenFactory::setNeighbors | ( | GiaNeighbors * | neighbors | ) | [virtual] |
Set neighbors.
neighbors | pointer to our neighborlist |
Definition at line 52 of file GiaTokenFactory.cc.
Referenced by Gia::changeState().
void GiaTokenFactory::updateQueueVector | ( | ) | [protected] |
Update TokenQueue-Vector (for OMNeT++ WATCH).
Definition at line 103 of file GiaTokenFactory.cc.
Referenced by grantToken().
00104 { 00105 // fill tokenQueueVector 00106 tokenQueueVector.clear(); 00107 while (!tokenQueue.empty()) { 00108 tokenQueueVector.push_back(tokenQueue.top().node); 00109 tokenQueue.pop(); 00110 } 00111 }
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().
00114 { 00115 if (tokenQueue.empty()) return; 00116 00117 tokenQueue.top().info->sentTokens++; 00118 }
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.
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().