INET Framework for OMNeT++/OMNEST
inet::queueing::WrrScheduler Class Reference

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

#include <WrrScheduler.h>

Inheritance diagram for inet::queueing::WrrScheduler:
inet::queueing::PacketSchedulerBase inet::queueing::IPacketCollection inet::queueing::PacketProcessorBase inet::TransparentProtocolRegistrationListener inet::queueing::IPacketSink inet::queueing::IPacketSource inet::queueing::IActivePacketSource inet::queueing::IPassivePacketSource inet::queueing::IActivePacketSink inet::queueing::IPassivePacketSink inet::IProtocolRegistrationListener inet::StringFormat::IDirectiveResolver inet::queueing::IPacketProcessor

Public Member Functions

virtual ~WrrScheduler ()
 
virtual int getMaxNumPackets () const override
 Returns maximum allowed number of packets in the collection. More...
 
virtual int getNumPackets () const override
 Returns the number of available packets in the collection in the range [0, inf). More...
 
virtual b getMaxTotalLength () const override
 Returns maximum allowed total length of all packets in the collection. More...
 
virtual b getTotalLength () const override
 Returns the total length of all packets in the collection in the range [0, inf). More...
 
virtual bool isEmpty () const override
 Returns true if there are no packets available in the collection. More...
 
virtual PacketgetPacket (int index) const override
 Returns the packet at the given index. More...
 
virtual void removePacket (Packet *packet) override
 Removes a packet from the collection. More...
 
virtual void removeAllPackets () override
 Removes all packets from the collection. More...
 
- Public Member Functions inherited from inet::queueing::PacketSchedulerBase
virtual IPassivePacketSinkgetConsumer (cGate *gate) override
 Returns the passive packet sink where packets are pushed or nullptr if the connected module doesn't implement the interface. More...
 
virtual IPassivePacketSourcegetProvider (cGate *gate) override
 Returns the passive packet source from where packets are pulled or nullptr if the connected module doesn't implement the interface. More...
 
virtual bool supportsPacketPushing (cGate *gate) const override
 Returns true if the processor supports pushing packets at the given gate. More...
 
virtual bool supportsPacketPulling (cGate *gate) const override
 Returns true if the processor supports pulling packets at the given gate. More...
 
virtual bool supportsPacketStreaming (cGate *gate) const override
 Returns true if the processor supports streaming packets at the given gate. More...
 
virtual bool canPushSomePacket (cGate *gate) const override
 Returns false if the packet sink is full at the given gate and no more packets can be pushed into it without raising an error. More...
 
virtual bool canPushPacket (Packet *packet, cGate *gate) const override
 Returns true if the given packet can be pushed at the given gate into the packet sink without raising an error. More...
 
virtual void pushPacket (Packet *packet, cGate *gate) override
 Pushes the packet into the packet sink at the given gate. More...
 
virtual void pushPacketStart (Packet *packet, cGate *gate, bps datarate) override
 Starts pushing the packet into the packet sink at the given gate. More...
 
virtual void pushPacketEnd (Packet *packet, cGate *gate) override
 Ends pushing the packet into the packet sink at the given gate. More...
 
virtual void pushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength=b(0)) override
 Progresses pushing the packet into the packet sink at the given gate. More...
 
virtual void handleCanPushPacketChanged (cGate *gate) override
 Notifies about a change in the possibility of pushing some packet into the passive packet sink at the given gate. More...
 
virtual void handlePushPacketProcessed (Packet *packet, cGate *gate, bool successful) override
 Notifies about the completion of the packet processing for a packet that was pushed earlier independently whether the packet is passed or streamed. More...
 
virtual bool canPullSomePacket (cGate *gate) const override
 Returns false if the packet source is empty at the given gate and no more packets can be pulled from it without raising an error. More...
 
virtual PacketcanPullPacket (cGate *gate) const override
 Returns the packet that can be pulled at the given gate. More...
 
virtual PacketpullPacket (cGate *gate) override
 Pulls the packet from the packet source at the given gate. More...
 
virtual PacketpullPacketStart (cGate *gate, bps datarate) override
 Starts pulling the packet from the packet source at the given gate. More...
 
virtual PacketpullPacketEnd (cGate *gate) override
 Ends pulling the packet from the packet source at the given gate. More...
 
