blob: 4840c3465dcb2f6a601dff203b3e434b8ca5a646 [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
akmhoquefdbddb12014-05-02 18:35:19 -050025#include <boost/cstdint.hpp>
akmhoquec8a10f72014-04-25 18:42:55 -050026#include <ndn-cxx/util/scheduler.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050027#include <ndn-cxx/util/time.hpp>
28
akmhoque53353462014-04-22 08:43:45 -050029#include "adjacent.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050030#include "name-prefix-list.hpp"
31#include "adjacency-list.hpp"
akmhoque53353462014-04-22 08:43:45 -050032
33namespace 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
208 void
209 addAdjacent(Adjacent adj)
210 {
211 m_adl.insert(adj);
212 }
213
akmhoque31d1d4b2014-05-05 22:08:14 -0500214 const ndn::Name
215 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500216
Nick G97e34942016-07-11 14:46:27 -0500217 /*! \brief Returns the data this adjacency LSA has.
218
219 The format is: \<original
220 router\>|adjacency|\<seq. no.\>|\<exp. time\>|\<size\>|\<adjacency prefix
221 1\>|\<face uri 1\>|\<cost 1\>|...|\<adjacency prefix n\>|\<face uri
222 n\>|\<cost n\>|
223 */
akmhoque53353462014-04-22 08:43:45 -0500224 std::string
225 getData();
226
Nick G97e34942016-07-11 14:46:27 -0500227 /*! \brief Initializes this adj. LSA from the supplied content.
228
229 \param content The content that this LSA is to have, formatted
230 according to getData().
231 */
akmhoque53353462014-04-22 08:43:45 -0500232 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500233 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500234
235 uint32_t
236 getNoLink()
237 {
238 return m_noLink;
239 }
240
241 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500242 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500243
Nick G97e34942016-07-11 14:46:27 -0500244 /*! \brief Installs this LSA's name prefixes into the NPT.
245
246 \param pnlsr The NLSR top-level whose NPT you want to install the
247 entries into.
248 */
akmhoque53353462014-04-22 08:43:45 -0500249 void
250 addNptEntries(Nlsr& pnlsr);
251
252 void
253 removeNptEntries(Nlsr& pnlsr);
254
akmhoque674b0b12014-05-20 14:33:28 -0500255 void
256 writeLog();
257
alvydce3f182015-04-09 11:23:30 -0500258public:
259 const_iterator
260 begin() const
261 {
262 return m_adl.begin();
263 }
264
265 const_iterator
266 end() const
267 {
268 return m_adl.end();
269 }
270
akmhoque53353462014-04-22 08:43:45 -0500271private:
272 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500273 AdjacencyList m_adl;
alvy49b1c0c2014-12-19 13:57:46 -0600274
275public:
276 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500277};
278
akmhoqueb6450b12014-04-24 00:01:03 -0500279class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500280{
281public:
akmhoqueb6450b12014-04-24 00:01:03 -0500282 CoordinateLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600283 : Lsa(CoordinateLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500284 , m_corRad(0)
akmhoque53353462014-04-22 08:43:45 -0500285 {
akmhoque53353462014-04-22 08:43:45 -0500286 }
287
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600288 CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500289 const ndn::time::system_clock::TimePoint& lt,
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600290 double r, std::vector<double> theta);
akmhoque53353462014-04-22 08:43:45 -0500291
akmhoque31d1d4b2014-05-05 22:08:14 -0500292 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500293 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500294
Nick G97e34942016-07-11 14:46:27 -0500295 /*! \brief Returns the data that this coordinate LSA represents.
296
297 The format is: \<original
298 router\>|coordinate|\<seq. no.\>|\<exp. time\>|\<radians\>|\<theta\>|
299 */
akmhoque53353462014-04-22 08:43:45 -0500300 std::string
301 getData();
302
Nick G97e34942016-07-11 14:46:27 -0500303 /*! \brief Initializes this coordinate LSA with the data in content.
304
305 \param content The string content that is used to build the LSA.
306
307 This function initializes this LSA object to represent the data
308 specified by the parameter. The format that it is expecting is the
309 same as for getData();
310 */
akmhoque53353462014-04-22 08:43:45 -0500311 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500312 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500313
314 double
akmhoqueb6450b12014-04-24 00:01:03 -0500315 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500316 {
akmhoque53353462014-04-22 08:43:45 -0500317 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500318 }
319
320 void
321 setCorRadius(double cr)
322 {
akmhoque157b0a42014-05-13 00:26:37 -0500323 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500324 }
325
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600326 const std::vector<double>
akmhoqueb6450b12014-04-24 00:01:03 -0500327 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500328 {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600329 return m_angles;
akmhoque53353462014-04-22 08:43:45 -0500330 }
331
332 void
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600333 setCorTheta(std::vector<double> ct)
akmhoque53353462014-04-22 08:43:45 -0500334 {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600335 m_angles = ct;
akmhoque53353462014-04-22 08:43:45 -0500336 }
337
338 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500339 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500340
akmhoque674b0b12014-05-20 14:33:28 -0500341 void
342 writeLog();
343
akmhoque53353462014-04-22 08:43:45 -0500344private:
345 double m_corRad;
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600346 std::vector<double> m_angles;
akmhoque53353462014-04-22 08:43:45 -0500347
alvy49b1c0c2014-12-19 13:57:46 -0600348public:
349 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500350};
351
alvydce3f182015-04-09 11:23:30 -0500352std::ostream&
353operator<<(std::ostream& os, const AdjLsa& adjLsa);
354
Nick Gordonfad8e252016-08-11 14:21:38 -0500355} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500356
Nick Gordon56d1fae2017-05-26 16:39:25 -0500357#endif // NLSR_LSA_HPP