blob: 1db70d7b41b958d52eaf68702390f0c165392d7c [file] [log] [blame]
akmhoque53353462014-04-22 08:43:45 -05001#ifndef NLSR_LSA_HPP
2#define NLSR_LSA_HPP
3
akmhoquec8a10f72014-04-25 18:42:55 -05004#include <ndn-cxx/util/scheduler.hpp>
akmhoque53353462014-04-22 08:43:45 -05005#include "adjacent.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -05006#include "name-prefix-list.hpp"
7#include "adjacency-list.hpp"
akmhoque53353462014-04-22 08:43:45 -05008
9namespace nlsr {
10class Lsa
11{
12public:
13 Lsa()
14 : m_origRouter()
15 , m_lsSeqNo()
16 , m_lifeTime()
17 , m_expiringEventId()
18 {
19 }
20
21
22 void
23 setLsType(uint8_t lst)
24 {
25 m_lsType = lst;
26 }
27
28 uint8_t
29 getLsType() const
30 {
31 return m_lsType;
32 }
33
34 void
35 setLsSeqNo(uint32_t lsn)
36 {
37 m_lsSeqNo = lsn;
38 }
39
40 uint32_t
41 getLsSeqNo() const
42 {
43 return m_lsSeqNo;
44 }
45
46 std::string
47 getOrigRouter() const
48 {
49 return m_origRouter;
50 }
51
52 void
53 setOrigRouter(const std::string& org)
54 {
55 m_origRouter = org;
56 }
57
58 uint32_t
59 getLifeTime() const
60 {
61 return m_lifeTime;
62 }
63
64 void
65 setLifeTime(uint32_t lt)
66 {
67 m_lifeTime = lt;
68 }
69
70 void
71 setExpiringEventId(const ndn::EventId leei)
72 {
73 m_expiringEventId = leei;
74 }
75
76 ndn::EventId
77 getExpiringEventId() const
78 {
79 return m_expiringEventId;
80 }
81
82protected:
83 std::string m_origRouter;
84 uint8_t m_lsType;
85 uint32_t m_lsSeqNo;
86 uint32_t m_lifeTime;
87 ndn::EventId m_expiringEventId;
88};
89
90class NameLsa: public Lsa
91{
92public:
93 NameLsa()
94 : Lsa()
95 , m_npl()
96 {
97 setLsType(1);
98 }
99
akmhoquec8a10f72014-04-25 18:42:55 -0500100 NameLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
101 NamePrefixList npl);
akmhoque53353462014-04-22 08:43:45 -0500102
akmhoquec8a10f72014-04-25 18:42:55 -0500103 NamePrefixList&
akmhoque53353462014-04-22 08:43:45 -0500104 getNpl()
105 {
106 return m_npl;
107 }
108
109 void
110 addName(std::string& name)
111 {
112 m_npl.insert(name);
113 }
114
115 void
116 removeName(std::string& name)
117 {
118 m_npl.remove(name);
119 }
120
121 std::string
akmhoqueb6450b12014-04-24 00:01:03 -0500122 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500123
124 std::string
125 getData();
126
127 bool
128 initializeFromContent(std::string content);
129
130 void
131 writeLog();
132
133private:
akmhoquec8a10f72014-04-25 18:42:55 -0500134 NamePrefixList m_npl;
akmhoque53353462014-04-22 08:43:45 -0500135
136};
137
138std::ostream&
139operator<<(std::ostream& os, NameLsa& nLsa);
140
141class AdjLsa: public Lsa
142{
143public:
144 AdjLsa()
145 : Lsa()
146 , m_adl()
147 {
148 setLsType(2);
149 }
150
151 AdjLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
akmhoquec8a10f72014-04-25 18:42:55 -0500152 uint32_t nl , AdjacencyList adl);
akmhoque53353462014-04-22 08:43:45 -0500153
akmhoquec8a10f72014-04-25 18:42:55 -0500154 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500155 getAdl()
156 {
157 return m_adl;
158 }
159
160 void
161 addAdjacent(Adjacent adj)
162 {
163 m_adl.insert(adj);
164 }
165
166 std::string
167 getKey();
168
169 std::string
170 getData();
171
172 bool
173 initializeFromContent(std::string content);
174
175 uint32_t
176 getNoLink()
177 {
178 return m_noLink;
179 }
180
181 bool
182 isEqual(AdjLsa& alsa);
183
184 void
185 addNptEntries(Nlsr& pnlsr);
186
187 void
188 removeNptEntries(Nlsr& pnlsr);
189
190private:
191 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500192 AdjacencyList m_adl;
akmhoque53353462014-04-22 08:43:45 -0500193};
194
195std::ostream&
196operator<<(std::ostream& os, AdjLsa& aLsa);
197
akmhoqueb6450b12014-04-24 00:01:03 -0500198class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500199{
200public:
akmhoqueb6450b12014-04-24 00:01:03 -0500201 CoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500202 : Lsa()
203 , m_corRad(0)
204 , m_corTheta(0)
205 {
206 setLsType(3);
207 }
208
akmhoqueb6450b12014-04-24 00:01:03 -0500209 CoordinateLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt
210 , double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500211
212 std::string
akmhoqueb6450b12014-04-24 00:01:03 -0500213 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500214
215 std::string
216 getData();
217
218 bool
219 initializeFromContent(std::string content);
220
221 double
akmhoqueb6450b12014-04-24 00:01:03 -0500222 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500223 {
224 if (m_corRad >= 0)
225 {
226 return m_corRad;
227 }
228 else
229 {
230 return -1;
231 }
232 }
233
234 void
235 setCorRadius(double cr)
236 {
237 m_corRad = cr;
238 }
239
240 double
akmhoqueb6450b12014-04-24 00:01:03 -0500241 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500242 {
243 return m_corTheta;
244 }
245
246 void
247 setCorTheta(double ct)
248 {
249 m_corTheta = ct;
250 }
251
252 bool
akmhoqueb6450b12014-04-24 00:01:03 -0500253 isEqual(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500254
255private:
256 double m_corRad;
257 double m_corTheta;
258
259};
260
261std::ostream&
akmhoqueb6450b12014-04-24 00:01:03 -0500262operator<<(std::ostream& os, const CoordinateLsa& cLsa);
akmhoque53353462014-04-22 08:43:45 -0500263
264
265}//namespace nlsr
266
267#endif //NLSR_LSA_HPP