blob: 718ee5550a9856104ec1af91fb2858fbc3c62134 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoaf7a2112019-03-19 14:55:20 -04002/*
Ashlesh Gawande85998a12017-12-07 22:22:13 -06003 * Copyright (c) 2014-2019, 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 **/
Ashlesh Gawande5bf83172014-09-19 12:38:17 -050021
akmhoque53353462014-04-22 08:43:45 -050022#ifndef NLSR_LSDB_HPP
23#define NLSR_LSDB_HPP
24
Vince Lehman50df6b72015-03-03 12:06:40 -060025#include "conf-parameter.hpp"
akmhoque53353462014-04-22 08:43:45 -050026#include "lsa.hpp"
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050027#include "sequencing-manager.hpp"
Ashlesh Gawande5bf83172014-09-19 12:38:17 -050028#include "test-access-control.hpp"
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050029#include "communication/sync-logic-handler.hpp"
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060030#include "statistics.hpp"
Ashlesh Gawande85998a12017-12-07 22:22:13 -060031#include "route/name-prefix-table.hpp"
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060032
33#include <ndn-cxx/security/key-chain.hpp>
34#include <ndn-cxx/util/signal.hpp>
35#include <ndn-cxx/util/time.hpp>
Ashlesh Gawande744e4812018-08-22 16:26:24 -050036#include <ndn-cxx/util/segment-fetcher.hpp>
Ashlesh Gawande15052402018-12-12 20:20:00 -060037#include <ndn-cxx/ims/in-memory-storage-persistent.hpp>
Ashlesh Gawande744e4812018-08-22 16:26:24 -050038
Ashlesh Gawande939b6f82018-12-09 16:51:09 -060039#include <PSync/segment-publisher.hpp>
40
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060041#include <utility>
42#include <boost/cstdint.hpp>
akmhoque53353462014-04-22 08:43:45 -050043
Nick Gordone98480b2017-05-24 11:23:03 -050044namespace nlsr {
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070045
akmhoque53353462014-04-22 08:43:45 -050046class Lsdb
47{
48public:
Ashlesh Gawande85998a12017-12-07 22:22:13 -060049 Lsdb(ndn::Face& face, ndn::KeyChain& keyChain,
50 ndn::security::SigningInfo& signingInfo, ConfParameter& confParam,
51 NamePrefixTable& namePrefixTable, RoutingTable& routingTable);
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050052
Ashlesh Gawande744e4812018-08-22 16:26:24 -050053 ~Lsdb();
54
akmhoque53353462014-04-22 08:43:45 -050055 bool
Nick Gordon727d4832017-10-13 18:04:25 -050056 isLsaNew(const ndn::Name& routerName, const Lsa::Type& lsaType, const uint64_t& sequenceNumber);
akmhoque53353462014-04-22 08:43:45 -050057
Nick Gordon8f23b5d2017-08-31 17:53:07 -050058 bool
Nick Gordon727d4832017-10-13 18:04:25 -050059 doesLsaExist(const ndn::Name& key, const Lsa::Type& lsType);
Nick G97e34942016-07-11 14:46:27 -050060
61 /*! \brief Builds a name LSA for this router and then installs it
62 into the LSDB.
63 */
akmhoque53353462014-04-22 08:43:45 -050064 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050065 buildAndInstallOwnNameLsa();
akmhoque53353462014-04-22 08:43:45 -050066
Nick G97e34942016-07-11 14:46:27 -050067 /*! \brief Returns the name LSA with the given key.
68 \param key The name of the router that the desired LSA comes from.
69 */
akmhoqueb6450b12014-04-24 00:01:03 -050070 NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050071 findNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050072
Nick G97e34942016-07-11 14:46:27 -050073 /*! \brief Installs a name LSA into the LSDB
74 \param nlsa The name LSA to install into the LSDB.
75 */
akmhoque53353462014-04-22 08:43:45 -050076 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050077 installNameLsa(NameLsa& nlsa);
akmhoque53353462014-04-22 08:43:45 -050078
Nick G97e34942016-07-11 14:46:27 -050079 /*! \brief Remove a name LSA from the LSDB.
80 \param key The name of the router that published the LSA to remove.
81
82 This function will remove a name LSA from the LSDB by finding an
83 LSA whose name matches key. This removal also causes the NPT to
84 remove those name prefixes if no more LSAs advertise them.
85 */
akmhoque53353462014-04-22 08:43:45 -050086 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050087 removeNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050088
Nick G97e34942016-07-11 14:46:27 -050089 /*! Returns whether a seq. no. from a certain router signals a new LSA.
90 \param key The name of the originating router.
91 \param seqNo The sequence number to check.
92 */
akmhoque53353462014-04-22 08:43:45 -050093 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050094 isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -050095
96 void
akmhoque2f423352014-06-03 11:49:35 -050097 writeNameLsdbLog();
akmhoque53353462014-04-22 08:43:45 -050098
Jiewen Tana0497d82015-02-02 21:59:18 -080099 const std::list<NameLsa>&
Nick Gordon114537f2017-08-09 14:51:37 -0500100 getNameLsdb() const;
Jiewen Tana0497d82015-02-02 21:59:18 -0800101
Nick G97e34942016-07-11 14:46:27 -0500102 /*! \brief Builds a cor. LSA for this router and installs it into the LSDB. */
akmhoque53353462014-04-22 08:43:45 -0500103 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500104 buildAndInstallOwnCoordinateLsa();
akmhoque53353462014-04-22 08:43:45 -0500105
Nick G97e34942016-07-11 14:46:27 -0500106 /*! \brief Finds a cor. LSA in the LSDB.
107 \param key The name of the originating router that published the LSA.
108 */
akmhoqueb6450b12014-04-24 00:01:03 -0500109 CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500110 findCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500111
Nick G97e34942016-07-11 14:46:27 -0500112 /*! \brief Installs a cor. LSA into the LSDB.
113 \param clsa The cor. LSA to install.
114 */
akmhoque53353462014-04-22 08:43:45 -0500115 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500116 installCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500117
Nick G97e34942016-07-11 14:46:27 -0500118 /*! \brief Removes a cor. LSA from the LSDB.
119 \param key The name of the router that published the LSA to remove.
120
121 Removes the coordinate LSA whose origin router name matches that
122 given by key. Additionally, ask the NPT to remove the prefix,
123 which will occur if no other LSAs point there.
124 */
akmhoque53353462014-04-22 08:43:45 -0500125 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500126 removeCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500127
Nick G97e34942016-07-11 14:46:27 -0500128 /*! \brief Returns whether a cor. LSA from a router is new or not.
129 \param key The name prefix of the originating router.
130 \param seqNo The sequence number of the candidate LSA.
131 */
akmhoque53353462014-04-22 08:43:45 -0500132 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500133 isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500134
135 void
akmhoque2f423352014-06-03 11:49:35 -0500136 writeCorLsdbLog();
akmhoque53353462014-04-22 08:43:45 -0500137
Jiewen Tana0497d82015-02-02 21:59:18 -0800138 const std::list<CoordinateLsa>&
Nick Gordon114537f2017-08-09 14:51:37 -0500139 getCoordinateLsdb() const;
Jiewen Tana0497d82015-02-02 21:59:18 -0800140
Nick G97e34942016-07-11 14:46:27 -0500141 //function related to Adj LSDB
142
143 /*! \brief Schedules a build of this router's LSA. */
akmhoque53353462014-04-22 08:43:45 -0500144 void
Vince Lehman50df6b72015-03-03 12:06:40 -0600145 scheduleAdjLsaBuild();
akmhoque53353462014-04-22 08:43:45 -0500146
Nick G97e34942016-07-11 14:46:27 -0500147 /*! \brief Wrapper event to build and install an adj. LSA for this router. */
akmhoque53353462014-04-22 08:43:45 -0500148 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500149 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500150
Nick G97e34942016-07-11 14:46:27 -0500151 /*! \brief Removes an adj. LSA from the LSDB.
152 \param key The name of the publishing router whose LSA to remove.
153 */
akmhoque53353462014-04-22 08:43:45 -0500154 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500155 removeAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500156
Nick G97e34942016-07-11 14:46:27 -0500157 /*! \brief Returns whether an LSA is new.
158 \param key The name of the publishing router.
159 \param seqNo The seq. no. of the candidate LSA.
160
161 This function determines whether the LSA with the name key and
162 seq. no. seqNo would be new to this LSDB.
163 */
akmhoque53353462014-04-22 08:43:45 -0500164 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500165 isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
Jiewen Tana0497d82015-02-02 21:59:18 -0800166
Nick G97e34942016-07-11 14:46:27 -0500167 /*! \brief Installs an adj. LSA into the LSDB.
168 \param alsa The adj. LSA to add to the LSDB.
169 */
akmhoque53353462014-04-22 08:43:45 -0500170 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500171 installAdjLsa(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500172
Nick G97e34942016-07-11 14:46:27 -0500173 /*! \brief Finds an adj. LSA in the LSDB.
174 \param key The name of the publishing router whose LSA to find.
175 */
akmhoqueb6450b12014-04-24 00:01:03 -0500176 AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500177 findAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500178
Jiewen Tana0497d82015-02-02 21:59:18 -0800179 const std::list<AdjLsa>&
Nick Gordon114537f2017-08-09 14:51:37 -0500180 getAdjLsdb() const;
akmhoque53353462014-04-22 08:43:45 -0500181
182 void
Vince Lehman50df6b72015-03-03 12:06:40 -0600183 setAdjLsaBuildInterval(uint32_t interval)
184 {
185 m_adjLsaBuildInterval = ndn::time::seconds(interval);
186 }
187
Vince Lehman50df6b72015-03-03 12:06:40 -0600188 void
akmhoque2f423352014-06-03 11:49:35 -0500189 writeAdjLsdbLog();
akmhoque53353462014-04-22 08:43:45 -0500190
akmhoque53353462014-04-22 08:43:45 -0500191 void
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500192 expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
Nick Gordone98480b2017-05-24 11:23:03 -0500193 ndn::time::steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500194
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600195 /* \brief Process interest which can be either:
196 * 1) Discovery interest from segment fetcher:
197 * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>
198 * 2) Interest containing segment number:
199 * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>/<version>/<segmentNo>
200 */
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500201 void
202 processInterest(const ndn::Name& name, const ndn::Interest& interest);
203
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600204 bool
205 getIsBuildAdjLsaSheduled()
206 {
207 return m_isBuildAdjLsaSheduled;
208 }
209
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500210 SyncLogicHandler&
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500211 getSync() {
212 return m_sync;
213 }
214
akmhoque53353462014-04-22 08:43:45 -0500215private:
Nick G97e34942016-07-11 14:46:27 -0500216 /* \brief Add a name LSA to the LSDB if it isn't already there.
217 \param nlsa The candidade name LSA.
218 */
akmhoque53353462014-04-22 08:43:45 -0500219 bool
220 addNameLsa(NameLsa& nlsa);
221
Nick G97e34942016-07-11 14:46:27 -0500222 /*! \brief Returns whether the LSDB contains some LSA.
223 \param key The name of the publishing router whose LSA to check for.
224 */
akmhoque53353462014-04-22 08:43:45 -0500225 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500226 doesNameLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500227
Nick G97e34942016-07-11 14:46:27 -0500228 /*! \brief Adds a cor. LSA to the LSDB if it isn't already there.
229 \param clsa The candidate cor. LSA.
230 */
akmhoque53353462014-04-22 08:43:45 -0500231 bool
akmhoqueb6450b12014-04-24 00:01:03 -0500232 addCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500233
Nick G97e34942016-07-11 14:46:27 -0500234 /*! \brief Returns whether a cor. LSA is in the LSDB.
235 \param key The name of the router that published the queried LSA.
236 */
akmhoque53353462014-04-22 08:43:45 -0500237 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500238 doesCoordinateLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500239
Nick G97e34942016-07-11 14:46:27 -0500240 /*! \brief Attempts to construct an adj. LSA.
241
242 This function will attempt to construct an adjacency LSA. An LSA
243 can only be built when the status of all of the router's neighbors
244 is known. That is, when we are not currently trying to contact any
245 neighbor.
246 */
Vince Lehman50df6b72015-03-03 12:06:40 -0600247 void
248 buildAdjLsa();
249
Nick G97e34942016-07-11 14:46:27 -0500250 /*! \brief Adds an adj. LSA to the LSDB if it isn't already there.
251 \param alsa The candidate adj. LSA to add to the LSDB.
252 */
akmhoque53353462014-04-22 08:43:45 -0500253 bool
254 addAdjLsa(AdjLsa& alsa);
255
Nick G97e34942016-07-11 14:46:27 -0500256 /*! \brief Returns whether the LSDB contains an LSA.
257 \param key The name of a router whose LSA to check for in the LSDB.
258 */
akmhoque53353462014-04-22 08:43:45 -0500259 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500260 doesAdjLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500261
Nick G97e34942016-07-11 14:46:27 -0500262 /*! \brief Schedules a refresh/expire event in the scheduler.
263 \param key The name of the router that published the LSA.
264 \param seqNo The seq. no. associated with the LSA.
265 \param expTime How many seconds to wait before triggering the event.
266 */
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400267 ndn::scheduler::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500268 scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
Nick Gordone98480b2017-05-24 11:23:03 -0500269 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500270
Nick G97e34942016-07-11 14:46:27 -0500271 /*! \brief Either allow to expire, or refresh a name LSA.
272 \param lsaKey The name of the router that published the LSA.
273 \param seqNo The seq. no. of the LSA to check.
274 */
akmhoque53353462014-04-22 08:43:45 -0500275 void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500276 expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500277
Vince Lehman199e9cf2015-04-07 13:22:16 -0500278PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick G97e34942016-07-11 14:46:27 -0500279 /*! \brief Schedules an expire/refresh event in the LSA.
280 \param key The name of the router whose LSA is in question.
281 \param seqNo The sequence number of the LSA to check.
282 \param expTime The number of seconds to wait before triggering the event.
283 */
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400284 ndn::scheduler::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500285 scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
Nick Gordone98480b2017-05-24 11:23:03 -0500286 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500287
Vince Lehman199e9cf2015-04-07 13:22:16 -0500288private:
akmhoque53353462014-04-22 08:43:45 -0500289 void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500290 expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500291
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400292 ndn::scheduler::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500293 scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
Nick Gordone98480b2017-05-24 11:23:03 -0500294 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500295
296 void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500297 expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400298 uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500299
akmhoque31d1d4b2014-05-05 22:08:14 -0500300 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500301 processInterestForNameLsa(const ndn::Interest& interest,
302 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500303 uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500304
akmhoque31d1d4b2014-05-05 22:08:14 -0500305 void
306 processInterestForAdjacencyLsa(const ndn::Interest& interest,
307 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500308 uint64_t seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500309
310 void
311 processInterestForCoordinateLsa(const ndn::Interest& interest,
312 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500313 uint64_t seqNo);
Ashlesh Gawande15052402018-12-12 20:20:00 -0600314
akmhoque31d1d4b2014-05-05 22:08:14 -0500315 void
dmcoomes9f936662017-03-02 10:33:09 -0600316 onContentValidated(const std::shared_ptr<const ndn::Data>& data);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700317
318 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500319 processContentNameLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500320 uint64_t lsSeqNo, std::string& dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500321
322 void
323 processContentAdjacencyLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500324 uint64_t lsSeqNo, std::string& dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500325
326 void
327 processContentCoordinateLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500328 uint64_t lsSeqNo, std::string& dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500329
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500330PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick G97e34942016-07-11 14:46:27 -0500331 /*!
332 \brief Error callback when SegmentFetcher fails to return an LSA
333
334 In all error cases, a reattempt to fetch the LSA will be made.
335
336 Segment validation can fail either because the packet does not have a
337 valid signature (fatal) or because some of the certificates in the trust chain
338 could not be fetched (non-fatal).
339
340 Currently, the library does not provide clear indication (besides a plain-text message
341 in the error callback) of the reason for the failure nor the segment that failed
342 to be validated, thus we will continue to try to fetch the LSA until the deadline
343 is reached.
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500344 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500345 void
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500346 onFetchLsaError(uint32_t errorCode,
347 const std::string& msg,
Ashlesh Gawande744e4812018-08-22 16:26:24 -0500348 const ndn::Name& interestName,
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500349 uint32_t retransmitNo,
350 const ndn::time::steady_clock::TimePoint& deadline,
351 ndn::Name lsaName,
352 uint64_t seqNo);
353
Nick G97e34942016-07-11 14:46:27 -0500354 /*!
355 \brief Success callback when SegmentFetcher returns a valid LSA
356
Nick Gordonb50e51b2016-07-22 16:05:57 -0500357 \param interestName The base Interest used to fetch the LSA in the format:
Nick G97e34942016-07-11 14:46:27 -0500358 /<network>/NLSR/LSA/<site>/%C1.Router/<router>/<lsa-type>/<seqNo>
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500359 */
360 void
Ashlesh Gawande744e4812018-08-22 16:26:24 -0500361 afterFetchLsa(const ndn::ConstBufferPtr& data, const ndn::Name& interestName);
akmhoque31d1d4b2014-05-05 22:08:14 -0500362
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500363private:
Nick Gordone98480b2017-05-24 11:23:03 -0500364 ndn::time::system_clock::TimePoint
akmhoquec7a79b22014-05-26 08:06:19 -0500365 getLsaExpirationTimePoint();
366
Jiewen Tana0497d82015-02-02 21:59:18 -0800367public:
368 static const ndn::Name::Component NAME_COMPONENT;
369
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600370 ndn::util::signal::Signal<Lsdb, Statistics::PacketType> lsaIncrementSignal;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600371 ndn::util::signal::Signal<Lsdb, const ndn::Data&> afterSegmentValidatedSignal;
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600372
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500373private:
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600374 ndn::Face& m_face;
375 ndn::Scheduler m_scheduler;
376 ndn::security::SigningInfo& m_signingInfo;
377
378 ConfParameter& m_confParam;
379 NamePrefixTable& m_namePrefixTable;
380 RoutingTable& m_routingTable;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600381
382PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande15052402018-12-12 20:20:00 -0600383 SyncLogicHandler m_sync;
Vince Lehman7c603292014-09-11 17:48:16 -0500384
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600385private:
akmhoque53353462014-04-22 08:43:45 -0500386 std::list<NameLsa> m_nameLsdb;
387 std::list<AdjLsa> m_adjLsdb;
akmhoqueb6450b12014-04-24 00:01:03 -0500388 std::list<CoordinateLsa> m_corLsdb;
akmhoque53353462014-04-22 08:43:45 -0500389
Nick Gordone98480b2017-05-24 11:23:03 -0500390 ndn::time::seconds m_lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500391 std::string m_thisRouterPrefix;
392
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500393 typedef std::map<ndn::Name, uint64_t> SequenceNumberMap;
394
395 // Maps the name of an LSA to its highest known sequence number from sync;
396 // Used to stop NLSR from trying to fetch outdated LSAs
397 SequenceNumberMap m_highestSeqNo;
398
Vince Lehman18841082014-08-19 17:15:24 -0500399 static const ndn::time::seconds GRACE_PERIOD;
Nick Gordone98480b2017-05-24 11:23:03 -0500400 static const ndn::time::steady_clock::TimePoint DEFAULT_LSA_RETRIEVAL_DEADLINE;
Vince Lehman50df6b72015-03-03 12:06:40 -0600401
Ashlesh Gawande15052402018-12-12 20:20:00 -0600402PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Vince Lehman50df6b72015-03-03 12:06:40 -0600403 ndn::time::seconds m_adjLsaBuildInterval;
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500404
405 SequencingManager m_sequencingManager;
Nick Gordon9eac4d92017-08-29 17:31:29 -0500406
Ashlesh Gawande15052402018-12-12 20:20:00 -0600407private:
Nick Gordon9eac4d92017-08-29 17:31:29 -0500408 ndn::util::signal::ScopedConnection m_onNewLsaConnection;
Ashlesh Gawande744e4812018-08-22 16:26:24 -0500409
410 std::set<std::shared_ptr<ndn::util::SegmentFetcher>> m_fetchers;
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600411 psync::SegmentPublisher m_segmentPublisher;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600412
413 bool m_isBuildAdjLsaSheduled;
414 int64_t m_adjBuildCount;
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500415 ndn::scheduler::ScopedEventId m_scheduledAdjLsaBuild;
Ashlesh Gawande15052402018-12-12 20:20:00 -0600416
417PUBLIC_WITH_TESTS_ELSE_PRIVATE:
418 ndn::InMemoryStoragePersistent m_lsaStorage;
akmhoque53353462014-04-22 08:43:45 -0500419};
420
Nick Gordonfad8e252016-08-11 14:21:38 -0500421} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500422
dmcoomes9f936662017-03-02 10:33:09 -0600423#endif // NLSR_LSDB_HPP