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

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

#include <REDDropper.h>

Inheritance diagram for inet::REDDropper:
inet::AlgorithmicDropperBase inet::IQueueAccess

Public Member Functions

 REDDropper ()
 
- Public Member Functions inherited from inet::AlgorithmicDropperBase
 AlgorithmicDropperBase ()
 
virtual ~AlgorithmicDropperBase ()
 
- Public Member Functions inherited from inet::IQueueAccess
virtual ~IQueueAccess ()
 

Protected Member Functions

virtual ~REDDropper ()
 
virtual void initialize () override
 
virtual bool shouldDrop (cPacket *packet) override
 
virtual void sendOut (cPacket *packet) override
 
- Protected Member Functions inherited from inet::AlgorithmicDropperBase
virtual void handleMessage (cMessage *msg) override
 
virtual void dropPacket (cPacket *packet)
 
virtual int getLength () const override
 Returns the number of frames in the queue. More...
 
virtual int getByteLength () const override
 Returns the number of bytes in the queue. More...
 

Protected Attributes

double wq = 0.0
 
double * minths = nullptr
 
double * maxths = nullptr
 
double * maxps = nullptr
 
double * pkrates = nullptr
 
double * count = nullptr
 
double avg = 0.0
 
simtime_t q_time
 
- Protected Attributes inherited from inet::AlgorithmicDropperBase
int numGates
 
std::vector< IQueueAccess * > outQueues
 
std::set< IQueueAccess * > outQueueSet
 

Detailed Description

Implementation of Random Early Detection (RED).

Constructor & Destructor Documentation

inet::REDDropper::REDDropper ( )
inline
45 {}
inet::REDDropper::~REDDropper ( )
protectedvirtual
28 {
29  delete[] minths;
30  delete[] maxths;
31  delete[] maxps;
32  delete[] pkrates;
33  delete[] count;
34  q_time = 0;
35 }
simtime_t q_time
Definition: REDDropper.h:42
double * maxps
Definition: REDDropper.h:37
double * count
Definition: REDDropper.h:39
double * pkrates
Definition: REDDropper.h:38
double * maxths
Definition: REDDropper.h:36
double * minths
Definition: REDDropper.h:35

Member Function Documentation

void inet::REDDropper::initialize ( )
overrideprotectedvirtual

Reimplemented from inet::AlgorithmicDropperBase.

38 {
40 
41  wq = par("wq");
42  if (wq < 0.0 || wq > 1.0)
43  throw cRuntimeError("Invalid value for wq parameter: %g", wq);
44 
45  minths = new double[numGates];
46  maxths = new double[numGates];
47  maxps = new double[numGates];
48  pkrates = new double[numGates];
49  count = new double[numGates];
50 
51  cStringTokenizer minthTokens(par("minths"));
52  cStringTokenizer maxthTokens(par("maxths"));
53  cStringTokenizer maxpTokens(par("maxps"));
54  cStringTokenizer pkrateTokens(par("pkrates"));
55  for (int i = 0; i < numGates; ++i) {
56  minths[i] = minthTokens.hasMoreTokens() ? utils::atod(minthTokens.nextToken()) :
57  (i > 0 ? minths[i - 1] : 5.0);
58  maxths[i] = maxthTokens.hasMoreTokens() ? utils::atod(maxthTokens.nextToken()) :
59  (i > 0 ? maxths[i - 1] : 50.0);
60  maxps[i] = maxpTokens.hasMoreTokens() ? utils::atod(maxpTokens.nextToken()) :
61  (i > 0 ? maxps[i - 1] : 0.02);
62  pkrates[i] = pkrateTokens.hasMoreTokens() ? utils::atod(pkrateTokens.nextToken()) :
63  (i > 0 ? pkrates[i-1] : 150);
64  count[i] = -1;
65 
66  if (minths[i] < 0.0)
67  throw cRuntimeError("minth parameter must not be negative");
68  if (maxths[i] < 0.0)
69  throw cRuntimeError("maxth parameter must not be negative");
70  if (minths[i] >= maxths[i])
71  throw cRuntimeError("minth must be smaller than maxth");
72  if (maxps[i] < 0.0 || maxps[i] > 1.0)
73  throw cRuntimeError("Invalid value for maxp parameter: %g", maxps[i]);
74  if (pkrates[i] < 0.0)
75  throw cRuntimeError("Invalid value for pkrates parameter: %g", pkrates[i]);
76  }
77 }
double wq
Definition: REDDropper.h:34
double * maxps
Definition: REDDropper.h:37
double atod(const char *s)
Converts string to double.
Definition: INETUtils.cc:38
double * count
Definition: REDDropper.h:39
double * pkrates
Definition: REDDropper.h:38
double * maxths
Definition: REDDropper.h:36
double * minths
Definition: REDDropper.h:35
int numGates
Definition: AlgorithmicDropperBase.h:33
virtual void initialize() override
Definition: AlgorithmicDropperBase.cc:23
void inet::REDDropper::sendOut ( cPacket *  packet)
overrideprotectedvirtual

