RINASim  October 2016
Documentation of framework for OMNeT++
AEVoice.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 "AEVoice.h"
17 
18 namespace AEVoice {
19 
21 
22 int Stream::nextId = 0;
23 
25  id = nextId++;
26  wt = 0.03;
27  brt = 8.0;
28  avgSTime = 10.0;
29  avgWTime = 10.0;
30  varSTime = 2.0;
31  varWTime = 2.0;
32  //rng = &uniform;
33 }
34 
35 void Stream::setWt(double val) {
36  wt = val;
37 }
38 
39 void Stream::setBrt(double val) {
40  brt = val*1024;
41 }
42 
43 void Stream::setAvgSTime(double val){
44  avgSTime = val;
45 }
46 
47 void Stream::setAvgWTime(double val){
48  avgWTime = val;
49 }
50 
51 void Stream::setVarSTime(double val){
52  varSTime = val;
53 }
54 
55 void Stream::setVarWTime(double val){
56  varWTime = val;
57 }
58 
60  rng = val;
61 }
62 
63 void Stream::setState(bool val) {
64  state = val;
65 }
66 
68  return id;
69 }
70 
72  packetSize = (int) ceil(brt*wt);
77 }
78 
80  return rng(minSTime, maxSTime,0);
81 }
82 
84  return rng(minWTime, maxWTime,0);
85 }
86 
87 
88 double Stream::getWt() {
89  return wt;
90 }
91 
93  return packetSize;
94 }
95 
97  return state;
98 }
99 
100 State_Change::State_Change(int id, bool state){
101  streamId = id;
102  newState = state;
103 }
104 
106  streamId = id;
107 }
108 
109 void AEVoice::doIni() {
110  startVar = par("startVar");
111 
112 
113  cXMLElement* slXml = NULL;
114  if (par("streamList").xmlValue() != NULL && par("streamList").xmlValue()->hasChildren()){
115  slXml = par("streamList").xmlValue();
116  } else {
117  error("streamList parameter not initialized!");
118  }
119 
120  cXMLElementList streamsXML = slXml->getChildrenByTagName("Stream");
121  for (cXMLElementList::iterator it = streamsXML.begin(); it != streamsXML.end(); ++it) {
122  cXMLElement* m = *it;
123 
124  std::string streamType = "";
125  if (m->getAttribute("type")) {
126  streamType = m->getAttribute("type");
127  }
128 
129  Stream st;
130  if(streamType == "GSM_06.10" || streamType == "1"){
131  st.setWt(0.02);
132  st.setBrt(13);
133  } else if(streamType == "G.729" || streamType == "2"){
134  st.setWt(0.06);
135  st.setBrt(8);
136  } else if(streamType == "G.723.1_A" || streamType == "3"){
137  st.setWt(0.03);
138  st.setBrt(6.4);
139  } else if(streamType == "G.723.1_B" || streamType == "4"){
140  st.setWt(0.03);
141  st.setBrt(5.3);
142  } else if(streamType == "ILBC_A" || streamType == "5"){
143  st.setWt(0.02);
144  st.setBrt(15.2);
145  } else if(streamType == "ILBC_B" || streamType == "6"){
146  st.setWt(0.03);
147  st.setBrt(13.33);
148  }
149 
150  cXMLElementList attrs = m->getChildren();
151  for (cXMLElementList::iterator jt = attrs.begin(); jt != attrs.end(); ++jt) {
152  cXMLElement* n = *jt;
153  if ( !strcmp(n->getTagName(), "wt") ) {
154  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
155  if (v > 0) { st.setWt(v); }
156  } else if ( !strcmp(n->getTagName(), "brt") ) {
157  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
158  if (v > 0) { st.setBrt(v); }
159  } else if ( !strcmp(n->getTagName(), "avgS") ) {
160  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
161  if (v > 0) { st.setAvgSTime(v); }
162  } else if ( !strcmp(n->getTagName(), "avgW") ) {
163  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
164  if (v > 0) { st.setAvgSTime(v); }
165  } else if ( !strcmp(n->getTagName(), "varS") ) {
166  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
167  if (v > 0) { st.setVarSTime(v); }
168  } else if ( !strcmp(n->getTagName(), "varW") ) {
169  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
170  if (v > 0) { st.setVarSTime(v); }
171  } else if ( !strcmp(n->getTagName(), "rng") ) {
172  string nodeVal = n->getNodeValue();
173  if(nodeVal == "uniform"){
174  //st.setRNG(&uniform);
175  } else if(nodeVal == "normal"){
176  st.setRNG(&minMaxNormal);
177  }
178  }
179  }
180  st.compute();
181 
182  streams.push_back(st);
183  }
184 }
185 
186 void AEVoice::doFin(){
187  for(sVecIt it = streams.begin(); it != streams.end(); it++){
188  EV << 1/it->getWt() << " -> " << it->getDataSize() << endl;
189  }
190 }
191 
192 void AEVoice::iniCom(){
193  for(sVecIt it = streams.begin(); it != streams.end(); it++){
194  it->setState(false);
195  scheduleAt(uniform(simTime(), simTime()+startVar), new State_Change(it->getid(), true) );
196  }
197 }
198 
199 void AEVoice::processMsg(_AESInt_self * msg){
200  if(inTime){
201  if(State_Change * stc = dynamic_cast<State_Change*>(msg)){
202  if(stc->newState){
203  Stream *s = &streams[stc->streamId];
204  s->setState(true);
205  scheduleAt(simTime()+s->nexWaitT(), new State_Change(stc->streamId, false) );
206  scheduleAt(simTime(), new Stream_Timer(stc->streamId) );
207  } else {
208  Stream *s = &streams[stc->streamId];
209  s->setState(false);
210  scheduleAt(simTime()+s->nexWaitT(), new State_Change(stc->streamId, true) );
211  }
212  } else if(Stream_Timer * st = dynamic_cast<Stream_Timer*>(msg)){
213  Stream *s = &streams[st->streamId];
214  if(s->getState()){
215  int data = s->getDataSize();
216  while(data > 0){
217  sendMsg(new _PingMsg(), min(data, maxSize));
218  data -= maxSize;
219  }
220  scheduleAt(simTime()+s->getWt(), new Stream_Timer(st->streamId) );
221  }
222  }
223  }
224  delete msg;
225 }
226 
227 }
double varWTime
Definition: AEVoice.h:64
void setAvgWTime(double)
Definition: AEVoice.cc:47
sVec::iterator sVecIt
Definition: AEVoice.h:69
double nexSendT()
Definition: AEVoice.cc:79
void setBrt(double)
Definition: AEVoice.cc:39
double minSTime
Definition: AEVoice.h:60
double minMaxNormal(double a, double b, int rng)
Definition: AESInt.cc:30
int getDataSize()
Definition: AEVoice.cc:92
double varSTime
Definition: AEVoice.h:64
double maxSTime
Definition: AEVoice.h:60
double brt
Definition: AEVoice.h:56
static int nextId
Definition: AEVoice.h:52
double minWTime
Definition: AEVoice.h:61
double avgWTime
Definition: AEVoice.h:63
Define_Module(AEVoice)
double(* RNG_function)(double, double, int rng)
Definition: AEVoice.h:26
int packetSize
Definition: AEVoice.h:58
void setAvgSTime(double)
Definition: AEVoice.cc:43
void setRNG(RNG_function)
Definition: AEVoice.cc:59
State_Change(int, bool)
Definition: AEVoice.cc:100
void setVarSTime(double)
Definition: AEVoice.cc:51
double getWt()
Definition: AEVoice.cc:88
void setWt(double)
Definition: AEVoice.cc:35
double nexWaitT()
Definition: AEVoice.cc:83
double avgSTime
Definition: AEVoice.h:63
void setVarWTime(double)
Definition: AEVoice.cc:55
double wt
Definition: AEVoice.h:56
RNG_function rng
Definition: AEVoice.h:65
void setState(bool)
Definition: AEVoice.cc:63
double maxWTime
Definition: AEVoice.h:61
bool getState()
Definition: AEVoice.cc:96
void compute()
Definition: AEVoice.cc:71