blob: 21370694a554c58d8fbe18af4783f9e4ce8dc9f2 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoque53353462014-04-22 08:43:45 -050023#ifndef NLSR_LSA_HPP
24#define NLSR_LSA_HPP
25
akmhoquefdbddb12014-05-02 18:35:19 -050026#include <boost/cstdint.hpp>
akmhoquec8a10f72014-04-25 18:42:55 -050027#include <ndn-cxx/util/scheduler.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050028#include <ndn-cxx/util/time.hpp>
29
akmhoque53353462014-04-22 08:43:45 -050030#include "adjacent.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050031#include "name-prefix-list.hpp"
32#include "adjacency-list.hpp"
akmhoque53353462014-04-22 08:43:45 -050033
34namespace nlsr {
akmhoque31d1d4b2014-05-05 22:08:14 -050035
akmhoque53353462014-04-22 08:43:45 -050036class Lsa
37{
38public:
39 Lsa()
40 : m_origRouter()
41 , m_lsSeqNo()
akmhoquec7a79b22014-05-26 08:06:19 -050042 , m_expirationTimePoint()
akmhoque53353462014-04-22 08:43:45 -050043 , m_expiringEventId()
44 {
45 }
46
47
48 void
akmhoque31d1d4b2014-05-05 22:08:14 -050049 setLsType(const std::string& lst)
akmhoque53353462014-04-22 08:43:45 -050050 {
51 m_lsType = lst;
52 }
53
akmhoque31d1d4b2014-05-05 22:08:14 -050054 const std::string&
akmhoque53353462014-04-22 08:43:45 -050055 getLsType() const
56 {
57 return m_lsType;
58 }
59
60 void
61 setLsSeqNo(uint32_t lsn)
62 {
63 m_lsSeqNo = lsn;
64 }
65
66 uint32_t
67 getLsSeqNo() const
68 {
69 return m_lsSeqNo;
70 }
71
akmhoque31d1d4b2014-05-05 22:08:14 -050072 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -050073 getOrigRouter() const
74 {
75 return m_origRouter;
76 }
77
78 void
akmhoque31d1d4b2014-05-05 22:08:14 -050079 setOrigRouter(const ndn::Name& org)
akmhoque53353462014-04-22 08:43:45 -050080 {
81 m_origRouter = org;
82 }
83
akmhoquec7a79b22014-05-26 08:06:19 -050084 const ndn::time::system_clock::TimePoint&
85 getExpirationTimePoint() const
akmhoque53353462014-04-22 08:43:45 -050086 {
akmhoquec7a79b22014-05-26 08:06:19 -050087 return m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -050088 }
89
90 void
akmhoquec7a79b22014-05-26 08:06:19 -050091 setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
akmhoque53353462014-04-22 08:43:45 -050092 {
akmhoquec7a79b22014-05-26 08:06:19 -050093 m_expirationTimePoint = lt;
akmhoque53353462014-04-22 08:43:45 -050094 }
95
96 void
97 setExpiringEventId(const ndn::EventId leei)
98 {
99 m_expiringEventId = leei;
100 }
101
102 ndn::EventId
103 getExpiringEventId() const
104 {
105 return m_expiringEventId;
106 }
107
108protected:
akmhoque31d1d4b2014-05-05 22:08:14 -0500109 ndn::Name m_origRouter;
110 std::string m_lsType;
akmhoque53353462014-04-22 08:43:45 -0500111 uint32_t m_lsSeqNo;
akmhoquec7a79b22014-05-26 08:06:19 -0500112 ndn::time::system_clock::TimePoint m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -0500113 ndn::EventId m_expiringEventId;
114};
115
116class NameLsa: public Lsa
117{
118public:
119 NameLsa()
120 : Lsa()
121 , m_npl()
122 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500123 setLsType("name");
akmhoque53353462014-04-22 08:43:45 -0500124 }
125
akmhoque31d1d4b2014-05-05 22:08:14 -0500126 NameLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500127 const ndn::time::system_clock::TimePoint& lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500128 NamePrefixList& npl);
akmhoque53353462014-04-22 08:43:45 -0500129
akmhoquec8a10f72014-04-25 18:42:55 -0500130 NamePrefixList&
akmhoque53353462014-04-22 08:43:45 -0500131 getNpl()
132 {
133 return m_npl;
134 }
135
136 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500137 addName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500138 {
139 m_npl.insert(name);
140 }
141
142 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500143 removeName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500144 {
145 m_npl.remove(name);
146 }
147
akmhoque31d1d4b2014-05-05 22:08:14 -0500148 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500149 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500150
151 std::string
152 getData();
153
154 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500155 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500156
157 void
158 writeLog();
159
160private:
akmhoquec8a10f72014-04-25 18:42:55 -0500161 NamePrefixList m_npl;
akmhoque53353462014-04-22 08:43:45 -0500162
163};
164
akmhoque53353462014-04-22 08:43:45 -0500165class AdjLsa: public Lsa
166{
167public:
168 AdjLsa()
169 : Lsa()
170 , m_adl()
171 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500172 setLsType("adjacency");
akmhoque53353462014-04-22 08:43:45 -0500173 }
174
akmhoque31d1d4b2014-05-05 22:08:14 -0500175 AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500176 const ndn::time::system_clock::TimePoint& lt,
177 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500178
akmhoquec8a10f72014-04-25 18:42:55 -0500179 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500180 getAdl()
181 {
182 return m_adl;
183 }
184
185 void
186 addAdjacent(Adjacent adj)
187 {
188 m_adl.insert(adj);
189 }
190
akmhoque31d1d4b2014-05-05 22:08:14 -0500191 const ndn::Name
192 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500193
194 std::string
195 getData();
196
197 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500198 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500199
200 uint32_t
201 getNoLink()
202 {
203 return m_noLink;
204 }
205
206 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500207 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500208
209 void
210 addNptEntries(Nlsr& pnlsr);
211
212 void
213 removeNptEntries(Nlsr& pnlsr);
214
akmhoque674b0b12014-05-20 14:33:28 -0500215 void
216 writeLog();
217
akmhoque53353462014-04-22 08:43:45 -0500218private:
219 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500220 AdjacencyList m_adl;
akmhoque53353462014-04-22 08:43:45 -0500221};
222
akmhoqueb6450b12014-04-24 00:01:03 -0500223class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500224{
225public:
akmhoqueb6450b12014-04-24 00:01:03 -0500226 CoordinateLsa()
akmhoque53353462014-04-22 08:43:45 -0500227 : Lsa()
228 , m_corRad(0)
229 , m_corTheta(0)
230 {
akmhoque31d1d4b2014-05-05 22:08:14 -0500231 setLsType("coordinate");
akmhoque53353462014-04-22 08:43:45 -0500232 }
233
akmhoque31d1d4b2014-05-05 22:08:14 -0500234 CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500235 const ndn::time::system_clock::TimePoint& lt,
236 double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500237
akmhoque31d1d4b2014-05-05 22:08:14 -0500238 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500239 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500240
241 std::string
242 getData();
243
244 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500245 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500246
247 double
akmhoqueb6450b12014-04-24 00:01:03 -0500248 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500249 {
akmhoque53353462014-04-22 08:43:45 -0500250 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500251 }
252
253 void
254 setCorRadius(double cr)
255 {
akmhoque157b0a42014-05-13 00:26:37 -0500256 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500257 }
258
259 double
akmhoqueb6450b12014-04-24 00:01:03 -0500260 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500261 {
262 return m_corTheta;
263 }
264
265 void
266 setCorTheta(double ct)
267 {
268 m_corTheta = ct;
269 }
270
271 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500272 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500273
akmhoque674b0b12014-05-20 14:33:28 -0500274 void
275 writeLog();
276
akmhoque53353462014-04-22 08:43:45 -0500277private:
278 double m_corRad;
279 double m_corTheta;
280
281};
282
akmhoque53353462014-04-22 08:43:45 -0500283}//namespace nlsr
284
285#endif //NLSR_LSA_HPP