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

Implementation of Random Early Detection (RED). More...

#include <RedDropper.h>

Inheritance diagram for inet::queueing::RedDropper:
inet::queueing::PacketFilterBase inet::queueing::PacketProcessorBase inet::queueing::IPacketFilter inet::queueing::IPacketProcessor inet::StringFormat::IDirectiveResolver inet::queueing::IPacketFlow inet::queueing::IPacketSink inet::queueing::IPacketSource inet::queueing::IPassivePacketSink inet::queueing::IActivePacketSink inet::queueing::IPassivePacketSource inet::queueing::IActivePacketSource

Public Member Functions

virtual bool matchesPacket (const Packet *packet) const override
 Returns true if the filter matches the given packet. More...
 
- Public Member Functions inherited from inet::queueing::PacketFilterBase
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 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...
 
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...
 
- 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...
 
- Public Member Functions inherited from inet::queueing::IPacketProcessor
virtual ~IPacketProcessor ()
 
- 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 Types

enum  RedResult {
  QUEUE_FULL, RANDOMLY_ABOVE_LIMIT, RANDOMLY_BELOW_LIMIT, ABOVE_MAX_LIMIT,
  BELOW_MIN_LIMIT
}
 
- Protected Types inherited from inet::queueing::PacketProcessorBase
enum  Action { PUSH, PULL }
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual RedResult doRandomEarlyDetection (const Packet *packet)
 
virtual void processPacket (Packet *packet) override
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 
- Protected Member Functions inherited from inet::queueing::PacketFilterBase
virtual void handleMessage (cMessage *message) override
 
virtual bool isStreamingPacket () const
 
virtual void startPacketStreaming (Packet *packet)
 
virtual void endPacketStreaming (Packet *packet)
 
virtual void checkPacketStreaming (Packet *packet)
 
virtual void dropPacket (Packet *packet)
 
virtual void dropPacket (Packet *packet, PacketDropReason reason, int limit=-1) override
 
virtual const char * resolveDirective (char directive) const override
 
- 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 updateDisplayString () const
 

Protected Attributes

double wq = 0.0
 
double minth = NaN
 
double maxth = NaN
 
double maxp = NaN
 
double pkrate = NaN
 
double count = NaN
 
double avg = 0.0
 
simtime_t q_time
 
int packetCapacity = -1
 
bool useEcn = false
 
bool markNext = false
 
RedResult lastResult
 
ModuleRef< IPacketCollectioncollection
 
- Protected Attributes inherited from inet::queueing::PacketFilterBase
bool backpressure = false
 
cGate * inputGate = nullptr
 
ModuleRef< IActivePacketSourceproducer
 
ModuleRef< IPassivePacketSourceprovider
 
cGate * outputGate = nullptr
 
ModuleRef< IPassivePacketSinkconsumer
 
ModuleRef< IActivePacketSinkcollector
 
int inProgressStreamId = -1
 
int numDroppedPackets = 0
 
b droppedTotalLength = b(-1)
 
- Protected Attributes inherited from inet::queueing::PacketProcessorBase
const char * displayStringTextFormat = nullptr
 
int numProcessedPackets = -1
 
b processedTotalLength = b(-1)
 

Detailed Description

Implementation of Random Early Detection (RED).

Member Enumeration Documentation

◆ RedResult

Enumerator
QUEUE_FULL 
RANDOMLY_ABOVE_LIMIT 
RANDOMLY_BELOW_LIMIT 
ABOVE_MAX_LIMIT 
BELOW_MIN_LIMIT 

Member Function Documentation

◆ doRandomEarlyDetection()

RedDropper::RedResult inet::queueing::RedDropper::doRandomEarlyDetection ( const Packet packet)
protectedvirtual
58 {
59  int queueLength = collection->getNumPackets();
60 
61  if (queueLength > 0) {
62  // TD: This following calculation is only useful when the queue is not empty!
63  avg = (1 - wq) * avg + wq * queueLength;
64  }
65  else {
66  // TD: Added behaviour for empty queue.
67  const double m = SIMTIME_DBL(simTime() - q_time) * pkrate;
68  avg = pow(1 - wq, m) * avg;
69  q_time = simTime();
70  }
71 
72  if (queueLength >= packetCapacity) { // maxth is also the "hard" limit
73  EV_DEBUG << "Queue length >= capacity" << EV_FIELD(queueLength) << EV_FIELD(packetCapacity) << EV_ENDL;
74  count = 0;
75  return QUEUE_FULL;
76  }
77  else if (minth <= avg && avg < maxth) {
78  count++;
79  const double pb = maxp * (avg - minth) / (maxth - minth);
80  const double pa = pb / (1 - count * pb); // TD: Adapted to work as in [Floyd93].
81  if (dblrand() < pa) {
82  EV_DEBUG << "Random early packet detected" << EV_FIELD(averageQueueLength, avg) << EV_FIELD(probability, pa) << EV_ENDL;
83  count = 0;
84  return RANDOMLY_ABOVE_LIMIT;
85  }
86  else
87  return RANDOMLY_BELOW_LIMIT;
88  }
89  else if (avg >= maxth) {
90  EV_DEBUG << "Average queue length >= maxth" << EV_FIELD(averageQueueLength, avg) << EV_FIELD(maxth) << EV_ENDL;
91  count = 0;
92  return ABOVE_MAX_LIMIT;
93  }
94  else {
95  count = -1;
96  }
97 
98  return BELOW_MIN_LIMIT;
99 }

