|
a |
|
b/src/DAF/DA/NamingInformation.cc |
|
|
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 "NamingInformation.h"
|
|
|
17 |
|
|
|
18 |
//Constants
|
|
|
19 |
const char* ELEM_NAMINGTABLE = "NamingInfo";
|
|
|
20 |
const char* ELEM_SYNONYM = "Synonym";
|
|
|
21 |
|
|
|
22 |
Define_Module(NamingInformation);
|
|
|
23 |
|
|
|
24 |
void NamingInformation::initialize()
|
|
|
25 |
{
|
|
|
26 |
//Parse XML config
|
|
|
27 |
parseConfig(par(PAR_CONFIGDATA).xmlValue());
|
|
|
28 |
|
|
|
29 |
//Init watchers
|
|
|
30 |
WATCH_LIST(NamingInfoTable);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
void NamingInformation::addNamingEntry(const APN& apn) {
|
|
|
34 |
NamingInfoTable.push_back(NamingInformationEntry(apn));
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
NamingInformationEntry* NamingInformation::findNamingEntryByApn(const APN& apn) {
|
|
|
38 |
for (NamingItem it = NamingInfoTable.begin(); it != NamingInfoTable.end(); ++it) {
|
|
|
39 |
if (it->getApn() == apn)
|
|
|
40 |
return &(*it);
|
|
|
41 |
}
|
|
|
42 |
return NULL;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
void NamingInformation::addNewSynonym(const APN& apn, const APN& synonym) {
|
|
|
46 |
findNamingEntryByApn(apn)->addSynonym(synonym);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
void NamingInformation::removeNamingEntry(const APN& apn) {
|
|
|
50 |
NamingInfoTable.remove(*(findNamingEntryByApn(apn)));
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
NamingInformationEntry* NamingInformation::findNamingEntryBySynonym(const APN& synonym) {
|
|
|
54 |
for (NamingItem it = NamingInfoTable.begin(); it != NamingInfoTable.end(); ++it) {
|
|
|
55 |
if (it->hasSynonym(synonym))
|
|
|
56 |
return &(*it);
|
|
|
57 |
}
|
|
|
58 |
return NULL;
|
|
|
59 |
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
const APN* NamingInformation::findApnBySynonym(const APN& synonym) {
|
|
|
63 |
NamingInformationEntry* entry = findNamingEntryBySynonym(synonym);
|
|
|
64 |
return entry ? &(entry->getApn()) : NULL;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
void NamingInformation::handleMessage(cMessage *msg)
|
|
|
68 |
{
|
|
|
69 |
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
const APNList NamingInformation::findAllApnNames(const APN& apn) {
|
|
|
73 |
NamingInformationEntry* entry1 = findNamingEntryByApn(apn);
|
|
|
74 |
NamingInformationEntry* entry2 = findNamingEntryBySynonym(apn);
|
|
|
75 |
|
|
|
76 |
APNList result = APNList();
|
|
|
77 |
//APN does not exist within NamingInfo
|
|
|
78 |
if (entry1 == NULL && entry2 == NULL) {
|
|
|
79 |
EV << "No NamingInfo thus considering " << apn << " as unique!" << endl;
|
|
|
80 |
result.push_back(apn);
|
|
|
81 |
}
|
|
|
82 |
//APN without any synonyms
|
|
|
83 |
else if (entry1 != NULL && entry2 == NULL) {
|
|
|
84 |
result.push_back(apn);
|
|
|
85 |
}
|
|
|
86 |
//Found based on synonym
|
|
|
87 |
else if (entry1 == NULL && entry2 != NULL) {
|
|
|
88 |
result = entry2->getSynonyms();
|
|
|
89 |
result.push_back(apn);
|
|
|
90 |
}
|
|
|
91 |
//Inconsistancy where two different NI are returned
|
|
|
92 |
else {
|
|
|
93 |
EV << "NamingInfo contains inconsistency" << endl
|
|
|
94 |
<< *entry1 << endl
|
|
|
95 |
<< *entry2 << endl;
|
|
|
96 |
}
|
|
|
97 |
return result;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
void NamingInformation::parseConfig(cXMLElement* config) {
|
|
|
101 |
cXMLElement* mainTag = NULL;
|
|
|
102 |
if (config != NULL && config->hasChildren() && config->getFirstChildWithTag(ELEM_NAMINGTABLE))
|
|
|
103 |
mainTag = config->getFirstChildWithTag(ELEM_NAMINGTABLE);
|
|
|
104 |
else {
|
|
|
105 |
EV << "configData parameter not initialized!" << endl;
|
|
|
106 |
return;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
cXMLElementList apnlist = mainTag->getChildrenByTagName(ELEM_APN);
|
|
|
111 |
for (cXMLElementList::const_iterator it = apnlist.begin(); it != apnlist.end(); ++it) {
|
|
|
112 |
cXMLElement* m = *it;
|
|
|
113 |
|
|
|
114 |
if (!(m->getAttribute(ATTR_APN) && m->getFirstChildWithTag(ELEM_SYNONYM))) {
|
|
|
115 |
EV << "\nError when parsing NaimingInfo record" << endl;
|
|
|
116 |
continue;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
APN newapn = APN(m->getAttribute(ATTR_APN));
|
|
|
120 |
|
|
|
121 |
addNamingEntry(newapn);
|
|
|
122 |
|
|
|
123 |
cXMLElementList synonymlist = m->getChildrenByTagName(ELEM_SYNONYM);
|
|
|
124 |
for (cXMLElementList::const_iterator jt = synonymlist.begin(); jt != synonymlist.end(); ++jt) {
|
|
|
125 |
cXMLElement* n = *jt;
|
|
|
126 |
|
|
|
127 |
if (!(n->getAttribute(ATTR_APN))) {
|
|
|
128 |
EV << "\nError when parsing Synonym record" << endl;
|
|
|
129 |
continue;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
addNewSynonym(newapn, APN(n->getAttribute(ATTR_APN)));
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|