blob: 041e32c14095c0ac85596b549eb2a79de78bda67 [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,
akmhoque157b0a42014-05-13 00:26:37 -0500155 uint32_t lt, uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500156
akmhoquec8a10f72014-04-25 18:42:55 -0500157 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500158 getAdl()
159 {
160 return m_adl;
161 }
162
163 void
164 addAdjacent(Adjacent adj)
165 {
166 m_adl.insert(adj);
167 }
168
akmhoque31d1d4b2014-05-05 22:08:14 -0500169 const ndn::Name
170 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500171
172 std::string
173 getData();
174
175 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500176 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500177
178 uint32_t
179 getNoLink()
180 {
181 return m_noLink;
182 }
183
184 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500185 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500186
187 void
188 addNptEntries(Nlsr& pnlsr);
189
190 void
191 removeNptEntries(Nlsr& pnlsr);
192
193private:
194 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500195 AdjacencyList m_adl;
akmhoque53353462014-04-22 08:43:45 -0500196};
197
198std::ostream&
199operator<<(std::ostream& os, AdjLsa& aLsa);
200
akmhoqueb6450b12014-04-24 00:01:03 -0500201class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500202{
203public:
akmhoqueb6450b12014-04-24 00:01:03 -0500204 CoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500205 : Lsa()
206 , m_corRad(0)
207 , m_corTheta(0)
208 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500209 setLsType("coordinate");
akmhoque53353462014-04-22 08:43:45 -0500210 }
211
akmhoque31d1d4b2014-05-05 22:08:14 -0500212 CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn,
213 uint32_t lt
akmhoqueb6450b12014-04-24 00:01:03 -0500214 , double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500215
akmhoque31d1d4b2014-05-05 22:08:14 -0500216 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500217 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500218
219 std::string
220 getData();
221
222 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500223 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500224
225 double
akmhoqueb6450b12014-04-24 00:01:03 -0500226 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500227 {
akmhoque53353462014-04-22 08:43:45 -0500228 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500229 }
230
231 void
232 setCorRadius(double cr)
233 {
akmhoque157b0a42014-05-13 00:26:37 -0500234 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500235 }
236
237 double
akmhoqueb6450b12014-04-24 00:01:03 -0500238 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500239 {
240 return m_corTheta;
241 }
242
243 void
244 setCorTheta(double ct)
245 {
246 m_corTheta = ct;
247 }
248
249 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500250 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500251
252private:
253 double m_corRad;
254 double m_corTheta;
255
256};
257
258std::ostream&
akmhoqueb6450b12014-04-24 00:01:03 -0500259operator<<(std::ostream& os, const CoordinateLsa& cLsa);
akmhoque53353462014-04-22 08:43:45 -0500260
261
262}//namespace nlsr
263
264#endif //NLSR_LSA_HPP