blob: 3a86c09cf309e17d6a39e83439d2f574f6854d2c [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 {
11class Lsa
12{
13public:
14 Lsa()
15 : m_origRouter()
16 , m_lsSeqNo()
17 , m_lifeTime()
18 , m_expiringEventId()
19 {
20 }
21
22
23 void
24 setLsType(uint8_t lst)
25 {
26 m_lsType = lst;
27 }
28
29 uint8_t
30 getLsType() const
31 {
32 return m_lsType;
33 }
34
35 void
36 setLsSeqNo(uint32_t lsn)
37 {
38 m_lsSeqNo = lsn;
39 }
40
41 uint32_t
42 getLsSeqNo() const
43 {
44 return m_lsSeqNo;
45 }
46
47 std::string
48 getOrigRouter() const
49 {
50 return m_origRouter;
51 }
52
53 void
54 setOrigRouter(const std::string& org)
55 {
56 m_origRouter = org;
57 }
58
59 uint32_t
60 getLifeTime() const
61 {
62 return m_lifeTime;
63 }
64
65 void
66 setLifeTime(uint32_t lt)
67 {
68 m_lifeTime = lt;
69 }
70
71 void
72 setExpiringEventId(const ndn::EventId leei)
73 {
74 m_expiringEventId = leei;
75 }
76
77 ndn::EventId
78 getExpiringEventId() const
79 {
80 return m_expiringEventId;
81 }
82
83protected:
84 std::string m_origRouter;
85 uint8_t m_lsType;
86 uint32_t m_lsSeqNo;
87 uint32_t m_lifeTime;
88 ndn::EventId m_expiringEventId;
89};
90
91class NameLsa: public Lsa
92{
93public:
94 NameLsa()
95 : Lsa()
96 , m_npl()
97 {
98 setLsType(1);
99 }
100
akmhoquec8a10f72014-04-25 18:42:55 -0500101 NameLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500102 NamePrefixList& npl);
akmhoque53353462014-04-22 08:43:45 -0500103
akmhoquec8a10f72014-04-25 18:42:55 -0500104 NamePrefixList&
akmhoque53353462014-04-22 08:43:45 -0500105 getNpl()
106 {
107 return m_npl;
108 }
109
110 void
111 addName(std::string& name)
112 {
113 m_npl.insert(name);
114 }
115
116 void
117 removeName(std::string& name)
118 {
119 m_npl.remove(name);
120 }
121
122 std::string
akmhoqueb6450b12014-04-24 00:01:03 -0500123 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500124
125 std::string
126 getData();
127
128 bool
129 initializeFromContent(std::string content);
130
131 void
132 writeLog();
133
134private:
akmhoquec8a10f72014-04-25 18:42:55 -0500135 NamePrefixList m_npl;
akmhoque53353462014-04-22 08:43:45 -0500136
137};
138
139std::ostream&
140operator<<(std::ostream& os, NameLsa& nLsa);
141
142class AdjLsa: public Lsa
143{
144public:
145 AdjLsa()
146 : Lsa()
147 , m_adl()
148 {
149 setLsType(2);
150 }
151
152 AdjLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500153 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500154
akmhoquec8a10f72014-04-25 18:42:55 -0500155 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500156 getAdl()
157 {
158 return m_adl;
159 }
160
161 void
162 addAdjacent(Adjacent adj)
163 {
164 m_adl.insert(adj);
165 }
166
167 std::string
168 getKey();
169
170 std::string
171 getData();
172
173 bool
174 initializeFromContent(std::string content);
175
176 uint32_t
177 getNoLink()
178 {
179 return m_noLink;
180 }
181
182 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500183 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500184
185 void
186 addNptEntries(Nlsr& pnlsr);
187
188 void
189 removeNptEntries(Nlsr& pnlsr);
190
191private:
192 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500193 AdjacencyList m_adl;
akmhoque53353462014-04-22 08:43:45 -0500194};
195
196std::ostream&
197operator<<(std::ostream& os, AdjLsa& aLsa);
198
akmhoqueb6450b12014-04-24 00:01:03 -0500199class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500200{
201public:
akmhoqueb6450b12014-04-24 00:01:03 -0500202 CoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500203 : Lsa()
204 , m_corRad(0)
205 , m_corTheta(0)
206 {
207 setLsType(3);
208 }
209
akmhoqueb6450b12014-04-24 00:01:03 -0500210 CoordinateLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt
211 , double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500212
213 std::string
akmhoqueb6450b12014-04-24 00:01:03 -0500214 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500215
216 std::string
217 getData();
218
219 bool
220 initializeFromContent(std::string content);
221
222 double
akmhoqueb6450b12014-04-24 00:01:03 -0500223 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500224 {
225 if (m_corRad >= 0)
226 {
227 return m_corRad;
228 }
229 else
230 {
231 return -1;
232 }
233 }
234
235 void
236 setCorRadius(double cr)
237 {
238 m_corRad = cr;
239 }
240
241 double
akmhoqueb6450b12014-04-24 00:01:03 -0500242 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500243 {
244 return m_corTheta;
245 }
246
247 void
248 setCorTheta(double ct)
249 {
250 m_corTheta = ct;
251 }
252
253 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500254 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500255
256private:
257 double m_corRad;
258 double m_corTheta;
259
260};
261
262std::ostream&
akmhoqueb6450b12014-04-24 00:01:03 -0500263operator<<(std::ostream& os, const CoordinateLsa& cLsa);
akmhoque53353462014-04-22 08:43:45 -0500264
265
266}//namespace nlsr
267
268#endif //NLSR_LSA_HPP