RINASim  October 2016
Documentation of framework for OMNeT++
eDLMonitor.cc
Go to the documentation of this file.
1 //
2 // The MIT License (MIT)
3 //
4 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 
24 #include <eDLMonitor.h>
25 
26 namespace eDLMonitor {
27 
29 
31  CUId = "";
32  queue = "outQ_";
33  urgency = 0;
34  threshold = 0;
35  dropProb = 1;
36  absThreshold = 0;
37 }
38 dlCUInfo::dlCUInfo(std::string id){
39  CUId = id;
40  queue = "outQ_";
41  queue.append(CUId);
42  urgency = 0;
43  threshold = 0;
44  dropProb = 1;
45  absThreshold = 0;
46 }
47 dlCUInfo::dlCUInfo(std::string id, std::string _queue, int urg, int thre, double dropP, int absThre){
48  CUId = id;
49  queue = _queue;
50  urgency = urg;
51  threshold = thre;
52  dropProb = dropP;
53  absThreshold = absThre;
54 }
55 
56 void eDLMonitor::onPolicyInit(){
57 
58  cXMLElement* cuXml = NULL;
59  if (par("cuData").xmlValue() != NULL && par("cuData").xmlValue()->hasChildren()){
60  cuXml = par("cuData").xmlValue();
61  } else {
62  error("cuData parameter not initialized!");
63  }
64 
65  cXMLElementList cus = cuXml->getChildrenByTagName("CUItem");
66  for (cXMLElementList::iterator it = cus.begin(); it != cus.end(); ++it) {
67  cXMLElement* m = *it;
68  if (!m->getAttribute("id")) {
69  EV << "Error parsing CU. Its ID is missing!" << endl;
70  continue;
71  }
72 
73  std::string cu = m->getAttribute("id");
74  if (cu == "") {
75  EV << "Error parsing CU. Its ID is missing!" << endl;
76  continue;
77  }
78 
79  dlCUInfo inf = dlCUInfo(cu);
80 
81  cXMLElementList attrs = m->getChildren();
82  for (cXMLElementList::iterator jt = attrs.begin(); jt != attrs.end(); ++jt) {
83  cXMLElement* n = *jt;
84  if ( !strcmp(n->getTagName(), "urgency") ) {
85  inf.urgency = n->getNodeValue() ? atoi(n->getNodeValue()) : 0;
86  if (inf.urgency < 0)
87  inf.urgency = 0;
88  } else if ( !strcmp(n->getTagName(), "cherishThreshold") ) {
89  inf.threshold = n->getNodeValue() ? atoi(n->getNodeValue()) : 0;
90  if (inf.threshold < 0)
91  inf.threshold = 0;
92  } else if ( !strcmp(n->getTagName(), "cherishAbsThreshold") ) {
93  inf.absThreshold = n->getNodeValue() ? atoi(n->getNodeValue()) : 0;
94  if (inf.absThreshold < 0)
95  inf.absThreshold = 0;
96  } else if ( !strcmp(n->getTagName(), "cherishDropProbability") ) {
97  inf.dropProb = n->getNodeValue() ? atof(n->getNodeValue()) : 0.0;
98  if (inf.dropProb < 0.0)
99  inf.dropProb = 0.0;
100  else if (inf.dropProb > 1.0)
101  inf.dropProb = 1.0;
102  }
103  }
104 
105  if(inf.absThreshold < inf.threshold) { inf.absThreshold = inf.threshold; }
106 
107  CUs[cu] = inf;
108  }
109 
110 
111  cXMLElement* urgXml = NULL;
112  if (par("urgData").xmlValue() != NULL && par("urgData").xmlValue()->hasChildren()){
113  urgXml = par("urgData").xmlValue();
114  } else {
115  error("urgData parameter not initialized!");
116  }
117 
118  cXMLElementList urgs = urgXml->getChildrenByTagName("urgency");
119  for (cXMLElementList::iterator it = urgs.begin(); it != urgs.end(); ++it) {
120  cXMLElement* m = *it;
121  if (!m->getAttribute("val")) {
122  EV << "Error parsing urgency. Its val is missing!" << endl;
123  continue;
124  }
125  std::string valS = m->getAttribute("val");
126  if (valS == "") {
127  EV << "Error parsing urgency. Its val is missing!" << endl;
128  continue;
129  }
130 
131  if (!m->getAttribute("prob")) {
132  EV << "Error parsing urgency. Its prob is missing!" << endl;
133  continue;
134  }
135  std::string probS = m->getAttribute("prob");
136  if (probS == "") {
137  EV << "Error parsing urgency. Its prob is missing!" << endl;
138  continue;
139  }
140 
141  int val = atoi(valS.c_str());
142  if(val<0) { val = 0; }
143 
144  double prob = atof(probS.c_str());
145  if(prob<0) { prob = 0; }
146  if(prob>1) { prob = 1; }
147 
148  probs[val] = prob;
149  }
150 }
151 
152 void eDLMonitor::postPDUInsertion(RMTQueue* queue) {
153  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
154  if(port != NULL){
155  if(queue->getType() == RMTQueue::INPUT){
156  inC[port] ++;
157  inQ[port].push_back(queue);
158  }
159  if(queue->getType() == RMTQueue::OUTPUT){
160  outC[port] ++;
161  std::string cu = Q2CU[queue];
162  int urgency = CUs[cu].urgency;
163  outQs[port][urgency].push_back(queue);
164  lastInsertedUrgency[port] = urgency;
165  }
166  }
167 }
168 
169 void eDLMonitor::onMessageDrop(RMTQueue* queue, const cPacket* pdu) {
170  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
171  if(port != NULL){
172  if(queue->getType() == RMTQueue::INPUT){
173  inC[port] --;
174  inQ[port].pop_back();
175  } else {
176  outC[port] --;
177  outQs[port][lastInsertedUrgency[port]].pop_back();
178  }
179  }
180 }
181 
182 void eDLMonitor::postQueueCreation(RMTQueue* queue){
183  if(queue->getType() == RMTQueue::OUTPUT) {
184  std::string cu = "BE";
185 
186  for(cuRepoiterator it = CUs.begin(); it != CUs.end(); it++){
187  if(it->second.queue == queue->getName()){
188  cu = it->first;
189  }
190  }
191  Q2CU[queue] = cu;
192  }
193 }
194 
195 
196 RMTQueue* eDLMonitor::getNextInput(RMTPort* port){
197  RMTQueue* q = NULL;
198 
199  QueuesList* ql = &(inQ[port]);
200  if(!ql->empty()) {
201  q = ql->front();
202  ql->pop_front();
203  }
204 
205  if(q != NULL){
206  inC[port]--;
207  }
208 
209  return q;
210 }
211 
212 RMTQueue* eDLMonitor::getNextOutput(RMTPort* port){
213  RMTQueue* q = NULL;
214 
215  PriorityQueuesList * qs = & outQs[port];
216  PQListRIterator tit = qs->rend();
217  for(PQListRIterator it = qs->rbegin(); it != qs->rend() && q == NULL; it++){
218  if(!it->second.empty()){
219  tit = it;
220  double tP = probs[it->first];
221  if(tP <= 0 || tP < uniform(0,1) ){
222  q = it->second.front();
223  it->second.pop_front();
224  }
225  }
226  }
227  if(q == NULL && tit != qs->rend()){
228  q = tit->second.front();
229  tit->second.pop_front();
230  }
231 
232  if(q != NULL){
233  outC[port]--;
234  } else {
235  error("No queue found");
236  }
237 
238  return q;
239 }
240 
241 
242 double eDLMonitor::getInDropProb(RMTQueue * queue) {
243  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
244  if(port == NULL){ error("RMTPort for RMTQueue not found."); }
245 
246  return ( (int)inC[port] < queue->getMaxLength() )? 0 : 1;
247 }
248 
249 double eDLMonitor::getOutDropProb(RMTQueue * queue) {
250  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
251  if(port == NULL){ error("RMTPort for RMTQueue not found."); }
252 
253  dlCUInfo din = CUs[Q2CU[queue]];
254  int count = outC[port];
255 
256  return ( count < din.threshold )? 0 : ( ( count < din.absThreshold )? din.dropProb : 1) ;
257 
258 
259 }
260 
261 
262 }
list< RMTQueue * > QueuesList
Definition: eDLMonitor.h:38
queueType getType() const
Definition: RMTQueue.cc:241
PriorityQueuesList::reverse_iterator PQListRIterator
Definition: eDLMonitor.h:65
cuRepo::iterator cuRepoiterator
Definition: eDLMonitor.h:58
int getMaxLength() const
Definition: RMTQueue.cc:215
std::map< int, QueuesList > PriorityQueuesList
Definition: eDLMonitor.h:63
std::string CUId
Definition: eDLMonitor.h:46
Define_Module(eDLMonitor)
std::string queue
Definition: eDLMonitor.h:46