RINASim  October 2016
Documentation of framework for OMNeT++
EnrollmentStateTable.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 "EnrollmentStateTable.h"
33 
34 const char* ELEM_ENSTATETAB = "EnrollmentStateTable";
35 const char* ELEM_ENSTATE = "State";
36 const char* ATTR_CACE = "cace";
37 const char* ATTR_ENROLL = "enroll";
38 
40 
42 {
43  //Parse XML config
44  parseConfig(par(PAR_CONFIGDATA).xmlValue());
45 
46  //Init watchers
47  WATCH_LIST(StateTable);
48 }
49 
51  if (!findEntryByDstAPN(entry.getRemote().getApn())) {
52  StateTable.push_back(entry);
53  }
54 }
55 
57  for(auto it = StateTable.begin(); it != StateTable.end(); ++it) {
58  EnrollmentStateTableEntry est = *it;
59  if (est.getRemote().getApn() == apn) {
60  return &(*it);
61  }
62  }
63  return NULL;
64 }
65 
66 
68 {
69 
70 }
71 
72 
74  for(auto it = StateTable.begin(); it != StateTable.end(); ++it) {
75  EnrollmentStateTableEntry est = *it;
76  //EV << est.getLocal().getApn() << " " << est.getEnrollmentStatusString() << endl;
77  if (est.getLocal().getApn() == myApn
79  return true;
80  }
81  }
82  return false;
83 }
84 
85 void EnrollmentStateTable::parseConfig(cXMLElement* config) {
86  cXMLElement* mainTag = NULL;
87  if (config != NULL && config->hasChildren() && config->getFirstChildWithTag(ELEM_ENSTATETAB))
88  mainTag = config->getFirstChildWithTag(ELEM_ENSTATETAB);
89  else {
90  EV << "configData parameter not initialized!" << endl;
91  return;
92  }
93 
94  cXMLElementList enrll = mainTag->getChildrenByTagName(ELEM_ENSTATE);
95  for (cXMLElementList::const_iterator it = enrll.begin(); it != enrll.end(); ++it) {
96  cXMLElement* m = *it;
97 
98  if (!(m->getAttribute(ATTR_SRC))
99  && !(m->getAttribute(ATTR_DST))
100  ) {
101  EV << "\nError when parsing EnrollmentState record" << endl;
102  continue;
103  }
104 
105 
106  APNamingInfo src = APNamingInfo(APN(m->getAttribute(ATTR_SRC)));
107  APNamingInfo dst = APNamingInfo(APN(m->getAttribute(ATTR_DST)));
108 
109 
111  if ( m->getAttribute(ATTR_CACE) ) {
112  std::string statstr(m->getAttribute(ATTR_CACE));
113  if (!statstr.compare("CON_ERROR"))
115  else if (!statstr.compare("CON_NIL"))
117  else if (!statstr.compare("CON_FLOWPENDING"))
119  else if (!statstr.compare("CON_CONNECTPENDING"))
121  else if (!statstr.compare("CON_AUTHENTICATING"))
123  else if (!statstr.compare("CON_ESTABLISHED"))
125  else if (!statstr.compare("CON_RELEASING"))
127  }
128 
130  if ( m->getAttribute(ATTR_ENROLL) ) {
131  std::string enrlstr(m->getAttribute(ATTR_ENROLL));
132  if (!enrlstr.compare("ENROLL_ERROR"))
134  else if (!enrlstr.compare("ENROLL_NIL"))
136  else if (!enrlstr.compare("ENROLL_WAIT_START_ENROLLMENT"))
138  else if (!enrlstr.compare("ENROLL_WAIT_START_RESPONSE_ENROLLMENT"))
140  else if (!enrlstr.compare("ENROLL_WAIT_STOP_ENROLLMENT"))
142  else if (!enrlstr.compare("ENROLL_WAIT_STOP_RESPONSE_ENROLLMENT"))
144  else if (!enrlstr.compare("ENROLL_WAIT_READ_RESPONSE"))
146  else if (!enrlstr.compare("ENROLL_WAIT_START_OPERATION"))
148  else if (!enrlstr.compare("ENROLL_CREATING_OBJ"))
150  else if (!enrlstr.compare("ENROLL_ENROLLED"))
152  }
153 
154  insert(EnrollmentStateTableEntry(src, dst, stat, enrl));
155  }
156 }
Enrollment state table .
const char * ATTR_CACE
Application Process Name class.
Definition: APN.h:36
const char * ELEM_ENSTATE
virtual void handleMessage(cMessage *msg)
void insert(EnrollmentStateTableEntry entry)
const char * ATTR_SRC
const char * PAR_CONFIGDATA
const APNamingInfo & getLocal() const
EnrollmentStateTableEntry * findEntryByDstAPN(const APN &apn)
const APN & getApn() const
Getter of APN.
Definition: APNamingInfo.h:142
EnrollStateTable StateTable
const char * ELEM_ENSTATETAB
APNamingInfo holds complete naming info for particular application process.
Definition: APNamingInfo.h:43
bool isEnrolled(const APN &myApn)
const APNamingInfo & getRemote() const
const char * ATTR_ENROLL
Define_Module(EnrollmentStateTable)
const char * ATTR_DST
void parseConfig(cXMLElement *config)
EnrollmentStateTableEntry::EnrollmentStatus getEnrollmentStatus() const