RINASim  October 2016
Documentation of framework for OMNeT++
AESender.cc
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 
23 #include "AESender.h"
24 
26 
28  pingAt = simTime();
29 }
30 
32  auto *t = new PingMsgg(*this);
33  t->pingAt = pingAt;
34  return t;
35 }
36 
37 PongMsgg::PongMsgg(simtime_t _pingAt){
38  pingAt = _pingAt;
39  pongAt = simTime();
40 }
41 
43  auto *t = new PongMsgg(pingAt);
44  t->pongAt = pongAt;
45  return t;
46  }
47 
49  S_TIM_START = "StartCommunication";
50  S_TIM_COM = "MakeCommunication";
51  S_TIM_STOP = "StopCommunication";
52 
53  S_PAR_START = "startAt";
54  S_PAR_STOP = "stopAt";
55  S_PAR_SEND = "sendAfter";
56 
57  S_PAR_DSTAPNAME = "dstApName";
58  S_PAR_DSTAPINSTANCE = "dstApInstance";
59  S_PAR_DSTAENAME = "dstAeName";
60  S_PAR_DSTAEINSTANCE = "dstAeInstance";
61 
62  S_PAR_RATE = "rate";
63  S_PAR_RATE_VAR = "ratevar";
64  S_PAR_SIZE = "size";
65  S_PAR_SIZE_VAR = "sizevar";
66 
67  S_MSG_PING = "PING-";
68  S_PAR_PING = "pingAt";
69  S_VAL_MODULEPATH = "getFullPath()";
70 }
71 
74  FlowObject = NULL;
75  Irm = NULL;
76  Cdap = NULL;
77 }
78 
80  //Schedule AllocateRequest
81  cMessage* m1 = new cMessage(S_TIM_START);
82  scheduleAt(startAt, m1);
83 }
84 
85 
87  //Schedule DeallocateRequest
88  cMessage* m3 = new cMessage(S_TIM_STOP);
89  scheduleAt(stopAt, m3);
90 }
91 
93 {
94  //Init pointers
95  initPointers();
96  //Source info
98  //Setup signals
100  //Init QoSRequirements
102 
103  //Timers
104  startAt = simTime() + par(S_PAR_START);
105  stopAt = simTime() + par(S_PAR_STOP);
106  sendAfter = par(S_PAR_SEND);
107  if(sendAfter<1){
108  sendAfter = 1;
109  }
110 
111  //Time between PDUS (s)
112  rate = par(S_PAR_RATE).doubleValue();
113  ratevar = par(S_PAR_RATE_VAR).doubleValue();
114 
115  //SIZE of PDU
116  size = par(S_PAR_SIZE);
117  sizevar = par(S_PAR_SIZE_VAR);
118 
119  //Destination for flow
120  dstApName = this->par(S_PAR_DSTAPNAME).stringValue();
121  dstApInstance = this->par(S_PAR_DSTAPINSTANCE).stringValue();
122  dstAeName = this->par(S_PAR_DSTAENAME).stringValue();
123  dstAeInstance = this->par(S_PAR_DSTAEINSTANCE).stringValue();
124 
125  if (!dstAeName.compare("AeErr")) {
126  EV << "Destination AEName is set to default which is AeErr. AeErr is for special testing purposes. Are you sure that it is right?" << endl;
127  }
128 
129  //Schedule AllocateRequest
130  if (startAt > 0)
132  //Schedule DeallocateRequest
133  /*
134  if (stopAt > 0)
135  prepareDeallocateRequest();
136  */
137  myPath = this->getFullPath();
138 
139  send = 0;
140  received = 0;
141  pingreceived = 0;
142  sendSize = 0;
143  receivedSize = 0;
144  pingreceivedSize = 0;
145 
146  minDelay = 999;
147  maxDelay = -1;
148  firstR = -1;
149  lastR = 0;
150 
151  recTimes = par("recTimes").boolValue();
152 
153  pduburst = par("pduburst").longValue();
154  if(pduburst<1) { pduburst = 1; }
155 
156  //Watchers
157  WATCH(FlowObject);
158  WATCH(send);
159  WATCH(received);
160  WATCH(pingreceived);
161  WATCH(sendSize);
162  WATCH(receivedSize);
163  WATCH(pingreceivedSize);
164  WATCH(minDelay);
165  WATCH(maxDelay);
166 }
167 
169 {
170  if(par("printAtEnd").boolValue()){
171  EV << "At "<<this->getApni()<<endl;
172  if(FlowObject != NULL) {
173  EV << "With QoS " << FlowObject->getConId().getQoSId() <<endl;
174  }
175  EV << "send " << send << " ("<<sendSize << ")"<<endl;
176  // EV << "pingsRcv " << pingreceived << " ("<<pingreceivedSize << ")"<<endl;
177  EV << "pongsRcv " << received << " ("<<receivedSize << ")"<<endl;
178  EV << "delay " << minDelay << " / "<<maxDelay<<endl;
179  EV << "timestamps " << firstR << " -> "<<lastR<<endl;
180 
181  if(recTimes){
182  EV << "-----------------"<<endl;
183  for(std::map<double, int>::iterator it = times.begin(); it!=times.end(); it++) {
184  EV << " " << it->first << " " << it->second <<endl;
185  }
186  EV << "-----------------"<<endl;
187  }
188  EV << "-----------------"<<endl;
189  }
190 }
191 
192 void AESender::handleSelfMessage(cMessage *msg) {
193  //EV << flows.back().info() << endl;
194  if ( !strcmp(msg->getName(), S_TIM_START) ) {
195  //FIXME: Vesely - last flow in a list?!
196 
197  //Flow
198  APNamingInfo src = this->getApni();
199  APNamingInfo dst = APNamingInfo( APN(this->dstApName), this->dstApInstance,
200  this->dstAeName, this->dstAeInstance);
201 
202  FlowObject = new Flow(src, dst);
204 
205  //Insert it to the Flows ADT
206  insertFlow();
207 
209 
210  //Schedule ComRequest
211  cMessage* m = new cMessage(S_TIM_COM);
212  scheduleAt(simTime()+sendAfter+uniform(0,rate), m);
213  }
214  else if ( !strcmp(msg->getName(), S_TIM_STOP) ) {
216  }
217  else if ( !strcmp(msg->getName(), S_TIM_COM) ) {
218  if(stopAt > simTime()){
219  int tburst = intuniform(1,pduburst);
220 
221  double msgWait = tburst*rate;
222  for(int i = 0; i < tburst; i++){
223  int msgSize = size + intuniform(-sizevar,sizevar);
224  msgWait += uniform(-ratevar,ratevar);
225  //Create PING messsage
226  CDAP_M_Read* ping = new PingMsgg();
227 
228  // std::cout << "sendPing"<<endl;
229  ping->setByteLength(msgSize);
230 
231  //Send message
232  sendData(FlowObject, ping);
233  send++;
234  sendSize += msgSize;
235  }
236  //Schedule ComRequest
237  cMessage* m = new cMessage(S_TIM_COM);
238  scheduleAt(simTime()+msgWait, m);
239  }
240  }
241  else
242  EV << this->getFullPath() << " received unknown self-message " << msg->getName();
243  delete(msg);
244 }
245 
246 void AESender::handleMessage(cMessage *msg)
247 {
248  if ( msg->isSelfMessage() )
249  this->handleSelfMessage(msg);
250 }
251 
253  PingMsgg* ping = check_and_cast<PingMsgg*>(msg);
254  if(ping){
255  PongMsgg* pong = new PongMsgg(ping->pingAt);
256  pong->setByteLength(msg->getByteLength());
257 
258  sendData(FlowObject, pong);
259 /*
260  pingreceived++;
261  pingreceivedSize += msg->getByteLength();
262  simtime_t delay = simTime() - ping->pingAt;
263  if(minDelay>delay){
264  minDelay = delay;
265  }
266  if(maxDelay<delay){
267  maxDelay = delay;
268  }
269  if(firstR<0) {
270  firstR = simTime();
271  }
272  lastR = simTime();
273 */
274  }
275 }
276 
278  PongMsgg* pong = check_and_cast<PongMsgg*>(msg);
279  if(pong){
280  received++;
281  receivedSize += msg->getByteLength();
282  simtime_t delay = simTime() - pong->pingAt;
283  if(minDelay>delay){
284  minDelay = delay;
285  }
286  if(maxDelay<delay){
287  maxDelay = delay;
288  }
289  if(firstR<0) {
290  firstR = simTime();
291  }
292  lastR = simTime();
293 
294  if(recTimes){
295  double dl = dround(delay.dbl(), 3);
296  times[dl]++;
297  }
298  }
299 }
300 
301 
302 double AESender::dround(double a, int ndigits) {
303 
304  int exp_base10 = round(log10(a));
305  double man_base10 = a*pow(10.0,-exp_base10);
306  double factor = pow(10.0,-ndigits+1);
307  double truncated_man_base10 = man_base10 - fmod(man_base10,factor);
308  double rounded_remainder = fmod(man_base10,factor)/factor;
309 
310  rounded_remainder = rounded_remainder > 0.5 ? 1.0*factor : 0.0;
311 
312  return (truncated_man_base10 + rounded_remainder)*pow(10.0,exp_base10) ;
313 }
simtime_t minDelay
Definition: AESender.h:114
Class representing flow object with attributes from specs.
Definition: Flow.h:45
void setQosRequirements(const QoSReq &qosReqs)
Sets QoS parameters wanted by flow initiator.
Definition: Flow.cc:323
const char * S_PAR_DSTAPNAME
Definition: AESender.h:60
std::map< double, int > times
Definition: AESender.h:127
const char * S_PAR_DSTAPINSTANCE
Definition: AESender.h:61
Flow * FlowObject
Definition: AEBase.h:90
void prepareAllocateRequest()
Definition: AESender.cc:79
virtual void processMReadR(CDAPMessage *msg)
Definition: AESender.cc:277
CDAPConnectionState connectionState
Definition: AEBase.h:106
Application Process Name class.
Definition: APN.h:36
Definition: AE.h:44
const APNamingInfo & getApni() const
Definition: AEBase.cc:47
unsigned int sizevar
Definition: AESender.h:105
std::string getQoSId() const
Getter of selected QoS-cube identifier.
Definition: ConnectionId.cc:44
double ratevar
Definition: AESender.h:102
cModule * Cdap
Definition: AE.h:74
virtual void finish()
Definition: AESender.cc:168
simtime_t lastR
Definition: AESender.h:117
const char * S_PAR_RATE_VAR
Definition: AESender.h:66
const char * S_VAL_MODULEPATH
Definition: AESender.h:72
unsigned int size
Definition: AESender.h:104
virtual ~AESender()
Definition: AESender.cc:72
void initNamingInfo()
Definition: AEBase.cc:111
simtime_t pongAt
Definition: AESender.h:45
const char * S_MSG_PING
Definition: AESender.h:70
Definition: AEBase.h:58
long pingreceived
Definition: AESender.h:108
APNamingInfo holds complete naming info for particular application process.
Definition: APNamingInfo.h:43
std::string dstApInstance
Definition: AESender.h:89
virtual void processMRead(CDAPMessage *msg)
Definition: AESender.cc:252
AESender()
Definition: AESender.cc:48
void initPointers()
Definition: AE.cc:56
void initQoSRequiremets()
Definition: AEBase.cc:136
IRM * Irm
Definition: AE.h:73
const char * S_TIM_STOP
Definition: AESender.h:54
void prepareDeallocateRequest()
Definition: AESender.cc:86
const char * S_PAR_PING
Definition: AESender.h:71
simtime_t stopAt
Definition: AESender.h:98
void insertFlow()
Definition: AE.cc:200
const char * S_PAR_START
Definition: AESender.h:56
const char * S_PAR_RATE
Definition: AESender.h:65
double rate
Definition: AESender.h:101
simtime_t pingAt
Definition: AESender.h:45
void sendDeallocationRequest(Flow *flow)
Definition: AE.cc:377
const char * S_PAR_SEND
Definition: AESender.h:58
std::string dstAeInstance
Definition: AESender.h:91
const char * S_PAR_STOP
Definition: AESender.h:57
const ConnectionId & getConId() const
Gets read-only Flow's ConnectionId.
Definition: Flow.cc:86
virtual PingMsgg * dup() const
Definition: AESender.cc:31
const QoSReq & getQoSRequirements() const
Definition: AEBase.cc:128
double dround(double a, int ndigits)
Definition: AESender.cc:302
long received
Definition: AESender.h:109
std::string myPath
Definition: AESender.h:86
void initSignalsAndListeners()
Definition: AE.cc:67
long pingreceivedSize
Definition: AESender.h:111
virtual void handleMessage(cMessage *msg)
Definition: AESender.cc:246
virtual void initialize()
Definition: AESender.cc:92
simtime_t firstR
Definition: AESender.h:116
std::string dstApName
Definition: AESender.h:88
long receivedSize
Definition: AESender.h:112
simtime_t maxDelay
Definition: AESender.h:115
const char * S_PAR_SIZE_VAR
Definition: AESender.h:68
double recTimes
Definition: AESender.h:95
simtime_t pingAt
Definition: AESender.h:38
long send
Definition: AESender.h:107
Define_Module(AESender)
void sendData(Flow *flow, CDAPMessage *msg)
Definition: AE.cc:383
const char * S_PAR_DSTAENAME
Definition: AESender.h:62
std::string dstAeName
Definition: AESender.h:90
int pduburst
Definition: AESender.h:93
virtual PongMsgg * dup() const
Definition: AESender.cc:42
PongMsgg(simtime_t pingAt)
Definition: AESender.cc:37
PingMsgg()
Definition: AESender.cc:27
long sendSize
Definition: AESender.h:110
const char * S_PAR_SIZE
Definition: AESender.h:67
void sendAllocationRequest(Flow *flow)
Definition: AE.cc:369
const char * S_TIM_COM
Definition: AESender.h:53
void handleSelfMessage(cMessage *msg)
Definition: AESender.cc:192
simtime_t startAt
Definition: AESender.h:97
const char * S_PAR_DSTAEINSTANCE
Definition: AESender.h:63
simtime_t sendAfter
Definition: AESender.h:99
const char * S_TIM_START
Definition: AESender.h:52