RINASim  October 2016
Documentation of framework for OMNeT++
MM_P_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_P_Out.h>
19 
20 namespace MM_P_Out {
21 
23 
24 void MM_P_Out::initialize() {
25  defaultPriority = par("defPriority").longValue();
26  if(defaultPriority < 0) { error("Error at P_Out. defPriority must be >=0!"); }
27 
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 P_Out Queue. Its ID is missing!"); }
38  std::string id = queue->getAttribute("id");
39  if (id=="") { error("Error parsing P_Out Queue. Queue ID cannot be empty!"); }
40 
41  if (!queue->getAttribute("priority")) { error("Error parsing P_Out Queue. Its Priority is missing!"); }
42  int priority = atoi(queue->getAttribute("priority"));
43  if (priority<=0) { error("Error parsing P_Out Queue. Queue Priority must be >0!"); }
44 
45  queueName2Priority[id] = priority;
46  }
47 }
48 
49 MM_P_Out::~MM_P_Out(){}
50 
51 void MM_P_Out::finish() {}
52 
53 void MM_P_Out::pduInsertered(RMTQueue * q, RMTPort * p) {}
54 
55 void MM_P_Out::pduDropped(RMTQueue * q, const cPacket * s, RMTPort * p) {}
56 
57 void MM_P_Out::pduReleased(RMTQueue * q, RMTPort * p) {}
58 
59 void MM_P_Out::queueCreated(RMTQueue * q, RMTPort * p) {
60  if(queueName2Priority.find(q->getName()) != queueName2Priority.end()) {
61  queuePriority[q] = queueName2Priority[q->getName()];
62  } else {
63  queuePriority[q] = defaultPriority;
64  }
65  portQueues[p].insert(q);
66 }
67 
68 RMTQueue * MM_P_Out::getnextQueue(RMTPort * p) {
69  int sumPrior = 0;
70  for(auto pQ : portQueues[p]){
71  if(pQ->getLength() > 0) {
72  sumPrior += queuePriority[pQ];
73  }
74  }
75 
76  if(sumPrior<=0) { return NULL; }
77 
78  int until = intuniform(0, sumPrior);
79  sumPrior = 0;
80  RMTQueue * q = NULL;
81  for(auto pQ : portQueues[p]){
82  if(pQ->getLength() > 0) {
83  q = pQ;
84  sumPrior += queuePriority[pQ];
85  if(sumPrior > until) { break; }
86  }
87  }
88 
89  return q;
90 }
91 
92 simtime_t MM_P_Out::getnextTime(RMTPort * p) {
93  return 0;
94 }
95 
96 }
Define_Module(MM_P_Out)