Child: [180d2e] (diff)

Download this file

REDDropper.cc    110 lines (99 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
//
// Copyright Š 2014 PRISTINE Consortium (http://ict-pristine.eu)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#include "REDDropper.h"
Define_Module(REDDropper);
void REDDropper::onPolicyInit()
{
monitor = dynamic_cast<REDMonitor*>(qMonPolicy);
if (monitor == NULL)
{
EV << "!!! REDDropper has to be used in conjecture with REDMonitor!" << endl;
}
}
/**
* Either drops or marks the last PDU in given queue (depending on the NED setting).
*
* @param queue target queue
* @return true for PDU drop, false for PDU mark
*/
bool REDDropper::dropOrMark(RMTQueue* queue)
{
if (par("marking").boolValue() == true)
{
EV << "REDDropper: Marking the last message in " << queue->getFullName()
<< " with an ECN bit." << endl;
queue->markCongestionOnLast();
return false;
}
else
{
EV << "REDDropper: executing tail drop in " << queue->getFullName() << endl;
return true;
}
}
/**
* Decides whether to mark/drop last incoming packet in a queue.
*
* @param queue target queue
* @return true for PDU drop, false for PDU mark
*/
bool REDDropper::run(RMTQueue* queue)
{
if (monitor == NULL)
{
return false;
}
// gather some variables from the queue, the monitoring policy and the NED module
const char* qname = queue->getFullName();
int length = queue->getLength();
int minThresh = queue->getThreshLength();
int maxThresh = queue->getMaxLength();
double avr = monitor->qAvgLengths[queue];
int count = monitor->qCounters[queue];
double maxP = par("dropProbability").doubleValue();
bool dropped = false;
if (minThresh <= avr && avr < maxThresh)
{
monitor->qCounters[queue] += 1;
const double pb = maxP * (avr - minThresh) / (maxThresh - minThresh);
const double pa = pb / (1 - count * pb);
const double rand = dblrand();
if (rand < pa)
{
EV << "REDDropper: rand < pa (" << rand << " < " << pa << ")" << endl;
monitor->qCounters[queue] = 0;
dropped = dropOrMark(queue);
}
}
else if (avr >= maxThresh)
{
EV << "REDDropper: Average queue length in " << qname << " exceeds the maximum threshold." << endl;
monitor->qCounters[queue] = 0;
dropped = dropOrMark(queue);
}
else if (length >= maxThresh)
{
EV << "REDDropper: Queue length in " << qname << " exceeds the maximum threshold." << endl;
monitor->qCounters[queue] = 0;
dropped = dropOrMark(queue);
}
else
{
monitor->qCounters[queue] = -1;
}
return dropped;
}