RINASim  October 2016
Documentation of framework for OMNeT++
AEBStream.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include "AEBStream.h"
17 
18 namespace AEBStream {
19 
21 
22 int Stream::nextId = 0;
23 
25  id = nextId++;
26  wt = 0.03;
27  brt = 8.0;
28  //rng = &uniform;
29  //rngb = &uniform;
30 
31  pduS=1024;
32  varPduS=0;
33  burstS=10240;
34  varBurstS=0;
35  burstProb=0.05;
36 }
37 
38 void Stream::setBrt(double val) {
39  brt = val*1024;
40 }
41 
42 void Stream::setPduS(int val){
43  pduS = val;
44 }
45 void Stream::setVarPduS(double val){
46  varPduS = val;
47 }
48 
49 void Stream::setBurstS(int val){
50  burstS = val;
51 }
52 void Stream::setVarBurstS(double val){
53  varBurstS = val;
54 }
55 
56 void Stream::setBurstProb(double val){
57  burstProb = val;
58 }
59 
61  rng = val;
62 }
63 
65  rngb = val;
66 }
67 
68 
70  return id;
71 }
72 
73 double Stream::getWt(int size) {
74  return wt*size;
75 }
76 
78  return (int) rng(minPduS, maxPduS, 0);
79 }
80 
82  return (int) rng(minBurstS, maxBurstS, 0);
83 }
84 
86  return burstProb;
87 }
88 
89 void Stream::setState(bool val){
90  state = val;
91 }
93  return state;
94 }
95 
97  wt = 1/brt;
98  minPduS = (int) ceil(pduS*(1-varPduS));
99  maxPduS = (int) ceil(pduS*(1+varPduS));
100  minBurstS = (int) ceil(burstS*(1-varBurstS));
101  maxBurstS = (int) ceil(burstS*(1+varBurstS));
102 }
103 
105  streamId = id;
106 }
107 
108 void AEBStream::doIni() {
109  startVar = par("startVar");
110 
111  cXMLElement* slXml = NULL;
112  if (par("streamList").xmlValue() != NULL && par("streamList").xmlValue()->hasChildren()){
113  slXml = par("streamList").xmlValue();
114  } else {
115  error("streamList parameter not initialized!");
116  }
117 
118  cXMLElementList streamsXML = slXml->getChildrenByTagName("Stream");
119  for (cXMLElementList::iterator it = streamsXML.begin(); it != streamsXML.end(); ++it) {
120  cXMLElement* m = *it;
121 
122  Stream st;
123 
124  cXMLElementList attrs = m->getChildren();
125  for (cXMLElementList::iterator jt = attrs.begin(); jt != attrs.end(); ++jt) {
126  cXMLElement* n = *jt;
127  if ( !strcmp(n->getTagName(), "brt") ) {
128  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
129  if (v > 0) { st.setBrt(v); }
130  } else if ( !strcmp(n->getTagName(), "pduS") ) {
131  double v = n->getNodeValue() ? atoi(n->getNodeValue()) : 0;
132  if (v >= 0) { st.setPduS(v); }
133  } else if ( !strcmp(n->getTagName(), "varPduS") ) {
134  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
135  if (v >= 0 && v <= 1) { st.setVarPduS(v); }
136  } else if ( !strcmp(n->getTagName(), "BurstS") ) {
137  double v = n->getNodeValue() ? atoi(n->getNodeValue()) : 0;
138  if (v >= 0) { st.setBurstS(v); }
139  } else if ( !strcmp(n->getTagName(), "varBurstS") ) {
140  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
141  if (v >= 0 && v <= 1) { st.setVarBurstS(v); }
142  } else if ( !strcmp(n->getTagName(), "burstProb") ) {
143  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
144  if (v >= 0 && v <= 1) { st.setBurstProb(v); }
145  } else if ( !strcmp(n->getTagName(), "rng") ) {
146  string nodeVal = n->getNodeValue();
147  if(nodeVal == "uniform"){
148  //st.setRNG(&uniform);
149  } else if(nodeVal == "normal"){
150  st.setRNG(&minMaxNormal);
151  }
152  } else if ( !strcmp(n->getTagName(), "rngb") ) {
153  string nodeVal = n->getNodeValue();
154  if(nodeVal == "uniform"){
155  //st.setBRNG(&uniform);
156  } else if(nodeVal == "normal"){
157  st.setBRNG(&minMaxNormal);
158  }
159  }
160  }
161  st.compute();
162 
163  streams.push_back(st);
164  }
165 }
166 
167 void AEBStream::doFin(){}
168 
169 void AEBStream::iniCom(){
170  for(sVecIt it = streams.begin(); it != streams.end(); it++){
171  it->setState(false);
172  scheduleAt(uniform(simTime(), simTime()+startVar), new Stream_Timer(it->getid()) );
173  }
174 }
175 
176 void AEBStream::processMsg(_AESInt_self * msg){
177  Stream_Timer * st = dynamic_cast<Stream_Timer*>(msg);
178  if(inTime && st){
179  Stream *s = &streams[st->streamId];
180  int data;
181  if(s->getState()){
182  data = s->getPDU();
183  if(uniform(0,1) < s->getBurstProb()){ s->setState(true); }
184  } else {
185  data = s->getBurst();
186  s->setState(false);
187  }
188  int remaining = data;
189 
190  while(remaining > 0){
191  sendMsg(new _PingMsg(), min(remaining, maxSize));
192  remaining -= maxSize;
193  }
194 
195  scheduleAt(simTime()+s->getWt(data), new Stream_Timer(st->streamId) );
196  }
197  delete msg;
198 }
199 
200 }
double minMaxNormal(double a, double b, int rng)
Definition: AESInt.cc:30
double getBurstProb()
Definition: AEBStream.cc:85
void setState(bool)
Definition: AEBStream.cc:89
void setVarPduS(double)
Definition: AEBStream.cc:45
double varBurstS
Definition: AEBStream.h:65
RNG_function rng
Definition: AEBStream.h:71
static int nextId
Definition: AEBStream.h:57
sVec::iterator sVecIt
Definition: AEBStream.h:75
void setBurstS(int)
Definition: AEBStream.cc:49
void setBRNG(RNG_function)
Definition: AEBStream.cc:64
RNG_function rngb
Definition: AEBStream.h:71
void setVarBurstS(double)
Definition: AEBStream.cc:52
Define_Module(AEBStream)
void setPduS(int)
Definition: AEBStream.cc:42
void setBurstProb(double)
Definition: AEBStream.cc:56
double getWt(int size)
Definition: AEBStream.cc:73
double(* RNG_function)(double, double, int rng)
Definition: AEBStream.h:26
double burstProb
Definition: AEBStream.h:66
void setRNG(RNG_function)
Definition: AEBStream.cc:60
void setBrt(double)
Definition: AEBStream.cc:38