INET Framework for OMNeT++/OMNEST
inet::WRRScheduler Class Reference

This module implements a Weighted Round Robin Scheduler. More...

#include <WRRScheduler.h>

Inheritance diagram for inet::WRRScheduler:
inet::SchedulerBase inet::IPassiveQueue inet::IPassiveQueueListener

Public Member Functions

 WRRScheduler ()
 
- Public Member Functions inherited from inet::SchedulerBase
 SchedulerBase ()
 
virtual ~SchedulerBase ()
 
virtual void requestPacket () override
 The queue should send a packet whenever this method is invoked. More...
 
virtual int getNumPendingRequests () override
 Returns number of pending requests. More...
 
virtual bool isEmpty () override
 Return true when queue is empty, otherwise return false. More...
 
virtual void clear () override
 Clear all queued packets and stored requests. More...
 
virtual cMessage * pop () override
 Returns a packet directly from the queue, bypassing the primary, send-on-request mechanism. More...
 
virtual void packetEnqueued (IPassiveQueue *inputQueue) override
 A packet arrived and it was added to the queue (the queue length increased by one). More...
 
virtual void addListener (IPassiveQueueListener *listener) override
 Adds a new listener to the listener list. More...
 
virtual void removeListener (IPassiveQueueListener *listener) override
 Removes a listener from the listener list. More...
 
- Public Member Functions inherited from inet::IPassiveQueue
virtual ~IPassiveQueue ()
 
- Public Member Functions inherited from inet::IPassiveQueueListener
virtual ~IPassiveQueueListener ()
 

Protected Member Functions

virtual ~WRRScheduler ()
 
virtual void initialize () override
 
virtual bool schedulePacket () override
 
- Protected Member Functions inherited from inet::SchedulerBase
virtual void finalize ()
 
virtual void handleMessage (cMessage *msg) override
 
virtual void sendOut (cMessage *msg)
 
virtual void notifyListeners ()
 

Protected Attributes

int numInputs
 
int * weights
 
int * buckets
 
- Protected Attributes inherited from inet::SchedulerBase
int packetsRequestedFromUs
 
int packetsToBeRequestedFromInputs
 
std::vector< IPassiveQueue * > inputQueues
 
cGate * outGate
 
std::list< IPassiveQueueListener * > listeners
 

Detailed Description

This module implements a Weighted Round Robin Scheduler.

Constructor & Destructor Documentation

inet::WRRScheduler::WRRScheduler ( )
inline
38 : numInputs(0), weights(nullptr), buckets(nullptr) {}
int numInputs
Definition: WRRScheduler.h:33
int * weights
Definition: WRRScheduler.h:34
int * buckets
Definition: WRRScheduler.h:35
inet::WRRScheduler::~WRRScheduler ( )
protectedvirtual
26 {
27  delete[] weights;
28  delete[] buckets;
29 }
int * weights
Definition: WRRScheduler.h:34
int * buckets
Definition: WRRScheduler.h:35

Member Function Documentation

void inet::WRRScheduler::initialize ( )
overrideprotectedvirtual

Reimplemented from inet::SchedulerBase.

32 {
34 
35  numInputs = gateSize("in");
36  ASSERT(numInputs == (int)inputQueues.size());
37 
38  weights = new int[numInputs];
39  buckets = new int[numInputs];
40 
41  cStringTokenizer tokenizer(par("weights"));
42  int i;
43  for (i = 0; i < numInputs && tokenizer.hasMoreTokens(); ++i)
44  buckets[i] = weights[i] = (int)utils::atoul(tokenizer.nextToken());
45 
46  if (i < numInputs)
47  throw cRuntimeError("Too few values given in the weights parameter.");
48  if (tokenizer.hasMoreTokens())
49  throw cRuntimeError("Too many values given in the weights parameter.");
50 }
int numInputs
Definition: WRRScheduler.h:33
int * weights
Definition: WRRScheduler.h:34
std::vector< IPassiveQueue * > inputQueues
Definition: SchedulerBase.h:46
int * buckets
Definition: WRRScheduler.h:35
unsigned long atoul(const char *s)
Converts string to unsigned long.
Definition: INETUtils.cc:47
virtual void initialize() override
Definition: SchedulerBase.cc:34
bool inet::WRRScheduler::schedulePacket ( )
overrideprotectedvirtual

Implements inet::SchedulerBase.

53 {
54  bool allQueueIsEmpty = true;
55  for (int i = 0; i < numInputs; ++i) {
56  if (!inputQueues[i]->isEmpty()) {
57  allQueueIsEmpty = false;
58  if (buckets[i] > 0) {
59  buckets[i]--;
60  inputQueues[i]->requestPacket();
61  return true;
62  }
63  }
64  }
65 
66  if (allQueueIsEmpty)
67  return false;
68 
69  bool packetRequested = false;
70  for (int i = 0; i < numInputs; ++i) {
71  buckets[i] = weights[i];
72  if (!packetRequested && buckets[i] > 0 && !inputQueues[i]->isEmpty()) {
73  buckets[i]--;
74  inputQueues[i]->requestPacket();
75  packetRequested = true;
76  }
77  }
78 
79  return packetRequested;
80 }
virtual bool isEmpty() override
Return true when queue is empty, otherwise return false.
Definition: SchedulerBase.cc:96
int numInputs
Definition: WRRScheduler.h:33
int * weights
Definition: WRRScheduler.h:34
std::vector< IPassiveQueue * > inputQueues
Definition: SchedulerBase.h:46
int * buckets
Definition: WRRScheduler.h:35

Member Data Documentation

int* inet::WRRScheduler::buckets
protected
int inet::WRRScheduler::numInputs
protected

Referenced by initialize(), and schedulePacket().

int* inet::WRRScheduler::weights
protected

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