RINASim  October 2016
Documentation of framework for OMNeT++
AEExtendedPing.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 "AEExtendedPing.h"
24 
26 
27 //Consts
28 const char* TIM_START_E = "StartCommunication";
29 const char* TIM_CONNECT_E = "StartConnection";
30 const char* TIM_STOP_E = "StopCommunication";
31 const char* MSG_PING_E = "PING-";
32 const char* PAR_START_E = "startAt";
33 const char* PAR_STOP_E = "stopAt";
34 const char* PAR_CONNECT_E = "connectAt";
35 const char* PAR_PING_E = "pingAt";
36 const char* PAR_RATE_E = "rate";
37 const char* PAR_SIZE_E = "size";
38 const char* PAR_DSTAPNAME_E = "dstApName";
39 const char* PAR_DSTAPINSTANCE_E = "dstApInstance";
40 const char* PAR_DSTAENAME_E = "dstAeName";
41 const char* PAR_DSTAEINSTANCE_E = "dstAeInstance";
42 const char* PAR_AUTH_TYPE_E = "authType";
43 const char* PAR_AUTH_NAME_E = "authName";
44 const char* PAR_AUTH_OTHER_E = "authOther";
45 const char* PAR_AUTH_PASS_E = "authPassword";
46 const char* VAL_MODULEPATH_E = "getFullPath()";
47 const char* VAL_CONNECTION_E = "connect";
48 const char* VAL_RELEASE_E = "release";
49 
50 
52 }
53 
56  FlowObject = NULL;
57  Irm = NULL;
58  Cdap = NULL;
59 }
60 
62  //Schedule AllocateRequest
63  cMessage* m1 = new cMessage(TIM_START_E);
64  scheduleAt(startAt, m1);
65 }
66 
68  //Schedule Data transfer
69  for (int i = 0; i < rate && pingAt + i < stopAt; i++) {
70  std::ostringstream ss;
71  ss << MSG_PING_E << i;
72  cMessage* m2 = new cMessage(ss.str().c_str());
73  scheduleAt(pingAt + i, m2);
74  }
75 }
76 
78  //Schedule DeallocateRequest
79  cMessage* m3 = new cMessage(TIM_STOP_E);
80  scheduleAt(stopAt, m3);
81 }
82 
84  cMessage* m4 = new cMessage(TIM_CONNECT_E);
85  scheduleAt(connectAt, m4);
86 }
87 
89 {
90  //Init pointers
91  initPointers();
92  //Source info
94  //Setup signals
96  //Init QoSRequirements
98 
99  //Timers
100  startAt = simTime() + par(PAR_START_E);
101  stopAt = simTime() + par(PAR_STOP_E);
102  connectAt = simTime() + par(PAR_CONNECT_E);
103  pingAt = simTime() + par(PAR_PING_E);
104  rate = par(PAR_RATE_E);
105  size = par(PAR_SIZE_E);
106 
107  //Authentication for application
108  authType = par(PAR_AUTH_TYPE_E);
109  authName = this->par(PAR_AUTH_NAME_E).stringValue();
110  authPassword = this->par(PAR_AUTH_PASS_E).stringValue();
111  authOther = this->par(PAR_AUTH_OTHER_E).stringValue();
112 
113  //Destination for flow
114  dstApName = this->par(PAR_DSTAPNAME_E).stringValue();
115  dstApInstance = this->par(PAR_DSTAPINSTANCE_E).stringValue();
116  dstAeName = this->par(PAR_DSTAENAME_E).stringValue();
117  dstAeInstance = this->par(PAR_DSTAEINSTANCE_E).stringValue();
118 
119  //Schedule AllocateRequest
120  if (startAt > 0)
122  //Schedule Data transfer
123  if (pingAt > 0)
124  preparePing();
125 
126  //Schedule CACEConnectionRequest
127  if (connectAt > 0)
129 
130  //Schedule DeallocateRequest
131  if (stopAt > 0)
133 
134  myPath = this->getFullPath();
135 
136  //Watchers
137  WATCH(FlowObject);
138  //WATCH_LIST(flows);
139  WATCH(connectionState);
140 }
141 
143  //EV << flows.back().info() << endl;
144  if ( !strcmp(msg->getName(), TIM_START_E) ) {
145  //FIXME: Vesely - last flow in a list?!
146 
147  //Flow
148  APNamingInfo src = this->getApni();
149  APNamingInfo dst = APNamingInfo( APN(this->dstApName), this->dstApInstance,
150  this->dstAeName, this->dstAeInstance);
151 
152  FlowObject = new Flow(src, dst);
154 
155  //Insert it to the Flows ADT
156  insertFlow();
157 
159  }
160  else if ( !strcmp(msg->getName(), TIM_CONNECT_E)){
161  //Create MConnect message
163  authValue_t aValue;
164  aValue.authName = authName;
165  aValue.authPassword = authPassword;
166  aValue.authOther = authOther;
167 
168  auth_t auth;
169  auth.authType = authType;
170  auth.authValue = aValue;
171 
172  connect->setAuth(auth);
173  connect->setAbsSyntax(GPB);
174  connect->setOpCode(M_CONNECT);
175 
176  //Send message
177  sendData(FlowObject, connect);
178  }
179  else if ( !strcmp(msg->getName(), TIM_STOP_E) ) {
180  CDAP_M_Release* releaseRequest = new CDAP_M_Release(VAL_RELEASE_E);
181  releaseRequest->setInvokeID(0);
182 
183  sendData(FlowObject, releaseRequest);
184 
185  }
186  else if ( strstr(msg->getName(), MSG_PING_E) ) {
187  //Create PING messsage
189  object_t obj;
191  obj.objectClass = "string";
192  obj.objectInstance = -1;
193  obj.objectVal = (cObject*)(&myPath);
194  ping->setObjectItem(obj);
195  ping->setByteLength(size);
196 
197  //Send message
198  sendData(FlowObject, ping);
199  }
200  else
201  EV << this->getFullPath() << " received unknown self-message " << msg->getName();
202  delete(msg);
203 }
204 
205 void AEExtendedPing::handleMessage(cMessage *msg)
206 {
207  if ( msg->isSelfMessage() )
208  this->handleSelfMessage(msg);
209 }
210 
212  CDAP_M_Read* msg1 = check_and_cast<CDAP_M_Read*>(msg);
213 
214  EV << "Received M_Read";
215  object_t object = msg1->getObjectItem();
216  EV << " with object '" << object.objectClass << "'" << endl;
217 
218  if ( strstr(object.objectName.c_str(), VAL_MODULEPATH_E) ) {
219  std::string* source = (std::string*)(object.objectVal);
220  std::ostringstream os;
221  os << "Ping requested by " << *source << endl;
222  bubble(os.str().c_str());
223  EV << os.str().c_str();
224 
225  //Create PING response
227  object_t obj;
229  obj.objectClass = "string";
230  obj.objectInstance = -1;
231  obj.objectVal = (cObject*)(&myPath);
232  pong->setObjectItem(obj);
233 
234  sendData(FlowObject, pong);
235  }
236 }
237 
239  CDAP_M_Read_R* msg1 = check_and_cast<CDAP_M_Read_R*>(msg);
240 
241  EV << "Received M_Read_R";
242  object_t object = msg1->getObjectItem();
243  EV << " with object '" << object.objectClass << "'" << endl;
244 
245  if ( strstr(object.objectName.c_str(), VAL_MODULEPATH_E) ) {
246  std::string* source = (std::string*)(object.objectVal);
247  std::ostringstream os;
248  os << "Ping replied by " << *source << endl;
249  bubble(os.str().c_str());
250  EV << os.str().c_str();
251  }
252 }
253 
std::string myPath
const char * VAL_CONNECTION_E
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
::omnetpp::opp_string objectClass
const char * PAR_DSTAPNAME_E
virtual void setAuth(const auth_t &auth)
void prepareConnectionRequest()
Flow * FlowObject
Definition: AEBase.h:90
int objectInstance
const char * PAR_STOP_E
virtual object_t & getObjectItem()
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 prepareAllocateRequest()
virtual ~AEExtendedPing()
simtime_t pingAt
const char * VAL_MODULEPATH_E
virtual void setAbsSyntax(int32_t absSyntax)
::omnetpp::opp_string authName
authValue_t authValue
Flow * getFlowObject() const
Definition: AEBase.cc:181
void initNamingInfo()
Definition: AEBase.cc:111
const char * PAR_DSTAENAME_E
const char * PAR_AUTH_OTHER_E
std::string authName
Definition: AEBase.h:99
virtual void setObjectItem(const object_t &objectItem)
const char * VAL_RELEASE_E
virtual void processMReadR(CDAPMessage *msg)
const char * MSG_PING_E
unsigned char authType
Definition: AEBase.h:58
const char * PAR_DSTAPINSTANCE_E
virtual void connect()
Definition: AE.cc:521
const char * TIM_STOP_E
APNamingInfo holds complete naming info for particular application process.
Definition: APNamingInfo.h:43
const char * TIM_CONNECT_E
void initPointers()
Definition: AE.cc:56
void initQoSRequiremets()
Definition: AEBase.cc:136
IRM * Irm
Definition: AE.h:73
const char * PAR_AUTH_TYPE_E
const char * PAR_RATE_E
Define_Module(AEExtendedPing)
unsigned int size
std::string authOther
Definition: AEBase.h:101
std::string dstApName
simtime_t connectAt
std::string authPassword
Definition: AEBase.h:100
std::string dstAeName
virtual void handleMessage(cMessage *msg)
virtual void setInvokeID(int32_t invokeID)
void insertFlow()
Definition: AE.cc:200
void prepareDeallocateRequest()
void handleSelfMessage(cMessage *msg)
const char * PAR_CONNECT_E
const char * PAR_AUTH_PASS_E
virtual void setOpCode(int32_t opCode)
const char * PAR_DSTAEINSTANCE_E
virtual void processMRead(CDAPMessage *msg)
const char * TIM_START_E
const QoSReq & getQoSRequirements() const
Definition: AEBase.cc:128
const char * PAR_SIZE_E
ObjectPtr objectVal
void initSignalsAndListeners()
Definition: AE.cc:67
int authType
Definition: AEBase.h:98
std::string dstApInstance
const char * PAR_AUTH_NAME_E
simtime_t startAt
const char * PAR_START_E
simtime_t stopAt
::omnetpp::opp_string authPassword
virtual void initialize()
std::string dstAeInstance
::omnetpp::opp_string objectName
::omnetpp::opp_string authOther
const char * PAR_PING_E
void sendData(Flow *flow, CDAPMessage *msg)
Definition: AE.cc:383
virtual object_t & getObjectItem()
void sendAllocationRequest(Flow *flow)
Definition: AE.cc:369
virtual void setObjectItem(const object_t &objectItem)