blob: d27ddd6b6fdd2fcaf52330bbdfd5e0f114a0ad7e [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehmanc2e51f62015-01-20 15:03:11 -060021
akmhoque53353462014-04-22 08:43:45 -050022#ifndef NLSR_LSA_HPP
23#define NLSR_LSA_HPP
24
Nick Gordon22b5c952017-08-10 17:48:15 -050025#include "name-prefix-list.hpp"
26#include "adjacent.hpp"
27#include "adjacency-list.hpp"
28
akmhoquefdbddb12014-05-02 18:35:19 -050029#include <boost/cstdint.hpp>
akmhoquec8a10f72014-04-25 18:42:55 -050030#include <ndn-cxx/util/scheduler.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050031#include <ndn-cxx/util/time.hpp>
32
akmhoque53353462014-04-22 08:43:45 -050033namespace nlsr {
akmhoque31d1d4b2014-05-05 22:08:14 -050034
Vince Lehmanf7eec4f2015-05-08 19:02:31 -050035class Nlsr;
36
akmhoque53353462014-04-22 08:43:45 -050037class Lsa
38{
39public:
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060040 Lsa(const std::string& lsaType)
akmhoque53353462014-04-22 08:43:45 -050041 : m_origRouter()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -060042 , m_lsType(lsaType)
akmhoque53353462014-04-22 08:43:45 -050043 , m_lsSeqNo()
akmhoquec7a79b22014-05-26 08:06:19 -050044 , m_expirationTimePoint()
akmhoque53353462014-04-22 08:43:45 -050045 , m_expiringEventId()
46 {
47 }
48
akmhoque31d1d4b2014-05-05 22:08:14 -050049 const std::string&
akmhoque53353462014-04-22 08:43:45 -050050 getLsType() const
51 {
52 return m_lsType;
53 }
54
55 void
56 setLsSeqNo(uint32_t lsn)
57 {
58 m_lsSeqNo = lsn;
59 }
60
61 uint32_t
62 getLsSeqNo() const
63 {
64 return m_lsSeqNo;
65 }
66
akmhoque31d1d4b2014-05-05 22:08:14 -050067 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -050068 getOrigRouter() const
69 {
70 return m_origRouter;
71 }
72
73 void
akmhoque31d1d4b2014-05-05 22:08:14 -050074 setOrigRouter(const ndn::Name& org)
akmhoque53353462014-04-22 08:43:45 -050075 {
76 m_origRouter = org;
77 }
78
akmhoquec7a79b22014-05-26 08:06:19 -050079 const ndn::time::system_clock::TimePoint&
80 getExpirationTimePoint() const
akmhoque53353462014-04-22 08:43:45 -050081 {
akmhoquec7a79b22014-05-26 08:06:19 -050082 return m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -050083 }
84
85 void
akmhoquec7a79b22014-05-26 08:06:19 -050086 setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
akmhoque53353462014-04-22 08:43:45 -050087 {
akmhoquec7a79b22014-05-26 08:06:19 -050088 m_expirationTimePoint = lt;
akmhoque53353462014-04-22 08:43:45 -050089 }
90
91 void
92 setExpiringEventId(const ndn::EventId leei)
93 {
94 m_expiringEventId = leei;
95 }
96
97 ndn::EventId
98 getExpiringEventId() const
99 {
100 return m_expiringEventId;
101 }
102
103protected:
akmhoque31d1d4b2014-05-05 22:08:14 -0500104 ndn::Name m_origRouter;
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600105 const std::string m_lsType;
akmhoque53353462014-04-22 08:43:45 -0500106 uint32_t m_lsSeqNo;
akmhoquec7a79b22014-05-26 08:06:19 -0500107 ndn::time::system_clock::TimePoint m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -0500108 ndn::EventId m_expiringEventId;
109};
110
111class NameLsa: public Lsa
112{
113public:
114 NameLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600115 : Lsa(NameLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500116 , m_npl()
117 {
akmhoque53353462014-04-22 08:43:45 -0500118 }
119
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600120 NameLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500121 const ndn::time::system_clock::TimePoint& lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500122 NamePrefixList& npl);
akmhoque53353462014-04-22 08:43:45 -0500123
akmhoquec8a10f72014-04-25 18:42:55 -0500124 NamePrefixList&
akmhoque53353462014-04-22 08:43:45 -0500125 getNpl()
126 {
127 return m_npl;
128 }
129
Nick Gordon56d1fae2017-05-26 16:39:25 -0500130 const NamePrefixList&
131 getNpl() const
132 {
133 return m_npl;
134 }
135
akmhoque53353462014-04-22 08:43:45 -0500136 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
Nick G97e34942016-07-11 14:46:27 -0500148 /*! \brief Gets the key for this LSA.
149
150 Format is: \<router name\>/\<LSA type>\
151 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500152 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500153 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500154
Nick G97e34942016-07-11 14:46:27 -0500155 /*! \brief Returns the data that this name LSA has.
156
157 Format is: \<original router
158 prefix\>|name|\<seq. no.\>|\<exp. time\>|\<prefix 1\>|\<prefix
159 2\>|...|\<prefix n\>|
160 */
akmhoque53353462014-04-22 08:43:45 -0500161 std::string
162 getData();
163
Nick G97e34942016-07-11 14:46:27 -0500164 /*! \brief Initializes this LSA object with content's data.
165
166 \param content The data (e.g. name prefixes) to initialize this LSA with.
167
168 This function initializes this object to represent the data
169 contained in content. The format for this is the same as for
170 getData(); getData() returns data of this format, in other words.
171 */
akmhoque53353462014-04-22 08:43:45 -0500172 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500173 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500174
Nick Gordon56d1fae2017-05-26 16:39:25 -0500175 bool
176 isEqualContent(const NameLsa& other) const;
177
akmhoque53353462014-04-22 08:43:45 -0500178 void
179 writeLog();
180
181private:
akmhoquec8a10f72014-04-25 18:42:55 -0500182 NamePrefixList m_npl;
alvy49b1c0c2014-12-19 13:57:46 -0600183public:
184 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500185};
186
akmhoque53353462014-04-22 08:43:45 -0500187class AdjLsa: public Lsa
188{
189public:
alvydce3f182015-04-09 11:23:30 -0500190 typedef AdjacencyList::const_iterator const_iterator;
191
akmhoque53353462014-04-22 08:43:45 -0500192 AdjLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600193 : Lsa(AdjLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500194 , m_adl()
195 {
akmhoque53353462014-04-22 08:43:45 -0500196 }
197
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600198 AdjLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500199 const ndn::time::system_clock::TimePoint& lt,
200 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500201
akmhoquec8a10f72014-04-25 18:42:55 -0500202 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500203 getAdl()
204 {
205 return m_adl;
206 }
207
Nick Gordon22b5c952017-08-10 17:48:15 -0500208 const AdjacencyList&
209 getAdl() const
210 {
211 return m_adl;
212 }
213
akmhoque53353462014-04-22 08:43:45 -0500214 void
215 addAdjacent(Adjacent adj)
216 {
217 m_adl.insert(adj);
218 }
219
akmhoque31d1d4b2014-05-05 22:08:14 -0500220 const ndn::Name
221 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500222
Nick G97e34942016-07-11 14:46:27 -0500223 /*! \brief Returns the data this adjacency LSA has.
224
225 The format is: \<original
226 router\>|adjacency|\<seq. no.\>|\<exp. time\>|\<size\>|\<adjacency prefix
227 1\>|\<face uri 1\>|\<cost 1\>|...|\<adjacency prefix n\>|\<face uri
228 n\>|\<cost n\>|
229 */
akmhoque53353462014-04-22 08:43:45 -0500230 std::string
231 getData();
232
Nick G97e34942016-07-11 14:46:27 -0500233 /*! \brief Initializes this adj. LSA from the supplied content.
234
235 \param content The content that this LSA is to have, formatted
236 according to getData().
237 */
akmhoque53353462014-04-22 08:43:45 -0500238 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500239 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500240
241 uint32_t
242 getNoLink()
243 {
244 return m_noLink;
245 }
246
247 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500248 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500249
Nick G97e34942016-07-11 14:46:27 -0500250 /*! \brief Installs this LSA's name prefixes into the NPT.
251
252 \param pnlsr The NLSR top-level whose NPT you want to install the
253 entries into.
254 */
akmhoque53353462014-04-22 08:43:45 -0500255 void
256 addNptEntries(Nlsr& pnlsr);
257
258 void
259 removeNptEntries(Nlsr& pnlsr);
260
akmhoque674b0b12014-05-20 14:33:28 -0500261 void
262 writeLog();
263
alvydce3f182015-04-09 11:23:30 -0500264public:
265 const_iterator
266 begin() const
267 {
268 return m_adl.begin();
269 }
270
271 const_iterator
272 end() const
273 {
274 return m_adl.end();
275 }
276
akmhoque53353462014-04-22 08:43:45 -0500277private:
278 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500279 AdjacencyList m_adl;
alvy49b1c0c2014-12-19 13:57:46 -0600280
281public:
282 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500283};
284
akmhoqueb6450b12014-04-24 00:01:03 -0500285class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500286{
287public:
akmhoqueb6450b12014-04-24 00:01:03 -0500288 CoordinateLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600289 : Lsa(CoordinateLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500290 , m_corRad(0)
akmhoque53353462014-04-22 08:43:45 -0500291 {
akmhoque53353462014-04-22 08:43:45 -0500292 }
293
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600294 CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500295 const ndn::time::system_clock::TimePoint& lt,
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600296 double r, std::vector<double> theta);
akmhoque53353462014-04-22 08:43:45 -0500297
akmhoque31d1d4b2014-05-05 22:08:14 -0500298 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500299 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500300
Nick G97e34942016-07-11 14:46:27 -0500301 /*! \brief Returns the data that this coordinate LSA represents.
302
303 The format is: \<original
304 router\>|coordinate|\<seq. no.\>|\<exp. time\>|\<radians\>|\<theta\>|
305 */
akmhoque53353462014-04-22 08:43:45 -0500306 std::string
307 getData();
308
Nick G97e34942016-07-11 14:46:27 -0500309 /*! \brief Initializes this coordinate LSA with the data in content.
310
311 \param content The string content that is used to build the LSA.
312
313 This function initializes this LSA object to represent the data
314 specified by the parameter. The format that it is expecting is the
315 same as for getData();
316 */
akmhoque53353462014-04-22 08:43:45 -0500317 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500318 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500319
320 double
akmhoqueb6450b12014-04-24 00:01:03 -0500321 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500322 {
akmhoque53353462014-04-22 08:43:45 -0500323 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500324 }
325
326 void
327 setCorRadius(double cr)
328 {
akmhoque157b0a42014-05-13 00:26:37 -0500329 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500330 }
331
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600332 const std::vector<double>
akmhoqueb6450b12014-04-24 00:01:03 -0500333 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500334 {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600335 return m_angles;
akmhoque53353462014-04-22 08:43:45 -0500336 }
337
338 void
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600339 setCorTheta(std::vector<double> ct)
akmhoque53353462014-04-22 08:43:45 -0500340 {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600341 m_angles = ct;
akmhoque53353462014-04-22 08:43:45 -0500342 }
343
344 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500345 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500346
akmhoque674b0b12014-05-20 14:33:28 -0500347 void
348 writeLog();
349
akmhoque53353462014-04-22 08:43:45 -0500350private:
351 double m_corRad;
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600352 std::vector<double> m_angles;
akmhoque53353462014-04-22 08:43:45 -0500353
alvy49b1c0c2014-12-19 13:57:46 -0600354public:
355 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500356};
357
alvydce3f182015-04-09 11:23:30 -0500358std::ostream&
359operator<<(std::ostream& os, const AdjLsa& adjLsa);
360
Nick Gordonfad8e252016-08-11 14:21:38 -0500361} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500362
Nick Gordon56d1fae2017-05-26 16:39:25 -0500363#endif // NLSR_LSA_HPP