RINASim  October 2016
Documentation of framework for OMNeT++
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AEData.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 "AEData.h"
17 
18 namespace AEData {
19 
21 
22 int Stream::nextId = 0;
23 
25  id = nextId++;
26  state = false;
27 
28  wt = 0.03;
29  brt = 8.0;
30 
31  dataS = 10240;
32  //rng = &uniform;
33 
34  waitT = 0;
35  //rngwt = &uniform;
36 }
37 
38 void Stream::setBrt(double val) {
39  brt = val*1024;
40 }
41 
42 void Stream::setDataS(int val){
43  dataS = val;
44 }
45 void Stream::setVarDataS(double val){
46  varDataS = val;
47 }
48 
49 void Stream::setWaitT(double val){
50  waitT = val;
51 }
52 void Stream::setVarWaitT(double val){
53  varWaitT = val;
54 }
55 
57  rng = val;
58 }
59 
61  rngwt = val;
62 }
63 
64 
66  return id;
67 }
68 
70  return wData;
71 }
72 
73 int Stream::getNextPDU(int maxSize){
74  int ret = (wData < maxSize)? wData : maxSize;
75  wData -= ret;
76  return ret;
77 }
78 
80  state = false;
81  wData = 0;
82 }
84  state = true;
85  wData = (int) rng(minDataS, maxDataS, 0);
86 }
87 
89  return state;
90 }
91 
92 double Stream::getWt(int size){
93  return wt*size;
94 }
95 
96 double Stream::getWait(){
97  return rng(minWaitT, maxWaitT, 0);
98 }
99 
101  wt = 1/brt;
102  minDataS = (int) ceil(dataS*(1-varDataS));
103  maxDataS = (int) ceil(dataS*(1+varDataS));
104  minWaitT = (int) ceil(waitT*(1-varWaitT));
105  maxWaitT = (int) ceil(waitT*(1+varWaitT));
106 }
107 
108 State_Change::State_Change(int id, bool state){
109  streamId = id;
110  newState = state;
111 }
112 
114  streamId = id;
115 }
116 
117 void AEData::doIni() {
118  startVar = par("startVar");
119 
120  cXMLElement* slXml = NULL;
121  if (par("streamList").xmlValue() != NULL && par("streamList").xmlValue()->hasChildren()){
122  slXml = par("streamList").xmlValue();
123  } else {
124  error("streamList parameter not initialized!");
125  }
126 
127  cXMLElementList streamsXML = slXml->getChildrenByTagName("Stream");
128  for (cXMLElementList::iterator it = streamsXML.begin(); it != streamsXML.end(); ++it) {
129  cXMLElement* m = *it;
130 
131  Stream st;
132 
133  cXMLElementList attrs = m->getChildren();
134  for (cXMLElementList::iterator jt = attrs.begin(); jt != attrs.end(); ++jt) {
135  cXMLElement* n = *jt;
136  if ( !strcmp(n->getTagName(), "brt") ) {
137  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
138  if (v > 0) { st.setBrt(v); }
139  } else if ( !strcmp(n->getTagName(), "dataS") ) {
140  double v = n->getNodeValue() ? atoi(n->getNodeValue()) : 0;
141  if (v >= 0) { st.setDataS(v); }
142  } else if ( !strcmp(n->getTagName(), "vardataS") ) {
143  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
144  if (v >= 0 && v <= 1) { st.setVarDataS(v); }
145  } else if ( !strcmp(n->getTagName(), "waitT") ) {
146  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
147  if (v >= 0) { st.setWaitT(v); }
148  } else if ( !strcmp(n->getTagName(), "varWaitT") ) {
149  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
150  if (v >= 0 && v <= 1) { st.setVarWaitT(v); }
151  } else if ( !strcmp(n->getTagName(), "rng") ) {
152  string nodeVal = n->getNodeValue();
153  if(nodeVal == "uniform"){
154  //st.setRNG(&uniform);
155  } else if(nodeVal == "normal"){
156  st.setRNG(&minMaxNormal);
157  }
158  } else if ( !strcmp(n->getTagName(), "rngwt") ) {
159  string nodeVal = n->getNodeValue();
160  if(nodeVal == "uniform"){
161  //st.setWTRNG(&uniform);
162  } else if(nodeVal == "normal"){
163  st.setWTRNG(&minMaxNormal);
164  }
165  }
166  }
167  st.compute();
168 
169  streams.push_back(st);
170  }
171 }
172 
173 void AEData::doFin(){}
174 
175 void AEData::iniCom(){
176  for(sVecIt it = streams.begin(); it != streams.end(); it++){
177  it->setWaiting();
178  scheduleAt(uniform(simTime(), simTime()+startVar), new State_Change(it->getid(), true) );
179  }
180 }
181 
182 void AEData::processMsg(_AESInt_self * msg){
183  if(inTime){
184  if(State_Change * stc = dynamic_cast<State_Change*>(msg)){
185  if(stc->newState){
186  streams[stc->streamId].setSending();
187  scheduleAt(simTime(), new Stream_Timer(stc->streamId) );
188  } else {
189  Stream *s = &streams[stc->streamId];
190  s->setWaiting();
191  scheduleAt(simTime()+s->getWait(), new State_Change(stc->streamId, true) );
192  }
193  } else if(Stream_Timer * st = dynamic_cast<Stream_Timer*>(msg)){
194  Stream *s = &streams[st->streamId];
195  if(s->getState()){
196  if(s->getRemaining() <= 0){
197  scheduleAt(simTime(), new State_Change(st->streamId, false) );
198  } else {
199  int data = s->getNextPDU(maxSize);
200  sendMsg(new _PingMsg(), data);
201  scheduleAt(simTime()+s->getWt(data), new Stream_Timer(st->streamId) );
202  }
203  }
204  }
205  }
206  delete msg;
207 }
208 
209 }
double brt
Definition: AEData.h:62
double getWait()
Definition: AEData.cc:96
void setDataS(int)
Definition: AEData.cc:42
void setVarDataS(double)
Definition: AEData.cc:45
sVec::iterator sVecIt
Definition: AEData.h:78
int minDataS
Definition: AEData.h:68
double varWaitT
Definition: AEData.h:71
double minMaxNormal(double a, double b, int rng)
Definition: AESInt.cc:30
int getRemaining()
Definition: AEData.cc:69
bool getState()
Definition: AEData.cc:88
Definition: AEData.cc:18
void setWaitT(double)
Definition: AEData.cc:49
State_Change(int, bool)
Definition: AEData.cc:108
double(* RNG_function)(double, double, int rng)
Definition: AEData.h:26
int maxWaitT
Definition: AEData.h:72
double varDataS
Definition: AEData.h:67
int minWaitT
Definition: AEData.h:72
void setWTRNG(RNG_function)
Definition: AEData.cc:60
void setRNG(RNG_function)
Definition: AEData.cc:56
Define_Module(AEData)
static int nextId
Definition: AEData.h:57
void setWaiting()
Definition: AEData.cc:79
void setSending()
Definition: AEData.cc:83
void setBrt(double)
Definition: AEData.cc:38
int getid()
Definition: AEData.cc:65
double getWt(int)
Definition: AEData.cc:92
int maxDataS
Definition: AEData.h:68
double waitT
Definition: AEData.h:70
bool state
Definition: AEData.h:60
void compute()
Definition: AEData.cc:100
void setVarWaitT(double)
Definition: AEData.cc:52
double wt
Definition: AEData.h:62
int getNextPDU(int)
Definition: AEData.cc:73
RNG_function rngwt
Definition: AEData.h:74
RNG_function rng
Definition: AEData.h:74