Referenced by matchesPacket().

◆ initialize()

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

Reimplemented from inet::queueing::PacketFilterBase.

19 {
21 
22  if (stage == INITSTAGE_LOCAL) {
23  wq = par("wq");
24  if (wq < 0.0 || wq > 1.0)
25  throw cRuntimeError("Invalid value for wq parameter: %g", wq);
26  minth = par("minth");
27  maxth = par("maxth");
28  maxp = par("maxp");
29  pkrate = par("pkrate");
30  count = -1;
31  if (minth < 0.0)
32  throw cRuntimeError("minth parameter must not be negative");
33  if (maxth < 0.0)
34  throw cRuntimeError("maxth parameter must not be negative");
35  if (minth >= maxth)
36  throw cRuntimeError("minth must be smaller than maxth");
37  if (maxp < 0.0 || maxp > 1.0)
38  throw cRuntimeError("Invalid value for maxp parameter: %g", maxp);
39  if (pkrate < 0.0)
40  throw cRuntimeError("Invalid value for pkrate parameter: %g", pkrate);
41  useEcn = par("useEcn");
42  packetCapacity = par("packetCapacity");
43  if (maxth > packetCapacity)
44  throw cRuntimeError("Warning: packetCapacity < maxth. Setting capacity to maxth");
45  auto outputGate = gate("out");
46  collection.reference(outputGate, false);
47  if (!collection)
48  collection.reference(this, "collectionModule", true);
49  cModule * cm = check_and_cast<cModule *>(collection.get());
50  cm->subscribe(packetPushedSignal, this);
51  cm->subscribe(packetPulledSignal, this);
52  cm->subscribe(packetRemovedSignal, this);
53  cm->subscribe(packetDroppedSignal, this);
54  }
55 }

◆ matchesPacket()

bool inet::queueing::RedDropper::matchesPacket ( const Packet packet) const
overridevirtual

Returns true if the filter matches the given packet.

Implements inet::queueing::IPacketFilter.

102 {
103  lastResult = const_cast<RedDropper *>(this)->doRandomEarlyDetection(packet);
104  switch (lastResult) {
106  case ABOVE_MAX_LIMIT:
107  return useEcn && EcnMarker::getEcn(packet) != IP_ECN_NOT_ECT;
109  case BELOW_MIN_LIMIT:
110  return true;
111  case QUEUE_FULL:
112  return false;
113  default:
114  throw cRuntimeError("Unknown RED result");
115  }
116 }

◆ processPacket()

void inet::queueing::RedDropper::processPacket ( Packet packet)
overrideprotectedvirtual

Reimplemented from inet::queueing::PacketFilterBase.

119 {
120  switch (lastResult) {
122  case ABOVE_MAX_LIMIT: {
123  if (useEcn) {
124  IpEcnCode ecn = EcnMarker::getEcn(packet);
125  if (ecn != IP_ECN_NOT_ECT) {
126  // if next packet should be marked and it is not
127  if (markNext && ecn != IP_ECN_CE) {
128  EcnMarker::setEcn(packet, IP_ECN_CE);
129  markNext = false;
130  }
131  else {
132  if (ecn == IP_ECN_CE)
133  markNext = true;
134  else
135  EcnMarker::setEcn(packet, IP_ECN_CE);
136  }
137  }
138  }
139  }
141  case BELOW_MIN_LIMIT:
142  case QUEUE_FULL:
143  break;
144  default:
145  throw cRuntimeError("Unknown RED result");
146  }
147 }

◆ receiveSignal()

void inet::queueing::RedDropper::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
overrideprotectedvirtual
150 {
151  if (signalID == packetPushedSignal || signalID == packetPulledSignal || signalID == packetRemovedSignal || signalID == packetDroppedSignal)
152  q_time = simTime();
153 }

Member Data Documentation

◆ avg

double inet::queueing::RedDropper::avg = 0.0
protected

Referenced by doRandomEarlyDetection().

◆ collection

ModuleRef<IPacketCollection> inet::queueing::RedDropper::collection
protected

◆ count

double inet::queueing::RedDropper::count = NaN
protected

◆ lastResult

