RINASim  October 2016
Documentation of framework for OMNeT++
DLMonitor.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 <DLMonitor.h>
25 
26 namespace DLMonitor {
27 
29 
31  CUId = "";
32  queue = "outQ_";
33  urgency = 0;
34  threshold = 0;
35 }
36 dlCUInfo::dlCUInfo(std::string id){
37  CUId = id;
38  queue = "outQ_";
39  queue.append(CUId);
40  urgency = 0;
41  threshold = 0;
42 }
43 dlCUInfo::dlCUInfo(std::string id, std::string _queue, int urg, int thre){
44  CUId = id;
45  queue = _queue;
46  urgency = urg;
47  threshold = thre;
48 }
49 
50 void DLMonitor::onPolicyInit(){
51 
52  cXMLElement* cuXml = NULL;
53  if (par("cuData").xmlValue() != NULL && par("cuData").xmlValue()->hasChildren()){
54  cuXml = par("cuData").xmlValue();
55  } else {
56  error("cuData parameter not initialized!");
57  }
58 
59  cXMLElementList cus = cuXml->getChildrenByTagName("CUItem");
60  for (cXMLElementList::iterator it = cus.begin(); it != cus.end(); ++it) {
61  cXMLElement* m = *it;
62  if (!m->getAttribute("id")) {
63  EV << "Error parsing CU. Its ID is missing!" << endl;
64  continue;
65  }
66 
67  std::string cu = m->getAttribute("id");
68  if (cu == "") {
69  EV << "Error parsing CU. Its ID is missing!" << endl;
70  continue;
71  }
72 
73  dlCUInfo inf = dlCUInfo(cu);
74 
75  cXMLElementList attrs = m->getChildren();
76  for (cXMLElementList::iterator jt = attrs.begin(); jt != attrs.end(); ++jt) {
77  cXMLElement* n = *jt;
78  if ( !strcmp(n->getTagName(), "urgency") ) {
79  inf.urgency = n->getNodeValue() ? atoi(n->getNodeValue()) : 0;
80  if (inf.urgency < 0)
81  inf.urgency = 0;
82  } else if ( !strcmp(n->getTagName(), "cherishThreshold") ) {
83  inf.threshold = n->getNodeValue() ? atoi(n->getNodeValue()) : 0;
84  if (inf.threshold < 0)
85  inf.threshold = 0;
86  }
87  }
88 
89  CUs[cu] = inf;
90  }
91 }
92 
93 void DLMonitor::postPDUInsertion(RMTQueue* queue) {
94  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
95  if(port != NULL){
96  if(queue->getType() == RMTQueue::INPUT){
97  inC[port] ++;
98  inQ[port].push_back(queue);
99  }
100  if(queue->getType() == RMTQueue::OUTPUT){
101  outC[port] ++;
102  std::string cu = Q2CU[queue];
103 
104  int urgency = CUs[cu].urgency;
105  outQs[port][urgency].push_back(queue);
106  lastInsertedUrgency[port] = urgency;
107  }
108  }
109 }
110 
111 void DLMonitor::onMessageDrop(RMTQueue* queue, const cPacket* pdu) {
112  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
113  if(port != NULL){
114  if(queue->getType() == RMTQueue::INPUT){
115  inC[port] --;
116  inQ[port].pop_back();
117  } else {
118  outC[port] --;
119  outQs[port][lastInsertedUrgency[port]].pop_back();
120  }
121  }
122 }
123 
124 void DLMonitor::postQueueCreation(RMTQueue* queue){
125  std::string cu = "BE";
126 
127  for(cuRepoiterator it = CUs.begin(); it != CUs.end(); it++){
128  if(it->second.queue == queue->getName()){
129  cu = it->first;
130  }
131  }
132 
133  Q2CU[queue] = cu;
134 }
135 
136 RMTQueue* DLMonitor::getNextInput(RMTPort* port){
137  RMTQueue* q = NULL;
138 
139  QueuesList* ql = &(inQ[port]);
140  if(!ql->empty()) {
141  q = ql->front();
142  ql->pop_front();
143  }
144 
145  if(q != NULL){
146  inC[port]--;
147  }
148 
149  return q;
150 }
151 
152 RMTQueue* DLMonitor::getNextOutput(RMTPort* port){
153  RMTQueue* q = NULL;
154 
155  PriorityQueuesList * qs = & outQs[port];
156  for(PQListRIterator it = qs->rbegin(); it != qs->rend() && q == NULL; it++){
157  if(!it->second.empty()){
158  q = it->second.front();
159  it->second.pop_front();
160  }
161  }
162 
163  if(q != NULL){
164  outC[port]--;
165  }
166 
167  return q;
168 }
169 
170 double DLMonitor::getInDropProb(RMTQueue * queue) {
171  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
172  if(port == NULL){ error("RMTPort for RMTQueue not found."); }
173 
174  return ( (int)inC[port] < queue->getMaxLength() )? 0 : 1;
175 }
176 
177 double DLMonitor::getOutDropProb(RMTQueue * queue) {
178  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
179  if(port == NULL){ error("RMTPort for RMTQueue not found."); }
180 
181  return ( (int)outC[port] < CUs[Q2CU[queue]].threshold )? 0 : 1;
182 }
183 
184 }
std::map< int, QueuesList > PriorityQueuesList
Definition: DLMonitor.h:60
queueType getType() const
Definition: RMTQueue.cc:241
int getMaxLength() const
Definition: RMTQueue.cc:215
std::string CUId
Definition: DLMonitor.h:45
list< RMTQueue * > QueuesList
Definition: DLMonitor.h:38
Define_Module(DLMonitor)
PriorityQueuesList::reverse_iterator PQListRIterator
Definition: DLMonitor.h:62
std::string queue
Definition: DLMonitor.h:45
cuRepo::iterator cuRepoiterator
Definition: DLMonitor.h:55