RINASim  October 2016
Documentation of framework for OMNeT++
NeighborTable.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 "NeighborTable.h"
24 
25 //Constants
26 const char* ELEM_NEIGHTAB = "NeighborTable";
27 const char* ELEM_NEIGHBOR = "Neighbor";
28 
30 
32  std::ostringstream description;
33  description << NeiTable.size() << " entries";
34  this->getDisplayString().setTagArg("t", 0, description.str().c_str());
35  this->getDisplayString().setTagArg("t", 1, "t");
36 }
37 
39 {
40  //Parse XML config
41  parseConfig(par(PAR_CONFIGDATA).xmlValue());
42 
44  //Init watchers
45  WATCH_LIST(NeiTable);
46 }
47 
48 void NeighborTable::handleMessage(cMessage *msg)
49 {
50 
51 }
52 
54  NeiTable.push_back(NeighborTableEntry(apn));
55 }
56 
58  for (NeiEntryItem it = NeiTable.begin(); it != NeiTable.end(); ++it) {
59  if (it->getApn() == apn)
60  return &(*it);
61  }
62  return NULL;
63 }
64 
67  return entry ? &(entry->getNeigbors()) : NULL;
68 }
69 
70 void NeighborTable::addNewNeighbor(const APN& apn, const APN& neighbor) {
71  findNeighborEntryByApn(apn)->addNeighbor(neighbor);
72 }
73 
75  NeiTable.remove(*(findNeighborEntryByApn(apn)));
76 }
77 
79  APNList* apnlist = new APNList();
80  for (NeiEntryCItem it = NeiTable.begin(); it != NeiTable.end(); ++it) {
81  if (it->hasNeighbor(neighbor)) {
82  apnlist->push_back(it->getApn());
83  }
84  }
85  return apnlist;
86 }
87 
88 void NeighborTable::parseConfig(cXMLElement* config) {
89  cXMLElement* mainTag = NULL;
90  if (config != NULL && config->hasChildren() && config->getFirstChildWithTag(ELEM_NEIGHTAB))
91  mainTag = config->getFirstChildWithTag(ELEM_NEIGHTAB);
92  else {
93  EV << "configData parameter not initialized!" << endl;
94  return;
95  }
96 
97  cXMLElementList apnlist = mainTag->getChildrenByTagName(ELEM_APN);
98  for (cXMLElementList::const_iterator it = apnlist.begin(); it != apnlist.end(); ++it) {
99  cXMLElement* m = *it;
100 
101  if (!(m->getAttribute(ATTR_APN) && m->getFirstChildWithTag(ELEM_NEIGHBOR))) {
102  EV << "\nError when parsing NeighborTable record" << endl;
103  continue;
104  }
105 
106  APN newapn = APN(m->getAttribute(ATTR_APN));
107 
108  addNeighborEntry(newapn);
109 
110  cXMLElementList neighborlist = m->getChildrenByTagName(ELEM_NEIGHBOR);
111  for (cXMLElementList::const_iterator jt = neighborlist.begin(); jt != neighborlist.end(); ++jt) {
112  cXMLElement* n = *jt;
113 
114  if (!(n->getAttribute(ATTR_APN))) {
115  EV << "\nError when parsing Synonym record" << endl;
116  continue;
117  }
118 
119  addNewNeighbor(newapn, APN(n->getAttribute(ATTR_APN)));
120  }
121  }
122 
123 
124 }
const char * ELEM_NEIGHBOR
Application Process Name class.
Definition: APN.h:36
const char * ELEM_APN
void addNewNeighbor(const APN &apn, const APN &neighbor)
void parseConfig(cXMLElement *config)
NeighborEntries::const_iterator NeiEntryCItem
Definition: NeighborTable.h:33
std::list< APN > APNList
APNList represents the list of APNs.
Definition: APN.h:96
const char * PAR_CONFIGDATA
void addNeighborEntry(const APN &apn)
const char * ELEM_NEIGHTAB
Define_Module(NeighborTable)
void updateDisplayString()
virtual void initialize()
const APNList * findNeighborsByApn(const APN &apn)
const char * ATTR_APN
virtual void handleMessage(cMessage *msg)
void removeNeighborEntry(const APN &apn)
NeighborTableEntry * findNeighborEntryByApn(const APN &apn)
NeighborEntries NeiTable
Definition: NeighborTable.h:49
const APNList * findApnsByNeighbor(const APN &neighbor)
NeighborEntries::iterator NeiEntryItem
Definition: NeighborTable.h:32
void addNeighbor(const APN &neighbor)
const APNList & getNeigbors() const