RINASim  October 2016
Documentation of framework for OMNeT++
MM_eDL_Drop.cc
Go to the documentation of this file.
1 //
2 // Copyright © 2014 - 2015 PRISTINE Consortium (http://ict-pristine.eu)
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with this program. If not, see http://www.gnu.org/licenses/.
16 //
17 
18 #include <MM_eDL_Drop.h>
19 
20 namespace MM_eDL_Drop {
21 
23 
24 void MM_eDL_Drop::initialize() {
25 
26  defaultThreshold = par("defThreshold").longValue();
27  if(defaultThreshold <= 0) { error("Error at DL_Drop. defThreshold must be >0!"); }
28 
29  defaultAbsThreshold = par("defAbsThreshold").longValue();
30  if(defaultAbsThreshold <= 0) { error("Error at DL_Drop. defAbsThreshold must be >0!"); }
31 
32  defaultDropProb = par("defDropProb").doubleValue();
33  if(defaultDropProb < 0.0 || defaultDropProb > 1.0) { error("Error at DL_Drop. defDropProb must be between [0,1]!"); }
34 
35  cXMLElement* Xml = NULL;
36  if (par("data").xmlValue() != NULL && par("data").xmlValue()->hasChildren()){
37  Xml = par("data").xmlValue();
38  } else {
39  return;
40  }
41  cXMLElementList queues = Xml->getChildrenByTagName("queue");
42  for(auto queue : queues){
43  if (!queue->getAttribute("id")) { error("Error parsing DL_Drop Queue. Its ID is missing!"); }
44  std::string id = queue->getAttribute("id");
45  if (id=="") { error("Error parsing DL_Drop Queue. Queue ID cannot be empty!"); }
46 
47  if (!queue->getAttribute("threshold")) { error("Error parsing DL_Drop Queue. Its Threshold is missing!"); }
48  int threshold = atoi(queue->getAttribute("threshold"));
49  if (threshold<=0) { error("Error parsing DL_Drop Queue. Queue Threshold must be >0!"); }
50 
51  if (!queue->getAttribute("dropProb")) { error("Error parsing DL_Drop Queue. Its dropProb is missing!"); }
52  double dropProb = atof(queue->getAttribute("dropProb"));
53  if (dropProb<0 || dropProb > 1) { error("Error parsing DL_Drop Queue. Queue dropProb must be between [0,1]!"); }
54 
55  if (!queue->getAttribute("absThreshold")) { error("Error parsing DL_Drop Queue. Its absThreshold is missing!"); }
56  int absThreshold = atoi(queue->getAttribute("absThreshold"));
57  if (absThreshold<=0) { error("Error parsing DL_Drop Queue. Queue absThreshold must be >0!"); }
58 
59  queueName2Threshold[id] = threshold;
60  queueName2DropProb[id] = dropProb;
61  queueName2AbsThreshold[id] = absThreshold;
62  }
63 }
64 
65 MM_eDL_Drop::~MM_eDL_Drop(){
66  portCount.clear();
67 }
68 
69 void MM_eDL_Drop::pduInsertered(RMTQueue * q, RMTPort * p) {
70  portCount[p]++;
71 }
72 
73 void MM_eDL_Drop::pduDropped(RMTQueue * q, const cPacket * s, RMTPort * p) {
74  portCount[p]--;
75 }
76 
77 void MM_eDL_Drop::pduReleased(RMTQueue * q, RMTPort * p) {
78  portCount[p]--;
79 }
80 
81 void MM_eDL_Drop::queueCreated(RMTQueue * q, RMTPort * p) {
82  if(queueName2Threshold.find(q->getName()) != queueName2Threshold.end()) {
83  queueThreshold[q] = queueName2Threshold[q->getName()];
84  } else {
85  queueThreshold[q] = defaultThreshold;
86  }
87 
88  if(queueName2DropProb.find(q->getName()) != queueName2DropProb.end()) {
89  queueDropProb[q] = queueName2DropProb[q->getName()];
90  } else {
91  queueDropProb[q] = defaultDropProb;
92  }
93 
94  if(queueName2AbsThreshold.find(q->getName()) != queueName2AbsThreshold.end()) {
95  queueAbsThreshold[q] = queueName2AbsThreshold[q->getName()];
96  } else {
97  queueAbsThreshold[q] = defaultAbsThreshold;
98  }
99 
100  portCount[p] = 0;
101 }
102 
103 double MM_eDL_Drop::getDropProbability(RMTQueue * q, RMTPort * p) {
104  int count = portCount[p];
105  return (count > queueAbsThreshold[q])? 1.0 :
106  (queueThreshold[q] < portCount[p])? queueDropProb[q] : 0.0;
107 }
108 
109 }
Define_Module(MM_eDL_Drop)