RINASim  October 2016
Documentation of framework for OMNeT++
LS.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 /*
24  * LS.h
25  *
26  * Created on: Mar 23, 2015
27  * Author: gaixas1
28  */
29 
30 #ifndef LS_H_
31 #define LS_H_
32 
33 #include <DomainRouting/rModule.h>
34 
35 namespace DMRnmsLS {
36 
37 using namespace DMRnms;
38 
40 // Data structures
41 
42 typedef std::map<std::string, unsigned short> s2m;
43 typedef s2m::iterator s2mIt;
44 
45 struct linksU{
46  unsigned int sId;
47  s2m links;
49  :sId(0){}
50  linksU(const unsigned int &_sId)
51  :sId(_sId){}
52 };
53 
54 typedef std::map<std::string, linksU> linksSt;
55 typedef linksSt::iterator linksStIt;
56 
57 typedef std::map<Address, unsigned short> neighMetric;
58 typedef neighMetric::iterator neighMetricIt;
59 
60 typedef std::set<std::string> sSet;
61 typedef sSet::iterator sSetIt;
62 
63 typedef std::vector<std::string> sList;
64 typedef sList::iterator sListIt;
65 
66 
67 struct TreeNode {
68  std::string addr;
69  unsigned short metric;
70  std::set<TreeNode*> chl;
72  :addr(""), metric(UINT16_MAX) {}
73  TreeNode(const std::string &_addr, const unsigned short &_metric)
74  :addr(_addr), metric(_metric) {}
75 
76  bool operator == (const TreeNode &b) const { return addr == b.addr; }
77  bool operator < (const TreeNode &b) const { return addr < b.addr; }
78 
80  for(std::set<TreeNode *>::iterator it = chl.begin(); it != chl.end(); it++){
81  TreeNode * c = *it;
82  delete c;
83  }
84  }
85 };
86 typedef std::set<TreeNode *>::iterator TreeNodeIt;
87 
88 struct psT {
90  unsigned short metric;
91  psT()
92  :p(NULL), metric(UINT16_MAX){}
93  psT(TreeNode* _p, const unsigned short _metric)
94  :p(_p), metric(_metric){}
95 
96  bool operator == (const psT &b) const { return p == b.p; }
97  bool operator < (const psT &b) const { return p < b.p; }
98 };
99 typedef std::map<std::string, psT > wMap;
100 typedef wMap::iterator wMapIt;
101 
102 
104 // Update Message
105 
106 class LSUpdate : public RoutingUpdate {
107 public:
108  LSUpdate(const Address &_addr, const std::string &_domain);
109 
110  void addEntry(const std::string & _addr, linksU _neig);
111  void setEntries(linksSt _entries);
112 
113  linksStIt entriesBegin();
114  linksStIt entriesEnd();
115 
116 protected:
117  linksSt entries;
118 };
119 
121 // Routing Module
122 
123 
124 class LS: public rModule {
125 public:
126  LS(Routing * parent, const Address &_nAddr, const std::string &_domain, const std::string &_addr);
127 
128  bool processUpdate(RoutingUpdate * update);
129  void addFlow(const Address &_nAddr, const std::string &_addr, const unsigned short &_metric);
130  void removeFlow(const Address &_nAddr, const std::string &_addr);
131 
132  void addAddr(const std::string &_addr);
133  void removeAddr(const std::string &_addr);
134 
135  void setInfMetric(const unsigned short &inf);
136 
137  dmNxt getChanges();
138  dmNxt getAll();
139 
140  void handleMessage(cMessage *msg);
141 
142 protected:
143  sSet myAddrSet;
144 
145  neighMetric nei;
146  unsigned short infMetric;
147 
149  linksSt netState;
150  unsigned int secId;
151 
152  sSet changed;
153  linksSt getChangedEntries ();
154 
156  TreeNode constructTree();
157  void addRecursive(s2A &ret, const Address &next, TreeNode * t);
158 
160  void scheduleUpdate();
161 
162 };
163 
164 } /* namespace DomainRoutingLS */
165 
166 #endif /* LS_H_ */
std::map< Address, unsigned short > neighMetric
Definition: LS.h:57
TreeNode(const std::string &_addr, const unsigned short &_metric)
Definition: LS.h:73
unsigned short metric
Definition: LS.h:69
s2A currentTable
Definition: LS.h:155
linksSt::iterator linksStIt
Definition: LS.h:55
linksSt netState
Definition: LS.h:149
wMap::iterator wMapIt
Definition: LS.h:100
std::string addr
Definition: LS.h:68
neighMetric nei
Definition: LS.h:145
unsigned short infMetric
Definition: LS.h:146
std::set< std::string > sSet
Definition: LS.h:60
TreeNode * p
Definition: LS.h:89
bool scheduledUpdate
Definition: LS.h:159
Definition: LS.cc:33
sSet changed
Definition: LS.h:152
psT()
Definition: LS.h:91
sList::iterator sListIt
Definition: LS.h:64
linksSt entries
Definition: LS.h:117
sSet::iterator sSetIt
Definition: LS.h:61
s2m::iterator s2mIt
Definition: LS.h:43
sSet myAddrSet
Definition: LS.h:143
std::map< std::string, psT > wMap
Definition: LS.h:99
std::set< TreeNode * > chl
Definition: LS.h:70
s2A neigTable
Definition: LS.h:148
unsigned short metric
Definition: LS.h:90
std::set< TreeNode * >::iterator TreeNodeIt
Definition: LS.h:86
psT(TreeNode *_p, const unsigned short _metric)
Definition: LS.h:93
std::map< std::string, Address > s2A
Definition: rModule.h:43
std::map< std::string, linksU > linksSt
Definition: LS.h:54
std::map< std::string, unsigned short > s2m
Definition: LS.h:42
std::vector< std::string > sList
Definition: LS.h:63
neighMetric::iterator neighMetricIt
Definition: LS.h:58
unsigned int secId
Definition: LS.h:150
Address class holds IPC Process identification.
Definition: Address.h:42