RINASim  October 2016
Documentation of framework for OMNeT++
AEMyPing.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 "AEMyPing.h"
24 
26 
28  initPing();
29 }
30 
31 void AEMyPing::handleMessage(cMessage* msg) {
32  if ( msg->isSelfMessage() ) {
33  this->handleSelfMessage(msg);
34  }
35 }
36 
38  Enter_Method("afterOnStart()");
39  //Prepare flow's source and destination
40  APNamingInfo src = this->getApni();
42  this->dstAeName, this->dstAeInstance);
43 
44  //Create a flow
45  FlowObject = new Flow(src, dst);
47 
48  //Notify IRM about a new flow
49  insertFlow();
50 
51  //Call flow allocation request
53 }
54 
56  //Create PING messsage
57  CDAP_M_Read* ping = new CDAP_M_Read("ping");
58 
59  //Prepare timestamp structure that is going to be carried via ping/pong
60  timestamps_t* ts = new timestamps_t;
61  ts->t1 = simTime();
62 
63  //Prepare object and put timestamp structure inside
64  object_t obj;
65  obj.objectName = "ping_time";
66  obj.objectClass = "timestamps_t";
67  obj.objectInstance = -1;
68  obj.objectVal = (cObject*)(ts);
69  ping->setObjectItem(obj);
70  ping->setByteLength(size);
71 
72  //Send message
73  sendData(FlowObject, ping);
74 }
75 
77  //Call flow deallocation submit
79 }
80 
82  CDAP_M_Read* msg1 = check_and_cast<CDAP_M_Read*>(msg);
83  object_t object = msg1->getObjectItem();
84 
85  //Produce message to the console
86  EV << "Received M_Read with object '" << object.objectName
87  << "' of class '" << object.objectClass << "'" << endl;
88 
89  //Based on object inside do something
90  if ( strstr(object.objectName.c_str(), "ping_time") ) {
91  //Get timestamp structure inside and update it
92  timestamps_t* ts = (timestamps_t*)(object.objectVal);
93  ts->t2 = simTime();
94 
95  //Produce message to the console
96  EV << "PING sent at " << ts->t1
97  << "s, received at " << ts->t2
98  << "s, OWT1: " << (ts->t2 - ts->t1) << "s" << endl;
99 
100  //Create PING response
101  CDAP_M_Read_R* pong = new CDAP_M_Read_R("pong");
102 
103  //Prepare object and put timestamp structure inside
104  object_t obj;
105  obj.objectName = "pong_time";
106  obj.objectClass = "timestamps_t";
107  obj.objectInstance = -1;
108  obj.objectVal = (cObject*)(ts);
109  pong->setObjectItem(obj);
110  pong->setByteLength(msg1->getByteLength());
111 
112  //Send message
113  sendData(FlowObject, pong);
114  }
115 }
116 
117 
119  CDAP_M_Read_R* msg1 = check_and_cast<CDAP_M_Read_R*>(msg);
120  object_t object = msg1->getObjectItem();
121 
122  EV << "Received M_Read with object '" << object.objectName
123  << "' of class '" << object.objectClass << "'" << endl;
124 
125  //Based on object inside do something
126  if ( strstr(object.objectName.c_str(), "pong_time") ) {
127  //Get timestamp structure inside and update it
128  timestamps_t* ts = (timestamps_t*)(object.objectVal);
129  ts->t3 = simTime();
130 
131  //Produce message to the console
132  EV << "PING sent at " << ts->t1
133  << "s, received at " << ts->t2
134  << "s, responded at " << ts->t3
135  << "s, OWT1: " << (ts->t2 - ts->t1)
136  << "s, OWT2: " << (ts->t3 - ts->t2)
137  << "s, RTT: " << (ts->t3 - ts->t1) << "s" << endl;
138  }
139 }
Class representing flow object with attributes from specs.
Definition: Flow.h:45
virtual void onStop()
Definition: AEMyPing.cc:76
void setQosRequirements(const QoSReq &qosReqs)
Sets QoS parameters wanted by flow initiator.
Definition: Flow.cc:323
void handleSelfMessage(cMessage *msg)
Definition: AEPing.cc:123
::omnetpp::opp_string objectClass
Flow * FlowObject
Definition: AEBase.h:90
int objectInstance
virtual object_t & getObjectItem()
std::string dstApInstance
Definition: AEPing.h:55
Application Process Name class.
Definition: APN.h:36
const APNamingInfo & getApni() const
Definition: AEBase.cc:47
void initPing()
Definition: AEPing.cc:73
std::string dstApName
Definition: AEPing.h:54
simtime_t t3
Definition: AEMyPing.h:34
virtual void setObjectItem(const object_t &objectItem)
virtual void onPing()
Definition: AEMyPing.cc:55
APNamingInfo holds complete naming info for particular application process.
Definition: APNamingInfo.h:43
virtual void initialize()
Definition: AEMyPing.cc:27
std::string dstAeName
Definition: AEPing.h:56
unsigned int size
Definition: AEPing.h:63
void insertFlow()
Definition: AE.cc:200
virtual void processMReadR(CDAPMessage *msg)
Definition: AEMyPing.cc:118
Define_Module(AEMyPing)
void sendDeallocationRequest(Flow *flow)
Definition: AE.cc:377
virtual void afterOnStart()
Definition: AEMyPing.cc:37
const QoSReq & getQoSRequirements() const
Definition: AEBase.cc:128
ObjectPtr objectVal
virtual void handleMessage(cMessage *msg)
Definition: AEMyPing.cc:31
simtime_t t2
Definition: AEMyPing.h:33
virtual void processMRead(CDAPMessage *msg)
Definition: AEMyPing.cc:81
::omnetpp::opp_string objectName
simtime_t t1
Definition: AEMyPing.h:32
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)
std::string dstAeInstance
Definition: AEPing.h:57