RINASim  October 2016
Documentation of framework for OMNeT++
DAFEnrollment.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 
32 #include "DAFEnrollment.h"
33 
35 
36 const char* DAF_PAR_AUTH_TYPE = "authType";
37 const char* DAF_PAR_AUTH_NAME = "authName";
38 const char* DAF_PAR_AUTH_OTHER = "authOther";
39 const char* DAF_PAR_AUTH_PASS = "authPassword";
40 const char* DAF_PAR_CON_RETRIES = "maxConRetries";
41 const char* DAF_PAR_ISSELFENROL = "isSelfEnrolled";
42 
43 const char* DAF_MSG_ENRLCON = "Enrol-Connect";
44 const char* DAF_MSG_ENRLREL = "Enrol-Release";
45 
46 const char* DAF_ELEM_PREENROL = "Preenrollment";
47 const char* DAF_ELEM_SIMTIME = "SimTime";
48 const char* DAF_ELEM_CONNECT = "Connect";
49 const char* DAF_ELEM_RELEASE = "Release";
50 const char* DAF_ATTR_TIME = "t";
51 
52 DAFEnrollment::DAFEnrollment() : cace(NULL), StateTable(NULL)//, aemgmt(NULL)
53 {
54 }
55 
57  StateTable = NULL;
58  cace = NULL;
59  //aemgmt = NULL;
60 }
61 
63 {
65 
66  //Parse XML config
67  parseConfig(par(PAR_CONFIGDATA).xmlValue());
68 
70  initPointers();
71 
72  //Perform self-enrollment
73  bool isSelfEnrol = false;//par(DAF_PAR_ISSELFENROL).boolValue();
74  if (isSelfEnrol) {
81  }
82  else {
83  //TODO: Work more on checking of N-1 flow existence
86  else
88  }
89 
90 
91  apName = this->getModuleByPath("^.^")->par("apName").stringValue();
92  apInstance = this->getModuleByPath("^.^")->par("apInstance").stringValue();
94  authName = this->par(DAF_PAR_AUTH_NAME).stringValue();
95  authPassword = this->par(DAF_PAR_AUTH_PASS).stringValue();
96  authOther = this->par(DAF_PAR_AUTH_OTHER).stringValue();
97 
99 
100  cace = new CACEMgmt(this);
101 
102  WATCH_MAP(PreenrollConnects);
103  WATCH_MAP(PreenrollReleases);
104 
105 }
106 
108  //FIXME: Vesely: Unused variable commented
109  //cModule* Cdap = module->getModuleByPath("^.commonDistributedApplicationProtocol");
110  //FIXME: Vesely: Unused variable commented
111  //cGate* gCdapIn = Cdap->gateHalf(GATE_SOUTHIO, cGate::INPUT);
112  //FIXME: Vesely: Unused variable commented
113  //cGate* gCdapOut = Cdap->gateHalf(GATE_SOUTHIO, cGate::OUTPUT);
114 
115  //Get Socket South Gates
116  cModule* SocketMod = module->getModuleByPath("^.socket");
117  cGate* gSocketIn;
118  cGate* gSocketOut;
119  SocketMod->getOrCreateFirstUnconnectedGatePair("southIo", false, true, *&gSocketIn, *&gSocketOut);
120 
121  //Get Socket CDAP Gates
122  //FIXME: Vesely: Unused variable commented
123  //cGate* gSocketCdapIn = SocketMod->gateHalf("cdapIo", cGate::INPUT);
124  //FIXME: Vesely: Unused variable commented
125  //cGate* gSocketCdapOut = SocketMod->gateHalf("cdapIo", cGate::OUTPUT);
126 
127 
128  cModule* aeMgmt = module->getModuleByPath("^");
129  cGate* gaeMgmtIn;
130  cGate* gaeMgmtOut;
131  aeMgmt->getOrCreateFirstUnconnectedGatePair("aeIo", false, true, *&gaeMgmtIn, *&gaeMgmtOut);
132 
133  cModule* aeMgmtParent = module->getModuleByPath("^.^");
134  cGate* gaeMgmtParentIn;
135  cGate* gaeMgmtParentOut;
136  aeMgmtParent->getOrCreateFirstUnconnectedGatePair(GATE_SOUTHIO, false, true, *&gaeMgmtParentIn, *&gaeMgmtParentOut);
137 
138  //Create new gates
139  cGate* gIrmIn;
140  cGate* gIrmOut;
141  Irm->getOrCreateFirstUnconnectedGatePair(GATE_AEIO, false, true, *&gIrmIn, *&gIrmOut);
142 
143  cModule* IrmMod = Irm->getParentModule();
144  cGate* gIrmModIn;
145  cGate* gIrmModOut;
146  IrmMod->getOrCreateFirstUnconnectedGatePair(GATE_NORTHIO, false, true, *&gIrmModIn, *&gIrmModOut);
147 
148  cModule* ApMon = module->getModuleByPath("^.^.^");
149  cGate* gApIn;
150  cGate* gApOut;
151  ApMon->getOrCreateFirstUnconnectedGatePair(GATE_SOUTHIO, false, true, *&gApIn, *&gApOut);
152 
153  //Connect gates together
154  gIrmOut->connectTo(gIrmModOut);
155  gIrmModOut->connectTo(gApIn);
156  gApIn->connectTo(gaeMgmtParentIn);
157  gaeMgmtParentIn->connectTo(gaeMgmtIn);
158  gaeMgmtIn->connectTo(gSocketIn);
159  //gSocketCdapIn->connectTo(gCdapIn);
160 
161  //gCdapOut->connectTo(gSocketCdapOut);
162  gSocketOut->connectTo(gaeMgmtOut);
163  gaeMgmtOut->connectTo(gaeMgmtParentOut);
164  gaeMgmtParentOut->connectTo(gApOut);
165  gApOut->connectTo(gIrmModIn);
166  gIrmModIn->connectTo(gIrmIn);
167 
168  //Set north-half of the routing in ConnectionTable
169  Irm->setNorthGates(flow, gIrmIn, gIrmOut);
170 }
171 
173  StateTable = check_and_cast<DAFEnrollmentStateTable*>(getModuleByPath("^.enrollmentStateTable"));
174  //aemgmt = check_and_cast<AEMgmt*>( getModuleByPath("^.^.aemanagement.aemgmt") );
175  Irm = check_and_cast<IRM*>( getModuleByPath("^.^.^")->getSubmodule(MOD_IPCRESMANAGER)->getSubmodule(MOD_IRM) );
176  //FlowAlloc = check_and_cast<FABase*>( getModuleByPath("^.^.flowAllocator.fa") );
177 }
178 
180  cModule* catcher1 = this->getModuleByPath("^.^");
181  cModule* catcher2 = this->getModuleByPath("^.^");
182  cModule* catcher3 = this->getModuleByPath("^.^.^");
183 
193 
195 
198 
201  //catcher1->subscribe(SIG_RA_MgmtFlowAllocated, lisDAFEnrollmentAllResPosi);
202 
203  // AllocationRequest from FAI
206 
207 
209  catcher2->subscribe(SIG_AE_Enrolled, lisDAFEnrollmentRequest);
210 
211 
212 
215 
218 
221 
224 
227 
230 
233 
236 
239 }
240 /*
241 void DAFEnrollment::startCACE(Flow* flow) {
242  Enter_Method("startCACE()");
243 
244  //auto entry = DAFEnrollmentStateTableEntry(apnip->first, apnip->second, DAFEnrollmentStateTableEntry::CON_AUTHENTICATING);
245  //StateTable->insert(entry);
246 
247  auto entry = StateTable->findEntryByDstAPN(flow->getDstApni().getApn());
248 
249  CDAP_M_Connect* msg = new CDAP_M_Connect(DAF_MSG_CONREQ);
250 
251  authValue_t aValue;
252  aValue.authName = authName;
253  aValue.authPassword = authPassword;
254  aValue.authOther = authOther;
255 
256  auth_t auth;
257  auth.authType = authType;
258  auth.authValue = aValue;
259 
260  msg->setAuth(auth);
261  msg->setAbsSyntax(GPB);
262 
263  APNamingInfo src = APNamingInfo(entry->getLocal().getApn(),
264  entry->getLocal().getApinstance(),
265  entry->getLocal().getAename(),
266  entry->getLocal().getAeinstance());
267 
268  APNamingInfo dst = APNamingInfo(entry->getRemote().getApn(),
269  entry->getRemote().getApinstance(),
270  entry->getRemote().getAename(),
271  entry->getRemote().getAeinstance());
272  //XXX: Vesely@Jerabek> Removing unnecessary *.msg ADT when there exists
273  // exactly the same ADT in RINASim source codes.
274  naming_t dst;
275  dst.AEInst = entry.getRemote().getAeinstance();
276  dst.AEName = entry.getRemote().getAename();
277  dst.ApInst = entry.getRemote().getApinstance();
278  dst.ApName = entry.getRemote().getApn().getName();
279 
280  naming_t src;
281  src.AEInst = entry.getLocal().getAeinstance();
282  src.AEName = entry.getLocal().getAename();
283  src.ApInst = entry.getLocal().getApinstance();
284  src.ApName = entry.getLocal().getApn().getName();
285 
286 
287  msg->setSrc(src);
288  msg->setDst(dst);
289 
290  msg->setSrcAddr(Address(entry->getLocal().getApn()));
291  msg->setDstAddr(Address(entry->getRemote().getApn()));
292 
293  //send data to ribd to send
294  signalizeCACESendData(msg);
295 }
296 
297 void DAFEnrollment::insertStateTableEntry(Flow* flow){
298  Enter_Method("insertStateTableEntry()");
299  //insert only first flow created (management flow)
300  if(StateTable->findEntryByDstAPN(APN(flow->getDstAddr().getApn().getName().c_str())) != NULL) {
301  return;
302  }
303  StateTable->insert(DAFEnrollmentStateTableEntry(flow->getSrcApni(), flow->getDstApni(), DAFEnrollmentStateTableEntry::CON_CONNECTPENDING));
304 }
305 
306 void DAFEnrollment::receivePositiveConnectResponse(CDAPMessage* msg) {
307  Enter_Method("receivePositiveConnectResponse()");
308 
309  //signalizeEnrolled();
310 
311  // this is commented only for testing ---> refactoring of adress is need to be done
312  // CDAP_M_Connect_R* cmsg = check_and_cast<CDAP_M_Connect_R*>(msg);
313  DAFEnrollmentStateTableEntry* entry = StateTable->findEntryByDstAPN(cmsg->getSrc().getApn());
314 
315  //check appropriate state
316  if (entry->getCACEConStatus() != DAFEnrollmentStateTableEntry::CON_AUTHENTICATING) {
317  //TODO: send M_Release and invoke deallocate
318  return;
319  }
320 
321  entry->setCACEConStatus(DAFEnrollmentStateTableEntry::CON_ESTABLISHED);
322 
323  startEnrollment(entry);
324 
325 }
326 
327 void DAFEnrollment::receiveNegativeConnectResponse(CDAPMessage* msg) {
328  Enter_Method("receiveNegativeConnectResponse()");
329 
330  CDAP_M_Connect_R* cmsg = check_and_cast<CDAP_M_Connect_R*>(msg);
331  DAFEnrollmentStateTableEntry* entry = StateTable->findEntryByDstAPN(cmsg->getSrc().getApn());
332 
333  //check appropriate state
334  if (entry->getCACEConStatus() != DAFEnrollmentStateTableEntry::CON_AUTHENTICATING) {
335  //TODO: send M_Release and invoke deallocate
336  return;
337  }
338 
339  if (this->maxConRetries <= entry->getCurrentConnectRetries()) {
340  entry->setCACEConStatus(DAFEnrollmentStateTableEntry::CON_NIL);
341  //TODO: send release and deallocate
342  return;
343  }
344 
345 
346  entry->setCACEConStatus(DAFEnrollmentStateTableEntry::CON_CONNECTPENDING);
347  entry->increaseCurrentConnectRetries();
348  //create and send new connect retry
349  processNewConReq(entry);
350 }
351 
352 void DAFEnrollment::receiveConnectRequest(CDAPMessage* msg) {
353  Enter_Method("receiveConnectRequest()");
354 
355  CDAP_M_Connect* cmsg = check_and_cast<CDAP_M_Connect*>(msg);
356 
357  auto ent = DAFEnrollmentStateTableEntry(
358  cmsg->getDst(), cmsg->getSrc(), DAFEnrollmentStateTableEntry::CON_CONNECTPENDING);
359  StateTable->insert(ent);
360 
361  DAFEnrollmentStateTableEntry* entry = StateTable->findEntryByDstAPN(cmsg->getSrc().getApn());
362 
363  if (!entry) {
364  EV << "DAFEnrollment status not found for "
365  << cmsg->getSrc().getApn() << endl;
366  return;
367  }
368 
369  //check appropriate state
370  if (entry->getCACEConStatus() != DAFEnrollmentStateTableEntry::CON_CONNECTPENDING) {
371  //TODO: send M_Release and invoke deallocate
372  return;
373  }
374 
375  //check if message is valid
376  if (cmsg->getAbsSyntax() != GPB) {
377  this->processConResNega(entry, cmsg);
378  return;
379  }
380 
381  entry->setCACEConStatus(DAFEnrollmentStateTableEntry::CON_AUTHENTICATING);
382 
383  authenticate(entry, cmsg);
384 }
385 */
386 /* enrollment initiator */
387 
389  Enter_Method("startDAFEnrollment()");
390 
391  auto enrollObj = new DAFEnrollmentObj(Address(entry->getLocal().getApn()), Address(entry->getRemote().getApn()));
392 
393  //TODO: assign address to new one to send it
394  //enrollObj->setAddress(APN(aemgmt->getMyAddress().getIpcAddress().getName()));
395 
396  //TODO: add other necessary information
397 
398  //process enrollment object to ribd to send
400 
401  //set appropriate state
403 }
404 
406  Enter_Method("receiveStartDAFEnrollmentResponse()");
407 
408  CDAP_M_Start_R* smsg = check_and_cast<CDAP_M_Start_R*>(msg);
409 
410  //not expected message
411  if (!smsg) {
412  //TODO: send release and deallocate
413  return;
414  }
415 
416  DAFEnrollmentObj* enrollRec = (check_and_cast<DAFEnrollmentObj*>(smsg->getObjectItem().objectVal))->dup();
418 
419  //check for appropriate state
421  //TODO: send release and deallocate
422  return;
423  }
424 
425  //assign new, received address
426  //Address newAddr = aemgmt->getMyAddress();
427  //newAddr.setIpcAddress(APN(enrollRec->getAddress().getName().c_str()));
428  //aemgmt->setMyAddress(newAddr);
429 
430  //TODO: assign other received values
431 
432  //change state
434 
435  //TODO: wait for create messages and stop enrollment request
436 }
437 
439  Enter_Method("receiveStopDAFEnrollmentRequest()");
440 
441 
442  CDAP_M_Stop* smsg = check_and_cast<CDAP_M_Stop*>(msg);
443 
444  //not expected message
445  if (!smsg) {
446  //TODO: send release and deallocate
447  return;
448  }
449 
450  DAFEnrollmentObj* enrollRec = (check_and_cast<DAFEnrollmentObj*>(smsg->getObjectItem().objectVal))->dup();
452 
453  //check for appropriate state
455  //TODO: send release and deallocate
456  return;
457  }
458 
459  //set immediate transition to operational state
460  entry->setIsImmediateDAFEnrollment(enrollRec->getIsImmediate());
461 
462  //set appropriate state
464 
465  //TODO: send read requests, wait for responses, send Mstop enrollment
466  //for now send stop enrollment response
468 }
469 
471 
472  auto enrollObj = new DAFEnrollmentObj(Address(entry->getLocal().getApn()), Address(entry->getRemote().getApn()));
473 
475 
476 
477  if (entry->getIsImmediateDAFEnrollment()) {
480 
482  }
483  else {
485  //TODO: continue enrollment here
486  }
487 }
488 
490  Enter_Method("receiveStartOperationRequest()");
491 
492 }
493 
494 /* enrollment member */
495 
497  Enter_Method("receiveStartDAFEnrollmentRequest()");
498 
499  CDAP_M_Start* smsg = check_and_cast<CDAP_M_Start*>(msg);
500 
501  //not expected message
502  if (!smsg) {
503  //TODO: send release and deallocate
504  return;
505  }
506 
507  DAFEnrollmentObj* enrollRec = (check_and_cast<DAFEnrollmentObj*>(smsg->getObjectItem().objectVal))->dup();
509 
510  //check for appropriate state
512  //TODO: send release and deallocate
513  return;
514  }
515 
516 
517  auto enrollObj = new DAFEnrollmentObj(Address(entry->getLocal().getApn()), Address(entry->getRemote().getApn()));
518 
519  //TODO: repair this dummy address assign
520  //enrollObj->setAddress(APN(enrollRec->getAddress().getName()));
521 
522  //TODO: add other necessary information
523 
524  //process enrollment object to ribd to send
526 
527  //TODO: send create messages, wait for responses, then send stop enrollment
528  //for now send stop enrollment
530 }
531 
533  Enter_Method("receiveStopDAFEnrollmentResponse()");
534 
535  CDAP_M_Stop_R* smsg = check_and_cast<CDAP_M_Stop_R*>(msg);
536 
537  //not expected message
538  if (!smsg) {
539  //TODO: send release and deallocate
540  return;
541  }
542 
543  DAFEnrollmentObj* enrollRec = (check_and_cast<DAFEnrollmentObj*>(smsg->getObjectItem().objectVal))->dup();
545 
546  //check for appropriate state
548  //TODO: send release and deallocate
549  return;
550  }
551 
552  if (entry->getIsImmediateDAFEnrollment()) {
554  //TODO: emit signal somewhere and probably send rib update ...
555  }
556  else {
557  //TODO: add appropriate state for read and wait operation
558  }
559 }
560 
562  Enter_Method("receiveStartOperationResponse()");
563 
564 }
565 
567  auto enrollObj = new DAFEnrollmentObj(Address(entry->getLocal().getApn()), Address(entry->getRemote().getApn()));
568 
569  //set immediate
570  enrollObj->setIsImmediate(true);
571  entry->setIsImmediateDAFEnrollment(true);
572 
573  //TODO: add other necessary information
574 
576 
578 }
579 
580 /*void DAFEnrollment::authenticate(DAFEnrollmentStateTableEntry* entry, CDAP_M_Connect* msg) {
581  Enter_Method("authenticate()");
582 
583  //check and validate expected auth type
584  if (msg->getAuth().authType == authType) {
585  //none auth option
586  if (msg->getAuth().authType == AUTH_NONE) {
587  processConResPosi(entry, msg);
588  return;
589 
590  }
591  //passwd auth option
592  else if (msg->getAuth().authType == AUTH_PASSWD) {
593  //correct passwd
594  if (!strcmp(msg->getAuth().authValue.authPassword.c_str(), authPassword.c_str())) {
595  processConResPosi(entry, msg);
596  return;
597  }
598  }
599  //TODO: support for other options
600  }
601 
602  //not valid auth send negative response
603  processConResNega(entry, msg);
604 }
605 
606 void DAFEnrollment::processNewConReq(DAFEnrollmentStateTableEntry* entry) {
607  Enter_Method("processNewConReq()");
608 
609  //TODO: probably change values, this is retry
610 
611  CDAP_M_Connect* msg = new CDAP_M_Connect(DAF_MSG_CONREQRETRY);
612 
613  authValue_t aValue;
614  aValue.authName = authName;
615  aValue.authPassword = authPassword;
616  aValue.authOther = authOther;
617 
618  auth_t auth;
619  auth.authType = authType;
620  auth.authValue = aValue;
621 
622  msg->setAuth(auth);
623  msg->setAbsSyntax(GPB);
624 
625  APNamingInfo src = APNamingInfo(entry->getLocal().getApn(),
626  entry->getLocal().getApinstance(),
627  entry->getLocal().getAename(),
628  entry->getLocal().getAeinstance());
629 
630  APNamingInfo dst = APNamingInfo(entry->getRemote().getApn(),
631  entry->getRemote().getApinstance(),
632  entry->getRemote().getAename(),
633  entry->getRemote().getAeinstance());
634 
635  msg->setSrc(src);
636  msg->setDst(dst);
637 
638  msg->setSrcAddr(Address(entry->getLocal().getApn()));
639  msg->setDstAddr(Address(entry->getRemote().getApn()));
640 
641  //send data to ribd to send
642  signalizeCACESendData(msg);
643 
644  //change state to auth after send retry
645  entry->setCACEConStatus(DAFEnrollmentStateTableEntry::CON_AUTHENTICATING);
646 }
647 
648 void DAFEnrollment::processConResPosi(DAFEnrollmentStateTableEntry* entry, CDAPMessage* cmsg) {
649  CDAP_M_Connect_R* msg = new CDAP_M_Connect_R(DAF_MSG_CONRESPOS);
650  CDAP_M_Connect* cmsg1 = check_and_cast<CDAP_M_Connect*>(cmsg);
651 
652  APNamingInfo src = APNamingInfo(entry->getLocal().getApn(),
653  entry->getLocal().getApinstance(),
654  entry->getLocal().getAename(),
655  entry->getLocal().getAeinstance());
656 
657  APNamingInfo dst = APNamingInfo(entry->getRemote().getApn(),
658  entry->getRemote().getApinstance(),
659  entry->getRemote().getAename(),
660  entry->getRemote().getAeinstance());
661 
662  result_t result;
663  result.resultValue = R_SUCCESS;
664 
665  auth_t auth;
666  auth.authType = cmsg1->getAuth().authType;
667  auth.authValue = cmsg1->getAuth().authValue;
668 
669  msg->setAbsSyntax(GPB);
670  msg->setResult(result);
671  msg->setAuth(auth);
672 
673  msg->setSrc(src);
674  msg->setDst(dst);
675 
676  msg->setSrcAddr(Address(entry->getLocal().getApn()));
677  msg->setDstAddr(Address(entry->getRemote().getApn()));
678 
679  //send data to ribd to send
680  signalizeCACESendData(msg);
681 
682  entry->setCACEConStatus(DAFEnrollmentStateTableEntry::CON_ESTABLISHED);
683  entry->setDAFEnrollmentStatus(DAFEnrollmentStateTableEntry::ENROLL_WAIT_START_ENROLLMENT);
684 }
685 
686 void DAFEnrollment::processConResNega(DAFEnrollmentStateTableEntry* entry, CDAPMessage* cmsg) {
687  CDAP_M_Connect_R* msg = new CDAP_M_Connect_R(DAF_MSG_CONRESNEG);
688  CDAP_M_Connect* cmsg1 = check_and_cast<CDAP_M_Connect*>(cmsg);
689 
690  APNamingInfo src = APNamingInfo(entry->getLocal().getApn(),
691  entry->getLocal().getApinstance(),
692  entry->getLocal().getAename(),
693  entry->getLocal().getAeinstance());
694 
695  APNamingInfo dst = APNamingInfo(entry->getRemote().getApn(),
696  entry->getRemote().getApinstance(),
697  entry->getRemote().getAename(),
698  entry->getRemote().getAeinstance());
699 
700  result_t result;
701  result.resultValue = R_FAIL;
702 
703  auth_t auth;
704  auth.authType = cmsg1->getAuth().authType;
705  auth.authValue = cmsg1->getAuth().authValue;
706 
707  msg->setAbsSyntax(GPB);
708  msg->setResult(result);
709  msg->setAuth(auth);
710 
711  msg->setSrc(src);
712  msg->setDst(dst);
713 
714  msg->setSrcAddr(Address(entry->getLocal().getApn()));
715  msg->setDstAddr(Address(entry->getRemote().getApn()));
716 
717  //send data to send to ribd
718  signalizeCACESendData(msg);
719 
720  entry->setCACEConStatus(DAFEnrollmentStateTableEntry::CON_CONNECTPENDING);
721 
722  //increase number of connects
723  entry->increaseCurrentConnectRetries();
724 }
725 */
727  emit(sigDAFEnrollmentCACESendData, cmsg);
728 }
729 
732 }
733 
736 }
737 
739  //TODO: move following line somewhere else
742 }
743 
746 }
747 
749  emit(sigDAFEnrollmentStartOperReq, obj);
750 }
751 
753  emit(sigDAFEnrollmentStartOperRes, obj);
754 }
755 
758  APNIPair* apnip = new APNIPair(entry->getLocal(), entry->getRemote());
759  emit(sigDAFEnrollmentFinish, apnip);
760 }
761 
762 void DAFEnrollment::parseConfig(cXMLElement* config) {
763  cXMLElement* mainTag = NULL;
764  if (config != NULL && config->hasChildren() && config->getFirstChildWithTag(DAF_ELEM_PREENROL))
765  mainTag = config->getFirstChildWithTag(DAF_ELEM_PREENROL);
766  else {
767  EV << "configData parameter not initialized!" << endl;
768  return;
769  }
770 
771  cXMLElementList enrll = mainTag->getChildrenByTagName(DAF_ELEM_SIMTIME);
772  for (cXMLElementList::const_iterator it = enrll.begin(); it != enrll.end(); ++it) {
773  cXMLElement* m = *it;
774 
775  if (!m->getAttribute(DAF_ATTR_TIME)) {
776  EV << "\nSimTime tag is missing time attribute!" << endl;
777  continue;
778  }
779 
780  simtime_t cas = atof(m->getAttribute(DAF_ATTR_TIME));
781 
782  if (m->getFirstChildWithTag(DAF_ELEM_CONNECT)) {
783  PreenrollConnects[cas] = new APNIPairs();
784  cMessage* cmsg = new cMessage(DAF_MSG_ENRLCON);
785  scheduleAt(cas, cmsg);
786  }
787 
788  if (m->getFirstChildWithTag(DAF_ELEM_RELEASE)) {
789  PreenrollReleases[cas] = new APNIPairs();
790  cMessage* cmsg = new cMessage(DAF_MSG_ENRLREL);
791  scheduleAt(cas, cmsg);
792  }
793 
794  cXMLElementList coms = m->getChildren();
795  for (cXMLElementList::const_iterator jt = coms.begin(); jt != coms.end(); ++jt) {
796  cXMLElement* n = *jt;
797 
798  if ( !( strcmp(n->getTagName(), DAF_ELEM_CONNECT) xor strcmp(n->getTagName(), DAF_ELEM_RELEASE) )
799  && !(n->getAttribute(ATTR_SRC))
800  && !(n->getAttribute(ATTR_DST))
801  ) {
802  EV << "\nError when parsing Connect/Release record" << endl;
803  continue;
804  }
805 
806  if ( !strcmp(n->getTagName(), DAF_ELEM_CONNECT) ) {
807  PreenrollConnects[cas]->push_back( APNIPair(n->getAttribute(ATTR_SRC), n->getAttribute(ATTR_DST)) );
808  //EV << "!!!!!!!!!!!!!" << PreenrollConnects[cas]->size() << endl;
809  }
810  else if ( !strcmp(n->getTagName(), DAF_ELEM_RELEASE) ) {
811  PreenrollReleases[cas]->push_back( APNIPair(n->getAttribute(ATTR_SRC), n->getAttribute(ATTR_DST)) );
812  }
813  }
814  }
815 }
816 
818  cModule* ipc = this->getParentModule()->getParentModule();
819  std::string ico, col;
820  switch (status) {
821  case ENICON_ENROLLED: {ico="status/check"; col="green"; break;}
822  case ENICON_FLOWMIS: {ico="status/excl"; col="yellow";break;}
823  case ENICON_NOTENROLLED:
824  default: {ico="status/cross"; col="red"; break;}
825 
826  }
827  ipc->getDisplayString().setTagArg("i2", 0, ico.c_str());
828  ipc->getDisplayString().setTagArg("i2", 1, col.c_str());
829 }
830 
831 void DAFEnrollment::handleMessage(cMessage *msg)
832 {
833  if (msg->isSelfMessage()) {
834  if ( !opp_strcmp(msg->getName(), DAF_MSG_ENRLCON) ) {
835  APNIPairs* apnip = PreenrollConnects[simTime()];
836 
837  while (!apnip->empty())
838  {
839  APNIPair pair = apnip->front();
840  auto entry = StateTable->findEntryByDstAPN(pair.second.getApn());
841  if (!entry) {
843  }
844  apnip->pop_front();
845  }
846  }
847  else if ( !opp_strcmp(msg->getName(), DAF_MSG_ENRLREL) ) {
848  APNIPairs* apnip = PreenrollReleases[simTime()];
849  while (!apnip->empty())
850  {
851  APNIPair pair = apnip->front();
852  auto entry = StateTable->findEntryByDstAPN(pair.second.getApn());
853  if (entry && entry->getDAFEnrollmentStatus() == DAFEnrollmentStateTableEntry::ENROLL_ENROLLED ) {
854  //FIXME: Vesely->Jerabek: Here goes release part of DAFEnrollment
855  }
856  apnip->pop_front();
857  }
858  }
859  delete msg;
860  }
861 }
862 
865 }
866 
868  Enter_Method("checkEnrolled()");
869  if (!StateTable->findEntryByDstAPN(apnip->first.getApn())) {
870  createFlow(apnip);
871  }
872  else {
874  }
875 }
876 
878  Enter_Method("createFlow()");
879 
880 
881  APNamingInfo src = APNamingInfo(apnip->first.getApn(),
882  apnip->first.getApinstance(),
883  "mgmt",
884  std::to_string(currentMgmtAEInstanceId));
885 
886  APNamingInfo dst = APNamingInfo(apnip->second.getApn(),
887  apnip->second.getApinstance(),
888  "mgmt",
889  "0");
890 
891  //Create a flow
892  Flow* flow = new Flow(src,dst);
893  flow->setQosRequirements(QoSReq::MANAGEMENT);
894 
895  Irm->newFlow(flow);
897 }
898 
900  Enter_Method("receiveAllocationResponsePositive()");
901 
903 
904  auto module = createMgmtAE(flow);
905 
906  createBindings(flow, module);
907 
909  StateTable->insert(entry);
910 
911  cace->startCACE(flow);
912 
913 }
914 
916  cModuleType *moduleType = cModuleType::get("rina.src.DAF.AEManagement.AEmanagementModule");
917 
918  //Create a name
919  std::ostringstream ostr;
920  ostr << "mgmtae_" << currentMgmtAEInstanceId;
921 
922  //Instantiate module
923  cModule *module = moduleType->create(ostr.str().c_str(), this->getModuleByPath("^.^.aeManagement"));
924 
925  module->finalizeParameters();
926  module->buildInside();
927 
928  cModule *aemgmt = module->getSubmodule("aemgmt");
929  aemgmt->par("aeInstance") = std::to_string(currentMgmtAEInstanceId);
930  aemgmt->par("dstApName") = flow->getDstApni().getApn().getName();
931  aemgmt->par("dstApInstance") = flow->getDstApni().getApinstance();
932  aemgmt->par("dstAeName") = flow->getDstApni().getAename();
933  aemgmt->par("dstAeInstance") = flow->getDstApni().getAeinstance();
934 
935  //TODO: create activation message
936  //module->scheduleStart(simTime());
937  module->callInitialize();
938 
939  currentMgmtAEInstanceId += 1;
940 
941  DAFEnrollmentNotifier* enrollNotif = dynamic_cast<DAFEnrollmentNotifier*>(module->getSubmodule("enrollmentNotifier"));
942  enrollNotif->setFlow(flow);
943 
944  return enrollNotif;
945 }
946 
948  Enter_Method("receiveAllocationRequestFromFai()");
949 
951 
952  Irm->newFlow(flow);
953 
954  bool status = Irm->receiveAllocationResponsePositiveFromIpc(flow);
955 
956  //Change connection status
957  if (status) {
959  }
960  else {
961  EV << "IRM was unable to create bindings!" << endl;
962  }
963 
964  auto module = createMgmtAE(flow);
965 
966  createBindings(flow,module);
967  }
968  else {
969  EV << "QoS Requirement cannot be met, please check AE attributes!" << endl;
971  }
972 }
973 
975  emit(sigDAFEnrollmentAllocResPosi, flow);
976 }
977 
979  emit(sigDAFEnrollmentAllocResNega, flow);
980 }
LisDAFEnrollmentStopOperationReq * lisDAFEnrollmentStartOperationReq
const APNamingInfo & getRemote() const
Class representing flow object with attributes from specs.
Definition: Flow.h:45
const char * SIG_RIBD_StartEnrollmentRequest
Definition: RINASignals.cc:57
simsignal_t sigDAFEnrollmentStartEnrollReq
LisDAFEnrollmentStartOperationRes * lisDAFEnrollmentStartOperationRes
simsignal_t sigDAFEnrollmentStopEnrollReq
const char * DAF_ELEM_RELEASE
Define_Module(DAFEnrollment)
simsignal_t sigDAFEnrollmentStartEnrollRes
const APNamingInfo & getSrcApni() const
Gets read-only source APNamingInfo.
Definition: Flow.cc:134
const char * DAF_MSG_ENRLCON
const char * SIG_ENROLLMENT_CACEDataSend
Definition: RINASignals.cc:72
const char * SIG_RIBD_StartOperationResponse
Definition: RINASignals.cc:62
const char * SIG_AERIBD_AllocateResponsePositive
Definition: RINASignals.cc:91
LisDAFEnrollmentStopEnrollReq * lisDAFEnrollmentStopEnrollReq
friend class CACEMgmt
Definition: DAFEnrollment.h:75
LisDAFEnrollmentConReq * lisDAFEnrollmentConReq
Application Process Name class.
Definition: APN.h:36
simsignal_t sigDAFEnrollmentStartOperReq
const char * DAF_ELEM_PREENROL
virtual void setFlow(Flow *flow)
void signalizeStartEnrollmentResponse(DAFEnrollmentObj *obj)
void signalizeStopEnrollmentRequest(DAFEnrollmentObj *obj)
DAFEnrollmentStateTableEntry * findEntryByDstAPN(const APN &apn)
APNamingInfo first
Definition: APNamingInfo.h:200
std::string apName
simsignal_t sigDAFEnrollmentAllocResNega
virtual bool receiveMgmtAllocateRequest(Flow *mgmtflow)=0
const char * SIG_ENROLLMENT_Finished
Definition: RINASignals.cc:79
const char * GATE_AEIO
simsignal_t sigDAFEnrollmentAllocResPosi
void signalizeStopEnrollmentResponse(DAFEnrollmentObj *obj)
const char * SIG_RIBD_StartEnrollmentResponse
Definition: RINASignals.cc:58
Definition: IRM.h:41
DAFEnrollment and CACE .
const char * DAF_MSG_ENRLREL
void receiveStopEnrollmentResponse(CDAPMessage *msg)
LisDAFEnrollmentStartEnrollRes * lisDAFEnrollmentStartEnrollRes
std::string authOther
simsignal_t sigDAFEnrollmentSendData
void signalizeAllocateResponseNegative(Flow *flow)
const char * ATTR_SRC
void setDAFEnrollmentStatus(DAFEnrollmentStateTableEntry::DAFEnrollmentStatus status)
virtual DAFEnrollmentObj * dup() const
DAFEnrollCommands PreenrollConnects
const char * DAF_ELEM_CONNECT
const char * DAF_PAR_AUTH_NAME
LisDAFEnrollmentAllResPosi * lisDAFEnrollmentAllResPosi
void createBindings(Flow *flow, DAFEnrollmentNotifier *module)
const char * SIG_ENROLLMENT_StartEnrollmentRequest
Definition: RINASignals.cc:73
void receiveAllocationResponsePositive(Flow *flow)
const char * PAR_CONFIGDATA
virtual ~DAFEnrollment()
bool receiveAllocationRequestFromAe(Flow *flow)
Definition: IRM.cc:184
void parseConfig(cXMLElement *config)
DAFEnrollmentStateTable * StateTable
void signalizeStartEnrollmentRequest(DAFEnrollmentObj *obj)
const std::string & getAename() const
Getter of AE name.
Definition: APNamingInfo.h:110
void initSignalsAndListeners()
const APN & getApn() const
Getter of APN.
Definition: APNamingInfo.h:142
void insert(DAFEnrollmentStateTableEntry entry)
void receiveAllocationRequestFromFAI(Flow *flow)
FABase * FlowAlloc
LisDAFEnrollmentStopEnrollRes * lisDAFEnrollmentStopEnrollRes
LisDAFEnrollmentConResPosi * lisDAFEnrollmentConResPosi
LisDAFEnrollmentConResNega * lisDAFEnrollmentConResNega
APNamingInfo second
Definition: APNamingInfo.h:201
bool isEnrolled(const APN &myApn)
const char * SIG_RIBD_StopEnrollmentResponse
Definition: RINASignals.cc:60
std::string authName
APNamingInfo holds complete naming info for particular application process.
Definition: APNamingInfo.h:43
const QoSReq & getQosRequirements() const
Gets QoS parameters wanted by flow initiator.
Definition: Flow.cc:176
const char * DAF_PAR_AUTH_TYPE
std::list< APNIPair > APNIPairs
Definition: DAFEnrollment.h:69
DAFEnrollmentNotifier * createMgmtAE(Flow *flow)
bool getIsImmediate() const
DAFEnrollCommands PreenrollReleases
void signalizeEnrolled()
void newFlow(Flow *flow)
Definition: IRM.cc:235
void checkEnrolled(APNIPair *apnip)
LisDAFEnrollmentRequest * lisDAFEnrollmentRequest
virtual object_t & getObjectItem()
const char * SIG_RIBD_StopEnrollmentRequest
Definition: RINASignals.cc:59
const char * SIG_ENROLLMENT_DataSend
Definition: RINASignals.cc:71
simsignal_t sigDAFEnrollmentStartOperRes
void createFlow(APNIPair *apnip)
void receiveStopEnrollmentRequest(CDAPMessage *msg)
simsignal_t sigDAFEnrollmentEnrollPosi
simsignal_t sigDAFEnrollmentStopEnrollRes
virtual object_t & getObjectItem()
void receiveStartEnrollmentResponse(CDAPMessage *msg)
const char * MOD_IRM
Definition: ExternConsts.cc:50
void receiveStartOperationResponse(CDAPMessage *msg)
const char * DAF_PAR_AUTH_OTHER
const char * DAF_ATTR_TIME
void signalizeEnrollmentFinished(DAFEnrollmentStateTableEntry *entry)
void receiveStartEnrollmentRequest(CDAPMessage *msg)
const char * GATE_SOUTHIO
const char * DAF_ELEM_SIMTIME
void setIsImmediateDAFEnrollment(bool immediate)
void signalizeStartOperationRequest(DAFOperationObj *obj)
const char * SIG_ENROLLMENT_StartOperationRequest
Definition: RINASignals.cc:77
const char * SIG_AE_Enrolled
Definition: RINASignals.cc:39
void updateEnrollmentDisplay(DAFEnrollment::IconEnrolStatus status)
virtual void handleMessage(cMessage *msg)
const std::string & getAeinstance() const
Getter of AE-instance attribute.
Definition: APNamingInfo.h:94
const APNamingInfo & getLocal() const
void receiveStartOperationRequest(CDAPMessage *msg)
const Address & getSrcAddress() const
const char * SIG_RIBD_ConnectionResponsePositive
Definition: RINASignals.cc:64
std::string apInstance
const char * GATE_NORTHIO
const char * SIG_ENROLLMENT_StartEnrollmentResponse
Definition: RINASignals.cc:74
const std::string & getApinstance() const
Getter of AP-instance id.
Definition: APNamingInfo.h:126
int currentMgmtAEInstanceId
LisDAFEnrollmentStartEnrollReq * lisDAFEnrollmentStartEnrollReq
const Address & getMyAddress() const
Definition: FABase.cc:54
void processStopEnrollmentResponse(DAFEnrollmentStateTableEntry *entry)
std::string authPassword
const char * DAF_PAR_ISSELFENROL
void signalizeAllocateResponsePositive(Flow *flow)
const char * SIG_FAI_AllocateResponsePositive
Definition: RINASignals.cc:108
const char * SIG_AERIBD_AllocateResponseNegative
Definition: RINASignals.cc:92
const char * SIG_ENROLLMENT_StartOperationResponse
Definition: RINASignals.cc:78
void processStopEnrollmentImmediate(DAFEnrollmentStateTableEntry *entry)
const char * SIG_RIBD_ConnectionRequest
Definition: RINASignals.cc:66
ObjectPtr objectVal
bool getIsImmediateDAFEnrollment()
void setNorthGates(Flow *flow, cGate *nIn, cGate *nOut)
Definition: IRM.cc:342
simsignal_t sigDAFEnrollmentFinish
const char * SIG_ENROLLMENT_StopEnrollmentResponse
Definition: RINASignals.cc:76
simsignal_t sigDAFEnrollmentCACESendData
void signalizeStartOperationResponse(DAFOperationObj *obj)
const APN & getApn() const
Getter of unique APN which is initialized during object construction.
Definition: Address.cc:119
void signalizeCACESendData(CDAPMessage *cmsg)
const char * SIG_RIBD_ConnectionResponseNegative
Definition: RINASignals.cc:65
const char * SIG_ENROLLMENT_StopEnrollmentRequest
Definition: RINASignals.cc:75
bool compare(const QoSReq &other) const
Definition: QoSReq.cc:355
const char * SIG_RIBD_StartOperationRequest
Definition: RINASignals.cc:61
virtual object_t & getObjectItem()
LisDAFEnrollmentAllReqFromFai * lisDAFEnrollmentAllReqFromFai
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
CACEMgmt * cace
bool receiveAllocationResponsePositiveFromIpc(Flow *flow)
Definition: IRM.cc:276
const char * SIG_AEMGMT_ConnectionResponsePositive
Definition: RINASignals.cc:69
void startCACE(Flow *flow)
Definition: CACEMgmt.cc:56
void startEnrollment(DAFEnrollmentStateTableEntry *entry)
const char * DAF_PAR_AUTH_PASS
const char * SIG_FAI_AllocateRequest
Definition: RINASignals.cc:105
Address class holds IPC Process identification.
Definition: Address.h:42
const APNamingInfo & getDstApni() const
Gets read-only destination APNamingInfo.
Definition: Flow.cc:102
virtual void initialize()
const char * DAF_PAR_CON_RETRIES
const char * MOD_IPCRESMANAGER
Definition: ExternConsts.cc:49
virtual object_t & getObjectItem()
const char * ATTR_DST
DAFEnrollmentStateTableEntry::DAFEnrollmentStatus getDAFEnrollmentStatus() const
static const QoSReq MANAGEMENT
Definition: QoSReq.h:152