RINASim  October 2016
Documentation of framework for OMNeT++
AEStream.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 "AEStream.h"
24 
26 
28  //Consts
29  TIM_START = "StartCommunication";
30  TIM_STOP = "StopCommunication";
31  MSG_STDATA = "DATA-";
32  PAR_START = "startAt";
33  PAR_STOP = "stopAt";
34  PAR_BEGIN = "beginStreamAt";
35  PAR_END = "endStreamAt";
36  PAR_INTERVAL = "interval";
37  PAR_SIZE = "size";
38  PAR_DSTAPNAME = "dstApName";
39  PAR_DSTAPINSTANCE = "dstApInstance";
40  PAR_DSTAENAME = "dstAeName";
41  PAR_DSTAEINSTANCE = "dstAeInstance";
42 }
43 
44 
46 {
47  //Init pointers
48  initPointers();
49  //Source info
51  //Setup signals
53  //Init QoSRequirements
55 
56  //Destination for flow
57  dstApName = this->par(PAR_DSTAPNAME).stringValue();
58  dstApInstance = this->par(PAR_DSTAPINSTANCE).stringValue();
59  dstAeName = this->par(PAR_DSTAENAME).stringValue();
60  dstAeInstance = this->par(PAR_DSTAEINSTANCE).stringValue();
61 
62  if (!dstAeName.compare("AeErr")) {
63  EV << "Destination AEName is set to default which is AeErr. AeErr is for special testing purposes. Are you sure that it is right?" << endl;
64  }
65 
66  //Timers
67  startAt = simTime() + par(PAR_START);
68  stopAt = simTime() + par(PAR_STOP);
69  beginStreamAt = simTime() + par(PAR_BEGIN);
70  endStreamAt = simTime() + par(PAR_END);
71  interval = par(PAR_INTERVAL).doubleValue();
72  size = par(PAR_SIZE);
73 
74  //Schedule AllocateRequest
75  if (startAt > 0)
77  //Schedule Data transfer
80  //Schedule DeallocateRequest
81  if (stopAt > 0)
83 
84 
85 }
86 
87 void AEStream::handleMessage(cMessage *msg)
88 {
89  if ( msg->isSelfMessage() )
90  this->handleSelfMessage(msg);
91 }
92 
94 
95  APNIPair* apnip = new APNIPair(
98  srcAeName,
102  dstAeName,
103  dstAeInstance));
104 
105  emit(sigAEEnrolled, apnip);
106 }
107 
109  //Flow
110  APNamingInfo src = this->getApni();
111  APNamingInfo dst = APNamingInfo( APN(this->dstApName), this->dstApInstance,
112  this->dstAeName, this->dstAeInstance);
113 
114  FlowObject = new Flow(src, dst);
116 
117  //Insert it to the Flows ADT
118  insertFlow();
119 
121 }
122 
123 void AEStream::handleSelfMessage(cMessage* msg) {
124  if ( !strcmp(msg->getName(), TIM_START) ) {
125  onStart();
126  }
127  else if ( !strcmp(msg->getName(), TIM_STOP) ) {
129  }
130  else if ( strstr(msg->getName(), MSG_STDATA) ) {
131  //Create data stream chunk messsage
132  CDAP_M_Read* data = new CDAP_M_Read(msg->getName());
133  object_t obj;
134  obj.objectName = msg->getName();
135  obj.objectClass = "string";
136  obj.objectInstance = -1;
137  obj.objectVal = (cObject*)("0123456789abcdef");
138  data->setObjectItem(obj);
139  data->setByteLength(size);
140 
141  //Send message
142  sendData(FlowObject, data);
143  }
144  else
145  EV << this->getFullPath() << " received unknown self-message " << msg->getName();
146  delete(msg);
147 }
148 
150  //Schedule AllocateRequest
151  cMessage* m1 = new cMessage(TIM_START);
152  scheduleAt(startAt, m1);
153 }
154 
156  //Schedule stream data chunk
157  int j = 0;
158  for (simtime_t i = beginStreamAt; i < endStreamAt; i += interval) {
159  std::ostringstream ss;
160  ss << MSG_STDATA << j++;
161  cMessage* m2 = new cMessage(ss.str().c_str());
162  scheduleAt(i, m2);
163  }
164 }
165 
167  //Schedule DeallocateRequest
168  cMessage* m3 = new cMessage(TIM_STOP);
169  scheduleAt(stopAt, m3);
170 }
171 
173  CDAP_M_Read* msg1 = check_and_cast<CDAP_M_Read*>(msg);
174 
175  EV << "Received data M_DATA";
176  object_t object = msg1->getObjectItem();
177  EV << " with object '" << object.objectClass << "' and value '" << object.objectVal << "'" << endl;
178 
179 }
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
std::string dstApInstance
Definition: AEStream.h:54
virtual void initialize()
Definition: AEStream.cc:45
const char * MSG_STDATA
Definition: AEStream.h:37
Flow * FlowObject
Definition: AEBase.h:90
simsignal_t sigAEEnrolled
Definition: AE.h:95
Application Process Name class.
Definition: APN.h:36
Define_Module(AEStream)
Definition: AE.h:44
const APNamingInfo & getApni() const
Definition: AEBase.cc:47
const char * PAR_DSTAENAME
Definition: AEStream.h:46
void prepareDeallocateRequest()
Definition: AEStream.cc:166
simtime_t beginStreamAt
Definition: AEStream.h:60
std::string srcAeInstance
Definition: AEBase.h:96
const char * PAR_BEGIN
Definition: AEStream.h:40
std::string dstAeInstance
Definition: AEStream.h:56
void initNamingInfo()
Definition: AEBase.cc:111
virtual void setObjectItem(const object_t &objectItem)
std::string srcAeName
Definition: AEBase.h:95
const char * PAR_STOP
Definition: AEStream.h:39
APNamingInfo holds complete naming info for particular application process.
Definition: APNamingInfo.h:43
simtime_t startAt
Definition: AEStream.h:58
const char * PAR_END
Definition: AEStream.h:41
void initPointers()
Definition: AE.cc:56
void afterOnStart()
Definition: AEStream.cc:108
void initQoSRequiremets()
Definition: AEBase.cc:136
void prepareAllocateRequest()
Definition: AEStream.cc:149
const char * PAR_SIZE
Definition: AEStream.h:43
const char * PAR_START
Definition: AEStream.h:38
const char * PAR_DSTAEINSTANCE
Definition: AEStream.h:47
void insertFlow()
Definition: AE.cc:200
const char * TIM_STOP
Definition: AEStream.h:36
void sendDeallocationRequest(Flow *flow)
Definition: AE.cc:377
virtual void processMRead(CDAPMessage *msg)
Definition: AEStream.cc:172
void handleSelfMessage(cMessage *msg)
Definition: AEStream.cc:123
const QoSReq & getQoSRequirements() const
Definition: AEBase.cc:128
void initSignalsAndListeners()
Definition: AE.cc:67
AEStream()
Definition: AEStream.cc:27
double interval
Definition: AEStream.h:64
void prepareStreamData()
Definition: AEStream.cc:155
virtual void handleMessage(cMessage *msg)
Definition: AEStream.cc:87
std::string srcApInstance
Definition: AEBase.h:94
void onStart()
Definition: AEStream.cc:93
::omnetpp::opp_string objectName
const char * PAR_DSTAPINSTANCE
Definition: AEStream.h:45
void sendData(Flow *flow, CDAPMessage *msg)
Definition: AE.cc:383
const char * TIM_START
Definition: AEStream.h:35
virtual object_t & getObjectItem()
std::string srcApName
Definition: AEBase.h:93
std::string dstApName
Definition: AEStream.h:53
void sendAllocationRequest(Flow *flow)
Definition: AE.cc:369
unsigned int size
Definition: AEStream.h:63
simtime_t endStreamAt
Definition: AEStream.h:61
simtime_t stopAt
Definition: AEStream.h:59
const char * PAR_INTERVAL
Definition: AEStream.h:42
const char * PAR_DSTAPNAME
Definition: AEStream.h:44
std::string dstAeName
Definition: AEStream.h:55