blob: dd69d8e7e6d4d6f65b556bb626c4faca909ea5f4 [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:
Nick Gordon727d4832017-10-13 18:04:25 -050040 enum class Type {
41 ADJACENCY,
42 COORDINATE,
43 NAME,
44 BASE
45 };
46
47 Lsa()
akmhoque53353462014-04-22 08:43:45 -050048 : m_origRouter()
49 , m_lsSeqNo()
akmhoquec7a79b22014-05-26 08:06:19 -050050 , m_expirationTimePoint()
akmhoque53353462014-04-22 08:43:45 -050051 , m_expiringEventId()
52 {
53 }
54
Nick Gordon727d4832017-10-13 18:04:25 -050055 virtual Type
56 getType() const
akmhoque53353462014-04-22 08:43:45 -050057 {
Nick Gordon727d4832017-10-13 18:04:25 -050058 return Type::BASE;
akmhoque53353462014-04-22 08:43:45 -050059 }
60
61 void
62 setLsSeqNo(uint32_t lsn)
63 {
64 m_lsSeqNo = lsn;
65 }
66
67 uint32_t
68 getLsSeqNo() const
69 {
70 return m_lsSeqNo;
71 }
72
akmhoque31d1d4b2014-05-05 22:08:14 -050073 const ndn::Name&
akmhoque53353462014-04-22 08:43:45 -050074 getOrigRouter() const
75 {
76 return m_origRouter;
77 }
78
79 void
akmhoque31d1d4b2014-05-05 22:08:14 -050080 setOrigRouter(const ndn::Name& org)
akmhoque53353462014-04-22 08:43:45 -050081 {
82 m_origRouter = org;
83 }
84
akmhoquec7a79b22014-05-26 08:06:19 -050085 const ndn::time::system_clock::TimePoint&
86 getExpirationTimePoint() const
akmhoque53353462014-04-22 08:43:45 -050087 {
akmhoquec7a79b22014-05-26 08:06:19 -050088 return m_expirationTimePoint;
akmhoque53353462014-04-22 08:43:45 -050089 }
90
91 void
akmhoquec7a79b22014-05-26 08:06:19 -050092 setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
akmhoque53353462014-04-22 08:43:45 -050093 {
akmhoquec7a79b22014-05-26 08:06:19 -050094 m_expirationTimePoint = lt;
akmhoque53353462014-04-22 08:43:45 -050095 }
96
97 void
98 setExpiringEventId(const ndn::EventId leei)
99 {
100 m_expiringEventId = leei;
101 }
102
103 ndn::EventId
104 getExpiringEventId() const
105 {
106 return m_expiringEventId;
107 }
108
109protected:
akmhoque31d1d4b2014-05-05 22:08:14 -0500110 ndn::Name m_origRouter;
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()
akmhoque53353462014-04-22 08:43:45 -0500120 {
akmhoque53353462014-04-22 08:43:45 -0500121 }
122
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600123 NameLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500124 const ndn::time::system_clock::TimePoint& lt,
akmhoquefdbddb12014-05-02 18:35:19 -0500125 NamePrefixList& npl);
akmhoque53353462014-04-22 08:43:45 -0500126
Nick Gordon727d4832017-10-13 18:04:25 -0500127 Lsa::Type
128 getType() const override
129 {
130 return Lsa::Type::NAME;
131 }
132
akmhoquec8a10f72014-04-25 18:42:55 -0500133 NamePrefixList&
akmhoque53353462014-04-22 08:43:45 -0500134 getNpl()
135 {
136 return m_npl;
137 }
138
Nick Gordon56d1fae2017-05-26 16:39:25 -0500139 const NamePrefixList&
140 getNpl() const
141 {
142 return m_npl;
143 }
144
akmhoque53353462014-04-22 08:43:45 -0500145 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500146 addName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500147 {
148 m_npl.insert(name);
149 }
150
151 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500152 removeName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500153 {
154 m_npl.remove(name);
155 }
156
Nick G97e34942016-07-11 14:46:27 -0500157 /*! \brief Gets the key for this LSA.
158
159 Format is: \<router name\>/\<LSA type>\
160 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500161 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500162 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500163
Nick G97e34942016-07-11 14:46:27 -0500164 /*! \brief Returns the data that this name LSA has.
165
166 Format is: \<original router
167 prefix\>|name|\<seq. no.\>|\<exp. time\>|\<prefix 1\>|\<prefix
168 2\>|...|\<prefix n\>|
169 */
akmhoque53353462014-04-22 08:43:45 -0500170 std::string
171 getData();
172
Nick G97e34942016-07-11 14:46:27 -0500173 /*! \brief Initializes this LSA object with content's data.
174
175 \param content The data (e.g. name prefixes) to initialize this LSA with.
176
177 This function initializes this object to represent the data
178 contained in content. The format for this is the same as for
179 getData(); getData() returns data of this format, in other words.
180 */
akmhoque53353462014-04-22 08:43:45 -0500181 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500182 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500183
Nick Gordon56d1fae2017-05-26 16:39:25 -0500184 bool
185 isEqualContent(const NameLsa& other) const;
186
akmhoque53353462014-04-22 08:43:45 -0500187 void
188 writeLog();
189
190private:
akmhoquec8a10f72014-04-25 18:42:55 -0500191 NamePrefixList m_npl;
akmhoque53353462014-04-22 08:43:45 -0500192};
193
akmhoque53353462014-04-22 08:43:45 -0500194class AdjLsa: public Lsa
195{
196public:
alvydce3f182015-04-09 11:23:30 -0500197 typedef AdjacencyList::const_iterator const_iterator;
198
akmhoque53353462014-04-22 08:43:45 -0500199 AdjLsa()
akmhoque53353462014-04-22 08:43:45 -0500200 {
akmhoque53353462014-04-22 08:43:45 -0500201 }
202
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600203 AdjLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500204 const ndn::time::system_clock::TimePoint& lt,
205 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500206
Nick Gordon727d4832017-10-13 18:04:25 -0500207 Lsa::Type
208 getType() const override
209 {
210 return Lsa::Type::ADJACENCY;
211 }
212
akmhoquec8a10f72014-04-25 18:42:55 -0500213 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500214 getAdl()
215 {
216 return m_adl;
217 }
218
Nick Gordon22b5c952017-08-10 17:48:15 -0500219 const AdjacencyList&
220 getAdl() const
221 {
222 return m_adl;
223 }
224
akmhoque53353462014-04-22 08:43:45 -0500225 void
226 addAdjacent(Adjacent adj)
227 {
228 m_adl.insert(adj);
229 }
230
akmhoque31d1d4b2014-05-05 22:08:14 -0500231 const ndn::Name
232 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500233
Nick G97e34942016-07-11 14:46:27 -0500234 /*! \brief Returns the data this adjacency LSA has.
235
236 The format is: \<original
237 router\>|adjacency|\<seq. no.\>|\<exp. time\>|\<size\>|\<adjacency prefix
238 1\>|\<face uri 1\>|\<cost 1\>|...|\<adjacency prefix n\>|\<face uri
239 n\>|\<cost n\>|
240 */
akmhoque53353462014-04-22 08:43:45 -0500241 std::string
242 getData();
243
Nick G97e34942016-07-11 14:46:27 -0500244 /*! \brief Initializes this adj. LSA from the supplied content.
245
246 \param content The content that this LSA is to have, formatted
247 according to getData().
248 */
akmhoque53353462014-04-22 08:43:45 -0500249 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500250 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500251
252 uint32_t
253 getNoLink()
254 {
255 return m_noLink;
256 }
257
258 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500259 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500260
Nick G97e34942016-07-11 14:46:27 -0500261 /*! \brief Installs this LSA's name prefixes into the NPT.
262
263 \param pnlsr The NLSR top-level whose NPT you want to install the
264 entries into.
265 */
akmhoque53353462014-04-22 08:43:45 -0500266 void
267 addNptEntries(Nlsr& pnlsr);
268
269 void
270 removeNptEntries(Nlsr& pnlsr);
271
akmhoque674b0b12014-05-20 14:33:28 -0500272 void
273 writeLog();
274
alvydce3f182015-04-09 11:23:30 -0500275public:
276 const_iterator
277 begin() const
278 {
279 return m_adl.begin();
280 }
281
282 const_iterator
283 end() const
284 {
285 return m_adl.end();
286 }
287
akmhoque53353462014-04-22 08:43:45 -0500288private:
289 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500290 AdjacencyList m_adl;
akmhoque53353462014-04-22 08:43:45 -0500291};
292
akmhoqueb6450b12014-04-24 00:01:03 -0500293class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500294{
295public:
akmhoqueb6450b12014-04-24 00:01:03 -0500296 CoordinateLsa()
Nick Gordon727d4832017-10-13 18:04:25 -0500297 : m_corRad(0)
akmhoque53353462014-04-22 08:43:45 -0500298 {
akmhoque53353462014-04-22 08:43:45 -0500299 }
300
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600301 CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500302 const ndn::time::system_clock::TimePoint& lt,
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600303 double r, std::vector<double> theta);
akmhoque53353462014-04-22 08:43:45 -0500304
Nick Gordon727d4832017-10-13 18:04:25 -0500305 Lsa::Type
306 getType() const override
307 {
308 return Lsa::Type::COORDINATE;
309 }
310
akmhoque31d1d4b2014-05-05 22:08:14 -0500311 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500312 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500313
Nick G97e34942016-07-11 14:46:27 -0500314 /*! \brief Returns the data that this coordinate LSA represents.
315
316 The format is: \<original
317 router\>|coordinate|\<seq. no.\>|\<exp. time\>|\<radians\>|\<theta\>|
318 */
akmhoque53353462014-04-22 08:43:45 -0500319 std::string
320 getData();
321
Nick G97e34942016-07-11 14:46:27 -0500322 /*! \brief Initializes this coordinate LSA with the data in content.
323
324 \param content The string content that is used to build the LSA.
325
326 This function initializes this LSA object to represent the data
327 specified by the parameter. The format that it is expecting is the
328 same as for getData();
329 */
akmhoque53353462014-04-22 08:43:45 -0500330 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500331 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500332
333 double
akmhoqueb6450b12014-04-24 00:01:03 -0500334 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500335 {
akmhoque53353462014-04-22 08:43:45 -0500336 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500337 }
338
339 void
340 setCorRadius(double cr)
341 {
akmhoque157b0a42014-05-13 00:26:37 -0500342 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500343 }
344
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600345 const std::vector<double>
akmhoqueb6450b12014-04-24 00:01:03 -0500346 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500347 {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600348 return m_angles;
akmhoque53353462014-04-22 08:43:45 -0500349 }
350
351 void
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600352 setCorTheta(std::vector<double> ct)
akmhoque53353462014-04-22 08:43:45 -0500353 {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600354 m_angles = ct;
akmhoque53353462014-04-22 08:43:45 -0500355 }
356
357 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500358 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500359
akmhoque674b0b12014-05-20 14:33:28 -0500360 void
361 writeLog();
362
akmhoque53353462014-04-22 08:43:45 -0500363private:
364 double m_corRad;
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600365 std::vector<double> m_angles;
akmhoque53353462014-04-22 08:43:45 -0500366};
367
alvydce3f182015-04-09 11:23:30 -0500368std::ostream&
369operator<<(std::ostream& os, const AdjLsa& adjLsa);
370
Nick Gordon727d4832017-10-13 18:04:25 -0500371std::ostream&
372operator<<(std::ostream& os, const Lsa::Type& type);
373
374std::istream&
375operator>>(std::istream& is, Lsa::Type& type);
376
Nick Gordonfad8e252016-08-11 14:21:38 -0500377} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500378
Nick Gordon727d4832017-10-13 18:04:25 -0500379namespace std {
380 std::string
381 to_string(const nlsr::Lsa::Type& type);
382} // namespace std
383
Nick Gordon56d1fae2017-05-26 16:39:25 -0500384#endif // NLSR_LSA_HPP