virtual PacketpullPacketProgress (cGate *gate, bps datarate, b position, b extraProcessableLength) override
 Progresses pulling the packet from the packet source at the given gate. More...
 
virtual void handleCanPullPacketChanged (cGate *gate) override
 Notifies about a change in the possibility of pulling some packet from the passive packet source at the given gate. More...
 
virtual void handlePullPacketProcessed (Packet *packet, cGate *gate, bool successful) override
 Notifies about the completion of the packet processing for a packet that was pulled earlier independently whether the packet is passed or streamed. More...
 
- Public Member Functions inherited from inet::queueing::PacketProcessorBase
virtual bool supportsPacketSending (cGate *gate) const override
 Returns true if the processor supports sending packets at the given gate. More...
 
virtual bool supportsPacketPassing (cGate *gate) const override
 Returns true if the processor supports passing packets as a whole at the given gate. More...
 
virtual const char * resolveDirective (char directive) const override
 
- Public Member Functions inherited from inet::queueing::IPacketProcessor
virtual ~IPacketProcessor ()
 
- Public Member Functions inherited from inet::TransparentProtocolRegistrationListener
virtual cGate * getRegistrationForwardingGate (cGate *gate)
 
virtual bool isForwardingProtocol (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) const
 
virtual bool isForwardingProtocolGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) const
 
virtual bool isForwardingAnyProtocol (cGate *gate, ServicePrimitive servicePrimitive) const
 
virtual bool isForwardingProtocol (cGate *gate, ServicePrimitive servicePrimitive) const
 
virtual bool isForwardingService (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) const
 
virtual bool isForwardingServiceGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) const
 
virtual bool isForwardingAnyService (cGate *gate, ServicePrimitive servicePrimitive) const
 
virtual bool isForwardingService (cGate *gate, ServicePrimitive servicePrimitive) const
 
virtual void handleRegisterService (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterProtocol (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterServiceGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterProtocolGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterAnyService (cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterAnyProtocol (cGate *gate, ServicePrimitive servicePrimitive) override
 
- Public Member Functions inherited from inet::queueing::IPassivePacketSink
virtual ~IPassivePacketSink ()
 
- Public Member Functions inherited from inet::queueing::IActivePacketSink
virtual ~IActivePacketSink ()
 
- Public Member Functions inherited from inet::queueing::IPassivePacketSource
virtual ~IPassivePacketSource ()
 
- Public Member Functions inherited from inet::queueing::IActivePacketSource
virtual ~IActivePacketSource ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int schedulePacket () override
 
- Protected Member Functions inherited from inet::queueing::PacketSchedulerBase
virtual void mapRegistrationForwardingGates (cGate *gate, std::function< void(cGate *)> f) override
 
virtual size_t getInputGateIndex (size_t i) const
 
virtual int callSchedulePacket () const
 
virtual bool isStreamingPacket () const
 
virtual void startPacketStreaming ()
 
virtual void endPacketStreaming (Packet *packet)
 
virtual void checkPacketStreaming (Packet *packet)
 
- Protected Member Functions inherited from inet::queueing::PacketProcessorBase
virtual int numInitStages () const override
 
virtual void refreshDisplay () const override
 
virtual void handlePacketProcessed (Packet *packet)
 
virtual void checkPacketOperationSupport (cGate *gate) const
 
virtual void checkPacketOperationSupport (cGate *startGate, cGate *endGate) const
 
virtual void animate (Packet *packet, cGate *gate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacket (Packet *packet, cGate *gate, Action action) const
 
virtual void animatePacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId, Action action) const
 
virtual void animatePacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacketEnd (Packet *packet, cGate *gate, long transmissionId, Action action) const
 
virtual void animatePacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId, Action action) const
 
virtual void animatePacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions, Action action) const
 
virtual void pushOrSendPacket (Packet *packet, cGate *gate, IPassivePacketSink *consumer)
 
virtual void pushOrSendPacketStart (Packet *packet, cGate *gate, IPassivePacketSink *consumer, bps datarate, int transmissionId)
 
virtual void pushOrSendPacketEnd (Packet *packet, cGate *gate, IPassivePacketSink *consumer, int transmissionId)
 
virtual void pushOrSendPacketProgress (Packet *packet, cGate *gate, IPassivePacketSink *consumer, bps datarate, b position, b extraProcessableLength, int transmissionId)
 
virtual void animatePush (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePushPacket (Packet *packet, cGate *gate) const
 
virtual void animatePushPacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId) const
 
virtual void animatePushPacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions) const
 
