RINASim  October 2016
Documentation of framework for OMNeT++
MM_maxWP_Out.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_maxWP_Out.h>
19 #include <limits.h>
20 
21 namespace MM_maxWP_Out {
22 
24 
25 void MM_maxWP_Out::initialize() {
26  defaultMaxWP = par("defWP").longValue();
27  if(defaultMaxWP < 0) { error("Error at DL_Out. defWP must be >=0!"); }
28 
29 
30  cXMLElement* Xml = NULL;
31  if (par("data").xmlValue() != NULL && par("data").xmlValue()->hasChildren()){
32  Xml = par("data").xmlValue();
33  } else {
34  return;
35  }
36  cXMLElementList queues = Xml->getChildrenByTagName("queue");
37  for(auto queue : queues){
38  if (!queue->getAttribute("id")) { error("Error parsing DL_Out Queue. Its ID is missing!"); }
39  std::string id = queue->getAttribute("id");
40  if (id=="") { error("Error parsing DL_Out Queue. Queue ID cannot be empty!"); }
41 
42  if (!queue->getAttribute("wp")) { error("Error parsing DL_Out Queue. Its wp is missing!"); }
43  int wp = atoi(queue->getAttribute("wp"));
44  if (wp<0) { error("Error parsing DL_Out Queue. Queue wp must be >=0!"); }
45 
46  double multip = 1.0;
47 
48  if (queue->getAttribute("multip")) {
49  multip = atof(queue->getAttribute("multip"));
50  if (multip<=0) { error("Error parsing DL_Out Queue. Queue multip must be >0!"); }
51  }
52 
53  queueName2WP[id] = wp;
54  queueName2Multip[id] = multip;
55  }
56 }
57 
58 MM_maxWP_Out::~MM_maxWP_Out(){}
59 
60 void MM_maxWP_Out::finish() {}
61 
62 void MM_maxWP_Out::pduInsertered(RMTQueue * q, RMTPort * p) {
63  queueInS[q].push_back(portS[p]);
64 
65 }
66 
67 void MM_maxWP_Out::pduDropped(RMTQueue * q, const cPacket * s, RMTPort * p) {
68  queueInS[q].pop_back();
69 }
70 
71 void MM_maxWP_Out::pduReleased(RMTQueue * q, RMTPort * p) {}
72 
73 void MM_maxWP_Out::queueCreated(RMTQueue * q, RMTPort * p) {
74  portQueues[p].insert(q);
75  if(queueName2WP.find(q->getName()) != queueName2WP.end()) {
76  queueWP[q] = queueName2WP[q->getName()];
77  } else {
78  queueWP[q] = defaultMaxWP;
79  }
80  if(queueName2Multip.find(q->getName()) != queueName2Multip.end()) {
81  queueMultip[q] = queueName2Multip[q->getName()];
82  } else {
83  queueMultip[q] = 1.0;
84  }
85 }
86 
87 RMTQueue * MM_maxWP_Out::getnextQueue(RMTPort * p) {
88  RMTQueue * ret = NULL;
89  double min = DBL_MAX;
90  int now = portS[p];
91 
92  for(auto & q : portQueues[p]) {
93  if(!queueInS[q].empty()) {
94  double temp = queueWP[q] - now + queueInS[q].front();
95  if(temp <= 0) {
96  temp *= queueMultip[q];
97  }
98  if(temp < min) {
99  ret = q;
100  min = temp;
101  }
102  }
103  }
104 
105  if(ret != NULL) {
106  queueInS[ret].pop_front();
107  portS[p]++;
108  }
109  return ret;
110 }
111 
112 simtime_t MM_maxWP_Out::getnextTime(RMTPort * p) {
113  return 0;
114 }
115 
116 }
Define_Module(MM_maxWP_Out)