Download this file

DLMonitor.cc    151 lines (126 with data), 4.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// Copyright Š 2014 - 2015 PRISTINE Consortium (http://ict-pristine.eu)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#include <DLMonitor.h>
Define_Module(DLMonitor);
dlCUInfo::dlCUInfo(){
CUId = "";
urgency = 0;
threshold = 0;
}
dlCUInfo::dlCUInfo(std::string id){
CUId = id;
urgency = 0;
threshold = 0;
}
dlCUInfo::dlCUInfo(std::string id, int urg, int thre){
CUId = id;
urgency = urg;
threshold = thre;
}
void DLMonitor::onPolicyInit(){
cXMLElement* cuXml = NULL;
if (par("cuData").xmlValue() != NULL && par("cuData").xmlValue()->hasChildren())
cuXml = par("cuData").xmlValue();
else
error("cuData parameter not initialized!");
cXMLElementList cus = cuXml->getChildrenByTagName("CUItem");
for (cXMLElementList::iterator it = cus.begin(); it != cus.end(); ++it) {
cXMLElement* m = *it;
if (!m->getAttribute("id")) {
EV << "Error parsing CU. Its ID is missing!" << endl;
continue;
}
std::string cu = m->getAttribute("id");
if (cu == "") {
EV << "Error parsing CU. Its ID is missing!" << endl;
continue;
}
dlCUInfo inf = dlCUInfo(cu);
cXMLElementList attrs = m->getChildren();
for (cXMLElementList::iterator jt = attrs.begin(); jt != attrs.end(); ++jt) {
cXMLElement* n = *jt;
if ( !strcmp(n->getTagName(), "urgency") ) {
inf.urgency = n->getNodeValue() ? atoi(n->getNodeValue()) : 0;
if (inf.urgency < 0)
inf.urgency = 0;
}
else if ( !strcmp(n->getTagName(), "cherishThreshold") ) {
inf.threshold = n->getNodeValue() ? atoi(n->getNodeValue()) : 0;
if (inf.threshold < 0)
inf.threshold = 0;
}
}
CUs[cu] = inf;
}
}
void DLMonitor::onMessageArrival(RMTQueue* queue) {
if(queue->getType() == RMTQueue::INPUT){
return;
}
RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
if(port != NULL){
count[port]++;
std::string cu = Q2CU[queue];
int urgency = CUs[cu].urgency;
queues[port][urgency].push_back(queue);
lastInsertedUrgency[port] = urgency;
}
}
void DLMonitor::onMessageDeparture(RMTQueue* queue) {
if(queue->getType() == RMTQueue::INPUT){
return;
}
RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
if(port != NULL){
count[port]--;
}
}
void DLMonitor::onMessageDrop(RMTQueue* queue, const cPacket* pdu) {
if(queue->getType() == RMTQueue::INPUT){
return;
}
RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
if(port != NULL){
count[port]--;
queues[port][lastInsertedUrgency[port]].pop_back();
}
}
void DLMonitor::postQueueCreation(RMTQueue* queue){
std::string cu = queue->getName();
if(CUs.find(cu) == CUs.end()){
cu == "BE";
}
Q2CU[queue] = cu;
}
int DLMonitor::getPortCount(RMTPort* port){
return count[port];
}
int DLMonitor::getThreshold(RMTQueue* queue){
std::string cu = Q2CU[queue];
return CUs[cu].threshold;
}
RMTQueue* DLMonitor::getNextUrgentQ(RMTPort * port){
PriorityQueuesList * qs = & queues[port];
for(PQListRIterator it = qs->rbegin(); it != qs->rend(); it++){
if(!it->second.empty()){
RMTQueue* q = it->second.front();
it->second.pop_front();
return q;
}
}
return NULL;
}