virtual void animatePushPacketEnd (Packet *packet, cGate *gate, long transmissionId) const
 
virtual void animatePushPacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId) const
 
virtual void animatePushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions) const
 
virtual void animatePull (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePullPacket (Packet *packet, cGate *gate) const
 
virtual void animatePullPacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId) const
 
virtual void animatePullPacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions) const
 
virtual void animatePullPacketEnd (Packet *packet, cGate *gate, long transmissionId) const
 
virtual void animatePullPacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePullPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId) const
 
virtual void animatePullPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions) const
 
virtual void dropPacket (Packet *packet, PacketDropReason reason, int limit=-1)
 
virtual void updateDisplayString () const
 

Protected Attributes

unsigned int * weights = nullptr
 
unsigned int * buckets = nullptr
 
std::vector< IPacketCollection * > collections
 
- Protected Attributes inherited from inet::queueing::PacketSchedulerBase
bool reverseOrder = false
 
std::vector< cGate * > inputGates
 
std::vector< IPassivePacketSource * > providers
 
std::vector< IActivePacketSource * > producers
 
cGate * outputGate = nullptr
 
IActivePacketSinkcollector = nullptr
 
IPassivePacketSinkconsumer = nullptr
 
int inProgressStreamId = -1
 
int inProgressGateIndex = -1
 
- Protected Attributes inherited from inet::queueing::PacketProcessorBase
const char * displayStringTextFormat = nullptr
 
int numProcessedPackets = -1
 
b processedTotalLength = b(-1)
 

Additional Inherited Members

- Protected Types inherited from inet::queueing::PacketProcessorBase
enum  Action { PUSH, PULL }
 

Detailed Description

This module implements a Weighted Round Robin Scheduler.

Constructor & Destructor Documentation

◆ ~WrrScheduler()

inet::queueing::WrrScheduler::~WrrScheduler ( )
virtual
18 {
19  delete[] weights;
20  delete[] buckets;
21 }

Member Function Documentation

◆ getMaxNumPackets()

virtual int inet::queueing::WrrScheduler::getMaxNumPackets ( ) const
inlineoverridevirtual

Returns maximum allowed number of packets in the collection.

The value -1 means no such limit.

Implements inet::queueing::IPacketCollection.

35 { return -1; }

◆ getMaxTotalLength()

virtual b inet::queueing::WrrScheduler::getMaxTotalLength ( ) const
inlineoverridevirtual

Returns maximum allowed total length of all packets in the collection.

The value -1 means no such limit.

Implements inet::queueing::IPacketCollection.

38 { return b(-1); }

◆ getNumPackets()

int inet::queueing::WrrScheduler::getNumPackets ( ) const
overridevirtual

Returns the number of available packets in the collection in the range [0, inf).

Implements inet::queueing::IPacketCollection.

46 {
47  int size = 0;
48  for (auto collection : collections)
49  size += collection->getNumPackets();
50  return size;
51 }

◆ getPacket()

virtual Packet* inet::queueing::WrrScheduler::getPacket ( int  index) const
inlineoverridevirtual

Returns the packet at the given index.

Throws error when the index is out of range.

Implements inet::queueing::IPacketCollection.

42 { throw cRuntimeError("Invalid operation"); }

◆ getTotalLength()

b inet::queueing::WrrScheduler::getTotalLength ( ) const
overridevirtual

Returns the total length of all packets in the collection in the range [0, inf).

Implements inet::queueing::IPacketCollection.

54 {
55  b totalLength(0);
56  for (auto collection : collections)
57  totalLength += collection->getTotalLength();
58  return totalLength;
59 }

◆ initialize()

void inet::queueing::WrrScheduler::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::queueing::PacketSchedulerBase.

