RINASim  October 2016
Documentation of framework for OMNeT++
CACEMgmt.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include <CACEMgmt.h>
17 
19 
20 }
21 
23 }
24 
26  this->outerClass = outerClass;
27  this->StateTable = outerClass->StateTable;
28 }
29 
31  //Enter_Method("authenticate()");
32 
33  //check and validate expected auth type
34  if (msg->getAuth().authType == this->outerClass->authType) {
35  //none auth option
36  if (msg->getAuth().authType == AUTH_NONE) {
37  processConResPosi(entry, msg);
38  return;
39 
40  }
41  //passwd auth option
42  else if (msg->getAuth().authType == AUTH_PASSWD) {
43  //correct passwd
44  if (!strcmp(msg->getAuth().authValue.authPassword.c_str(), this->outerClass->authPassword.c_str())) {
45  processConResPosi(entry, msg);
46  return;
47  }
48  }
49  //TODO: support for other options
50  }
51 
52  //not valid auth send negative response
53  processConResNega(entry, msg);
54 }
55 
57  //Enter_Method("startCACE()");
58 
59  //auto entry = DAFEnrollmentStateTableEntry(apnip->first, apnip->second, DAFEnrollmentStateTableEntry::CON_AUTHENTICATING);
60  //StateTable->insert(entry);
61 
62  auto entry = StateTable->findEntryByDstAPNI(flow->getDstApni());
63 
65 
66  authValue_t aValue;
67  aValue.authName = this->outerClass->authName;
68  aValue.authPassword = this->outerClass->authPassword;
69  aValue.authOther = this->outerClass->authOther;
70 
71  auth_t auth;
72  auth.authType = this->outerClass->authType;
73  auth.authValue = aValue;
74 
75  msg->setAuth(auth);
76  msg->setAbsSyntax(GPB);
77 
78  APNamingInfo src = APNamingInfo(entry->getLocal().getApn(),
79  entry->getLocal().getApinstance(),
80  entry->getLocal().getAename(),
81  entry->getLocal().getAeinstance());
82 
83  APNamingInfo dst = APNamingInfo(entry->getRemote().getApn(),
84  entry->getRemote().getApinstance(),
85  entry->getRemote().getAename(),
86  entry->getRemote().getAeinstance());
87  /*
88  * XXX: Vesely@Jerabek> Removing unnecessary *.msg ADT when there exists
89  * exactly the same ADT in RINASim source codes.
90  naming_t dst;
91  dst.AEInst = entry.getRemote().getAeinstance();
92  dst.AEName = entry.getRemote().getAename();
93  dst.ApInst = entry.getRemote().getApinstance();
94  dst.ApName = entry.getRemote().getApn().getName();
95 
96  naming_t src;
97  src.AEInst = entry.getLocal().getAeinstance();
98  src.AEName = entry.getLocal().getAename();
99  src.ApInst = entry.getLocal().getApinstance();
100  src.ApName = entry.getLocal().getApn().getName();
101  */
102 
103  msg->setSrc(src);
104  msg->setDst(dst);
105 
106  msg->setSrcAddr(Address(entry->getLocal().getApn()));
107  msg->setDstAddr(Address(entry->getRemote().getApn()));
108 
109  //send data to ribd to send
111 }
112 
114  //Enter_Method("insertStateTableEntry()");
115  //insert only first flow created (management flow)
116  if(StateTable->findEntryByDstAPNI(flow->getDstApni()) != NULL) {
117  return;
118  }
120 }
121 
123  //Enter_Method("receivePositiveConnectResponse()");
124 
125  //signalizeEnrolled();
126 
127  /* this is commented only for testing ---> refactoring of adress is need to be done*/
128  CDAP_M_Connect_R* cmsg = check_and_cast<CDAP_M_Connect_R*>(msg);
130  cmsg->getSrc().getApn(),
131  cmsg->getSrc().getApinstance(),
132  cmsg->getSrc().getAename(),
133  cmsg->getSrc().getAeinstance()));
134 
135  //check appropriate state
136  if (entry->getCACEConStatus() != DAFEnrollmentStateTableEntry::CON_AUTHENTICATING) {
137  //TODO: send M_Release and invoke deallocate
138  return;
139  }
140 
142 
143  outerClass->startEnrollment(entry);
144 }
145 
147  //Enter_Method("receiveNegativeConnectResponse()");
148 
149  CDAP_M_Connect_R* cmsg = check_and_cast<CDAP_M_Connect_R*>(msg);
151  cmsg->getSrc().getApn(),
152  cmsg->getSrc().getApinstance(),
153  cmsg->getSrc().getAename(),
154  cmsg->getSrc().getAeinstance()));
155 
156  //check appropriate state
157  if (entry->getCACEConStatus() != DAFEnrollmentStateTableEntry::CON_AUTHENTICATING) {
158  //TODO: send M_Release and invoke deallocate
159  return;
160  }
161 
162  if (this->outerClass->maxConRetries <= entry->getCurrentConnectRetries()) {
164  //TODO: send release and deallocate
165  return;
166  }
167 
168 
169  entry->setCACEConStatus(DAFEnrollmentStateTableEntry::CON_CONNECTPENDING);
170  entry->increaseCurrentConnectRetries();
171  //create and send new connect retry
172  processNewConReq(entry);
173 }
174 
176  //Enter_Method("receiveConnectRequest()");
177 
178  CDAP_M_Connect* cmsg = check_and_cast<CDAP_M_Connect*>(msg);
179 
180  auto ent = DAFEnrollmentStateTableEntry(
182  StateTable->insert(ent);
183 
185  cmsg->getSrc().getApn(),
186  cmsg->getSrc().getApinstance(),
187  cmsg->getSrc().getAename(),
188  cmsg->getSrc().getAeinstance()));
189 
190  if (!entry) {
191  EV << "DAFEnrollment status not found for "
192  << cmsg->getSrc().getApn() << endl;
193  return;
194  }
195 
196  //check appropriate state
198  //TODO: send M_Release and invoke deallocate
199  return;
200  }
201 
202  //check if message is valid
203  if (cmsg->getAbsSyntax() != GPB) {
204  this->processConResNega(entry, cmsg);
205  return;
206  }
207 
209 
210  authenticate(entry, cmsg);
211 }
212 
215  CDAP_M_Connect* cmsg1 = check_and_cast<CDAP_M_Connect*>(cmsg);
216 
217  APNamingInfo src = APNamingInfo(entry->getLocal().getApn(),
218  entry->getLocal().getApinstance(),
219  entry->getLocal().getAename(),
220  entry->getLocal().getAeinstance());
221 
222  APNamingInfo dst = APNamingInfo(entry->getRemote().getApn(),
223  entry->getRemote().getApinstance(),
224  entry->getRemote().getAename(),
225  entry->getRemote().getAeinstance());
226 
227  result_t result;
228  result.resultValue = R_SUCCESS;
229 
230  auth_t auth;
231  auth.authType = cmsg1->getAuth().authType;
232  auth.authValue = cmsg1->getAuth().authValue;
233 
234  msg->setAbsSyntax(GPB);
235  msg->setResult(result);
236  msg->setAuth(auth);
237 
238  msg->setSrc(src);
239  msg->setDst(dst);
240 
241  msg->setSrcAddr(Address(entry->getLocal().getApn()));
242  msg->setDstAddr(Address(entry->getRemote().getApn()));
243 
244  //send data to ribd to send
246 
249 }
250 
253  CDAP_M_Connect* cmsg1 = check_and_cast<CDAP_M_Connect*>(cmsg);
254 
255  APNamingInfo src = APNamingInfo(entry->getLocal().getApn(),
256  entry->getLocal().getApinstance(),
257  entry->getLocal().getAename(),
258  entry->getLocal().getAeinstance());
259 
260  APNamingInfo dst = APNamingInfo(entry->getRemote().getApn(),
261  entry->getRemote().getApinstance(),
262  entry->getRemote().getAename(),
263  entry->getRemote().getAeinstance());
264 
265  result_t result;
266  result.resultValue = R_FAIL;
267 
268  auth_t auth;
269  auth.authType = cmsg1->getAuth().authType;
270  auth.authValue = cmsg1->getAuth().authValue;
271 
272  msg->setAbsSyntax(GPB);
273  msg->setResult(result);
274  msg->setAuth(auth);
275 
276  msg->setSrc(src);
277  msg->setDst(dst);
278 
279  msg->setSrcAddr(Address(entry->getLocal().getApn()));
280  msg->setDstAddr(Address(entry->getRemote().getApn()));
281 
282  //send data to send to ribd
284 
286 
287  //increase number of connects
289 }
290 
292  //Enter_Method("processNewConReq()");
293 
294  //TODO: probably change values, this is retry
295 
297 
298  authValue_t aValue;
299  aValue.authName = this->outerClass->authName;
300  aValue.authPassword = this->outerClass->authPassword;
301  aValue.authOther = this->outerClass->authOther;
302 
303  auth_t auth;
304  auth.authType = this->outerClass->authType;
305  auth.authValue = aValue;
306 
307  msg->setAuth(auth);
308  msg->setAbsSyntax(GPB);
309 
310  APNamingInfo src = APNamingInfo(entry->getLocal().getApn(),
311  entry->getLocal().getApinstance(),
312  entry->getLocal().getAename(),
313  entry->getLocal().getAeinstance());
314 
315  APNamingInfo dst = APNamingInfo(entry->getRemote().getApn(),
316  entry->getRemote().getApinstance(),
317  entry->getRemote().getAename(),
318  entry->getRemote().getAeinstance());
319 
320  msg->setSrc(src);
321  msg->setDst(dst);
322 
323  msg->setSrcAddr(Address(entry->getLocal().getApn()));
324  msg->setDstAddr(Address(entry->getRemote().getApn()));
325 
326  //send data to ribd to send
328 
329  //change state to auth after send retry
331 }
void processConResNega(DAFEnrollmentStateTableEntry *entry, CDAPMessage *cmsg)
Definition: CACEMgmt.cc:251
virtual int32_t getAbsSyntax() const
const APNamingInfo & getRemote() const
void processConResPosi(DAFEnrollmentStateTableEntry *entry, CDAPMessage *cmsg)
Definition: CACEMgmt.cc:213
Class representing flow object with attributes from specs.
Definition: Flow.h:45
const APNamingInfo & getSrcApni() const
Gets read-only source APNamingInfo.
Definition: Flow.cc:134
virtual void setAuth(const auth_t &auth)
DAFEnrollmentStateTableEntry * findEntryByDstAPNI(const APNamingInfo &apni)
CACEMgmt()
Definition: CACEMgmt.cc:18
virtual void setAuth(const auth_t &auth)
void insertStateTableEntry(Flow *flow)
Definition: CACEMgmt.cc:113
virtual ~CACEMgmt()
Definition: CACEMgmt.cc:22
void receiveConnectRequest(CDAPMessage *msg)
Definition: CACEMgmt.cc:175
virtual APNamingInfo & getDst()
virtual void setSrcAddr(const Address &srcAddr)
virtual void setAbsSyntax(int32_t absSyntax)
std::string authOther
virtual void setDst(const APNamingInfo &dst)
virtual void setAbsSyntax(int32_t absSyntax)
void increaseCurrentConnectRetries()
void setDAFEnrollmentStatus(DAFEnrollmentStateTableEntry::DAFEnrollmentStatus status)
::omnetpp::opp_string authName
authValue_t authValue
const char * DAF_MSG_CONREQRETRY
Definition: CACEBase.cc:19
DAFEnrollmentStateTable * StateTable
const std::string & getAename() const
Getter of AE name.
Definition: APNamingInfo.h:110
const char * DAF_MSG_CONRESPOS
Definition: CACEBase.cc:20
const APN & getApn() const
Getter of APN.
Definition: APNamingInfo.h:142
unsigned char authType
void insert(DAFEnrollmentStateTableEntry entry)
virtual void setDst(const APNamingInfo &dst)
const char * DAF_MSG_CONREQ
Definition: CACEBase.cc:18
std::string authName
APNamingInfo holds complete naming info for particular application process.
Definition: APNamingInfo.h:43
DAFEnrollment * outerClass
Definition: CACEMgmt.h:47
virtual auth_t & getAuth()
DAFEnrollmentStateTable * StateTable
Definition: CACEBase.h:52
const APNamingInfo & getLocal() const
const std::string & getAeinstance() const
Getter of AE-instance attribute.
Definition: APNamingInfo.h:94
const std::string & getApinstance() const
Getter of AP-instance id.
Definition: APNamingInfo.h:126
std::string authPassword
DAFEnrollmentStateTableEntry::CACEConnectionStatus getCACEConStatus() const
virtual APNamingInfo & getSrc()
void processNewConReq(DAFEnrollmentStateTableEntry *entry)
Definition: CACEMgmt.cc:291
void authenticate(DAFEnrollmentStateTableEntry *entry, CDAP_M_Connect *msg)
Definition: CACEMgmt.cc:30
void setCACEConStatus(DAFEnrollmentStateTableEntry::CACEConnectionStatus status)
virtual void setDstAddr(const Address &dstAddr)
virtual void setSrc(const APNamingInfo &src)
void signalizeCACESendData(CDAPMessage *cmsg)
virtual void setSrc(const APNamingInfo &src)
::omnetpp::opp_string authPassword
void receivePositiveConnectResponse(CDAPMessage *msg)
Definition: CACEMgmt.cc:122
int32_t resultValue
::omnetpp::opp_string authOther
virtual APNamingInfo & getSrc()
void startCACE(Flow *flow)
Definition: CACEMgmt.cc:56
virtual void setResult(const result_t &result)
void startEnrollment(DAFEnrollmentStateTableEntry *entry)
Address class holds IPC Process identification.
Definition: Address.h:42
const APNamingInfo & getDstApni() const
Gets read-only destination APNamingInfo.
Definition: Flow.cc:102
void receiveNegativeConnectResponse(CDAPMessage *msg)
Definition: CACEMgmt.cc:146
const char * DAF_MSG_CONRESNEG
Definition: CACEBase.cc:21