RINASim  October 2016
Documentation of framework for OMNeT++
AP.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 <AP/AP.h>
24 
26 
28  this->isEnrolled = this->EnrollmentState::NOT_ENROLLED;
29 }
30 
32 }
33 
35  initPointers();
37 }
38 
40  cModule* catcher1 = this->getParentModule();
41  cModule* catcher2 = this->getModuleByPath("^.^");
42 
43  sigAPAEAPI = registerSignal(SIG_AP_AE_API);
44  sigAEEnrolled = registerSignal(SIG_AE_Enrolled);
45 
46  // AllocationRequest from FAI
48  catcher2->subscribe(SIG_FAI_AllocateRequest, lisAPAllReqFromFai);
49 
50 
51  // Enrollment
52  lisAPEnrolled = new LisAPEnrolled(this);
54 
55  // API listeners
56  lisAEAPAPI = new LisAEAPAPI(this);
57  catcher1->subscribe(SIG_AE_AP_API, lisAEAPAPI);
58 }
59 
61 }
62 
63 void AP::onA_getOpen(APIResult* result) {
64 }
65 
66 void AP::onA_getRead(APIResult* result) {
67 }
68 
69 void AP::onA_getWrite(APIResult* result) {
70 }
71 
72 void AP::onClose(APIResult* result) {
73 }
74 
75 bool AP::a_open(int invokeID, std::string APName, std::string APInst, std::string AEName, std::string AEInst) {
76  if (this->isEnrolled == this->EnrollmentState::NOT_ENROLLED) {
77  APNIPair* apnip = new APNIPair(
78  APNamingInfo(APN(this->getParentModule()->par("apName").stringValue()),
79  "0",
80  "Mgmt",
81  "0"),
82  APNamingInfo(APN(APName),
83  "0",
84  "Mgmt",
85  "0"));
86 
87  emit(sigAEEnrolled, apnip);
88  this->isEnrolled = this->EnrollmentState::ENROLLING;
89 
90  //insert connection requests to queue
91  Flow tmp = Flow(APNamingInfo(), APNamingInfo(APN(APName), APInst, AEName, AEInst));
92  tmp.setAllocInvokeId(invokeID);
93  this->insertAEReq(tmp);
94  }
95  else if (this->isEnrolled == this->EnrollmentState::ENROLLING) {
96  Flow tmp = Flow(APNamingInfo(), APNamingInfo(APN(APName), APInst, AEName, AEInst));
97  tmp.setAllocInvokeId(invokeID);
98  this->insertAEReq(tmp);
99  }
100  else
101  return createIAE(APName, APInst, AEName, AEInst, NULL, invokeID);
102 
103  return false;
104 }
105 
106 bool AP::a_open(int invokeID, Flow* flow){
107  return false;
108 }
109 
110 bool AP::a_close(int CDAPConn, int invokeID) {
111  APIReqObj* obj = new APIReqObj();
112  obj->setCDAPConId(CDAPConn);
114 
115  this->signalizeAPAEAPI(obj);
116  return true;
117 }
118 
119 bool AP::a_read(int CDAPConn, std::string objName, int invokeID) {
120  APIReqObj* obj = new APIReqObj();
121  obj->setCDAPConId(CDAPConn);
122  obj->setObjName(objName);
123  obj->setInvokeId(invokeID);
125 
126  this->signalizeAPAEAPI(obj);
127  return true;
128 }
129 
130 bool AP::a_write(int CDAPConn, std::string objName, object_t *obj, int invokeID) {
131  APIReqObj *req = new APIReqObj();
132  req->setCDAPConId(CDAPConn);
133  req->setObjName(objName);
134  req->setObj(obj);
135  req->setInvokeId(invokeID);
137 
138  this->signalizeAPAEAPI(req);
139  return true;
140 }
141 
142 APIRetObj* AP::a_getopen_r(int invokeID) {
143  return NULL;
144 }
145 
146 APIRetObj* AP::a_getclose_r(int CDAPConn, int invokeID) {
147  return NULL;
148 }
149 
150 bool AP::a_read_r(int CDAPconn, int invokeID, std::string objName, object_t *obj, bool complete) {
151  return false;
152 }
153 
154 APIRetObj* AP::a_get_read_r(int CDAPConn, int invokeID) {
155  return NULL;
156 }
157 
158 bool AP::a_cancelread_r(int CDAPConn, int invokeID) {
159  return false;
160 }
161 
162 APIRetObj* AP::a_getwrite_r(int CDAPconn, int invokeID, APIResult* result, std::string objName, object_t *obj){
163  return NULL;
164 }
165 
166 bool AP::createIAE(std::string APName, std::string APInst, std::string AEName, std::string AEInst, Flow* flow, int invokeID) {
167  std::string str = "^."+AEName;
168  cModule *submodule, *module = this->getModuleByPath(str.c_str());
169  cModuleType *moduleType;
170  std::ostringstream ostr;
171 
172  str = "rina.src.DAF.AE."+AEName;
173  cModuleType *moduleAEType = cModuleType::find(str.c_str());
174  if(!moduleAEType) {
175  str = "rina.src.DAF.AE."+AEName+"."+AEName;
176  moduleAEType = cModuleType::find(str.c_str());
177  }
178 
179  if(!moduleAEType) {
180  return false;
181  }
182 
183  int AEInstanceNum = getNewAEInstNum(AEName);
184 
185  //create module wrapper for AE if not exists
186  if(!module) {
187  moduleType = cModuleType::get("rina.src.DAF.AE.ApplicationEntity");
188  //Create a name
189  ostr << AEName;
190 
191  //Instantiate module
192  module = moduleType->create(ostr.str().c_str(), this->getModuleByPath("^"));
193  module->finalizeParameters();
194  module->buildInside();
195  module->callInitialize();
196  }
197 
198  //create whole module AEInst, inside IAE,Socket
199  str = "^."+AEName;
200  module = this->getModuleByPath(str.c_str());
201 
202  if (!module) {
203  return false;
204  }
205 
206  ostr.clear();
207  ostr.str("");
208 
209  ostr << AEName << "_" << AEInstanceNum;
210  moduleType = cModuleType::get("rina.src.DAF.AE.ApplicationEntityInstance");
211  module = moduleType->create(ostr.str().c_str(), this->getModuleByPath(str.c_str()));
212  module->par("aeType") = AEName;
213 
214  module->finalizeParameters();
215  module->buildInside();
216 
217  submodule = module->getSubmodule("iae");
218  submodule->par("aeName") = AEName;
219  submodule->par("aeInstance") = std::to_string(AEInstanceNum);
220  submodule->par("dstApName") = APName;
221  submodule->par("dstApInstance") = APInst;
222  submodule->par("dstAeName") = AEName;
223  submodule->par("dstAeInstance") = AEInst;
224 
225  if (flow == NULL)
226  submodule->par("initiator") = true;
227  else
228  submodule->par("initiator") = false;
229 
230  module->callInitialize();
231 
232  AE* aeModule = dynamic_cast<AE*>(module->getSubmodule("iae"));
233 
234  aeModule->setCdapConId(this->getNewCdapConID());
235  aeModule->setStartInvokeId(invokeID);
236  aeModule->start(flow);
237 
238  return true;
239 }
240 
242 
243  Enter_Method("receiveAllocationRequestFromFai()");
244  //EV << this->getFullPath() << " received AllocationRequest from FAI" << endl;
245 
246 // if ( QoSRequirements.compare(flow->getQosRequirements()) ) {
247 
248 
249 
250 
251 
252  //Initialize flow within AE
253  //TODO: tady dodelat vytvoreni a inicializace IAE
255  flow->getDstApni().getAename(), flow->getDstApni().getAeinstance(), flow, 0);
256  //FlowObject = flow;
257  //insertFlow();
258  //EV << "======================" << endl << flow->info() << endl;
259  //Interconnect IRM and IPC
260 
261  //bool status = Irm->receiveAllocationResponsePositiveFromIpc(flow);
262 
263  //Change connection status
264  /*if (status) {
265  this->signalizeAllocateResponsePositive(flow);
266  }
267  else {
268  EV << "IRM was unable to create bindings!" << endl;
269  }
270 // }
271 // else {
272 // EV << "QoS Requirement cannot be met, please check AE attributes!" << endl;
273 // this->signalizeAllocateResponseNegative(flow);
274 // }
275  *
276  */
277 }
278 
279 bool AP::deleteIAE(APIResult* result) {
280  //TODO: repair this crap
281  //std::string ae = result->getObjName().substr(0,result->getObjName().find("_",0));
282  //cModule* aen = this->getModuleByPath("^")->getSubmodule(ae.c_str());
283  //std::string iaes = result->getObjName();
284  //cModule* iaen = aen->getSubmodule(iaes.c_str());
285  //iaen->getSubmodule("socket")->callFinish();
286  //iaen->getSubmodule("socket")->deleteModule();
287  //aen->callFinish();
288  //aen->deleteModule();
289  return true;
290 }
291 
293  if (result->getAPIResType() == APIResult::A_GET_OPEN) {
294  Enter_Method("onA_getOpen()");
295  onA_getOpen(result);
296  }
297  if (result->getAPIResType() == APIResult::A_GET_READ) {
298  Enter_Method("onA_getRead()");
299  onA_getRead(result);
300  }
301  else if (result->getAPIResType() == APIResult::A_GET_WRITE) {
302  Enter_Method("onA_getWrite()");
303  onA_getWrite(result);
304  }
305  else if (result->getAPIResType() == APIResult::D_DELETE) {
306  deleteIAE(result);
307  }
308 }
309 
311  Enter_Method("startRequestedConnections()");
312  Flow tmp;
313  while (!this->ConReqStack.empty()) {
314  tmp = this->ConReqStack.back();
315  this->createIAE(tmp.getDstApni().getApn().getName(), tmp.getDstApni().getApinstance(),
316  tmp.getDstApni().getAename(), tmp.getDstApni().getAeinstance(),
317  NULL, tmp.getAllocInvokeId());
318  this->ConReqStack.pop_back();
319  }
320  this->isEnrolled = this->EnrollmentState::ENROLLED;
321 }
322 
324  this->ConReqStack.push_back(req);
325 }
326 
327 
328 
330  emit(sigAPAEAPI, obj);
331 }
LisAPAllReqFromFai * lisAPAllReqFromFai
Definition: AP.h:79
void receiveAllocationRequestFromFAI(Flow *flow)
Definition: AP.cc:241
Class representing flow object with attributes from specs.
Definition: Flow.h:45
virtual APIRetObj * a_getopen_r(int invokeID)
Definition: AP.cc:142
const char * SIG_AE_AP_API
Definition: RINASignals.cc:41
virtual void resultAssign(APIResult *result)
Definition: AP.cc:292
simsignal_t sigAEEnrolled
Definition: AP.h:76
virtual APIRetObj * a_getclose_r(int CDAPConn, int invokeID=0)
Definition: AP.cc:146
Definition: AP.h:40
Application Process Name class.
Definition: APN.h:36
Definition: AE.h:44
void insertAEReq(Flow req)
Definition: AP.cc:323
ConnectionRequests ConReqStack
Definition: AP.h:83
void setAllocInvokeId(long allocInvokeId)
Sets allocation InvokeId.
Definition: Flow.cc:281
bool deleteIAE(APIResult *result)
Definition: AP.cc:279
long getAllocInvokeId() const
Gets allocation InvokeId Used inside M_CREATE(_R)(flow) messages.
Definition: Flow.cc:277
virtual APIRetObj * a_get_read_r(int CDAPConn, int invokeID)
Definition: AP.cc:154
void start(Flow *flow)
Definition: AE.cc:226
void signalizeAPAEAPI(APIReqObj *obj)
Definition: AP.cc:329
virtual bool a_close(int CDAPConn, int invokeID=0)
Definition: AP.cc:110
const std::string & getAename() const
Getter of AE name.
Definition: APNamingInfo.h:110
const APN & getApn() const
Getter of APN.
Definition: APNamingInfo.h:142
virtual void initSignalsAndListeners()
Definition: AP.cc:39
APNamingInfo holds complete naming info for particular application process.
Definition: APNamingInfo.h:43
virtual bool a_read(int CDAPConn, std::string objName, int invokeID=0)
Definition: AP.cc:119
virtual void onA_getWrite(APIResult *result)
Definition: AP.cc:69
void setAPIReqType(APIReqObj::APIReqType type)
Definition: APIReqObj.cc:36
void setObjName(std::string objName)
Definition: APIReqObj.cc:53
virtual bool a_read_r(int CDAPconn, int invokeID, std::string objName, object_t *obj, bool complete=true)
Definition: AP.cc:150
unsigned long getNewCdapConID()
Definition: APBase.cc:55
bool createIAE(std::string APName, std::string APInst, std::string AEName, std::string AEInst, Flow *flow, int invokeID)
Definition: AP.cc:166
void setStartInvokeId(int invokeId)
Definition: AEBase.cc:206
const char * SIG_AP_AE_API
Definition: RINASignals.cc:32
virtual void initPointers()
Definition: AP.cc:60
const char * SIG_AE_Enrolled
Definition: RINASignals.cc:39
const std::string & getAeinstance() const
Getter of AE-instance attribute.
Definition: APNamingInfo.h:94
int getNewAEInstNum(std::string AEName)
Definition: APBase.cc:40
Define_Module(AP)
simsignal_t sigAPAEAPI
Definition: AP.h:75
void setInvokeId(unsigned long id)
Definition: APIObjBase.cc:40
const std::string & getApinstance() const
Getter of AP-instance id.
Definition: APNamingInfo.h:126
EnrollmentState isEnrolled
Definition: APBase.h:73
virtual void onA_getRead(APIResult *result)
Definition: AP.cc:66
virtual bool a_open(int invokeID, std::string APname, std::string APinst, std::string AEname, std::string AEinst)
Definition: AP.cc:75
void setCDAPConId(unsigned long id)
Definition: APIObjBase.cc:32
virtual void startRequestedConnections()
Definition: AP.cc:310
LisAEAPAPI * lisAEAPAPI
Definition: AP.h:81
virtual bool a_write(int CDAPConn, std::string objName, object_t *obj, int invokeID=0)
Definition: AP.cc:130
APIResult::APIResType getAPIResType()
Definition: APIResult.cc:35
AP()
Definition: AP.cc:27
virtual void onClose(APIResult *result)
Definition: AP.cc:72
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
virtual ~AP()
Definition: AP.cc:31
virtual bool a_cancelread_r(int CDAPConn, int invokeID=0)
Definition: AP.cc:158
const char * SIG_AEMGMT_ConnectionResponsePositive
Definition: RINASignals.cc:69
const char * SIG_FAI_AllocateRequest
Definition: RINASignals.cc:105
virtual void initialize()
Definition: AP.cc:34
const APNamingInfo & getDstApni() const
Gets read-only destination APNamingInfo.
Definition: Flow.cc:102
void setObj(object_t *obj)
Definition: APIReqObj.cc:45
LisAPEnrolled * lisAPEnrolled
Definition: AP.h:80
virtual void onA_getOpen(APIResult *result)
Definition: AP.cc:63
void setCdapConId(unsigned long cdapConId)
Definition: AEBase.cc:197
virtual APIRetObj * a_getwrite_r(int CDAPconn, int invokeID, APIResult *result, std::string objName, object_t *obj=NULL)
Definition: AP.cc:162