RINASim  October 2016
Documentation of framework for OMNeT++
REDDropper.cc
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 
23 #include "REDDropper.h"
24 
26 
28 {
29  monitor = dynamic_cast<REDMonitor*>(qMonPolicy);
30  if (monitor == NULL)
31  {
32  EV << "!!! REDDropper has to be used in conjecture with REDMonitor!" << endl;
33  }
34 }
35 
43 {
44  if (par("marking").boolValue() == true)
45  {
46  EV << "REDDropper: Marking the last message in " << queue->getFullName()
47  << " with an ECN bit." << endl;
48  queue->markCongestionOnLast();
49  return false;
50  }
51  else
52  {
53  EV << "REDDropper: executing tail drop in " << queue->getFullName() << endl;
54  return true;
55  }
56 }
57 
65 {
66  if (monitor == NULL)
67  {
68  return false;
69  }
70 
71  // gather some variables from the queue, the monitoring policy and the NED module
72  const char* qname = queue->getFullName();
73  int length = queue->getLength();
74  int minThresh = queue->getThreshLength();
75  int maxThresh = queue->getMaxLength();
76  double avr = monitor->qAvgLengths[queue];
77  int count = monitor->qCounters[queue];
78  double maxP = par("dropProbability").doubleValue();
79 
80  bool dropped = false;
81 
82  if (minThresh <= avr && avr < maxThresh)
83  {
84  monitor->qCounters[queue] += 1;
85  const double pb = maxP * (avr - minThresh) / (maxThresh - minThresh);
86  double pa;
87  if ((count * pb) < 1)
88  {
89  pa = pb / (1 - (count * pb));
90  }
91  else
92  {
93  pa = 1.0;
94  }
95 
96  const double rand = dblrand();
97 
98  if (rand < pa)
99  {
100  EV << "REDDropper: rand < pa (" << rand << " < " << pa << ")" << endl;
101  monitor->qCounters[queue] = 0;
102  dropped = dropOrMark(queue);
103  }
104  }
105  else if (avr >= maxThresh)
106  {
107  EV << "REDDropper: Average queue length in " << qname << " exceeds the maximum threshold." << endl;
108  monitor->qCounters[queue] = 0;
109  dropped = dropOrMark(queue);
110  }
111  else if (length >= maxThresh)
112  {
113  EV << "REDDropper: Queue length in " << qname << " exceeds the maximum threshold." << endl;
114  monitor->qCounters[queue] = 0;
115  dropped = dropOrMark(queue);
116  }
117  else
118  {
119  monitor->qCounters[queue] = -1;
120  }
121 
122  return dropped;
123 }
RMTQMonitorBase * qMonPolicy
Definition: RMTMaxQBase.h:80
REDMonitor * monitor
Definition: REDDropper.h:38
int getMaxLength() const
Definition: RMTQueue.cc:215
bool dropOrMark(RMTQueue *queue)
Definition: REDDropper.cc:42
void onPolicyInit()
Definition: REDDropper.cc:27
int getLength() const
Definition: RMTQueue.cc:210
int getThreshLength() const
Definition: RMTQueue.cc:226
REDParamMap qAvgLengths
Definition: REDMonitor.h:41
void markCongestionOnLast()
Definition: RMTQueue.cc:194
virtual bool run(RMTQueue *queue)
Definition: REDDropper.cc:64
Define_Module(REDDropper)
REDParamMap qCounters
Definition: REDMonitor.h:43