blob: 183f3dc5d2f3ea6a77d4a08f438409e1ff3f4099 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +00003 * Copyright (c) 2014-2018, 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"
32
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>
37
Ashlesh Gawande939b6f82018-12-09 16:51:09 -060038#include <PSync/segment-publisher.hpp>
39
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060040#include <utility>
41#include <boost/cstdint.hpp>
akmhoque53353462014-04-22 08:43:45 -050042
Nick Gordone98480b2017-05-24 11:23:03 -050043namespace nlsr {
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070044
akmhoque53353462014-04-22 08:43:45 -050045class Nlsr;
46
47class Lsdb
48{
49public:
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050050 Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler);
51
Ashlesh Gawande744e4812018-08-22 16:26:24 -050052 ~Lsdb();
53
Ashlesh Gawande3e105a02017-05-16 17:36:56 -050054 SyncLogicHandler&
55 getSyncLogicHandler()
56 {
57 return m_sync;
58 }
akmhoque53353462014-04-22 08:43:45 -050059
akmhoque53353462014-04-22 08:43:45 -050060 bool
Nick Gordon727d4832017-10-13 18:04:25 -050061 isLsaNew(const ndn::Name& routerName, const Lsa::Type& lsaType, const uint64_t& sequenceNumber);
akmhoque53353462014-04-22 08:43:45 -050062
Nick Gordon8f23b5d2017-08-31 17:53:07 -050063 bool
Nick Gordon727d4832017-10-13 18:04:25 -050064 doesLsaExist(const ndn::Name& key, const Lsa::Type& lsType);
Nick G97e34942016-07-11 14:46:27 -050065
66 /*! \brief Builds a name LSA for this router and then installs it
67 into the LSDB.
68 */
akmhoque53353462014-04-22 08:43:45 -050069 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050070 buildAndInstallOwnNameLsa();
akmhoque53353462014-04-22 08:43:45 -050071
Nick G97e34942016-07-11 14:46:27 -050072 /*! \brief Returns the name LSA with the given key.
73 \param key The name of the router that the desired LSA comes from.
74 */
akmhoqueb6450b12014-04-24 00:01:03 -050075 NameLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -050076 findNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050077
Nick G97e34942016-07-11 14:46:27 -050078 /*! \brief Installs a name LSA into the LSDB
79 \param nlsa The name LSA to install into the LSDB.
80 */
akmhoque53353462014-04-22 08:43:45 -050081 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050082 installNameLsa(NameLsa& nlsa);
akmhoque53353462014-04-22 08:43:45 -050083
Nick G97e34942016-07-11 14:46:27 -050084 /*! \brief Remove a name LSA from the LSDB.
85 \param key The name of the router that published the LSA to remove.
86
87 This function will remove a name LSA from the LSDB by finding an
88 LSA whose name matches key. This removal also causes the NPT to
89 remove those name prefixes if no more LSAs advertise them.
90 */
akmhoque53353462014-04-22 08:43:45 -050091 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050092 removeNameLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -050093
Nick G97e34942016-07-11 14:46:27 -050094 /*! Returns whether a seq. no. from a certain router signals a new LSA.
95 \param key The name of the originating router.
96 \param seqNo The sequence number to check.
97 */
akmhoque53353462014-04-22 08:43:45 -050098 bool
akmhoque31d1d4b2014-05-05 22:08:14 -050099 isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500100
101 void
akmhoque2f423352014-06-03 11:49:35 -0500102 writeNameLsdbLog();
akmhoque53353462014-04-22 08:43:45 -0500103
Jiewen Tana0497d82015-02-02 21:59:18 -0800104 const std::list<NameLsa>&
Nick Gordon114537f2017-08-09 14:51:37 -0500105 getNameLsdb() const;
Jiewen Tana0497d82015-02-02 21:59:18 -0800106
Nick G97e34942016-07-11 14:46:27 -0500107 /*! \brief Builds a cor. LSA for this router and installs it into the LSDB. */
akmhoque53353462014-04-22 08:43:45 -0500108 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500109 buildAndInstallOwnCoordinateLsa();
akmhoque53353462014-04-22 08:43:45 -0500110
Nick G97e34942016-07-11 14:46:27 -0500111 /*! \brief Finds a cor. LSA in the LSDB.
112 \param key The name of the originating router that published the LSA.
113 */
akmhoqueb6450b12014-04-24 00:01:03 -0500114 CoordinateLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500115 findCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500116
Nick G97e34942016-07-11 14:46:27 -0500117 /*! \brief Installs a cor. LSA into the LSDB.
118 \param clsa The cor. LSA to install.
119 */
akmhoque53353462014-04-22 08:43:45 -0500120 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500121 installCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500122
Nick G97e34942016-07-11 14:46:27 -0500123 /*! \brief Removes a cor. LSA from the LSDB.
124 \param key The name of the router that published the LSA to remove.
125
126 Removes the coordinate LSA whose origin router name matches that
127 given by key. Additionally, ask the NPT to remove the prefix,
128 which will occur if no other LSAs point there.
129 */
akmhoque53353462014-04-22 08:43:45 -0500130 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500131 removeCoordinateLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500132
Nick G97e34942016-07-11 14:46:27 -0500133 /*! \brief Returns whether a cor. LSA from a router is new or not.
134 \param key The name prefix of the originating router.
135 \param seqNo The sequence number of the candidate LSA.
136 */
akmhoque53353462014-04-22 08:43:45 -0500137 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500138 isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500139
140 void
akmhoque2f423352014-06-03 11:49:35 -0500141 writeCorLsdbLog();
akmhoque53353462014-04-22 08:43:45 -0500142
Jiewen Tana0497d82015-02-02 21:59:18 -0800143 const std::list<CoordinateLsa>&
Nick Gordon114537f2017-08-09 14:51:37 -0500144 getCoordinateLsdb() const;
Jiewen Tana0497d82015-02-02 21:59:18 -0800145
Nick G97e34942016-07-11 14:46:27 -0500146 //function related to Adj LSDB
147
148 /*! \brief Schedules a build of this router's LSA. */
akmhoque53353462014-04-22 08:43:45 -0500149 void
Vince Lehman50df6b72015-03-03 12:06:40 -0600150 scheduleAdjLsaBuild();
akmhoque53353462014-04-22 08:43:45 -0500151
Nick G97e34942016-07-11 14:46:27 -0500152 /*! \brief Wrapper event to build and install an adj. LSA for this router. */
akmhoque53353462014-04-22 08:43:45 -0500153 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500154 buildAndInstallOwnAdjLsa();
akmhoque53353462014-04-22 08:43:45 -0500155
Nick G97e34942016-07-11 14:46:27 -0500156 /*! \brief Removes an adj. LSA from the LSDB.
157 \param key The name of the publishing router whose LSA to remove.
158 */
akmhoque53353462014-04-22 08:43:45 -0500159 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500160 removeAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500161
Nick G97e34942016-07-11 14:46:27 -0500162 /*! \brief Returns whether an LSA is new.
163 \param key The name of the publishing router.
164 \param seqNo The seq. no. of the candidate LSA.
165
166 This function determines whether the LSA with the name key and
167 seq. no. seqNo would be new to this LSDB.
168 */
akmhoque53353462014-04-22 08:43:45 -0500169 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500170 isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
Jiewen Tana0497d82015-02-02 21:59:18 -0800171
Nick G97e34942016-07-11 14:46:27 -0500172 /*! \brief Installs an adj. LSA into the LSDB.
173 \param alsa The adj. LSA to add to the LSDB.
174 */
akmhoque53353462014-04-22 08:43:45 -0500175 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500176 installAdjLsa(AdjLsa& alsa);
akmhoque53353462014-04-22 08:43:45 -0500177
Nick G97e34942016-07-11 14:46:27 -0500178 /*! \brief Finds an adj. LSA in the LSDB.
179 \param key The name of the publishing router whose LSA to find.
180 */
akmhoqueb6450b12014-04-24 00:01:03 -0500181 AdjLsa*
akmhoque31d1d4b2014-05-05 22:08:14 -0500182 findAdjLsa(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500183
Jiewen Tana0497d82015-02-02 21:59:18 -0800184 const std::list<AdjLsa>&
Nick Gordon114537f2017-08-09 14:51:37 -0500185 getAdjLsdb() const;
akmhoque53353462014-04-22 08:43:45 -0500186
187 void
Vince Lehman50df6b72015-03-03 12:06:40 -0600188 setAdjLsaBuildInterval(uint32_t interval)
189 {
190 m_adjLsaBuildInterval = ndn::time::seconds(interval);
191 }
192
193 const ndn::time::seconds&
194 getAdjLsaBuildInterval() const
195 {
196 return m_adjLsaBuildInterval;
197 }
198
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500199 SequencingManager&
200 getSequencingManager()
201 {
202 return m_sequencingManager;
203 }
204
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000205 LsaSegmentStorage&
Ashlesh Gawande304bebf2018-02-07 17:10:35 -0600206 getLsaStorage()
207 {
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000208 return m_lsaStorage;
209 }
210
Vince Lehman50df6b72015-03-03 12:06:40 -0600211 void
akmhoque2f423352014-06-03 11:49:35 -0500212 writeAdjLsdbLog();
akmhoque53353462014-04-22 08:43:45 -0500213
akmhoque53353462014-04-22 08:43:45 -0500214 void
Nick Gordone98480b2017-05-24 11:23:03 -0500215 setLsaRefreshTime(const ndn::time::seconds& lsaRefreshTime);
akmhoque53353462014-04-22 08:43:45 -0500216
217 void
218 setThisRouterPrefix(std::string trp);
219
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500220 void
221 expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
Nick Gordone98480b2017-05-24 11:23:03 -0500222 ndn::time::steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE);
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500223
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600224 /* \brief Process interest which can be either:
225 * 1) Discovery interest from segment fetcher:
226 * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>
227 * 2) Interest containing segment number:
228 * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>/<version>/<segmentNo>
229 */
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500230 void
231 processInterest(const ndn::Name& name, const ndn::Interest& interest);
232
akmhoque53353462014-04-22 08:43:45 -0500233private:
Nick G97e34942016-07-11 14:46:27 -0500234 /* \brief Add a name LSA to the LSDB if it isn't already there.
235 \param nlsa The candidade name LSA.
236 */
akmhoque53353462014-04-22 08:43:45 -0500237 bool
238 addNameLsa(NameLsa& nlsa);
239
Nick G97e34942016-07-11 14:46:27 -0500240 /*! \brief Returns whether the LSDB contains some LSA.
241 \param key The name of the publishing router whose LSA to check for.
242 */
akmhoque53353462014-04-22 08:43:45 -0500243 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500244 doesNameLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500245
Nick G97e34942016-07-11 14:46:27 -0500246 /*! \brief Adds a cor. LSA to the LSDB if it isn't already there.
247 \param clsa The candidate cor. LSA.
248 */
akmhoque53353462014-04-22 08:43:45 -0500249 bool
akmhoqueb6450b12014-04-24 00:01:03 -0500250 addCoordinateLsa(CoordinateLsa& clsa);
akmhoque53353462014-04-22 08:43:45 -0500251
Nick G97e34942016-07-11 14:46:27 -0500252 /*! \brief Returns whether a cor. LSA is in the LSDB.
253 \param key The name of the router that published the queried LSA.
254 */
akmhoque53353462014-04-22 08:43:45 -0500255 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500256 doesCoordinateLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500257
Nick G97e34942016-07-11 14:46:27 -0500258 /*! \brief Attempts to construct an adj. LSA.
259
260 This function will attempt to construct an adjacency LSA. An LSA
261 can only be built when the status of all of the router's neighbors
262 is known. That is, when we are not currently trying to contact any
263 neighbor.
264 */
Vince Lehman50df6b72015-03-03 12:06:40 -0600265 void
266 buildAdjLsa();
267
Nick G97e34942016-07-11 14:46:27 -0500268 /*! \brief Adds an adj. LSA to the LSDB if it isn't already there.
269 \param alsa The candidate adj. LSA to add to the LSDB.
270 */
akmhoque53353462014-04-22 08:43:45 -0500271 bool
272 addAdjLsa(AdjLsa& alsa);
273
Nick G97e34942016-07-11 14:46:27 -0500274 /*! \brief Returns whether the LSDB contains an LSA.
275 \param key The name of a router whose LSA to check for in the LSDB.
276 */
akmhoque53353462014-04-22 08:43:45 -0500277 bool
akmhoque31d1d4b2014-05-05 22:08:14 -0500278 doesAdjLsaExist(const ndn::Name& key);
akmhoque53353462014-04-22 08:43:45 -0500279
Nick G97e34942016-07-11 14:46:27 -0500280 /*! \brief Schedules a refresh/expire event in the scheduler.
281 \param key The name of the router that published the LSA.
282 \param seqNo The seq. no. associated with the LSA.
283 \param expTime How many seconds to wait before triggering the event.
284 */
akmhoque53353462014-04-22 08:43:45 -0500285 ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500286 scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
Nick Gordone98480b2017-05-24 11:23:03 -0500287 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500288
Nick G97e34942016-07-11 14:46:27 -0500289 /*! \brief Either allow to expire, or refresh a name LSA.
290 \param lsaKey The name of the router that published the LSA.
291 \param seqNo The seq. no. of the LSA to check.
292 */
akmhoque53353462014-04-22 08:43:45 -0500293 void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500294 expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500295
Vince Lehman199e9cf2015-04-07 13:22:16 -0500296PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick G97e34942016-07-11 14:46:27 -0500297 /*! \brief Schedules an expire/refresh event in the LSA.
298 \param key The name of the router whose LSA is in question.
299 \param seqNo The sequence number of the LSA to check.
300 \param expTime The number of seconds to wait before triggering the event.
301 */
akmhoque53353462014-04-22 08:43:45 -0500302 ndn::EventId
akmhoquec7a79b22014-05-26 08:06:19 -0500303 scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
Nick Gordone98480b2017-05-24 11:23:03 -0500304 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500305
Vince Lehman199e9cf2015-04-07 13:22:16 -0500306private:
Nick G97e34942016-07-11 14:46:27 -0500307
akmhoque53353462014-04-22 08:43:45 -0500308 void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500309 expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500310
311 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -0500312 scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
Nick Gordone98480b2017-05-24 11:23:03 -0500313 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -0500314
315 void
Ashlesh Gawande90173ad2017-08-09 15:19:50 -0500316 expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
akmhoqueb6450b12014-04-24 00:01:03 -0500317 uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500318
Nick G97e34942016-07-11 14:46:27 -0500319private:
320
akmhoque31d1d4b2014-05-05 22:08:14 -0500321 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500322 processInterestForNameLsa(const ndn::Interest& interest,
323 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500324 uint64_t seqNo);
akmhoque53353462014-04-22 08:43:45 -0500325
akmhoque31d1d4b2014-05-05 22:08:14 -0500326 void
327 processInterestForAdjacencyLsa(const ndn::Interest& interest,
328 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500329 uint64_t seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500330
331 void
332 processInterestForCoordinateLsa(const ndn::Interest& interest,
333 const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500334 uint64_t seqNo);
akmhoque31d1d4b2014-05-05 22:08:14 -0500335 void
dmcoomes9f936662017-03-02 10:33:09 -0600336 onContentValidated(const std::shared_ptr<const ndn::Data>& data);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700337
338 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500339 processContentNameLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500340 uint64_t lsSeqNo, std::string& dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500341
342 void
343 processContentAdjacencyLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500344 uint64_t lsSeqNo, std::string& dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500345
346 void
347 processContentCoordinateLsa(const ndn::Name& lsaKey,
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500348 uint64_t lsSeqNo, std::string& dataContent);
akmhoque31d1d4b2014-05-05 22:08:14 -0500349
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500350PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick G97e34942016-07-11 14:46:27 -0500351 /*!
352 \brief Error callback when SegmentFetcher fails to return an LSA
353
354 In all error cases, a reattempt to fetch the LSA will be made.
355
356 Segment validation can fail either because the packet does not have a
357 valid signature (fatal) or because some of the certificates in the trust chain
358 could not be fetched (non-fatal).
359
360 Currently, the library does not provide clear indication (besides a plain-text message
361 in the error callback) of the reason for the failure nor the segment that failed
362 to be validated, thus we will continue to try to fetch the LSA until the deadline
363 is reached.
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500364 */
akmhoque31d1d4b2014-05-05 22:08:14 -0500365 void
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500366 onFetchLsaError(uint32_t errorCode,
367 const std::string& msg,
Ashlesh Gawande744e4812018-08-22 16:26:24 -0500368 const ndn::Name& interestName,
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500369 uint32_t retransmitNo,
370 const ndn::time::steady_clock::TimePoint& deadline,
371 ndn::Name lsaName,
372 uint64_t seqNo);
373
Nick G97e34942016-07-11 14:46:27 -0500374 /*!
375 \brief Success callback when SegmentFetcher returns a valid LSA
376
Nick Gordonb50e51b2016-07-22 16:05:57 -0500377 \param interestName The base Interest used to fetch the LSA in the format:
Nick G97e34942016-07-11 14:46:27 -0500378 /<network>/NLSR/LSA/<site>/%C1.Router/<router>/<lsa-type>/<seqNo>
Muktadir R Chowdhuryaa3b0852015-08-06 13:08:56 -0500379 */
380 void
Ashlesh Gawande744e4812018-08-22 16:26:24 -0500381 afterFetchLsa(const ndn::ConstBufferPtr& data, const ndn::Name& interestName);
akmhoque31d1d4b2014-05-05 22:08:14 -0500382
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500383private:
Nick Gordone98480b2017-05-24 11:23:03 -0500384 ndn::time::system_clock::TimePoint
akmhoquec7a79b22014-05-26 08:06:19 -0500385 getLsaExpirationTimePoint();
386
Nick G97e34942016-07-11 14:46:27 -0500387 /*! \brief Cancels an event in the event scheduler. */
akmhoque31d1d4b2014-05-05 22:08:14 -0500388 void
389 cancelScheduleLsaExpiringEvent(ndn::EventId eid);
390
Jiewen Tana0497d82015-02-02 21:59:18 -0800391public:
392 static const ndn::Name::Component NAME_COMPONENT;
393
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600394 ndn::util::signal::Signal<Lsdb, Statistics::PacketType> lsaIncrementSignal;
395
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500396private:
akmhoque31d1d4b2014-05-05 22:08:14 -0500397 Nlsr& m_nlsr;
Vince Lehman7c603292014-09-11 17:48:16 -0500398 ndn::Scheduler& m_scheduler;
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500399 SyncLogicHandler m_sync;
Muktadir Chowdhuryc3ea26f2018-01-05 21:40:59 +0000400 LsaSegmentStorage m_lsaStorage;
Vince Lehman7c603292014-09-11 17:48:16 -0500401
akmhoque53353462014-04-22 08:43:45 -0500402 std::list<NameLsa> m_nameLsdb;
403 std::list<AdjLsa> m_adjLsdb;
akmhoqueb6450b12014-04-24 00:01:03 -0500404 std::list<CoordinateLsa> m_corLsdb;
akmhoque53353462014-04-22 08:43:45 -0500405
Nick Gordone98480b2017-05-24 11:23:03 -0500406 ndn::time::seconds m_lsaRefreshTime;
akmhoque53353462014-04-22 08:43:45 -0500407 std::string m_thisRouterPrefix;
408
Ashlesh Gawande5bf83172014-09-19 12:38:17 -0500409 typedef std::map<ndn::Name, uint64_t> SequenceNumberMap;
410
411 // Maps the name of an LSA to its highest known sequence number from sync;
412 // Used to stop NLSR from trying to fetch outdated LSAs
413 SequenceNumberMap m_highestSeqNo;
414
Vince Lehman18841082014-08-19 17:15:24 -0500415 static const ndn::time::seconds GRACE_PERIOD;
Nick Gordone98480b2017-05-24 11:23:03 -0500416 static const ndn::time::steady_clock::TimePoint DEFAULT_LSA_RETRIEVAL_DEADLINE;
Vince Lehman50df6b72015-03-03 12:06:40 -0600417
418 ndn::time::seconds m_adjLsaBuildInterval;
Ashlesh Gawande3e105a02017-05-16 17:36:56 -0500419
420 SequencingManager m_sequencingManager;
Nick Gordon9eac4d92017-08-29 17:31:29 -0500421
422 ndn::util::signal::ScopedConnection m_onNewLsaConnection;
Ashlesh Gawande744e4812018-08-22 16:26:24 -0500423
424 std::set<std::shared_ptr<ndn::util::SegmentFetcher>> m_fetchers;
Ashlesh Gawande939b6f82018-12-09 16:51:09 -0600425 psync::SegmentPublisher m_segmentPublisher;
akmhoque53353462014-04-22 08:43:45 -0500426};
427
Nick Gordonfad8e252016-08-11 14:21:38 -0500428} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500429
dmcoomes9f936662017-03-02 10:33:09 -0600430#endif // NLSR_LSDB_HPP