RINASim  October 2016
Documentation of framework for OMNeT++
dlCUInfo.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 "dlCUInfo.h"
19 #include <algorithm>
20 
21 namespace DQMonitor {
22 
23 ILimVals::ILimVals(double i, long long r, long long sr, double sv, double p):
24  index(i), rate(r), spaceRate(sr), spaceVar(sv), dropProb(p){}
25 
26 IDropProb::IDropProb(int i, double p):
27  index(i), prob(p){}
28 
29 PP::PP(int prio, double prob):
30  priority(prio), probability(prob) {}
31 
32 
33 IDegrad::IDegrad(double i):
34  index(i){}
35 
37  int p = def;
38 
39  double t = 0, lim = uniform(NULL,0,1);
40  for(PPlistIt it = PPs.begin(); it != PPs.end(); it++){
41  p = it->priority;
42  t += it->probability;
43  if(t > lim) { break; }
44  }
45 
46  return p;
47 }
48 
49 template <typename T> bool compareIndex(const T& a, const T& b) {
50  return a.index < b.index;
51 }
52 
54  serveT(0), spaceT(0) {}
55 
56 Times::Times(double se, double sp):
57  serveT(se), spaceT(sp) {}
58 
59 L::L(){}
60 
61 L::L(bool lim, bool spa, ILimValsList v, IDropProbList d):
62  limit(lim), space(spa), vl(v), dl(d) {
63  sort(vl.begin(), vl.end(), compareIndex<ILimVals>);
64  sort(dl.begin(), dl.end(), compareIndex<IDropProb>);
65 }
66 
67 
68 bool L::needRate() {
69  return space || limit;
70 }
71 
72 bool L::spaces() {
73  return space;
74 }
75 bool L::limits() {
76  return limit;
77 }
78 
79 Times L::getTimes(double wt, int size) {
80  Times t(0.0, 0.0);
81  long long rate = LLONG_MAX;
82  long long sprate = LLONG_MAX;
83  double spvar = 0.0;
84 
85  // int s = vl.size();
86  std::cout << "Holas?" << this << endl;
87 
88  for(ILimVals lv : vl) {
89  if(wt <= lv.index) {
90  rate = lv.rate;
91  sprate = lv.spaceRate;
92  spvar = lv.spaceVar;
93  }
94  }
95 
96  if(limit || space) {
97  if(rate!=LLONG_MAX){ t.serveT = ((double)size)/((double)rate); }
98  if(space && sprate!=LLONG_MAX){
99  double avg = ((double)size)/((double)sprate);
100  t.spaceT = avg*uniform(NULL, 1-spvar, 1+spvar);
101  }
102  }
103 
104  return t;
105 }
106 
107 double L::getDropProb(double wt, int ws) {
108  if(limit) {
109  double tw = 0, ts = 0;
110  for(ILimValsIt it = vl.begin(); it != vl.end(); it++) {
111  if(wt >= it->index) { tw = it->dropProb; }
112  else { break; }
113  }
114  for(IDropProbIt it = dl.begin(); it != dl.end(); it++) {
115  if(ws >= it->index) { ts = it->prob; }
116  else { break; }
117  }
118  return max(tw, ts);
119  }
120  return 0;
121 }
122 
123 C::C(){}
124 
125 C::C(double dd, IDropProbList d):
126  defaultDropProb(dd), dl(d) {
127  sort(dl.begin(), dl.end(), compareIndex<IDropProb>);
128 }
129 
130 double C::getDropProb(int s) {
131  double t = defaultDropProb;
132  for(IDropProbIt it = dl.begin(); it != dl.end(); it++) {
133  if(s >= it->index) { t = it->prob; }
134  else { break; }
135  }
136  return t;
137 }
138 
139 U::U(){}
140 
141 U::U(int dp, bool deg, long long r, IDegradList d):
142  defaultPriority(dp), degrad(deg), rate(r), dl(d){
143  sort(dl.begin(), dl.end(), compareIndex<IDegrad>);
144 }
145 
147  return degrad;
148 }
149 
150 double U::getTime(int size) {
151  if(degrad) { return ((double)size)/((double)rate); }
152  else { return 0.0; }
153 }
154 
155 int U::getPriority(double wt) {
156  if(!degrad) { return defaultPriority; }
157 
158  IDegrad * pr = NULL;
159 
160  for(IDegradIt it = dl.begin(); it != dl.end(); it++) {
161  if(wt >= it->index) { pr = &(*it); }
162  else { break; }
163  }
164 
165  if(pr == NULL) { return defaultPriority; }
166 
168 }
169 
171  queueName(""), limit(NULL), cherish(NULL), urgency(NULL) {}
172 dlCUInfo::dlCUInfo(string qn, L * l, C * c, U * u) :
173  queueName(qn), limit(l), cherish(c), urgency(u) {}
174 
175 }
PPlist::iterator PPlistIt
Definition: dlCUInfo.h:58
IDropProbList dl
Definition: dlCUInfo.h:92
bool space
Definition: dlCUInfo.h:89
ILimVals(double i, long long r, long long sr, double sv, double p)
Definition: dlCUInfo.cc:23
bool isDegraded()
Definition: dlCUInfo.cc:146
bool needRate()
Definition: dlCUInfo.cc:68
double defaultDropProb
Definition: dlCUInfo.h:107
ILimValsList vl
Definition: dlCUInfo.h:91
IDegrad(double i)
Definition: dlCUInfo.cc:33
bool limits()
Definition: dlCUInfo.cc:75
int getPriority(double wt)
Definition: dlCUInfo.cc:155
vector< IDropProb > IDropProbList
Definition: dlCUInfo.h:72
double getDropProb(int s)
Definition: dlCUInfo.cc:130
bool limit
Definition: dlCUInfo.h:89
bool spaces()
Definition: dlCUInfo.cc:72
int getRandomPriority(int def)
Definition: dlCUInfo.cc:36
bool degrad
Definition: dlCUInfo.h:121
long long rate
Definition: dlCUInfo.h:123
PP(int prio, double prob)
Definition: dlCUInfo.cc:29
double getTime(int size)
Definition: dlCUInfo.cc:150
Times getTimes(double wt, int size)
Definition: dlCUInfo.cc:79
bool compareIndex(const T &a, const T &b)
Definition: dlCUInfo.cc:49
IDegradList dl
Definition: dlCUInfo.h:124
IDropProbList dl
Definition: dlCUInfo.h:108
double serveT
Definition: dlCUInfo.h:80
int defaultPriority
Definition: dlCUInfo.h:119
IDegradList::iterator IDegradIt
Definition: dlCUInfo.h:77
IDropProbList::iterator IDropProbIt
Definition: dlCUInfo.h:76
IDropProb(int i, double p)
Definition: dlCUInfo.cc:26
ILimValsList::iterator ILimValsIt
Definition: dlCUInfo.h:75
double spaceT
Definition: dlCUInfo.h:81
double getDropProb(double wt, int ws)
Definition: dlCUInfo.cc:107
vector< ILimVals > ILimValsList
Definition: dlCUInfo.h:71
vector< IDegrad > IDegradList
Definition: dlCUInfo.h:73