blob: 03fc7b6cf9a2a59e6e34babc647425607d2a3afc [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>
akmhoquec7a79b22014-05-26 08:06:19 -05006#include <ndn-cxx/util/time.hpp>
7
akmhoque53353462014-04-22 08:43:45 -05008#include "adjacent.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -05009#include "name-prefix-list.hpp"
10#include "adjacency-list.hpp"
akmhoque53353462014-04-22 08:43:45 -050011
12namespace nlsr {
akmhoque31d1d4b2014-05-05 22:08:14 -050013
akmhoque53353462014-04-22 08:43:45 -050014class Lsa
15{
16public:
17 Lsa()
18 : m_origRouter()
19 , m_lsSeqNo()
akmhoquec7a79b22014-05-26 08:06:19 -050020 , m_expirationTimePoint()
akmhoque53353462014-04-22 08:43:45 -050021 , m_expiringEventId()
22 {
23 }
24
25
26 void
akmhoque31d1d4b2014-05-05 22:08:14 -050027 setLsType(const std::string& lst)
akmhoque53353462014-04-22 08:43:45 -050028 {
29 m_lsType = lst;
30 }
31
akmhoque31d1d4b2014-05-05 22:08:14 -050032 const std::string&
akmhoque53353462014-04-22 08:43:45 -050033 getLsType() const
34 {
35 return m_lsType;
36 }
37
38 void
39 setLsSeqNo(uint32_t lsn)
40 {
41 m_lsSeqNo = lsn;
42 }
43
44 uint32_t
45 getLsSeqNo() const
46 {
47 return m_lsSeqNo;
48 }
49
akmhoque31d1d4b2014-05-05 22:08:14 -050050 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -050051 getOrigRouter() const
52 {
53 return m_origRouter;
54 }
55
56 void
akmhoque31d1d4b2014-05-05 22:08:14 -050057 setOrigRouter(const ndn::Name& org)
akmhoque53353462014-04-22 08:43:45 -050058 {
59 m_origRouter = org;
60 }
61
akmhoquec7a79b22014-05-26 08:06:19 -050062 const ndn::time::system_clock::TimePoint&
63 getExpirationTimePoint() const
akmhoque53353462014-04-22 08:43:45 -050064 {
akmhoquec7a79b22014-05-26 08:06:19 -050065 return m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -050066 }
67
68 void
akmhoquec7a79b22014-05-26 08:06:19 -050069 setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
akmhoque53353462014-04-22 08:43:45 -050070 {
akmhoquec7a79b22014-05-26 08:06:19 -050071 m_expirationTimePoint = lt;
akmhoque53353462014-04-22 08:43:45 -050072 }
73
74 void
75 setExpiringEventId(const ndn::EventId leei)
76 {
77 m_expiringEventId = leei;
78 }
79
80 ndn::EventId
81 getExpiringEventId() const
82 {
83 return m_expiringEventId;
84 }
85
86protected:
akmhoque31d1d4b2014-05-05 22:08:14 -050087 ndn::Name m_origRouter;
88 std::string m_lsType;
akmhoque53353462014-04-22 08:43:45 -050089 uint32_t m_lsSeqNo;
akmhoquec7a79b22014-05-26 08:06:19 -050090 ndn::time::system_clock::TimePoint m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -050091 ndn::EventId m_expiringEventId;
92};
93
94class NameLsa: public Lsa
95{
96public:
97 NameLsa()
98 : Lsa()
99 , m_npl()
100 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500101 setLsType("name");
akmhoque53353462014-04-22 08:43:45 -0500102 }
103
akmhoque31d1d4b2014-05-05 22:08:14 -0500104 NameLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500105 const ndn::time::system_clock::TimePoint& lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500106 NamePrefixList& npl);
akmhoque53353462014-04-22 08:43:45 -0500107
akmhoquec8a10f72014-04-25 18:42:55 -0500108 NamePrefixList&
akmhoque53353462014-04-22 08:43:45 -0500109 getNpl()
110 {
111 return m_npl;
112 }
113
114 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500115 addName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500116 {
117 m_npl.insert(name);
118 }
119
120 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500121 removeName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500122 {
123 m_npl.remove(name);
124 }
125
akmhoque31d1d4b2014-05-05 22:08:14 -0500126 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500127 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500128
129 std::string
130 getData();
131
132 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500133 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500134
135 void
136 writeLog();
137
138private:
akmhoquec8a10f72014-04-25 18:42:55 -0500139 NamePrefixList m_npl;
akmhoque53353462014-04-22 08:43:45 -0500140
141};
142
143std::ostream&
144operator<<(std::ostream& os, NameLsa& nLsa);
145
146class AdjLsa: public Lsa
147{
148public:
149 AdjLsa()
150 : Lsa()
151 , m_adl()
152 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500153 setLsType("adjacency");
akmhoque53353462014-04-22 08:43:45 -0500154 }
155
akmhoque31d1d4b2014-05-05 22:08:14 -0500156 AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500157 const ndn::time::system_clock::TimePoint& lt,
158 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500159
akmhoquec8a10f72014-04-25 18:42:55 -0500160 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500161 getAdl()
162 {
163 return m_adl;
164 }
165
166 void
167 addAdjacent(Adjacent adj)
168 {
169 m_adl.insert(adj);
170 }
171
akmhoque31d1d4b2014-05-05 22:08:14 -0500172 const ndn::Name
173 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500174
175 std::string
176 getData();
177
178 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500179 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500180
181 uint32_t
182 getNoLink()
183 {
184 return m_noLink;
185 }
186
187 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500188 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500189
190 void
191 addNptEntries(Nlsr& pnlsr);
192
193 void
194 removeNptEntries(Nlsr& pnlsr);
195
akmhoque674b0b12014-05-20 14:33:28 -0500196 void
197 writeLog();
198
akmhoque53353462014-04-22 08:43:45 -0500199private:
200 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500201 AdjacencyList m_adl;
akmhoque53353462014-04-22 08:43:45 -0500202};
203
204std::ostream&
205operator<<(std::ostream& os, AdjLsa& aLsa);
206
akmhoqueb6450b12014-04-24 00:01:03 -0500207class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500208{
209public:
akmhoqueb6450b12014-04-24 00:01:03 -0500210 CoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500211 : Lsa()
212 , m_corRad(0)
213 , m_corTheta(0)
214 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500215 setLsType("coordinate");
akmhoque53353462014-04-22 08:43:45 -0500216 }
217
akmhoque31d1d4b2014-05-05 22:08:14 -0500218 CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500219 const ndn::time::system_clock::TimePoint& lt,
220 double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500221
akmhoque31d1d4b2014-05-05 22:08:14 -0500222 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500223 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500224
225 std::string
226 getData();
227
228 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500229 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500230
231 double
akmhoqueb6450b12014-04-24 00:01:03 -0500232 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500233 {
akmhoque53353462014-04-22 08:43:45 -0500234 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500235 }
236
237 void
238 setCorRadius(double cr)
239 {
akmhoque157b0a42014-05-13 00:26:37 -0500240 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500241 }
242
243 double
akmhoqueb6450b12014-04-24 00:01:03 -0500244 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500245 {
246 return m_corTheta;
247 }
248
249 void
250 setCorTheta(double ct)
251 {
252 m_corTheta = ct;
253 }
254
255 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500256 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500257
akmhoque674b0b12014-05-20 14:33:28 -0500258 void
259 writeLog();
260
akmhoque53353462014-04-22 08:43:45 -0500261private:
262 double m_corRad;
263 double m_corTheta;
264
265};
266
267std::ostream&
akmhoqueb6450b12014-04-24 00:01:03 -0500268operator<<(std::ostream& os, const CoordinateLsa& cLsa);
akmhoque53353462014-04-22 08:43:45 -0500269
270
271}//namespace nlsr
272
273#endif //NLSR_LSA_HPP