blob: 022089738d6ac29d2514d57838da0fb9379e6f50 [file] [log] [blame]
akmhoque53353462014-04-22 08:43:45 -05001#ifndef NLSR_LSA_HPP
2#define NLSR_LSA_HPP
3
akmhoquefdbddb12014-05-02 18:35:19 -05004#include <boost/cstdint.hpp>
akmhoquec8a10f72014-04-25 18:42:55 -05005#include <ndn-cxx/util/scheduler.hpp>
akmhoque53353462014-04-22 08:43:45 -05006#include "adjacent.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -05007#include "name-prefix-list.hpp"
8#include "adjacency-list.hpp"
akmhoque53353462014-04-22 08:43:45 -05009
10namespace nlsr {
akmhoque31d1d4b2014-05-05 22:08:14 -050011
akmhoque53353462014-04-22 08:43:45 -050012class Lsa
13{
14public:
15 Lsa()
16 : m_origRouter()
17 , m_lsSeqNo()
18 , m_lifeTime()
19 , m_expiringEventId()
20 {
21 }
22
23
24 void
akmhoque31d1d4b2014-05-05 22:08:14 -050025 setLsType(const std::string& lst)
akmhoque53353462014-04-22 08:43:45 -050026 {
27 m_lsType = lst;
28 }
29
akmhoque31d1d4b2014-05-05 22:08:14 -050030 const std::string&
akmhoque53353462014-04-22 08:43:45 -050031 getLsType() const
32 {
33 return m_lsType;
34 }
35
36 void
37 setLsSeqNo(uint32_t lsn)
38 {
39 m_lsSeqNo = lsn;
40 }
41
42 uint32_t
43 getLsSeqNo() const
44 {
45 return m_lsSeqNo;
46 }
47
akmhoque31d1d4b2014-05-05 22:08:14 -050048 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -050049 getOrigRouter() const
50 {
51 return m_origRouter;
52 }
53
54 void
akmhoque31d1d4b2014-05-05 22:08:14 -050055 setOrigRouter(const ndn::Name& org)
akmhoque53353462014-04-22 08:43:45 -050056 {
57 m_origRouter = org;
58 }
59
60 uint32_t
61 getLifeTime() const
62 {
63 return m_lifeTime;
64 }
65
66 void
67 setLifeTime(uint32_t lt)
68 {
69 m_lifeTime = lt;
70 }
71
72 void
73 setExpiringEventId(const ndn::EventId leei)
74 {
75 m_expiringEventId = leei;
76 }
77
78 ndn::EventId
79 getExpiringEventId() const
80 {
81 return m_expiringEventId;
82 }
83
84protected:
akmhoque31d1d4b2014-05-05 22:08:14 -050085 ndn::Name m_origRouter;
86 std::string m_lsType;
akmhoque53353462014-04-22 08:43:45 -050087 uint32_t m_lsSeqNo;
88 uint32_t m_lifeTime;
89 ndn::EventId m_expiringEventId;
90};
91
92class NameLsa: public Lsa
93{
94public:
95 NameLsa()
96 : Lsa()
97 , m_npl()
98 {
akmhoque31d1d4b2014-05-05 22:08:14 -050099 setLsType("name");
akmhoque53353462014-04-22 08:43:45 -0500100 }
101
akmhoque31d1d4b2014-05-05 22:08:14 -0500102 NameLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
103 uint32_t lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500104 NamePrefixList& npl);
akmhoque53353462014-04-22 08:43:45 -0500105
akmhoquec8a10f72014-04-25 18:42:55 -0500106 NamePrefixList&
akmhoque53353462014-04-22 08:43:45 -0500107 getNpl()
108 {
109 return m_npl;
110 }
111
112 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500113 addName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500114 {
115 m_npl.insert(name);
116 }
117
118 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500119 removeName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500120 {
121 m_npl.remove(name);
122 }
123
akmhoque31d1d4b2014-05-05 22:08:14 -0500124 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500125 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500126
127 std::string
128 getData();
129
130 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500131 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500132
133 void
134 writeLog();
135
136private:
akmhoquec8a10f72014-04-25 18:42:55 -0500137 NamePrefixList m_npl;
akmhoque53353462014-04-22 08:43:45 -0500138
139};
140
141std::ostream&
142operator<<(std::ostream& os, NameLsa& nLsa);
143
144class AdjLsa: public Lsa
145{
146public:
147 AdjLsa()
148 : Lsa()
149 , m_adl()
150 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500151 setLsType("adjacency");
akmhoque53353462014-04-22 08:43:45 -0500152 }
153
akmhoque31d1d4b2014-05-05 22:08:14 -0500154 AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
155 uint32_t lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500156 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500157
akmhoquec8a10f72014-04-25 18:42:55 -0500158 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500159 getAdl()
160 {
161 return m_adl;
162 }
163
164 void
165 addAdjacent(Adjacent adj)
166 {
167 m_adl.insert(adj);
168 }
169
akmhoque31d1d4b2014-05-05 22:08:14 -0500170 const ndn::Name
171 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500172
173 std::string
174 getData();
175
176 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500177 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500178
179 uint32_t
180 getNoLink()
181 {
182 return m_noLink;
183 }
184
185 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500186 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500187
188 void
189 addNptEntries(Nlsr& pnlsr);
190
191 void
192 removeNptEntries(Nlsr& pnlsr);
193
194private:
195 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500196 AdjacencyList m_adl;
akmhoque53353462014-04-22 08:43:45 -0500197};
198
199std::ostream&
200operator<<(std::ostream& os, AdjLsa& aLsa);
201
akmhoqueb6450b12014-04-24 00:01:03 -0500202class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500203{
204public:
akmhoqueb6450b12014-04-24 00:01:03 -0500205 CoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500206 : Lsa()
207 , m_corRad(0)
208 , m_corTheta(0)
209 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500210 setLsType("coordinate");
akmhoque53353462014-04-22 08:43:45 -0500211 }
212
akmhoque31d1d4b2014-05-05 22:08:14 -0500213 CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn,
214 uint32_t lt
akmhoqueb6450b12014-04-24 00:01:03 -0500215 , double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500216
akmhoque31d1d4b2014-05-05 22:08:14 -0500217 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500218 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500219
220 std::string
221 getData();
222
223 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500224 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500225
226 double
akmhoqueb6450b12014-04-24 00:01:03 -0500227 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500228 {
229 if (m_corRad >= 0)
230 {
231 return m_corRad;
232 }
233 else
234 {
235 return -1;
236 }
237 }
238
239 void
240 setCorRadius(double cr)
241 {
242 m_corRad = cr;
243 }
244
245 double
akmhoqueb6450b12014-04-24 00:01:03 -0500246 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500247 {
248 return m_corTheta;
249 }
250
251 void
252 setCorTheta(double ct)
253 {
254 m_corTheta = ct;
255 }
256
257 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500258 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500259
260private:
261 double m_corRad;
262 double m_corTheta;
263
264};
265
266std::ostream&
akmhoqueb6450b12014-04-24 00:01:03 -0500267operator<<(std::ostream& os, const CoordinateLsa& cLsa);
akmhoque53353462014-04-22 08:43:45 -0500268
269
270}//namespace nlsr
271
272#endif //NLSR_LSA_HPP