INET Framework for OMNeT++/OMNEST
inet::SchedulerBase Class Referenceabstract

Base class for packet schedulers. More...

#include <SchedulerBase.h>

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

Public Member Functions

 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 void initialize () override
 
virtual void finalize ()
 
virtual void handleMessage (cMessage *msg) override
 
virtual void sendOut (cMessage *msg)
 
virtual void notifyListeners ()
 
virtual bool schedulePacket ()=0
 

Protected Attributes

int packetsRequestedFromUs
 
int packetsToBeRequestedFromInputs
 
std::vector< IPassiveQueue * > inputQueues
 
cGate * outGate
 
std::list< IPassiveQueueListener * > listeners
 

Detailed Description

Base class for packet schedulers.

Schedulers are attached to the 'out' end of queues and decide from which queue a packet needs to be dequeued.

Schedulers behave as passive queues (they provide a view for the actual queues behind them), and can be cascaded. They must be able to notice when a new packet arrives at one of their inputs without dequeueing it, so they hook themselves as listeners on their inputs.

Constructor & Destructor Documentation

inet::SchedulerBase::SchedulerBase ( )
27 {
28 }
int packetsToBeRequestedFromInputs
Definition: SchedulerBase.h:45
cGate * outGate
Definition: SchedulerBase.h:47
int packetsRequestedFromUs
Definition: SchedulerBase.h:44
inet::SchedulerBase::~SchedulerBase ( )
virtual
31 {
32 }

Member Function Documentation

void inet::SchedulerBase::addListener ( IPassiveQueueListener listener)
overridevirtual

Adds a new listener to the listener list.

It does nothing, if the listener list already contains the listener (by pointer equality).

Implements inet::IPassiveQueue.

124 {
125  auto it = find(listeners.begin(), listeners.end(), listener);
126  if (it == listeners.end())
127  listeners.push_back(listener);
128 }
std::list< IPassiveQueueListener * > listeners
Definition: SchedulerBase.h:48
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
void inet::SchedulerBase::clear ( )
overridevirtual

Clear all queued packets and stored requests.

Implements inet::IPassiveQueue.

106 {
107  for (auto & elem : inputQueues)
108  (elem)->clear();
109 
112 }
int packetsToBeRequestedFromInputs
Definition: SchedulerBase.h:45
int packetsRequestedFromUs
Definition: SchedulerBase.h:44
std::vector< IPassiveQueue * > inputQueues
Definition: SchedulerBase.h:46
virtual void clear() override
Clear all queued packets and stored requests.
Definition: SchedulerBase.cc:105
void inet::SchedulerBase::finalize ( )
protectedvirtual
55 {
56  for (auto & elem : inputQueues)
57  (elem)->removeListener(this);
58 }
virtual void removeListener(IPassiveQueueListener *listener) override
Removes a listener from the listener list.
Definition: SchedulerBase.cc:130
std::vector< IPassiveQueue * > inputQueues
Definition: SchedulerBase.h:46
virtual int inet::SchedulerBase::getNumPendingRequests ( )
inlineoverridevirtual

Returns number of pending requests.

Implements inet::IPassiveQueue.

64 { return packetsRequestedFromUs; }
int packetsRequestedFromUs
Definition: SchedulerBase.h:44
void inet::SchedulerBase::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
61 {
62  ASSERT(packetsRequestedFromUs > 0);
64  sendOut(msg);
65 }
int packetsRequestedFromUs
Definition: SchedulerBase.h:44
virtual void sendOut(cMessage *msg)
Definition: SchedulerBase.cc:91
void inet::SchedulerBase::initialize ( )
overrideprotectedvirtual

Reimplemented in inet::WRRScheduler.

Referenced by inet::WRRScheduler::initialize().

35 {
36  int numInputs = gateSize("in");
37  for (int i = 0; i < numInputs; ++i) {
38  cGate *inGate = isGateVector("in") ? gate("in", i) : gate("in");
39  cGate *connectedGate = inGate->getPathStartGate();
40  if (!connectedGate)
41  throw cRuntimeError("Scheduler input gate %d is not connected", i);
42  IPassiveQueue *inputModule = dynamic_cast<IPassiveQueue *>(connectedGate->getOwnerModule());
43  if (!inputModule)
44  throw cRuntimeError("Scheduler input gate %d should be connected to an IPassiveQueue", i);
45  inputModule->addListener(this);
46  inputQueues.push_back(inputModule);
47  }
48 
49  outGate = gate("out");
50 
51  // TODO update state when topology changes
52 }
cGate * outGate
Definition: SchedulerBase.h:47
std::vector< IPassiveQueue * > inputQueues
Definition: SchedulerBase.h:46
bool inet::SchedulerBase::isEmpty ( )
overridevirtual

