blob: 934ba40e5b3f7dc4289f925bd432f8497031309f [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
130 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500131 addName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500132 {
133 m_npl.insert(name);
134 }
135
136 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500137 removeName(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500138 {
139 m_npl.remove(name);
140 }
141
Nick G97e34942016-07-11 14:46:27 -0500142 /*! \brief Gets the key for this LSA.
143
144 Format is: \<router name\>/\<LSA type>\
145 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500146 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500147 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500148
Nick G97e34942016-07-11 14:46:27 -0500149 /*! \brief Returns the data that this name LSA has.
150
151 Format is: \<original router
152 prefix\>|name|\<seq. no.\>|\<exp. time\>|\<prefix 1\>|\<prefix
153 2\>|...|\<prefix n\>|
154 */
akmhoque53353462014-04-22 08:43:45 -0500155 std::string
156 getData();
157
Nick G97e34942016-07-11 14:46:27 -0500158 /*! \brief Initializes this LSA object with content's data.
159
160 \param content The data (e.g. name prefixes) to initialize this LSA with.
161
162 This function initializes this object to represent the data
163 contained in content. The format for this is the same as for
164 getData(); getData() returns data of this format, in other words.
165 */
akmhoque53353462014-04-22 08:43:45 -0500166 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500167 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500168
169 void
170 writeLog();
171
172private:
akmhoquec8a10f72014-04-25 18:42:55 -0500173 NamePrefixList m_npl;
alvy49b1c0c2014-12-19 13:57:46 -0600174public:
175 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500176};
177
akmhoque53353462014-04-22 08:43:45 -0500178class AdjLsa: public Lsa
179{
180public:
alvydce3f182015-04-09 11:23:30 -0500181 typedef AdjacencyList::const_iterator const_iterator;
182
akmhoque53353462014-04-22 08:43:45 -0500183 AdjLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600184 : Lsa(AdjLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500185 , m_adl()
186 {
akmhoque53353462014-04-22 08:43:45 -0500187 }
188
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600189 AdjLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500190 const ndn::time::system_clock::TimePoint& lt,
191 uint32_t nl , AdjacencyList& adl);
akmhoque53353462014-04-22 08:43:45 -0500192
akmhoquec8a10f72014-04-25 18:42:55 -0500193 AdjacencyList&
akmhoque53353462014-04-22 08:43:45 -0500194 getAdl()
195 {
196 return m_adl;
197 }
198
199 void
200 addAdjacent(Adjacent adj)
201 {
202 m_adl.insert(adj);
203 }
204
akmhoque31d1d4b2014-05-05 22:08:14 -0500205 const ndn::Name
206 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500207
Nick G97e34942016-07-11 14:46:27 -0500208 /*! \brief Returns the data this adjacency LSA has.
209
210 The format is: \<original
211 router\>|adjacency|\<seq. no.\>|\<exp. time\>|\<size\>|\<adjacency prefix
212 1\>|\<face uri 1\>|\<cost 1\>|...|\<adjacency prefix n\>|\<face uri
213 n\>|\<cost n\>|
214 */
akmhoque53353462014-04-22 08:43:45 -0500215 std::string
216 getData();
217
Nick G97e34942016-07-11 14:46:27 -0500218 /*! \brief Initializes this adj. LSA from the supplied content.
219
220 \param content The content that this LSA is to have, formatted
221 according to getData().
222 */
akmhoque53353462014-04-22 08:43:45 -0500223 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500224 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500225
226 uint32_t
227 getNoLink()
228 {
229 return m_noLink;
230 }
231
232 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500233 isEqualContent(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500234
Nick G97e34942016-07-11 14:46:27 -0500235 /*! \brief Installs this LSA's name prefixes into the NPT.
236
237 \param pnlsr The NLSR top-level whose NPT you want to install the
238 entries into.
239 */
akmhoque53353462014-04-22 08:43:45 -0500240 void
241 addNptEntries(Nlsr& pnlsr);
242
243 void
244 removeNptEntries(Nlsr& pnlsr);
245
akmhoque674b0b12014-05-20 14:33:28 -0500246 void
247 writeLog();
248
alvydce3f182015-04-09 11:23:30 -0500249public:
250 const_iterator
251 begin() const
252 {
253 return m_adl.begin();
254 }
255
256 const_iterator
257 end() const
258 {
259 return m_adl.end();
260 }
261
akmhoque53353462014-04-22 08:43:45 -0500262private:
263 uint32_t m_noLink;
akmhoquec8a10f72014-04-25 18:42:55 -0500264 AdjacencyList m_adl;
alvy49b1c0c2014-12-19 13:57:46 -0600265
266public:
267 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500268};
269
akmhoqueb6450b12014-04-24 00:01:03 -0500270class CoordinateLsa: public Lsa
akmhoque53353462014-04-22 08:43:45 -0500271{
272public:
akmhoqueb6450b12014-04-24 00:01:03 -0500273 CoordinateLsa()
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600274 : Lsa(CoordinateLsa::TYPE_STRING)
akmhoque53353462014-04-22 08:43:45 -0500275 , m_corRad(0)
276 , m_corTheta(0)
277 {
akmhoque53353462014-04-22 08:43:45 -0500278 }
279
Ashlesh Gawanded02c3882015-12-29 16:02:51 -0600280 CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
akmhoquec7a79b22014-05-26 08:06:19 -0500281 const ndn::time::system_clock::TimePoint& lt,
282 double r, double theta);
akmhoque53353462014-04-22 08:43:45 -0500283
akmhoque31d1d4b2014-05-05 22:08:14 -0500284 const ndn::Name
akmhoqueb6450b12014-04-24 00:01:03 -0500285 getKey() const;
akmhoque53353462014-04-22 08:43:45 -0500286
Nick G97e34942016-07-11 14:46:27 -0500287 /*! \brief Returns the data that this coordinate LSA represents.
288
289 The format is: \<original
290 router\>|coordinate|\<seq. no.\>|\<exp. time\>|\<radians\>|\<theta\>|
291 */
akmhoque53353462014-04-22 08:43:45 -0500292 std::string
293 getData();
294
Nick G97e34942016-07-11 14:46:27 -0500295 /*! \brief Initializes this coordinate LSA with the data in content.
296
297 \param content The string content that is used to build the LSA.
298
299 This function initializes this LSA object to represent the data
300 specified by the parameter. The format that it is expecting is the
301 same as for getData();
302 */
akmhoque53353462014-04-22 08:43:45 -0500303 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500304 initializeFromContent(const std::string& content);
akmhoque53353462014-04-22 08:43:45 -0500305
306 double
akmhoqueb6450b12014-04-24 00:01:03 -0500307 getCorRadius() const
akmhoque53353462014-04-22 08:43:45 -0500308 {
akmhoque53353462014-04-22 08:43:45 -0500309 return m_corRad;
akmhoque53353462014-04-22 08:43:45 -0500310 }
311
312 void
313 setCorRadius(double cr)
314 {
akmhoque157b0a42014-05-13 00:26:37 -0500315 m_corRad = cr;
akmhoque53353462014-04-22 08:43:45 -0500316 }
317
318 double
akmhoqueb6450b12014-04-24 00:01:03 -0500319 getCorTheta() const
akmhoque53353462014-04-22 08:43:45 -0500320 {
321 return m_corTheta;
322 }
323
324 void
325 setCorTheta(double ct)
326 {
327 m_corTheta = ct;
328 }
329
330 bool
akmhoquefdbddb12014-05-02 18:35:19 -0500331 isEqualContent(const CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500332
akmhoque674b0b12014-05-20 14:33:28 -0500333 void
334 writeLog();
335
akmhoque53353462014-04-22 08:43:45 -0500336private:
337 double m_corRad;
338 double m_corTheta;
339
alvy49b1c0c2014-12-19 13:57:46 -0600340public:
341 static const std::string TYPE_STRING;
akmhoque53353462014-04-22 08:43:45 -0500342};
343
alvydce3f182015-04-09 11:23:30 -0500344std::ostream&
345operator<<(std::ostream& os, const AdjLsa& adjLsa);
346
Nick Gordonfad8e252016-08-11 14:21:38 -0500347} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500348
349#endif //NLSR_LSA_HPP