RINASim  October 2016
Documentation of framework for OMNeT++
AEPing.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 "AEPing.h"
24 
26 
28  //Consts
29  TIM_START = "StartCommunication";
30  TIM_STOP = "StopCommunication";
31  MSG_PING = "PING-";
32  PAR_START = "startAt";
33  PAR_STOP = "stopAt";
34  PAR_PING = "pingAt";
35  PAR_RATE = "rate";
36  PAR_SIZE = "size";
37  PAR_DSTAPNAME = "dstApName";
38  PAR_DSTAPINSTANCE = "dstApInstance";
39  PAR_DSTAENAME = "dstAeName";
40  PAR_DSTAEINSTANCE = "dstAeInstance";
41  VAL_MODULEPATH = "getFullPath()";
42 }
43 
46  FlowObject = NULL;
47  Irm = NULL;
48  Cdap = NULL;
49 }
50 
52  //Schedule AllocateRequest
53  cMessage* m1 = new cMessage(TIM_START);
54  scheduleAt(startAt, m1);
55 }
56 
58  //Schedule Data transfer
59  for (int i = 0; i < rate && pingAt + i < stopAt; i++) {
60  std::ostringstream ss;
61  ss << MSG_PING << i;
62  cMessage* m2 = new cMessage(ss.str().c_str());
63  scheduleAt(pingAt + i, m2);
64  }
65 }
66 
68  //Schedule DeallocateRequest
69  cMessage* m3 = new cMessage(TIM_STOP);
70  scheduleAt(stopAt, m3);
71 }
72 
74  //Init pointers
75  initPointers();
76  //Source info
78  //Setup signals
80  //Init QoSRequirements
82 
83  //Timers
84  startAt = simTime() + par(PAR_START);
85  stopAt = simTime() + par(PAR_STOP);
86  pingAt = simTime() + par(PAR_PING);
87  rate = par(PAR_RATE);
88  size = par(PAR_SIZE);
89 
90  //Destination for flow
91  dstApName = this->par(PAR_DSTAPNAME).stringValue();
92  dstApInstance = this->par(PAR_DSTAPINSTANCE).stringValue();
93  dstAeName = this->par(PAR_DSTAENAME).stringValue();
94  dstAeInstance = this->par(PAR_DSTAEINSTANCE).stringValue();
95 
96  if (!dstAeName.compare("AeErr")) {
97  EV << "AEName is set to default which is AeErr. AeErr is for special testing purposes. Are you sure that it is right?" << endl;
98  }
99 
100  //Schedule AllocateRequest
101  if (startAt > 0)
103  //Schedule Data transfer
104  if (pingAt > 0)
105  preparePing();
106  //Schedule DeallocateRequest
107  if (stopAt > 0)
109 
110  //Watchers
111  WATCH(FlowObject);
112  WATCH(connectionState);
113 
114 }
115 
117 {
118  initPing();
119 
120  myPath = this->getFullPath();
121 }
122 
123 void AEPing::handleSelfMessage(cMessage *msg) {
124  //EV << flows.back().info() << endl;
125  if ( !strcmp(msg->getName(), TIM_START) ) {
126  onStart();
127  }
128  else if ( !strcmp(msg->getName(), TIM_STOP) ) {
129  onStop();
130  }
131  else if ( strstr(msg->getName(), MSG_PING) ) {
132  onPing();
133  }
134  else
135  EV << this->getFullPath() << " received unknown self-message " << msg->getName();
136  delete(msg);
137 }
138 
139 void AEPing::handleMessage(cMessage *msg)
140 {
141  if ( msg->isSelfMessage() )
142  this->handleSelfMessage(msg);
143 }
144 
146  AEPing::connect();
147 }
148 
150  APNIPair* apnip = new APNIPair(
153  srcAeName,
154  srcAeInstance),
157  dstAeName,
158  dstAeInstance));
159 
160  emit(sigAEEnrolled, apnip);
161 }
162 
164  Enter_Method("afterConnect()");
165  //Prepare flow's source and destination
166  APNamingInfo src = this->getApni();
167  APNamingInfo dst = APNamingInfo( APN(this->dstApName), this->dstApInstance,
168  this->dstAeName, this->dstAeInstance);
169 
170  //Create a flow
171  FlowObject = new Flow(src, dst);
173 
174  //Notify IRM about a new flow
175  insertFlow();
176 
177  //Call flow allocation request
179 }
180 
182 
183  //Create PING messsage
185  object_t obj;
187  obj.objectClass = "string";
188  obj.objectInstance = -1;
189  obj.objectVal = (cObject*)(&myPath);
190  ping->setObjectItem(obj);
191  ping->setByteLength(size);
192 
193  //Send message
194  sendData(FlowObject, ping);
195 
196 }
197 
199 
200  //Call flow deallocation submit
202 }
203 
205  CDAP_M_Read* msg1 = check_and_cast<CDAP_M_Read*>(msg);
206 
207  EV << "Received M_Read";
208  object_t object = msg1->getObjectItem();
209  EV << " with object '" << object.objectClass << "'" << endl;
210 
211  if ( strstr(object.objectName.c_str(), VAL_MODULEPATH) ) {
212  std::string* source = (std::string*)(object.objectVal);
213  std::ostringstream os;
214  os << "Ping requested by " << *source << endl;
215  bubble(os.str().c_str());
216  EV << os.str().c_str();
217 
218  //Create PING response
220  object_t obj;
222  obj.objectClass = "string";
223  obj.objectInstance = -1;
224  obj.objectVal = (cObject*)(&myPath);
225  pong->setObjectItem(obj);
226 
227  sendData(FlowObject, pong);
228  }
229 }
230 
232  CDAP_M_Read_R* msg1 = check_and_cast<CDAP_M_Read_R*>(msg);
233 
234  EV << "Received M_Read_R";
235  object_t object = msg1->getObjectItem();
236  EV << " with object '" << object.objectClass << "'" << endl;
237 
238  if ( strstr(object.objectName.c_str(), VAL_MODULEPATH) ) {
239  std::string* source = (std::string*)(object.objectVal);
240  std::ostringstream os;
241  os << "Ping replied by " << *source << endl;
242  bubble(os.str().c_str());
243  EV << os.str().c_str();
244  }
245 }
const char * MSG_PING
Definition: AEPing.h:36
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
void handleSelfMessage(cMessage *msg)
Definition: AEPing.cc:123
simtime_t startAt
Definition: AEPing.h:59
::omnetpp::opp_string objectClass
Definition: AEPing.h:31
const char * PAR_DSTAPINSTANCE
Definition: AEPing.h:43
const char * PAR_START
Definition: AEPing.h:37
Flow * FlowObject
Definition: AEBase.h:90
simsignal_t sigAEEnrolled
Definition: AE.h:95
int objectInstance
void prepareAllocateRequest()
Definition: AEPing.cc:51
AEPing()
Definition: AEPing.cc:27
virtual object_t & getObjectItem()
std::string dstApInstance
Definition: AEPing.h:55
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
cModule * Cdap
Definition: AE.h:74
void connect()
Definition: AEPing.cc:149
virtual void onStop()
Definition: AEPing.cc:198
void initPing()
Definition: AEPing.cc:73
simtime_t pingAt
Definition: AEPing.h:61
std::string dstApName
Definition: AEPing.h:54
std::string srcAeInstance
Definition: AEBase.h:96
const char * TIM_START
Definition: AEPing.h:34
virtual ~AEPing()
Definition: AEPing.cc:44
void initNamingInfo()
Definition: AEBase.cc:111
virtual void processMReadR(CDAPMessage *msg)
Definition: AEPing.cc:231
virtual void setObjectItem(const object_t &objectItem)
Definition: AEBase.h:58
const char * PAR_DSTAPNAME
Definition: AEPing.h:42
std::string srcAeName
Definition: AEBase.h:95
APNamingInfo holds complete naming info for particular application process.
Definition: APNamingInfo.h:43
const char * PAR_DSTAEINSTANCE
Definition: AEPing.h:45
void initPointers()
Definition: AE.cc:56
void initQoSRequiremets()
Definition: AEBase.cc:136
const char * VAL_MODULEPATH
Definition: AEPing.h:46
IRM * Irm
Definition: AE.h:73
const char * PAR_DSTAENAME
Definition: AEPing.h:44
std::string dstAeName
Definition: AEPing.h:56
virtual void handleMessage(cMessage *msg)
Definition: AEPing.cc:139
unsigned int size
Definition: AEPing.h:63
Define_Module(AEPing)
const char * PAR_PING
Definition: AEPing.h:39
void insertFlow()
Definition: AE.cc:200
void onStart()
Definition: AEPing.cc:145
void sendDeallocationRequest(Flow *flow)
Definition: AE.cc:377
void prepareDeallocateRequest()
Definition: AEPing.cc:67
virtual void processMRead(CDAPMessage *msg)
Definition: AEPing.cc:204
virtual void afterOnStart()
Definition: AEPing.cc:163
const QoSReq & getQoSRequirements() const
Definition: AEBase.cc:128
ObjectPtr objectVal
void initSignalsAndListeners()
Definition: AE.cc:67
std::string myPath
Definition: AEPing.h:87
void preparePing()
Definition: AEPing.cc:57
const char * PAR_SIZE
Definition: AEPing.h:41
std::string srcApInstance
Definition: AEBase.h:94
::omnetpp::opp_string objectName
const char * PAR_STOP
Definition: AEPing.h:38
const char * TIM_STOP
Definition: AEPing.h:35
int rate
Definition: AEPing.h:62
simtime_t stopAt
Definition: AEPing.h:60
void sendData(Flow *flow, CDAPMessage *msg)
Definition: AE.cc:383
virtual void onPing()
Definition: AEPing.cc:181
virtual object_t & getObjectItem()
std::string srcApName
Definition: AEBase.h:93
void sendAllocationRequest(Flow *flow)
Definition: AE.cc:369
virtual void initialize()
Definition: AEPing.cc:116
virtual void setObjectItem(const object_t &objectItem)
const char * PAR_RATE
Definition: AEPing.h:40
std::string dstAeInstance
Definition: AEPing.h:57