24 void DQMonitor::onPolicyInit() {
27 if (par(
"lData").xmlValue() != NULL
28 && par(
"lData").xmlValue()->hasChildren()) {
29 parseL(par(
"lData").xmlValue());
31 error(
"lData parameter not initialized!");
36 if (par(
"cData").xmlValue() != NULL
37 && par(
"cData").xmlValue()->hasChildren()) {
38 parseC(par(
"cData").xmlValue());
40 error(
"cData parameter not initialized!");
45 if (par(
"uData").xmlValue() != NULL
46 && par(
"uData").xmlValue()->hasChildren()) {
47 parseU(par(
"uData").xmlValue());
49 error(
"uData parameter not initialized!");
54 cXMLElement* xml = NULL;
55 if (par(
"cuData").xmlValue() != NULL
56 && par(
"cuData").xmlValue()->hasChildren()) {
57 xml = par(
"cuData").xmlValue();
59 error(
"cuData parameter not initialized!");
61 cXMLElementList cus = xml->getChildrenByTagName(
"CUItem");
62 for(cXMLElement * m : cus){
63 if (!m->getAttribute(
"id")) {
64 error(
"Error parsing CU. Its ID is missing!");
67 std::string
id = m->getAttribute(
"id");
69 error(
"Error parsing CU. Its ID is missing!");
77 cXMLElementList attrs = m->getChildren();
78 for(cXMLElement * n : attrs ){
79 string val = n->getNodeValue();
80 if (!strcmp(n->getTagName(),
"limit")) {
81 if (Ls.find(val) != Ls.end()) {
84 std::cout <<
"Limit " << val <<
"not found" <<endl;
86 }
else if (!strcmp(n->getTagName(),
"cherish")) {
87 if (Cs.find(val) != Cs.end()) {
90 std::cout <<
"Cherish " << val <<
"not found" <<endl;
92 }
else if (!strcmp(n->getTagName(),
"urgency")) {
93 if (Us.find(val) != Us.end()) {
96 std::cout <<
"Urgency " << val <<
"not found" <<endl;
98 }
else if (!strcmp(n->getTagName(),
"queue")) {
102 if(l == NULL || u == NULL || c == NULL) {
103 std::cout << l <<
" " << c <<
" " << u <<endl;
104 error(
"L/C/U missing");
111 void DQMonitor::parseL(cXMLElement* xml) {
112 cXMLElementList ls = xml->getChildrenByTagName(
"L");
113 for(cXMLElement* m : ls){
114 if (!m->getAttribute(
"id")) {
115 error(
"Error parsing L. Its ID is missing!");
118 std::string
id = m->getAttribute(
"id");
120 error(
"Error parsing L. Its ID is missing!");
123 bool limit = (m->getChildrenByTagName(
"limit").size() > 0);
124 bool space = (m->getChildrenByTagName(
"space").size() > 0);
129 if (limit || space) {
130 cXMLElementList limVals = m->getChildrenByTagName(
"limVals");
131 for(cXMLElement* n : limVals) {
138 if (!n->getAttribute(
"wt")) {
139 error(
"Error parsing limVals. Its wt is missing!");
141 index = atof(n->getAttribute(
"wt"));
143 error(
"Error parsing limVals. wt cannot be negative");
147 if (n->getChildrenByTagName(
"rate").size() != 1) {
148 error(
"Error parsing limVals. There must be one an only one rate per limVals");
150 rate = atoll((*n->getChildrenByTagName(
"rate").begin())->getNodeValue());
152 error(
"Error parsing limVals. rate cannot be 0 or negative");
156 if (n->getChildrenByTagName(
"spaceRate").size() != 1) {
157 error(
"Error parsing limVals. There must be one an only one spaceRate per limVals");
159 spaceRate = atoll((*n->getChildrenByTagName(
"spaceRate").begin())->getNodeValue());
160 if (spaceRate <= 0) {
161 error(
"Error parsing limVals. spaceRate cannot be 0 or negative");
165 if (n->getChildrenByTagName(
"spaceVar").size() != 1) {
166 error(
"Error parsing limVals. There must be one an only one spaceVar per limVals");
168 spaceVar = atof((*n->getChildrenByTagName(
"spaceVar").begin())->getNodeValue());
169 if (spaceVar < 0 || spaceVar > 1) {
170 error(
"Error parsing limVals. spaceVar must be between 0 and 1");
175 if (n->getChildrenByTagName(
"dropProb").size() != 1) {
176 error(
"Error parsing limVals. There must be one an only one dropProb per limVals");
178 dropProb = atof((*n->getChildrenByTagName(
"dropProb").begin())->getNodeValue());
179 if (dropProb < 0 || dropProb > 1) {
180 error(
"Error parsing limVals. dropProb must be between 0 and 1");
184 v.push_back(
ILimVals(index, rate, spaceRate, spaceVar, dropProb));
189 cXMLElementList dropVals = m->getChildrenByTagName(
"dropProb");
190 for(cXMLElement* n : dropVals) {
194 if (!n->getAttribute(
"ws")) {
195 error(
"Error parsing dropProb. Its ws is missing!");
197 index = atof(n->getAttribute(
"ws"));
199 error(
"Error parsing dropProb. ws cannot be negative");
204 if (!n->getAttribute(
"prob")) {
205 error(
"Error parsing dropProb. Its prob is missing!");
207 dropProb = atof(n->getAttribute(
"prob"));
208 if (dropProb < 0 || dropProb > 1 ) {
209 error(
"Error parsing dropProb. prob must be between 0 and 1");
215 Ls[id] =
L(limit, space, v, p);
216 std::cout <<
"L :: "<<
id <<
" => "<< &Ls[id] << endl;
220 void DQMonitor::parseC(cXMLElement* xml){
221 cXMLElementList ls = xml->getChildrenByTagName(
"C");
222 for(cXMLElement* m : ls) {
223 if (!m->getAttribute(
"id")) {
224 error(
"Error parsing C. Its ID is missing!");
227 std::string
id = m->getAttribute(
"id");
229 error(
"Error parsing C. Its ID is missing!");
235 if (m->getAttribute(
"defaultDropProb")) {
236 def = atof(m->getAttribute(
"defaultDropProb"));
237 if(def < 0 || def > 1) {
238 error(
"Error parsing C. defaultDropProb must be between 0 and 1");
242 cXMLElementList dropPVals = m->getChildrenByTagName(
"dropProb");
243 for (cXMLElement* n : dropPVals) {
247 if (!n->getAttribute(
"ws")) {
248 error(
"Error parsing dropProb. Its ws is missing!");
250 index = atof(n->getAttribute(
"ws"));
252 error(
"Error parsing dropProb. ws cannot be negative");
256 if (!n->getAttribute(
"prob")) {
257 error(
"Error parsing dropProb. Its prob is missing!");
259 dropProb = atof(n->getAttribute(
"prob"));
260 if (dropProb < 0 || dropProb > 1 ) {
261 error(
"Error parsing dropProb. prob must be between 0 and 1");
269 void DQMonitor::parseU(cXMLElement* xml) {
271 cXMLElementList ls = xml->getChildrenByTagName(
"U");
272 for(cXMLElement* m : ls){
273 if (!m->getAttribute(
"id")) {
274 error(
"Error parsing U. Its ID is missing!");
277 std::string
id = m->getAttribute(
"id");
279 error(
"Error parsing U. Its ID is missing!");
283 if (m->getAttribute(
"defaultPriority")) {
284 defPrio = atoi(m->getAttribute(
"defaultPriority"));
287 bool degraded = (m->getChildrenByTagName(
"degraded").size() > 0);
294 if (m->getChildrenByTagName(
"rate").size() != 1) {
295 error(
"Error parsing U. There must be one an only one rate per limVals");
297 rate = atoll((*m->getChildrenByTagName(
"rate").begin())->getNodeValue());
299 error(
"Error parsing U. rate cannot be 0 or negative");
302 cXMLElementList degVals = m->getChildrenByTagName(
"degradList");
303 for(cXMLElement* n : degVals) {
305 if (!n->getAttribute(
"wt")) {
306 error(
"Error parsing degradList. Its wt is missing!");
308 index = atof(n->getAttribute(
"wt"));
310 error(
"Error parsing degradList. rate wt be negative");
315 cXMLElementList ppl = n->getChildrenByTagName(
"PP");
316 for(cXMLElement* w : ppl) {
321 if (!w->getAttribute(
"priority")) {
322 error(
"Error parsing PP. There must be one an only one priority per PP");
325 prior = atoi(w->getAttribute(
"priority"));
328 if (!w->getAttribute(
"probability")) {
329 error(
"Error parsing PP. There must be one an only one probability per PP");
331 prob = atof(w->getAttribute(
"probability"));
333 error(
"Error parsing PP. probability must be between 0 and 1");
336 dd.
PPs.push_back(
PP(prior, prob));
342 Us[id] =
U(defPrio, degraded, rate, dl);
346 void DQMonitor::postPDUInsertion(
RMTQueue* queue) {
348 RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
351 if (port != NULL && cu != NULL ) {
358 list<simtime_t> * times = <imes[port][cu->
limit];
361 for(list<simtime_t>::iterator it = times->begin(); it != times->end();){
362 list<simtime_t>::iterator tmpIt = it++;
363 if(*tmpIt <= simTime()) { times->erase(tmpIt); }
369 std::cout << cu->
limit << endl;
376 LTimes[port][cu->
limit].push_back( t.
serveT+simTime() );
377 SpaceTimes[port][cu->
limit].push_back( t.
spaceT+simTime() );
380 LQueues[port][cu->
limit].push_back(queue);
391 list<simtime_t> * times = &UTimes[queue];
394 for(list<simtime_t>::iterator it = times->begin(); it != times->end();){
395 list<simtime_t>::iterator tmpIt = it++;
396 if(*tmpIt <= simTime()) { times->erase(tmpIt); }
400 simtime_t lt = simTime();
401 if(!times->empty()) { lt = times->back();}
406 lastUrgency[queue] = u;
410 times->push_back(lt);
413 UQueues[port][u].push_back(queue);
418 error (
"Unkown queue");
422 void DQMonitor::onMessageDrop(
RMTQueue* queue,
const cPacket* pdu) {
424 RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
427 if (port != NULL && cu != NULL ) {
434 LTimes[port][cu->
limit].pop_back();
435 SpaceTimes[port][cu->
limit].pop_back();
438 LQueues[port][cu->
limit].pop_back();
448 if(lastUrgency.find(queue) == lastUrgency.end()) { error(
"PDUs removed without going through monitor?"); }
451 int lastU = lastUrgency[queue];
452 lastUrgency.erase(queue);
456 UQueues[port][lastU].pop_back();
457 if(UQueues[port][lastU].empty()){ UQueues[port].erase(lastU); }
461 list<simtime_t> * times = &UTimes[queue];
462 if(!times->empty()) {
465 error(
"PDUs removed without going through monitor?");
472 void DQMonitor::postQueueCreation(
RMTQueue* queue) {
473 std::string cu =
"BE";
476 if(cl.second.queueName == queue->getName()){
481 Q2CU[queue] = &CUs[cu];
483 std::cout << queue->getName() <<
" => "<< cu<<endl;
486 double DQMonitor::getInDropProb(
RMTQueue * queue) {
488 RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
491 if (port != NULL && cu != NULL ) {
493 list<simtime_t> * times = <imes[port][cu->
limit];
504 simtime_t minT = DBL_MAX;
507 for(
auto l : SpaceTimes[port]) {
508 if(l.second.empty()){
509 simtime_t tmp = l.second.front();
519 nextServe[port] = minT;
522 if(minT <= simTime()) {
523 q = LQueues [port][minL].front();
524 LQueues [port][minL].pop_front();
525 LTimes [port][minL].pop_front();
526 SpaceTimes [port][minL].pop_front();
532 simtime_t DQMonitor::getNextInputTime(
RMTPort* port) {
534 return nextServe[port];
539 double DQMonitor::getOutDropProb(
RMTQueue * queue) {
541 RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
544 if (port == NULL || cu == NULL) { error (
"Unkown queue"); }
554 for(
auto uQ : UQueues[port]){
555 if(!uQ.second.empty()) {
557 uQ.second.pop_front();
queueType getType() const
int getPriority(double wt)
vector< IDropProb > IDropProbList
double getDropProb(int s)
const cPacket * getLastPDU() const
Times getTimes(double wt, int size)
double getDropProb(double wt, int ws)
vector< ILimVals > ILimValsList
vector< IDegrad > IDegradList