RINASim  October 2016
Documentation of framework for OMNeT++
MM_DL_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_DL_Out.h>
19 
20 namespace MM_DL_Out {
21 
23 
24 void MM_DL_Out::initialize() {
25  defaultPriority = par("defPriority").longValue();
26  if(defaultPriority < 0) { error("Error at DL_Out. defPriority must be >=0!"); }
27 
28  maxPriority = defaultPriority;
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("priority")) { error("Error parsing DL_Out Queue. Its Priority is missing!"); }
43  int priority = atoi(queue->getAttribute("priority"));
44  if (priority<0) { error("Error parsing DL_Out Queue. Queue Priority must be >=0!"); }
45 
46  queueName2Priority[id] = priority;
47 
48  if(maxPriority<priority) { maxPriority = priority ; }
49  }
50 }
51 
52 MM_DL_Out::~MM_DL_Out(){}
53 
54 void MM_DL_Out::finish() {}
55 
56 void MM_DL_Out::pduInsertered(RMTQueue * q, RMTPort * p) {
57  portQueues[p][queuePriority[q]].push_back(q);
58 }
59 
60 void MM_DL_Out::pduDropped(RMTQueue * q, const cPacket * s, RMTPort * p) {
61  portQueues[p][queuePriority[q]].pop_back();
62 }
63 
64 void MM_DL_Out::pduReleased(RMTQueue * q, RMTPort * p) {}
65 
66 void MM_DL_Out::queueCreated(RMTQueue * q, RMTPort * p) {
67  if(queueName2Priority.find(q->getName()) != queueName2Priority.end()) {
68  queuePriority[q] = maxPriority-queueName2Priority[q->getName()];
69  } else {
70  queuePriority[q] = maxPriority-defaultPriority;
71  }
72 }
73 
74 RMTQueue * MM_DL_Out::getnextQueue(RMTPort * p) {
75  for(auto & pQ : portQueues[p]){
76  while(!pQ.second.empty()) {
77  RMTQueue * q = pQ.second.front();
78  pQ.second.pop_front();
79  return q;
80  }
81  }
82  return NULL;
83 }
84 
85 simtime_t MM_DL_Out::getnextTime(RMTPort * p) {
86  return 0;
87 }
88 
89 }
Define_Module(MM_DL_Out)