24 {
26  if (stage == INITSTAGE_LOCAL) {
27  weights = new unsigned int[providers.size()];
28  buckets = new unsigned int[providers.size()];
29 
30  cStringTokenizer tokenizer(par("weights"));
31  size_t i;
32  for (i = 0; i < providers.size() && tokenizer.hasMoreTokens(); ++i)
33  buckets[i] = weights[i] = utils::atoul(tokenizer.nextToken());
34 
35  if (i < providers.size())
36  throw cRuntimeError("Too few values given in the weights parameter.");
37  if (tokenizer.hasMoreTokens())
38  throw cRuntimeError("Too many values given in the weights parameter.");
39 
40  for (auto provider : providers)
41  collections.push_back(dynamic_cast<IPacketCollection *>(provider));
42  }
43 }

◆ isEmpty()

virtual bool inet::queueing::WrrScheduler::isEmpty ( ) const
inlineoverridevirtual

Returns true if there are no packets available in the collection.

Implements inet::queueing::IPacketCollection.

41 { return getNumPackets() == 0; }

◆ removeAllPackets()

void inet::queueing::WrrScheduler::removeAllPackets ( )
overridevirtual

Removes all packets from the collection.

Implements inet::queueing::IPacketCollection.

62 {
63  Enter_Method("removeAllPackets");
64  for (auto collection : collections)
65  collection->removeAllPackets();
66 }

◆ removePacket()

virtual void inet::queueing::WrrScheduler::removePacket ( Packet packet)
inlineoverridevirtual

Removes a packet from the collection.

The collection must contain the packet.

Implements inet::queueing::IPacketCollection.

43 { throw cRuntimeError("Invalid operation"); }

◆ schedulePacket()

int inet::queueing::WrrScheduler::schedulePacket ( )
overrideprotectedvirtual

Implements inet::queueing::PacketSchedulerBase.

69 {
70  int firstWeighted = -1;
71  int firstNonWeighted = -1;
72  for (size_t i = 0; i < providers.size(); ++i) {
73  if (providers[i]->canPullSomePacket(inputGates[i]->getPathStartGate())) {
74  if (buckets[i] > 0) {
75  buckets[i]--;
76  return (int)i;
77  }
78  else if (firstWeighted == -1 && weights[i] > 0)
79  firstWeighted = (int)i;
80  else if (firstNonWeighted == -1 && weights[i] == 0)
81  firstNonWeighted = (int)i;
82  }
83  }
84 
85  if (firstWeighted != -1) {
86  for (size_t i = 0; i < providers.size(); ++i)
87  buckets[i] = weights[i];
88  buckets[firstWeighted]--;
89  return firstWeighted;
90  }
91 
92  if (firstNonWeighted != -1)
93  return firstNonWeighted;
94 
95  return -1;
96 }

Member Data Documentation

◆ buckets

unsigned int* inet::queueing::WrrScheduler::buckets = nullptr
protected

◆ collections

std::vector<IPacketCollection *> inet::queueing::WrrScheduler::collections
protected

◆ weights

unsigned int* inet::queueing::WrrScheduler::weights = nullptr
protected

The documentation for this class was generated from the following files:
inet::queueing::PacketSchedulerBase::initialize
virtual void initialize(int stage) override
Definition: PacketSchedulerBase.cc:16
inet::queueing::WrrScheduler::buckets
unsigned int * buckets
Definition: WrrScheduler.h:24
inet::queueing::PacketSchedulerBase::canPullSomePacket
virtual bool canPullSomePacket(cGate *gate) const override
Returns false if the packet source is empty at the given gate and no more packets can be pulled from ...
Definition: PacketSchedulerBase.cc:109
inet::queueing::WrrScheduler::collections
std::vector< IPacketCollection * > collections
Definition: WrrScheduler.h:26
inet::queueing::WrrScheduler::getNumPackets
virtual int getNumPackets() const override
Returns the number of available packets in the collection in the range [0, inf).
Definition: WrrScheduler.cc:45
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::utils::atoul
unsigned long atoul(const char *s)
Converts string to unsigned long.
Definition: INETUtils.cc:89
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::queueing::PacketSchedulerBase::providers
std::vector< IPassivePacketSource * > providers
Definition: PacketSchedulerBase.h:25
inet::queueing::PacketSchedulerBase::inputGates
std::vector< cGate * > inputGates
Definition: PacketSchedulerBase.h:24
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::queueing::WrrScheduler::weights
unsigned int * weights
Definition: WrrScheduler.h:23