RedResult inet::queueing::RedDropper::lastResult
mutableprotected

Referenced by matchesPacket(), and processPacket().

◆ markNext

bool inet::queueing::RedDropper::markNext = false
protected

Referenced by processPacket().

◆ maxp

double inet::queueing::RedDropper::maxp = NaN
protected

◆ maxth

double inet::queueing::RedDropper::maxth = NaN
protected

◆ minth

double inet::queueing::RedDropper::minth = NaN
protected

◆ packetCapacity

int inet::queueing::RedDropper::packetCapacity = -1
protected

◆ pkrate

double inet::queueing::RedDropper::pkrate = NaN
protected

◆ q_time

simtime_t inet::queueing::RedDropper::q_time
protected

◆ useEcn

bool inet::queueing::RedDropper::useEcn = false
protected

◆ wq

double inet::queueing::RedDropper::wq = 0.0
protected

The documentation for this class was generated from the following files:
inet::units::units::cm
centi< m >::type cm
Definition: Units.h:1068
inet::queueing::RedDropper::wq
double wq
Definition: RedDropper.h:28
inet::IP_ECN_CE
@ IP_ECN_CE
Definition: EcnTag_m.h:62
inet::queueing::RedDropper::RANDOMLY_BELOW_LIMIT
@ RANDOMLY_BELOW_LIMIT
Definition: RedDropper.h:25
inet::queueing::RedDropper::RANDOMLY_ABOVE_LIMIT
@ RANDOMLY_ABOVE_LIMIT
Definition: RedDropper.h:25
inet::IP_ECN_NOT_ECT
@ IP_ECN_NOT_ECT
Definition: EcnTag_m.h:59
inet::queueing::RedDropper::lastResult
RedResult lastResult
Definition: RedDropper.h:41
inet::queueing::RedDropper::count
double count
Definition: RedDropper.h:33
inet::packetRemovedSignal
simsignal_t packetRemovedSignal
Definition: Simsignals.cc:84
inet::queueing::RedDropper::pkrate
double pkrate
Definition: RedDropper.h:32
inet::IpEcnCode
IpEcnCode
Enum generated from inet/networklayer/common/EcnTag.msg:12 by opp_msgtool.
Definition: EcnTag_m.h:58
inet::packetPulledSignal
simsignal_t packetPulledSignal
Definition: Simsignals.cc:105
inet::queueing::PacketFilterBase::outputGate
cGate * outputGate
Definition: PacketFilterBase.h:27
inet::packetDroppedSignal
simsignal_t packetDroppedSignal
Definition: Simsignals.cc:85
inet::queueing::RedDropper::q_time
simtime_t q_time
Definition: RedDropper.h:36
inet::queueing::RedDropper::packetCapacity
int packetCapacity
Definition: RedDropper.h:38
inet::packetPushedSignal
simsignal_t packetPushedSignal
Definition: Simsignals.cc:99
inet::queueing::RedDropper::markNext
bool markNext
Definition: RedDropper.h:40
EV_FIELD
#define EV_FIELD(...)
Definition: INETDefs.h:112
inet::queueing::RedDropper::useEcn
bool useEcn
Definition: RedDropper.h:39
inet::queueing::EcnMarker::getEcn
static IpEcnCode getEcn(const Packet *packet)
Definition: EcnMarker.cc:74
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::queueing::RedDropper::doRandomEarlyDetection
virtual RedResult doRandomEarlyDetection(const Packet *packet)
Definition: RedDropper.cc:57
inet::queueing::RedDropper::maxth
double maxth
Definition: RedDropper.h:30
inet::queueing::RedDropper::BELOW_MIN_LIMIT
@ BELOW_MIN_LIMIT
Definition: RedDropper.h:25
inet::queueing::RedDropper::collection
ModuleRef< IPacketCollection > collection
Definition: RedDropper.h:43
inet::queueing::RedDropper::maxp
double maxp
Definition: RedDropper.h:31
inet::queueing::RedDropper::avg
double avg
Definition: RedDropper.h:35
inet::queueing::EcnMarker::setEcn
static void setEcn(Packet *packet, IpEcnCode ecn)
Definition: EcnMarker.cc:39
inet::queueing::PacketFilterBase::initialize
virtual void initialize(int stage) override
Definition: PacketFilterBase.cc:16
inet::queueing::RedDropper::QUEUE_FULL
@ QUEUE_FULL
Definition: RedDropper.h:25
inet::queueing::RedDropper::minth
double minth
Definition: RedDropper.h:29
inet::units::values::m
value< double, units::m > m
Definition: Units.h:1233
inet::queueing::RedDropper::ABOVE_MAX_LIMIT
@ ABOVE_MAX_LIMIT
Definition: RedDropper.h:25
EV_ENDL
#define EV_ENDL
Definition: INETDefs.h:114