blob: 2c68906a55df0aa7e7c6b9a5a6c8fecbb4cd880a [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"
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +000027#include "lsa-segment-storage.hpp"
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050028#include "sequencing-manager.hpp"
Ashlesh Gawande5bf83172014-09-19 12:38:17 -050029#include "test-access-control.hpp"
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050030#include "communication/sync-logic-handler.hpp"
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060031#include "statistics.hpp"
Ashlesh Gawande85998a12017-12-07 22:22:13 -060032#include "route/name-prefix-table.hpp"
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060033
34#include <ndn-cxx/security/key-chain.hpp>
35#include <ndn-cxx/util/signal.hpp>
36#include <ndn-cxx/util/time.hpp>
Ashlesh Gawande744e4812018-08-22 16:26:24 -050037#include <ndn-cxx/util/segment-fetcher.hpp>
38
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
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050055 SyncLogicHandler&
56 getSyncLogicHandler()
57 {
58 return m_sync;
59 }
akmhoque53353462014-04-22 08:43:45 -050060
akmhoque53353462014-04-22 08:43:45 -050061 bool
Nick Gordon727d4832017-10-13 18:04:25 -050062 isLsaNew(const ndn::Name& routerName, const Lsa::Type& lsaType, const uint64_t& sequenceNumber);
akmhoque53353462014-04-22 08:43:45 -050063
Nick Gordon8f23b5d2017-08-31 17:53:07 -050064 bool
Nick Gordon727d4832017-10-13 18:04:25 -050065 doesLsaExist(const ndn::Name& key, const Lsa::Type& lsType);
Nick G97e34942016-07-11 14:46:27 -050066
67 /*! \brief Builds a name LSA for this router and then installs it
68 into the LSDB.
69 */
akmhoque53353462014-04-22 08:43:45 -050070 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050071 buildAndInstallOwnNameLsa();
akmhoque53353462014-04-22 08:43:45 -050072
Nick G97e34942016-07-11 14:46:27 -050073 /*! \brief Returns the name LSA with the given key.
74 \param key The name of the router that the desired LSA comes from.
75 */
akmhoqueb6450b12014-04-24 00:01:03 -050076 NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050077 findNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050078
Nick G97e34942016-07-11 14:46:27 -050079 /*! \brief Installs a name LSA into the LSDB
80 \param nlsa The name LSA to install into the LSDB.
81 */
akmhoque53353462014-04-22 08:43:45 -050082 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050083 installNameLsa(NameLsa& nlsa);
akmhoque53353462014-04-22 08:43:45 -050084
Nick G97e34942016-07-11 14:46:27 -050085 /*! \brief Remove a name LSA from the LSDB.
86 \param key The name of the router that published the LSA to remove.
87
88 This function will remove a name LSA from the LSDB by finding an
89 LSA whose name matches key. This removal also causes the NPT to
90 remove those name prefixes if no more LSAs advertise them.
91 */
akmhoque53353462014-04-22 08:43:45 -050092 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050093 removeNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050094
Nick G97e34942016-07-11 14:46:27 -050095 /*! Returns whether a seq. no. from a certain router signals a new LSA.
96 \param key The name of the originating router.
97 \param seqNo The sequence number to check.
98 */
akmhoque53353462014-04-22 08:43:45 -050099 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500100 isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500101
102 void
akmhoque2f423352014-06-03 11:49:35 -0500103 writeNameLsdbLog();
akmhoque53353462014-04-22 08:43:45 -0500104
Jiewen Tana0497d82015-02-02 21:59:18 -0800105 const std::list<NameLsa>&
Nick Gordon114537f2017-08-09 14:51:37 -0500106 getNameLsdb() const;
Jiewen Tana0497d82015-02-02 21:59:18 -0800107
Nick G97e34942016-07-11 14:46:27 -0500108 /*! \brief Builds a cor. LSA for this router and installs it into the LSDB. */
akmhoque53353462014-04-22 08:43:45 -0500109 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500110 buildAndInstallOwnCoordinateLsa();
akmhoque53353462014-04-22 08:43:45 -0500111
Nick G97e34942016-07-11 14:46:27 -0500112 /*! \brief Finds a cor. LSA in the LSDB.
113 \param key The name of the originating router that published the LSA.
114 */
akmhoqueb6450b12014-04-24 00:01:03 -0500115 CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500116 findCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500117
Nick G97e34942016-07-11 14:46:27 -0500118 /*! \brief Installs a cor. LSA into the LSDB.
119 \param clsa The cor. LSA to install.
120 */
akmhoque53353462014-04-22 08:43:45 -0500121 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500122 installCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500123
Nick G97e34942016-07-11 14:46:27 -0500124 /*! \brief Removes a cor. LSA from the LSDB.
125 \param key The name of the router that published the LSA to remove.
126
127 Removes the coordinate LSA whose origin router name matches that
128 given by key. Additionally, ask the NPT to remove the prefix,
129 which will occur if no other LSAs point there.
130 */
akmhoque53353462014-04-22 08:43:45 -0500131 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500132 removeCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500133
Nick G97e34942016-07-11 14:46:27 -0500134 /*! \brief Returns whether a cor. LSA from a router is new or not.
135 \param key The name prefix of the originating router.
136 \param seqNo The sequence number of the candidate LSA.
137 */
akmhoque53353462014-04-22 08:43:45 -0500138 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500139 isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500140
141 void
akmhoque2f423352014-06-03 11:49:35 -0500142 writeCorLsdbLog();
akmhoque53353462014-04-22 08:43:45 -0500143
Jiewen Tana0497d82015-02-02 21:59:18 -0800144 const std::list<CoordinateLsa>&
Nick Gordon114537f2017-08-09 14:51:37 -0500145 getCoordinateLsdb() const;
Jiewen Tana0497d82015-02-02 21:59:18 -0800146
Nick G97e34942016-07-11 14:46:27 -0500147 //function related to Adj LSDB
148
149 /*! \brief Schedules a build of this router's LSA. */
akmhoque53353462014-04-22 08:43:45 -0500150 void
Vince Lehman50df6b72015-03-03 12:06:40 -0600151 scheduleAdjLsaBuild();
akmhoque53353462014-04-22 08:43:45 -0500152
Nick G97e34942016-07-11 14:46:27 -0500153 /*! \brief Wrapper event to build and install an adj. LSA for this router. */
akmhoque53353462014-04-22 08:43:45 -0500154 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500155 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500156
Nick G97e34942016-07-11 14:46:27 -0500157 /*! \brief Removes an adj. LSA from the LSDB.
158 \param key The name of the publishing router whose LSA to remove.
159 */
akmhoque53353462014-04-22 08:43:45 -0500160 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500161 removeAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500162
Nick G97e34942016-07-11 14:46:27 -0500163 /*! \brief Returns whether an LSA is new.
164 \param key The name of the publishing router.
165 \param seqNo The seq. no. of the candidate LSA.
166
167 This function determines whether the LSA with the name key and
168 seq. no. seqNo would be new to this LSDB.
169 */
akmhoque53353462014-04-22 08:43:45 -0500170 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500171 isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
Jiewen Tana0497d82015-02-02 21:59:18 -0800172
Nick G97e34942016-07-11 14:46:27 -0500173 /*! \brief Installs an adj. LSA into the LSDB.
174 \param alsa The adj. LSA to add to the LSDB.
175 */
akmhoque53353462014-04-22 08:43:45 -0500176 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500177 installAdjLsa(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500178
Nick G97e34942016-07-11 14:46:27 -0500179 /*! \brief Finds an adj. LSA in the LSDB.
180 \param key The name of the publishing router whose LSA to find.
181 */
akmhoqueb6450b12014-04-24 00:01:03 -0500182 AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500183 findAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500184
Jiewen Tana0497d82015-02-02 21:59:18 -0800185 const std::list<AdjLsa>&
Nick Gordon114537f2017-08-09 14:51:37 -0500186 getAdjLsdb() const;
akmhoque53353462014-04-22 08:43:45 -0500187
188 void
Vince Lehman50df6b72015-03-03 12:06:40 -0600189 setAdjLsaBuildInterval(uint32_t interval)
190 {
191 m_adjLsaBuildInterval = ndn::time::seconds(interval);
192 }
193
194 const ndn::time::seconds&
195 getAdjLsaBuildInterval() const
196 {
197 return m_adjLsaBuildInterval;
198 }
199
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500200 SequencingManager&
201 getSequencingManager()
202 {
203 return m_sequencingManager;
204 }
205
Vince Lehman50df6b72015-03-03 12:06:40 -0600206 void
akmhoque2f423352014-06-03 11:49:35 -0500207 writeAdjLsdbLog();
akmhoque53353462014-04-22 08:43:45 -0500208
akmhoque53353462014-04-22 08:43:45 -0500209 void
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500210 expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
Nick Gordone98480b2017-05-24 11:23:03 -0500211 ndn::time::steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500212
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600213 /* \brief Process interest which can be either:
214 * 1) Discovery interest from segment fetcher:
215 * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>
216 * 2) Interest containing segment number:
217 * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>/<version>/<segmentNo>
218 */
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500219 void
220 processInterest(const ndn::Name& name, const ndn::Interest& interest);
221
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600222 bool
223 getIsBuildAdjLsaSheduled()
224 {
225 return m_isBuildAdjLsaSheduled;
226 }
227
akmhoque53353462014-04-22 08:43:45 -0500228private:
Nick G97e34942016-07-11 14:46:27 -0500229 /* \brief Add a name LSA to the LSDB if it isn't already there.
230 \param nlsa The candidade name LSA.
231 */
akmhoque53353462014-04-22 08:43:45 -0500232 bool
233 addNameLsa(NameLsa& nlsa);
234
Nick G97e34942016-07-11 14:46:27 -0500235 /*! \brief Returns whether the LSDB contains some LSA.
236 \param key The name of the publishing router whose LSA to check for.
237 */
akmhoque53353462014-04-22 08:43:45 -0500238 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500239 doesNameLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500240
Nick G97e34942016-07-11 14:46:27 -0500241 /*! \brief Adds a cor. LSA to the LSDB if it isn't already there.
242 \param clsa The candidate cor. LSA.
243 */
akmhoque53353462014-04-22 08:43:45 -0500244 bool
akmhoqueb6450b12014-04-24 00:01:03 -0500245 addCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500246
Nick G97e34942016-07-11 14:46:27 -0500247 /*! \brief Returns whether a cor. LSA is in the LSDB.
248 \param key The name of the router that published the queried LSA.
249 */
akmhoque53353462014-04-22 08:43:45 -0500250 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500251 doesCoordinateLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500252
Nick G97e34942016-07-11 14:46:27 -0500253 /*! \brief Attempts to construct an adj. LSA.
254
255 This function will attempt to construct an adjacency LSA. An LSA
256 can only be built when the status of all of the router's neighbors
257 is known. That is, when we are not currently trying to contact any
258 neighbor.
259 */
Vince Lehman50df6b72015-03-03 12:06:40 -0600260 void
261 buildAdjLsa();
262
Nick G97e34942016-07-11 14:46:27 -0500263 /*! \brief Adds an adj. LSA to the LSDB if it isn't already there.
264 \param alsa The candidate adj. LSA to add to the LSDB.
265 */
akmhoque53353462014-04-22 08:43:45 -0500266 bool
267 addAdjLsa(AdjLsa& alsa);
268
Nick G97e34942016-07-11 14:46:27 -0500269 /*! \brief Returns whether the LSDB contains an LSA.
270 \param key The name of a router whose LSA to check for in the LSDB.
271 */
akmhoque53353462014-04-22 08:43:45 -0500272 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500273 doesAdjLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500274
Nick G97e34942016-07-11 14:46:27 -0500275 /*! \brief Schedules a refresh/expire event in the scheduler.
276 \param key The name of the router that published the LSA.
277 \param seqNo The seq. no. associated with the LSA.
278 \param expTime How many seconds to wait before triggering the event.
279 */
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400280 ndn::scheduler::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500281 scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
Nick Gordone98480b2017-05-24 11:23:03 -0500282 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500283
Nick G97e34942016-07-11 14:46:27 -0500284 /*! \brief Either allow to expire, or refresh a name LSA.
285 \param lsaKey The name of the router that published the LSA.
286 \param seqNo The seq. no. of the LSA to check.
287 */
akmhoque53353462014-04-22 08:43:45 -0500288 void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500289 expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500290
Vince Lehman199e9cf2015-04-07 13:22:16 -0500291PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick G97e34942016-07-11 14:46:27 -0500292 /*! \brief Schedules an expire/refresh event in the LSA.
293 \param key The name of the router whose LSA is in question.
294 \param seqNo The sequence number of the LSA to check.
295 \param expTime The number of seconds to wait before triggering the event.
296 */
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400297 ndn::scheduler::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500298 scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
Nick Gordone98480b2017-05-24 11:23:03 -0500299 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500300
Vince Lehman199e9cf2015-04-07 13:22:16 -0500301private:
akmhoque53353462014-04-22 08:43:45 -0500302 void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500303 expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500304
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400305 ndn::scheduler::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500306 scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
Nick Gordone98480b2017-05-24 11:23:03 -0500307 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500308
309 void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500310 expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400311 uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500312
Nick G97e34942016-07-11 14:46:27 -0500313private:
314
akmhoque31d1d4b2014-05-05 22:08:14 -0500315 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500316 processInterestForNameLsa(const ndn::Interest& interest,
317 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500318 uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500319
akmhoque31d1d4b2014-05-05 22:08:14 -0500320 void
321 processInterestForAdjacencyLsa(const ndn::Interest& interest,
322 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500323 uint64_t seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500324
325 void
326 processInterestForCoordinateLsa(const ndn::Interest& interest,
327 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500328 uint64_t seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500329 void
dmcoomes9f936662017-03-02 10:33:09 -0600330 onContentValidated(const std::shared_ptr<const ndn::Data>& data);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700331
332 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500333 processContentNameLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500334 uint64_t lsSeqNo, std::string& dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500335
336 void
337 processContentAdjacencyLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500338 uint64_t lsSeqNo, std::string& dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500339
340 void
341 processContentCoordinateLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500342 uint64_t lsSeqNo, std::string& dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500343
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500344PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick G97e34942016-07-11 14:46:27 -0500345 /*!
346 \brief Error callback when SegmentFetcher fails to return an LSA
347
348 In all error cases, a reattempt to fetch the LSA will be made.
349
350 Segment validation can fail either because the packet does not have a
351 valid signature (fatal) or because some of the certificates in the trust chain
352 could not be fetched (non-fatal).
353
354 Currently, the library does not provide clear indication (besides a plain-text message
355 in the error callback) of the reason for the failure nor the segment that failed
356 to be validated, thus we will continue to try to fetch the LSA until the deadline
357 is reached.
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500358 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500359 void
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500360 onFetchLsaError(uint32_t errorCode,
361 const std::string& msg,
Ashlesh Gawande744e4812018-08-22 16:26:24 -0500362 const ndn::Name& interestName,
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500363 uint32_t retransmitNo,
364 const ndn::time::steady_clock::TimePoint& deadline,
365 ndn::Name lsaName,
366 uint64_t seqNo);
367
Nick G97e34942016-07-11 14:46:27 -0500368 /*!
369 \brief Success callback when SegmentFetcher returns a valid LSA
370
Nick Gordonb50e51b2016-07-22 16:05:57 -0500371 \param interestName The base Interest used to fetch the LSA in the format:
Nick G97e34942016-07-11 14:46:27 -0500372 /<network>/NLSR/LSA/<site>/%C1.Router/<router>/<lsa-type>/<seqNo>
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500373 */
374 void
Ashlesh Gawande744e4812018-08-22 16:26:24 -0500375 afterFetchLsa(const ndn::ConstBufferPtr& data, const ndn::Name& interestName);
akmhoque31d1d4b2014-05-05 22:08:14 -0500376
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500377private:
Nick Gordone98480b2017-05-24 11:23:03 -0500378 ndn::time::system_clock::TimePoint
akmhoquec7a79b22014-05-26 08:06:19 -0500379 getLsaExpirationTimePoint();
380
Jiewen Tana0497d82015-02-02 21:59:18 -0800381public:
382 static const ndn::Name::Component NAME_COMPONENT;
383
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600384 ndn::util::signal::Signal<Lsdb, Statistics::PacketType> lsaIncrementSignal;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600385 ndn::util::signal::Signal<Lsdb, const ndn::Data&> afterSegmentValidatedSignal;
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600386
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500387private:
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600388 ndn::Face& m_face;
389 ndn::Scheduler m_scheduler;
390 ndn::security::SigningInfo& m_signingInfo;
391
392 ConfParameter& m_confParam;
393 NamePrefixTable& m_namePrefixTable;
394 RoutingTable& m_routingTable;
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500395 SyncLogicHandler m_sync;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600396
397PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000398 LsaSegmentStorage m_lsaStorage;
Vince Lehman7c603292014-09-11 17:48:16 -0500399
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600400private:
akmhoque53353462014-04-22 08:43:45 -0500401 std::list<NameLsa> m_nameLsdb;
402 std::list<AdjLsa> m_adjLsdb;
akmhoqueb6450b12014-04-24 00:01:03 -0500403 std::list<CoordinateLsa> m_corLsdb;
akmhoque53353462014-04-22 08:43:45 -0500404
Nick Gordone98480b2017-05-24 11:23:03 -0500405 ndn::time::seconds m_lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500406 std::string m_thisRouterPrefix;
407
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500408 typedef std::map<ndn::Name, uint64_t> SequenceNumberMap;
409
410 // Maps the name of an LSA to its highest known sequence number from sync;
411 // Used to stop NLSR from trying to fetch outdated LSAs
412 SequenceNumberMap m_highestSeqNo;
413
Vince Lehman18841082014-08-19 17:15:24 -0500414 static const ndn::time::seconds GRACE_PERIOD;
Nick Gordone98480b2017-05-24 11:23:03 -0500415 static const ndn::time::steady_clock::TimePoint DEFAULT_LSA_RETRIEVAL_DEADLINE;
Vince Lehman50df6b72015-03-03 12:06:40 -0600416
417 ndn::time::seconds m_adjLsaBuildInterval;
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500418
419 SequencingManager m_sequencingManager;
Nick Gordon9eac4d92017-08-29 17:31:29 -0500420
421 ndn::util::signal::ScopedConnection m_onNewLsaConnection;
Ashlesh Gawande744e4812018-08-22 16:26:24 -0500422
423 std::set<std::shared_ptr<ndn::util::SegmentFetcher>> m_fetchers;
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600424 psync::SegmentPublisher m_segmentPublisher;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600425
426 bool m_isBuildAdjLsaSheduled;
427 int64_t m_adjBuildCount;
akmhoque53353462014-04-22 08:43:45 -0500428};
429
Nick Gordonfad8e252016-08-11 14:21:38 -0500430} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500431
dmcoomes9f936662017-03-02 10:33:09 -0600432#endif // NLSR_LSDB_HPP