Return true when queue is empty, otherwise return false.

Implements inet::IPassiveQueue.

Referenced by pop(), and inet::WRRScheduler::schedulePacket().

97 {
98  for (auto & elem : inputQueues)
99  if (!(elem)->isEmpty())
100  return false;
101 
102  return true;
103 }
virtual bool isEmpty() override
Return true when queue is empty, otherwise return false.
Definition: SchedulerBase.cc:96
std::vector< IPassiveQueue * > inputQueues
Definition: SchedulerBase.h:46
void inet::SchedulerBase::notifyListeners ( )
protectedvirtual

Referenced by packetEnqueued().

138 {
139  for (auto & elem : listeners)
140  (elem)->packetEnqueued(this);
141 }
virtual void packetEnqueued(IPassiveQueue *inputQueue) override
A packet arrived and it was added to the queue (the queue length increased by one).
Definition: SchedulerBase.cc:67
std::list< IPassiveQueueListener * > listeners
Definition: SchedulerBase.h:48
void inet::SchedulerBase::packetEnqueued ( IPassiveQueue queue)
overridevirtual

A packet arrived and it was added to the queue (the queue length increased by one).

Therefore a subsequent requestPacket() call can deliver a packet immediately.

Implements inet::IPassiveQueueListener.

Referenced by notifyListeners().

68 {
69  Enter_Method("packetEnqueued(...)");
70 
72  bool success = schedulePacket();
73  if (success)
75  }
76  else if (packetsRequestedFromUs == 0)
78 }
int packetsToBeRequestedFromInputs
Definition: SchedulerBase.h:45
int packetsRequestedFromUs
Definition: SchedulerBase.h:44
virtual bool schedulePacket()=0
virtual void notifyListeners()
Definition: SchedulerBase.cc:137
cMessage * inet::SchedulerBase::pop ( )
overridevirtual

Returns a packet directly from the queue, bypassing the primary, send-on-request mechanism.

Returns nullptr if the queue is empty.

Implements inet::IPassiveQueue.

115 {
116  for (auto & elem : inputQueues)
117  if (!(elem)->isEmpty())
118  return (elem)->pop();
119 
120  return nullptr;
121 }
virtual bool isEmpty() override
Return true when queue is empty, otherwise return false.
Definition: SchedulerBase.cc:96
std::vector< IPassiveQueue * > inputQueues
Definition: SchedulerBase.h:46
void inet::SchedulerBase::removeListener ( IPassiveQueueListener listener)
overridevirtual

Removes a listener from the listener list.

It does nothing if the listener was not found on the listener list.

Implements inet::IPassiveQueue.

Referenced by finalize().

131 {
132  auto it = find(listeners.begin(), listeners.end(), listener);
133  if (it != listeners.end())
134  listeners.erase(it);
135 }
std::list< IPassiveQueueListener * > listeners
Definition: SchedulerBase.h:48
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
void inet::SchedulerBase::requestPacket ( )
overridevirtual

The queue should send a packet whenever this method is invoked.

If the queue is currently empty, it should send a packet when when one becomes available.

Implements inet::IPassiveQueue.

81 {
82  Enter_Method("requestPacket()");
83 
86  bool success = schedulePacket();
87  if (success)
89 }
int packetsToBeRequestedFromInputs
Definition: SchedulerBase.h:45
int packetsRequestedFromUs
Definition: SchedulerBase.h:44
virtual bool schedulePacket()=0
virtual bool inet::SchedulerBase::schedulePacket ( )
protectedpure virtual
void inet::SchedulerBase::sendOut ( cMessage *  msg)
protectedvirtual

Referenced by handleMessage().

92 {
93  send(msg, outGate);
94 }
cGate * outGate
Definition: SchedulerBase.h:47

Member Data Documentation

std::list<IPassiveQueueListener *> inet::SchedulerBase::listeners
protected
cGate* inet::SchedulerBase::outGate
protected

Referenced by initialize(), and sendOut().

int inet::SchedulerBase::packetsRequestedFromUs
protected
int inet::SchedulerBase::packetsToBeRequestedFromInputs
protected

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