RINASim  October 2016
Documentation of framework for OMNeT++
MM_WFQ_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_WFQ_Drop.h>
19 
20 namespace MM_WFQ_Drop {
21 
23 
24 void MM_WFQ_Drop::initialize() {
25 
26  defaultThreshold = par("defThreshold").longValue();
27  if(defaultThreshold <= 0) { error("Error at DL_Drop. defThreshold must be >0!"); }
28 
29  cXMLElement* Xml = NULL;
30  if (par("data").xmlValue() != NULL && par("data").xmlValue()->hasChildren()){
31  Xml = par("data").xmlValue();
32  } else {
33  return;
34  }
35  cXMLElementList queues = Xml->getChildrenByTagName("queue");
36  for(auto queue : queues){
37  if (!queue->getAttribute("id")) { error("Error parsing DL_Drop Queue. Its ID is missing!"); }
38  std::string id = queue->getAttribute("id");
39  if (id=="") { error("Error parsing DL_Drop Queue. Queue ID cannot be empty!"); }
40 
41  if (!queue->getAttribute("threshold")) { error("Error parsing DL_Drop Queue. Its Threshold is missing!"); }
42  int threshold = atoi(queue->getAttribute("threshold"));
43  if (threshold<=0) { error("Error parsing DL_Drop Queue. Queue Threshold must be >0!"); }
44  queueName2Threshold[id] = threshold;
45  }
46 }
47 
48 MM_WFQ_Drop::~MM_WFQ_Drop(){
49  queueCount.clear();
50 }
51 
52 void MM_WFQ_Drop::pduInsertered(RMTQueue * q, RMTPort * p) {
53  queueCount[q]++;
54 }
55 
56 void MM_WFQ_Drop::pduDropped(RMTQueue * q, const cPacket * s, RMTPort * p) {
57  queueCount[q]--;
58 }
59 
60 void MM_WFQ_Drop::pduReleased(RMTQueue * q, RMTPort * p) {
61  queueCount[q]--;
62 }
63 
64 void MM_WFQ_Drop::queueCreated(RMTQueue * q, RMTPort * p) {
65  if(queueName2Threshold.find(q->getName()) != queueName2Threshold.end()) {
66  queueThreshold[q] = queueName2Threshold[q->getName()];
67  } else {
68  queueThreshold[q] = defaultThreshold;
69  }
70  queueCount[q] = 0;
71 }
72 
73 double MM_WFQ_Drop::getDropProbability(RMTQueue * q, RMTPort * p) {
74  return (queueThreshold[q] < queueCount[q])? 1.0 : 0.0;
75 }
76 
77 }
Define_Module(MM_WFQ_Drop)