Reimplemented from inet::AlgorithmicDropperBase.

132 {
134  // TD: Set the time stamp q_time when the queue gets empty.
135  const int queueLength = getLength();
136  if (queueLength == 0)
137  q_time = simTime();
138 }
simtime_t q_time
Definition: REDDropper.h:42
virtual int getLength() const override
Returns the number of frames in the queue.
Definition: AlgorithmicDropperBase.cc:60
virtual void sendOut(cPacket *packet)
Definition: AlgorithmicDropperBase.cc:54
bool inet::REDDropper::shouldDrop ( cPacket *  packet)
overrideprotectedvirtual

Implements inet::AlgorithmicDropperBase.

80 {
81  const int i = packet->getArrivalGate()->getIndex();
82  ASSERT(i >= 0 && i < numGates);
83  const double minth = minths[i];
84  const double maxth = maxths[i];
85  const double maxp = maxps[i];
86  const double pkrate = pkrates[i];
87  const int queueLength = getLength();
88 
89  if (queueLength > 0)
90  {
91  // TD: This following calculation is only useful when the queue is not empty!
92  avg = (1 - wq) * avg + wq * queueLength;
93  }
94  else
95  {
96  // TD: Added behaviour for empty queue.
97  const double m = SIMTIME_DBL(simTime() - q_time) * pkrate;
98  avg = pow(1 - wq, m) * avg;
99  }
100 
101  if (minth <= avg && avg < maxth)
102  {
103  count[i]++;
104  const double pb = maxp * (avg - minth) / (maxth - minth);
105  const double pa = pb / (1 - count[i] * pb); // TD: Adapted to work as in [Floyd93].
106  if (dblrand() < pa)
107  {
108  EV << "Random early packet drop (avg queue len=" << avg << ", pa=" << pb << ")\n";
109  count[i] = 0;
110  return true;
111  }
112  }
113  else if (avg >= maxth) {
114  EV << "Avg queue len " << avg << " >= maxth, dropping packet.\n";
115  count[i] = 0;
116  return true;
117  }
118  else if (queueLength >= maxth) { // maxth is also the "hard" limit
119  EV << "Queue len " << queueLength << " >= maxth, dropping packet.\n";
120  count[i] = 0;
121  return true;
122  }
123  else
124  {
125  count[i] = -1;
126  }
127 
128  return false;
129 }
double wq
Definition: REDDropper.h:34
simtime_t q_time
Definition: REDDropper.h:42
double * maxps
Definition: REDDropper.h:37
double * count
Definition: REDDropper.h:39
double * pkrates
Definition: REDDropper.h:38
double * maxths
Definition: REDDropper.h:36
double * minths
Definition: REDDropper.h:35
virtual int getLength() const override
Returns the number of frames in the queue.
Definition: AlgorithmicDropperBase.cc:60
int numGates
Definition: AlgorithmicDropperBase.h:33
double avg
Definition: REDDropper.h:41
value< double, units::m > m
Definition: Units.h:1047

Member Data Documentation

double inet::REDDropper::avg = 0.0
protected

Referenced by shouldDrop().

double* inet::REDDropper::count = nullptr
protected

Referenced by initialize(), shouldDrop(), and ~REDDropper().

double* inet::REDDropper::maxps = nullptr
protected

Referenced by initialize(), shouldDrop(), and ~REDDropper().

double* inet::REDDropper::maxths = nullptr
protected

Referenced by initialize(), shouldDrop(), and ~REDDropper().

double* inet::REDDropper::minths = nullptr
protected

Referenced by initialize(), shouldDrop(), and ~REDDropper().

double* inet::REDDropper::pkrates = nullptr
protected

Referenced by initialize(), shouldDrop(), and ~REDDropper().

simtime_t inet::REDDropper::q_time
protected

Referenced by sendOut(), shouldDrop(), and ~REDDropper().

double inet::REDDropper::wq = 0.0
protected

Referenced by initialize(), and shouldDrop().


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