RINASim  October 2016
Documentation of framework for OMNeT++
MM_DQ_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_DQ_Drop.h>
19 
20 namespace MM_DQ_Drop {
21 
23 
24 Threshold::Threshold(int _limit, double _prob) {
25  limit = _limit;
26  prob = _prob;
27 }
28 
29 
31  id ="";
32  absThreshold = 0;
33 }
34 
35 QueueConfig::QueueConfig(string _id, int _absThreshold){
36  id =_id;
37  absThreshold = _absThreshold;
38 }
39 
40 void MM_DQ_Drop::initialize() {
41 
42  defaultThreshold = par("defaultThreshold").longValue();
43  if(defaultThreshold < 0) { error("Error at DL_Drop. defThreshold must be >= 0!"); }
44 
45  cXMLElement* Xml = NULL;
46  if (par("data").xmlValue() != NULL && par("data").xmlValue()->hasChildren()){
47  Xml = par("data").xmlValue();
48  } else { return; }
49 
50  cXMLElementList queues = Xml->getChildrenByTagName("queue");
51  for(auto queue : queues){
52  if (!queue->getAttribute("id")) { error("Error parsing DQ_Drop Queue. Its ID is missing!"); }
53  std::string id = queue->getAttribute("id");
54  if (id=="") { error("Error parsing DQ_Drop Queue. Queue ID cannot be empty!"); }
55 
56  if (!queue->getAttribute("absThreshold")) { error("Error parsing DQ_Drop Queue. Its absThreshold is missing!"); }
57  int absThreshold = atoi(queue->getAttribute("absThreshold"));
58  if (absThreshold<0) { error("Error parsing DQ_Drop Queue. Queue absThreshold must be >=0!"); }
59 
60  QueueConfig q(id, absThreshold);
61 
62  cXMLElementList THs = queue->getChildrenByTagName("TH");
63 
64  for(auto TH : THs){
65  if(!TH->getAttribute("threshold")) { error("Error parsing TH. threshold must be defined!"); }
66  int threshold = atoi(TH->getAttribute("threshold"));
67  if(threshold<0) { error("Error parsing PP. threshold must be >=0!"); }
68  if(absThreshold<=threshold) { continue; }
69 
70  if(!TH->getAttribute("dropProb")) { error("Error parsing TH. dropProb must be defined!"); }
71  double dropProb = atof(TH->getAttribute("dropProb"));
72  if(dropProb<=0 || dropProb>=1) { error("Error parsing TH. dropProb must be in (0,1)!"); }
73 
74  q.thresholdList.push_back(Threshold(threshold, dropProb));
75  }
76 
77  queuesConf[id] = q;
78  }
79 }
80 
81 MM_DQ_Drop::~MM_DQ_Drop(){
82  portCount.clear();
83 }
84 
85 void MM_DQ_Drop::pduInsertered(RMTQueue * q, RMTPort * p) {
86  portCount[p]++;
87 }
88 
89 void MM_DQ_Drop::pduDropped(RMTQueue * q, const cPacket * s, RMTPort * p) {
90  portCount[p]--;
91 }
92 
93 void MM_DQ_Drop::pduReleased(RMTQueue * q, RMTPort * p) {
94  portCount[p]--;
95 }
96 
97 void MM_DQ_Drop::queueCreated(RMTQueue * q, RMTPort * p) {
98  if(queuesConf.find(q->getName()) != queuesConf.end()) {
99  queueConf[q] = &queuesConf[q->getName()];
100  } else {
101  queueConf[q] = NULL;
102  }
103 
104  portQueues[p].insert(q);
105 }
106 
107 double MM_DQ_Drop::getDropProbability(RMTQueue * q, RMTPort * p) {
108  int count = portCount[p];
109  QueueConfig * qc = queueConf[q];
110 
111  if(count >= qc->absThreshold) {
112  return 1.0;
113  }
114 
115  double prob = 0.0;
116  int nearTH = 0;
117  for(Threshold & th : qc->thresholdList) {
118  if(count >= th.limit && nearTH < th.limit) {
119  nearTH = th.limit;
120  prob = th.prob;
121  }
122  }
123 
124  return prob;
125 }
126 
127 
128 void MM_DQ_Drop::finish() {
129 /*
130  cout << "MM_DQ_DROP "<< this->getFullPath() << endl;
131  for(auto qc : queueConf) {
132  cout << "\tQueue " << qc.second->id << endl;
133  cout << "\t\tAbsolute threshold " << qc.second->absThreshold<<endl;
134  for(Threshold & th : qc.second->thresholdList) {
135  cout << "\t\t-Threshold " << th.limit << " :: "<< th.prob <<endl;
136  }
137 
138  }
139 */
140 }
141 
142 }
Threshold(int, double)
Definition: MM_DQ_Drop.cc:24
Define_Module(MM_DQ_Drop)
vector< Threshold > thresholdList
Definition: MM_DQ_Drop.h:42