RINASim  October 2016
Documentation of framework for OMNeT++
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AESInt.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 "AESInt.h"
17 
19 
21  pingAt = simTime();
22 }
23 
24 _PongMsg::_PongMsg(simtime_t _pingAt){
25  pingAt = _pingAt;
26  pongAt = simTime();
27 }
28 
29 
30 double minMaxNormal (double a, double b, int rng){
31  double rn = normal(NULL, a+(b-a)/2, (b-a)/6);
32  if(rn < a) { rn = a; }
33  if(rn > b) { rn = b; }
34  return b;
35 }
36 
38 
41  FlowObject = NULL;
42  Irm = NULL;
43  Cdap = NULL;
44 }
45 
47 {
48  //Init pointers
49  initPointers();
50  //Source info
52  //Setup signals
54  //Init QoSRequirements
56 
57  //Timers
58  startAt = simTime() + par("startAt");
59  stopAt = simTime() + par("stopAt");
60  sendAfter = par("sendAfter");
61  sendDuring = par("stopAfter");
62 
63  if(sendAfter<1){ sendAfter = 1; }
64  if(sendDuring<1){ sendDuring = 1; }
66 
67  //Destination for flow
68  dstApName = par("dstApName").stringValue();
69  dstApInstance = par("dstApInstance").stringValue();
70  dstAeName = par("dstAeName").stringValue();
71  dstAeInstance = par("dstAeInstance").stringValue();
72 
73  if (!dstAeName.compare("AeErr")) {
74  EV << "Destination AEName is set to default which is AeErr. AeErr is for special testing purposes. Are you sure that it is right?" << endl;
75  }
76 
77  //Schedule AllocateRequest & DeallocateRequest
78  if (startAt > 0) {
79  scheduleAt(startAt, new cMessage("StartCommunication"));
80  scheduleAt(startAt + sendAfter + sendDuring, new cMessage("EndCommunication"));
81  scheduleAt(stopAt, new cMessage("StopCommunication"));
82  inTime = true;
83  } else {
84  inTime = false;
85  }
86 
87 
88  //MAX PDU Size
89  maxSize = par("maxPDUsize").longValue();
90 
91  send = 0;
92  sendSize = 0;
93 
94  received = 0;
95  receivedSize = 0;
96 
97  maxDelay = -1;
98  sumDelay = 0;
99 
100  recTimes = par("recTimes").boolValue();
101 
102  //Watchers
103  WATCH(FlowObject);
104  WATCH(send);
105  WATCH(received);
106  WATCH(sendSize);
107  WATCH(receivedSize);
108  WATCH(maxDelay);
109 
110  doIni();
111 }
112 
114 {
115  if(par("printAtEnd").boolValue()){
116  EV << "At "<<this->getApni()<<endl;
117  if(FlowObject != NULL) {
118  EV << "With QoS " << FlowObject->getConId().getQoSId() <<endl;
119  }
120  EV << "send " << send << " ("<<sendSize << ")"<<endl;
121  EV << "pongs Rcv " << received << " ("<<receivedSize << ")"<<endl;
122  if(received > 0){
123  EV << "Delay " << (sumDelay/received) << " ("<< maxDelay << ")" <<endl;
124  }
125 
126  if(recTimes){
127  EV << "-----------------"<<endl;
128  for(std::map<double, int>::iterator it = times.begin(); it!=times.end(); it++) {
129  EV << " " << it->first << " " << it->second <<endl;
130  }
131  EV << "-----------------"<<endl;
132  }
133  EV << "-----------------"<<endl;
134  }
135 
136  doFin();
137 }
138 
139 void AESInt::handleSelfMessage(cMessage *msg) {
140  if ( !strcmp(msg->getName(), "StartCommunication") ) {
141  APNamingInfo src = this->getApni();
142  APNamingInfo dst = APNamingInfo( APN(this->dstApName), this->dstApInstance, this->dstAeName, this->dstAeInstance);
143  FlowObject = new Flow(src, dst);
145  insertFlow();
147  scheduleAt(simTime()+sendAfter, new cMessage("MakeCommunication"));
148  } else if ( !strcmp(msg->getName(), "StopCommunication") ) {
150  } else if ( !strcmp(msg->getName(), "EndCommunication") ) {
151  inTime = false;
152  } else if ( !strcmp(msg->getName(), "MakeCommunication") ) {
153  if(stopAt > simTime()){ iniCom(); }
154  }
155 
156  delete(msg);
157 }
158 
159 void AESInt::handleMessage(cMessage *msg) {
160  if ( msg->isSelfMessage() ) {
161  if(_AESInt_self * smsg = dynamic_cast<_AESInt_self*>(msg)){
162  processMsg(smsg);
163  } else {
164  this->handleSelfMessage(msg);
165  }
166  }
167 }
168 
170  if(_PingMsg* ping = dynamic_cast<_PingMsg*>(msg)){
171  processMsg(ping);
172  }
173 }
174 
176  if(_PongMsg* pong = dynamic_cast<_PongMsg*>(msg)){
177  received++;
178  receivedSize += msg->getByteLength();
179 
180  simtime_t delay = simTime() - pong->pingAt;
181  sumDelay += delay;
182  if(maxDelay<delay){
183  maxDelay = delay;
184  }
185 
186  if(recTimes){
187  double dl = dround(delay.dbl(), 3);
188  times[dl]++;
189  }
190 
191  processMsg(pong);
192  }
193 }
194 
195 
196 void AESInt::sendMsg(_PingMsg * msg, int size){
197  send++;
198  sendSize += size;
199 
200  msg->setByteLength(size);
201  sendData(FlowObject, msg);
202 }
203 
204 void AESInt::sendMsg(_PongMsg * msg, int size){
205  msg->setByteLength(size);
206  sendData(FlowObject, msg);
207 }
208 
210 
212  _PongMsg* pong = new _PongMsg(ping->pingAt);
213  sendMsg(pong, ping->getByteLength());
214 }
215 
217 
218 
219 double AESInt::dround(double a, int ndigits) {
220  int exp_base10 = round(log10(a));
221  double man_base10 = a*pow(10.0,-exp_base10);
222  double factor = pow(10.0,-ndigits+1);
223  double truncated_man_base10 = man_base10 - fmod(man_base10,factor);
224  double rounded_remainder = fmod(man_base10,factor)/factor;
225 
226  rounded_remainder = rounded_remainder > 0.5 ? 1.0*factor : 0.0;
227 
228  return (truncated_man_base10 + rounded_remainder)*pow(10.0,exp_base10) ;
229 }
virtual ~AESInt()
Definition: AESInt.cc:39
double recTimes
Definition: AESInt.h:84
simtime_t sumDelay
Definition: AESInt.h:88
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
Flow * FlowObject
Definition: AEBase.h:90
virtual void processMsg(_AESInt_self *)
Definition: AESInt.cc:209
std::string dstApName
Definition: AESInt.h:69
CDAPConnectionState connectionState
Definition: AEBase.h:106
Application Process Name class.
Definition: APN.h:36
long send
Definition: AESInt.h:79
double minMaxNormal(double a, double b, int rng)
Definition: AESInt.cc:30
Definition: AE.h:44
virtual void doFin()=0
const APNamingInfo & getApni() const
Definition: AEBase.cc:47
std::string getQoSId() const
Getter of selected QoS-cube identifier.
Definition: ConnectionId.cc:44
cModule * Cdap
Definition: AE.h:74
virtual void processMReadR(CDAPMessage *msg)
Definition: AESInt.cc:175
std::map< double, int > times
Definition: AESInt.h:85
void initNamingInfo()
Definition: AEBase.cc:111
Definition: AEBase.h:58
virtual void finish()
Definition: AESInt.cc:113
APNamingInfo holds complete naming info for particular application process.
Definition: APNamingInfo.h:43
void initPointers()
Definition: AE.cc:56
void initQoSRequiremets()
Definition: AEBase.cc:136
simtime_t maxDelay
Definition: AESInt.h:87
IRM * Irm
Definition: AE.h:73
long receivedSize
Definition: AESInt.h:82
void sendMsg(_PingMsg *, int)
Definition: AESInt.cc:196
simtime_t sendAfter
Definition: AESInt.h:77
void insertFlow()
Definition: AE.cc:200
std::string dstApInstance
Definition: AESInt.h:70
long received
Definition: AESInt.h:80
simtime_t startAt
Definition: AESInt.h:74
std::string dstAeInstance
Definition: AESInt.h:72
void handleSelfMessage(cMessage *msg)
Definition: AESInt.cc:139
std::string dstAeName
Definition: AESInt.h:71
void sendDeallocationRequest(Flow *flow)
Definition: AE.cc:377
virtual void handleMessage(cMessage *msg)
Definition: AESInt.cc:159
const ConnectionId & getConId() const
Gets read-only Flow's ConnectionId.
Definition: Flow.cc:86
const QoSReq & getQoSRequirements() const
Definition: AEBase.cc:128
virtual void iniCom()=0
virtual void doIni()=0
void initSignalsAndListeners()
Definition: AE.cc:67
simtime_t sendDuring
Definition: AESInt.h:76
bool inTime
Definition: AESInt.h:54
virtual void initialize()
Definition: AESInt.cc:46
int maxSize
Definition: AESInt.h:55
simtime_t stopAt
Definition: AESInt.h:75
simtime_t pingAt
Definition: AESInt.h:36
virtual void processMRead(CDAPMessage *msg)
Definition: AESInt.cc:169
double dround(double a, int ndigits)
Definition: AESInt.cc:219
AESInt()
Definition: AESInt.cc:37
simtime_t pongAt
Definition: AESInt.h:42
_PingMsg()
Definition: AESInt.cc:20
simtime_t pingAt
Definition: AESInt.h:42
_PongMsg(simtime_t pingAt)
Definition: AESInt.cc:24
void sendData(Flow *flow, CDAPMessage *msg)
Definition: AE.cc:383
long sendSize
Definition: AESInt.h:81
_AESInt_self()
Definition: AESInt.cc:18
void sendAllocationRequest(Flow *flow)
Definition: AE.cc:369