RINASim  October 2016
Documentation of framework for OMNeT++
SimpleLS.h
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 #ifndef SimpleLS_H_
24 #define SimpleLS_H_
25 
26 #include <IntSimpleRouting.h>
27 
28 #include <vector>
29 #include <map>
30 
31 namespace SimpleLS {
32 
33 struct linksU{
34  unsigned int sId;
35  std::map<std::string, unsigned short> links;
36  linksU(){
37  sId = 0;
38  }
39  linksU(const unsigned int &_sId){
40  sId = _sId;
41  }
42 };
43 
44 typedef std::map<std::string, linksU> linksSt;
45 typedef std::pair<std::string, linksU> linksStEntry;
46 
47 typedef std::map<std::string, linksSt> linksStCol;
48 typedef std::pair<std::string, linksSt> linksStColEntry;
49 
50 typedef std::map<std::string, unsigned short>::iterator linksIt;
51 typedef linksSt::iterator linksStIt;
52 typedef linksStCol::iterator linksStColIt;
53 
54 typedef std::map<Address, unsigned short> neighMetric;
55 typedef std::map<std::string, neighMetric> qosNeighMetric;
56 typedef neighMetric::iterator neighMetricIt;
57 typedef qosNeighMetric::iterator qosNeighMetricIt;
58 
59 
60 typedef std::set<std::string> qosSet;
61 typedef std::set<std::string> addrSet;
62 typedef std::vector<std::string> addrList;
63 typedef std::map<std::string, addrSet> qos2addrSet;
64 typedef std::pair<std::string, addrSet> qos2addrSetEntry;
65 typedef qosSet::iterator qosSetIt;
66 typedef addrSet::iterator addrSetIt;
67 typedef qos2addrSet::iterator qos2addrSetIt;
68 
69 struct TreeNode {
70  std::string addr;
71  unsigned short metric;
72  std::set<TreeNode*> chldel;
73  std::set<TreeNode*> chl;
75  addr = "";
76  metric = UINT16_MAX;
77  }
78  TreeNode(const std::string &_addr, const unsigned short &_metric){
79  addr = _addr;
80  metric = _metric;
81  }
82  bool operator == (const TreeNode &b) const
83  {
84  return addr == b.addr;
85  }
86  bool operator < (const TreeNode &b) const
87  {
88  return addr < b.addr;
89  }
90 
92  for(TreeNode * c: chldel){
93  delete c;
94  }
95  }
96 
97 };
98 typedef std::set<TreeNode *>::iterator TreeNodeIt;
99 
100 struct psT {
101  std::set<TreeNode*> p;
102  unsigned short metric;
103  psT(){
104  metric = UINT16_MAX;
105  }
106  psT(TreeNode* _p, const unsigned short _metric){
107  p.insert(_p);
108  metric = _metric;
109  }
110 
111  void addParent(TreeNode* _p, const unsigned short _metric){
112  if(metric > _metric) {
113  metric = _metric;
114  p.clear();
115  }
116  if(metric == _metric) {
117  p.insert(_p);
118  }
119  }
120 
121  bool operator == (const psT &b) const
122  {
123  return p == b.p;
124  }
125  bool operator < (const psT &b) const
126  {
127  return p < b.p;
128  }
129 };
130 
131 typedef std::map<std::string, psT > wMap;
132 typedef std::map<std::string, unsigned short > aMap;
133 
134 typedef wMap::iterator wMapIt;
135 typedef aMap::iterator aMapIt;
136 
137 typedef std::vector<wMapIt> mList;
138 typedef mList::iterator mListIt;
139 
141 public:
142  RoutingUpdate(const Address &_addr, const std::string&_qos);
143 
144  std::string getQoS();
145 
146  void addEntry(const std::string &, linksU);
147  void setEntries(linksSt);
148 
149  linksStIt entriesBegin();
150  linksStIt entriesEnd();
151 
152 protected:
153  std::string qos;
154  linksSt entries;
155 };
156 
157 class SimpleLS: public IntSimpleRouting {
158 public:
159  //Process a Routing Update, return true => inform FWDG of the update
160  bool processUpdate(IntRoutingUpdate * update);
161 
162 
163  //Flow inserted/removed
164  void insertFlow(const Address &addr, const std::string &dst, const std::string& qos, const unsigned short &metric);
165  void removeFlow(const Address &addr, const std::string &dst, const std::string& qos);
166 
167  //Get Changes
168  entries2Next getChanges();
169  entries2Next getAll();
170 
171  void handleMessage(cMessage *msg);
172  void finish();
173 
174 protected:
175  // Called after initialize
176  void onPolicyInit();
177 
178 private:
179  unsigned short infMetric;
180  std::string myAddr;
181  qosNeighMetric neig;
182  linksStCol netState;
183  qos2addrSet lastChanges;
184  unsigned int secId;
185  linksSt getChangedEntries (const std::string& qos);
186 
187  TreeNode constructTree(linksSt &ls);
188  void addRecursive(entries2Next &ret, const std::string& qos, const std::string &next, TreeNode * t);
189 
191  void scheduleUpdate();
192 
194 
195 
196  void printTreeNode(TreeNode *t, const std::string &next);
197 };
198 
199 }
200 
201 #endif /* SimpleLS_H_ */
std::map< std::string, linksU > linksSt
Definition: SimpleLS.h:44
std::string getQoS()
Definition: SimpleLS.cc:36
qosSet::iterator qosSetIt
Definition: SimpleLS.h:65
void addEntry(const std::string &, linksU)
Definition: SimpleLS.cc:40
bool operator==(const psT &b) const
Definition: SimpleLS.h:121
unsigned short metric
Definition: SimpleLS.h:102
neighMetric::iterator neighMetricIt
Definition: SimpleLS.h:56
unsigned short metric
Definition: SimpleLS.h:71
std::map< std::string, unsigned short > aMap
Definition: SimpleLS.h:132
void addParent(TreeNode *_p, const unsigned short _metric)
Definition: SimpleLS.h:111
unsigned short infMetric
Definition: SimpleLS.h:179
std::map< std::string, neighMetric > qosNeighMetric
Definition: SimpleLS.h:55
std::map< std::string, addrSet > qos2addrSet
Definition: SimpleLS.h:63
addrSet::iterator addrSetIt
Definition: SimpleLS.h:66
std::set< TreeNode * > p
Definition: SimpleLS.h:101
std::set< std::string > addrSet
Definition: SimpleLS.h:61
std::map< Address, unsigned short > neighMetric
Definition: SimpleLS.h:54
std::map< std::string, psT > wMap
Definition: SimpleLS.h:131
mList::iterator mListIt
Definition: SimpleLS.h:138
std::vector< wMapIt > mList
Definition: SimpleLS.h:137
aMap::iterator aMapIt
Definition: SimpleLS.h:135
qos2addrSet::iterator qos2addrSetIt
Definition: SimpleLS.h:67
bool operator<(const TreeNode &b) const
Definition: SimpleLS.h:86
bool operator==(const TreeNode &b) const
Definition: SimpleLS.h:82
std::map< qosPaddr, std::string > entries2Next
qosNeighMetric neig
Definition: SimpleLS.h:181
wMap::iterator wMapIt
Definition: SimpleLS.h:134
psT(TreeNode *_p, const unsigned short _metric)
Definition: SimpleLS.h:106
std::map< std::string, linksSt > linksStCol
Definition: SimpleLS.h:47
bool operator<(const psT &b) const
Definition: SimpleLS.h:125
std::set< std::string > qosSet
Definition: SimpleLS.h:60
std::set< TreeNode * >::iterator TreeNodeIt
Definition: SimpleLS.h:98
qos2addrSet lastChanges
Definition: SimpleLS.h:183
std::string addr
Definition: SimpleLS.h:70
linksStIt entriesEnd()
Definition: SimpleLS.cc:51
std::vector< std::string > addrList
Definition: SimpleLS.h:62
std::string myAddr
Definition: SimpleLS.h:180
std::map< std::string, unsigned short >::iterator linksIt
Definition: SimpleLS.h:50
std::pair< std::string, linksSt > linksStColEntry
Definition: SimpleLS.h:48
linksStCol netState
Definition: SimpleLS.h:182
std::pair< std::string, linksU > linksStEntry
Definition: SimpleLS.h:45
linksStIt entriesBegin()
Definition: SimpleLS.cc:48
unsigned int secId
Definition: SimpleLS.h:184
entries2Next table
Definition: SimpleLS.h:193
std::pair< std::string, addrSet > qos2addrSetEntry
Definition: SimpleLS.h:64
TreeNode(const std::string &_addr, const unsigned short &_metric)
Definition: SimpleLS.h:78
std::set< TreeNode * > chldel
Definition: SimpleLS.h:72
qosNeighMetric::iterator qosNeighMetricIt
Definition: SimpleLS.h:57
linksStCol::iterator linksStColIt
Definition: SimpleLS.h:52
RoutingUpdate(const Address &_addr, const std::string &_qos)
Definition: SimpleLS.cc:32
std::set< TreeNode * > chl
Definition: SimpleLS.h:73
void setEntries(linksSt)
Definition: SimpleLS.cc:44
Address class holds IPC Process identification.
Definition: Address.h:42
linksSt::iterator linksStIt
Definition: SimpleLS.h:51