|
a |
|
b/src/DIF/RMT/policies/monitor/RED.cc |
|
|
1 |
/*
|
|
|
2 |
* RED.cpp
|
|
|
3 |
*
|
|
|
4 |
* Created on: 17. 11. 2014
|
|
|
5 |
* Author: cloq
|
|
|
6 |
*/
|
|
|
7 |
|
|
|
8 |
#include <RED.h>
|
|
|
9 |
|
|
|
10 |
Define_Module(RED);
|
|
|
11 |
|
|
|
12 |
void RED::postQueueCreation(RMTQueue* queue)
|
|
|
13 |
{
|
|
|
14 |
// TODO: fix variable initialization, these are just for demo purposes
|
|
|
15 |
qAvgLengths[queue] = 0.0;
|
|
|
16 |
qWeights[queue] = 0.5;
|
|
|
17 |
qProbabilities[queue] = 0.4;
|
|
|
18 |
qCounters[queue] = -1;
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
void RED::preQueueRemoval(RMTQueue* queue)
|
|
|
22 |
{
|
|
|
23 |
qAvgLengths.erase(queue);
|
|
|
24 |
qWeights.erase(queue);
|
|
|
25 |
qProbabilities.erase(queue);
|
|
|
26 |
qCounters.erase(queue);
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
void RED::run(RMTQueue* queue)
|
|
|
31 |
{
|
|
|
32 |
maxQPolicy = ModuleAccess<RMTMaxQBase>("maxQueuePolicy").get();
|
|
|
33 |
|
|
|
34 |
int length = queue->getLength();
|
|
|
35 |
int minThresh = queue->getThreshLength();
|
|
|
36 |
int maxThresh = queue->getMaxLength();
|
|
|
37 |
|
|
|
38 |
double avr = qAvgLengths[queue];
|
|
|
39 |
double wq = qWeights[queue];
|
|
|
40 |
double maxP = qProbabilities[queue];
|
|
|
41 |
int count = qCounters[queue];
|
|
|
42 |
|
|
|
43 |
simtime_t qTime = queue->getQTime();
|
|
|
44 |
const char* qname = queue->getFullName();
|
|
|
45 |
|
|
|
46 |
if (length > 0)
|
|
|
47 |
{
|
|
|
48 |
avr = (1 - wq) * avr + wq * length;
|
|
|
49 |
}
|
|
|
50 |
else
|
|
|
51 |
{
|
|
|
52 |
const double m = SIMTIME_DBL(simTime() - qTime);
|
|
|
53 |
avr = pow(1 - wq, m) * avr;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
qAvgLengths[queue] = avr;
|
|
|
57 |
|
|
|
58 |
if (length > maxThresh)
|
|
|
59 |
{
|
|
|
60 |
EV << "RED: Queue " << qname << " is full! Dropping the incoming message." << endl;
|
|
|
61 |
maxQPolicy->run(queue);
|
|
|
62 |
qCounters[queue] = 0;
|
|
|
63 |
}
|
|
|
64 |
else if (minThresh <= avr && avr < maxThresh)
|
|
|
65 |
{
|
|
|
66 |
qCounters[queue] += 1;
|
|
|
67 |
const double pb = maxP * (avr - minThresh) / (maxThresh - minThresh);
|
|
|
68 |
const double pa = pb / (1 - count * pb);
|
|
|
69 |
const double rand = dblrand();
|
|
|
70 |
|
|
|
71 |
if (rand < pa)
|
|
|
72 |
{
|
|
|
73 |
EV << "RED: rand < pa (" << rand << " < " << pa << ")! Executing MaxQPolicy." << endl;
|
|
|
74 |
maxQPolicy->run(queue);
|
|
|
75 |
qCounters[queue] = 0;
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
else
|
|
|
79 |
{
|
|
|
80 |
qCounters[queue] = -1;
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|