akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | af7a211 | 2019-03-19 14:55:20 -0400 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 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/>. |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 20 | */ |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 21 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 22 | #ifndef NLSR_LSDB_HPP |
| 23 | #define NLSR_LSDB_HPP |
| 24 | |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame^] | 25 | #include "communication/sync-logic-handler.hpp" |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 26 | #include "conf-parameter.hpp" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 27 | #include "lsa/lsa.hpp" |
| 28 | #include "lsa/name-lsa.hpp" |
| 29 | #include "lsa/coordinate-lsa.hpp" |
| 30 | #include "lsa/adj-lsa.hpp" |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 31 | #include "sequencing-manager.hpp" |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 32 | #include "statistics.hpp" |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame^] | 33 | #include "test-access-control.hpp" |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 34 | |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame^] | 35 | #include <ndn-cxx/ims/in-memory-storage-fifo.hpp> |
| 36 | #include <ndn-cxx/ims/in-memory-storage-persistent.hpp> |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 37 | #include <ndn-cxx/security/key-chain.hpp> |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame^] | 38 | #include <ndn-cxx/util/segmenter.hpp> |
| 39 | #include <ndn-cxx/util/segment-fetcher.hpp> |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 40 | #include <ndn-cxx/util/signal.hpp> |
| 41 | #include <ndn-cxx/util/time.hpp> |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 42 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 43 | #include <boost/multi_index_container.hpp> |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 44 | #include <boost/multi_index/composite_key.hpp> |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame^] | 45 | #include <boost/multi_index/hashed_index.hpp> |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 46 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 47 | namespace nlsr { |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 48 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 49 | namespace bmi = boost::multi_index; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 50 | |
| 51 | static constexpr ndn::time::seconds GRACE_PERIOD = 10_s; |
| 52 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 53 | enum class LsdbUpdate { |
| 54 | INSTALLED, |
| 55 | UPDATED, |
| 56 | REMOVED |
| 57 | }; |
| 58 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 59 | class Lsdb |
| 60 | { |
| 61 | public: |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 62 | Lsdb(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 63 | |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame^] | 64 | ~Lsdb(); |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 65 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 66 | /*! \brief Returns whether the LSDB contains some LSA. |
| 67 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 68 | bool |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 69 | doesLsaExist(const ndn::Name& router, Lsa::Type lsaType) |
| 70 | { |
| 71 | return m_lsdb.get<byName>().find(std::make_tuple(router, lsaType)) != m_lsdb.end(); |
| 72 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 73 | |
| 74 | /*! \brief Builds a name LSA for this router and then installs it |
| 75 | into the LSDB. |
| 76 | */ |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 77 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 78 | buildAndInstallOwnNameLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 79 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 80 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 81 | /*! \brief Builds a cor. LSA for this router and installs it into the LSDB. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 82 | void |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 83 | buildAndInstallOwnCoordinateLsa(); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 84 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 85 | public: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 86 | /*! \brief Schedules a build of this router's LSA. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 87 | void |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 88 | scheduleAdjLsaBuild(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 89 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 90 | void |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 91 | writeLog() const; |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 92 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 93 | /* \brief Process interest which can be either: |
| 94 | * 1) Discovery interest from segment fetcher: |
| 95 | * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo> |
| 96 | * 2) Interest containing segment number: |
| 97 | * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>/<version>/<segmentNo> |
| 98 | */ |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 99 | void |
| 100 | processInterest(const ndn::Name& name, const ndn::Interest& interest); |
| 101 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 102 | bool |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 103 | getIsBuildAdjLsaScheduled() const |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 104 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 105 | return m_isBuildAdjLsaScheduled; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 106 | } |
| 107 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 108 | SyncLogicHandler& |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 109 | getSync() |
| 110 | { |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 111 | return m_sync; |
| 112 | } |
| 113 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 114 | template<typename T> |
| 115 | std::shared_ptr<T> |
| 116 | findLsa(const ndn::Name& router) const |
| 117 | { |
| 118 | return std::static_pointer_cast<T>(findLsa(router, T::type())); |
| 119 | } |
| 120 | |
| 121 | struct name_hash { |
| 122 | int |
| 123 | operator()(const ndn::Name& name) const { |
| 124 | return std::hash<ndn::Name>{}(name); |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | struct enum_class_hash { |
| 129 | template<typename T> |
| 130 | int |
| 131 | operator()(T t) const { |
| 132 | return static_cast<int>(t); |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | struct byName{}; |
| 137 | struct byType{}; |
| 138 | |
| 139 | using LsaContainer = boost::multi_index_container< |
| 140 | std::shared_ptr<Lsa>, |
| 141 | bmi::indexed_by< |
| 142 | bmi::hashed_unique< |
| 143 | bmi::tag<byName>, |
| 144 | bmi::composite_key< |
| 145 | Lsa, |
| 146 | bmi::const_mem_fun<Lsa, ndn::Name, &Lsa::getOriginRouterCopy>, |
| 147 | bmi::const_mem_fun<Lsa, Lsa::Type, &Lsa::getType> |
| 148 | >, |
| 149 | bmi::composite_key_hash<name_hash, enum_class_hash> |
| 150 | >, |
| 151 | bmi::hashed_non_unique< |
| 152 | bmi::tag<byType>, |
| 153 | bmi::const_mem_fun<Lsa, Lsa::Type, &Lsa::getType>, |
| 154 | enum_class_hash |
| 155 | > |
| 156 | > |
| 157 | >; |
| 158 | |
| 159 | template<typename T> |
| 160 | std::pair<LsaContainer::index<Lsdb::byType>::type::iterator, |
| 161 | LsaContainer::index<Lsdb::byType>::type::iterator> |
| 162 | getLsdbIterator() const |
| 163 | { |
| 164 | return m_lsdb.get<byType>().equal_range(T::type()); |
| 165 | } |
| 166 | |
| 167 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 168 | std::shared_ptr<Lsa> |
| 169 | findLsa(const ndn::Name& router, Lsa::Type lsaType) const |
| 170 | { |
| 171 | auto it = m_lsdb.get<byName>().find(std::make_tuple(router, lsaType)); |
| 172 | return it != m_lsdb.end() ? *it : nullptr; |
| 173 | } |
| 174 | |
| 175 | void |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 176 | incrementDataSentStats(Lsa::Type lsaType) |
| 177 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 178 | if (lsaType == Lsa::Type::NAME) { |
| 179 | lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_DATA); |
| 180 | } |
| 181 | else if (lsaType == Lsa::Type::ADJACENCY) { |
| 182 | lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_DATA); |
| 183 | } |
| 184 | else if (lsaType == Lsa::Type::COORDINATE) { |
| 185 | lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_DATA); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | void |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 190 | incrementInterestRcvdStats(Lsa::Type lsaType) |
| 191 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 192 | if (lsaType == Lsa::Type::NAME) { |
| 193 | lsaIncrementSignal(Statistics::PacketType::RCV_NAME_LSA_INTEREST); |
| 194 | } |
| 195 | else if (lsaType == Lsa::Type::ADJACENCY) { |
| 196 | lsaIncrementSignal(Statistics::PacketType::RCV_ADJ_LSA_INTEREST); |
| 197 | } |
| 198 | else if (lsaType == Lsa::Type::COORDINATE) { |
| 199 | lsaIncrementSignal(Statistics::PacketType::RCV_COORD_LSA_INTEREST); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | void |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 204 | incrementInterestSentStats(Lsa::Type lsaType) |
| 205 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 206 | if (lsaType == Lsa::Type::NAME) { |
| 207 | lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_INTEREST); |
| 208 | } |
| 209 | else if (lsaType == Lsa::Type::ADJACENCY) { |
| 210 | lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_INTEREST); |
| 211 | } |
| 212 | else if (lsaType == Lsa::Type::COORDINATE) { |
| 213 | lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_INTEREST); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /*! Returns whether a seq. no. from a certain router signals a new LSA. |
| 218 | \param originRouter The name of the originating router. |
| 219 | \param lsaType The type of the LSA. |
| 220 | \param seqNo The sequence number to check. |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 221 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 222 | bool |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 223 | isLsaNew(const ndn::Name& originRouter, const Lsa::Type& lsaType, uint64_t lsSeqNo) const |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 224 | { |
| 225 | // Is the name in the LSDB and the supplied seq no is the highest so far |
| 226 | auto lsaPtr = findLsa(originRouter, lsaType); |
| 227 | return lsaPtr ? lsaPtr->getSeqNo() < lsSeqNo : true; |
| 228 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 229 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 230 | void |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 231 | installLsa(std::shared_ptr<Lsa> lsa); |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 232 | |
| 233 | /*! \brief Remove a name LSA from the LSDB. |
| 234 | \param router The name of the router that published the LSA to remove. |
| 235 | \param lsaType The type of the LSA. |
| 236 | |
| 237 | This function will remove a name LSA from the LSDB by finding an |
| 238 | LSA whose name matches key. This removal also causes the NPT to |
| 239 | remove those name prefixes if no more LSAs advertise them. |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 240 | */ |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 241 | void |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 242 | removeLsa(const ndn::Name& router, Lsa::Type lsaType); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 243 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 244 | void |
| 245 | removeLsa(const LsaContainer::index<Lsdb::byName>::type::iterator& lsaIt); |
| 246 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 247 | /*! \brief Attempts to construct an adj. LSA. |
| 248 | |
| 249 | This function will attempt to construct an adjacency LSA. An LSA |
| 250 | can only be built when the status of all of the router's neighbors |
| 251 | is known. That is, when we are not currently trying to contact any |
| 252 | neighbor. |
| 253 | */ |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 254 | void |
| 255 | buildAdjLsa(); |
| 256 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 257 | /*! \brief Wrapper event to build and install an adj. LSA for this router. */ |
| 258 | void |
| 259 | buildAndInstallOwnAdjLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 260 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 261 | /*! \brief Schedules a refresh/expire event in the scheduler. |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 262 | \param lsa The LSA. |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 263 | \param expTime How many seconds to wait before triggering the event. |
| 264 | */ |
Davide Pesavento | af7a211 | 2019-03-19 14:55:20 -0400 | [diff] [blame] | 265 | ndn::scheduler::EventId |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 266 | scheduleLsaExpiration(std::shared_ptr<Lsa> lsa, ndn::time::seconds expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 267 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 268 | /*! \brief Either allow to expire, or refresh a name LSA. |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 269 | \param lsa The LSA. |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 270 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 271 | void |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 272 | expireOrRefreshLsa(std::shared_ptr<Lsa> lsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 273 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 274 | bool |
| 275 | processInterestForLsa(const ndn::Interest& interest, const ndn::Name& originRouter, |
| 276 | Lsa::Type lsaType, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 277 | |
| 278 | void |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 279 | expressInterest(const ndn::Name& interestName, uint32_t timeoutCount, uint64_t incomingFaceId, |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 280 | ndn::time::steady_clock::time_point deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 281 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 282 | /*! |
| 283 | \brief Error callback when SegmentFetcher fails to return an LSA |
| 284 | |
| 285 | In all error cases, a reattempt to fetch the LSA will be made. |
| 286 | |
| 287 | Segment validation can fail either because the packet does not have a |
| 288 | valid signature (fatal) or because some of the certificates in the trust chain |
| 289 | could not be fetched (non-fatal). |
| 290 | |
| 291 | Currently, the library does not provide clear indication (besides a plain-text message |
| 292 | in the error callback) of the reason for the failure nor the segment that failed |
| 293 | to be validated, thus we will continue to try to fetch the LSA until the deadline |
| 294 | is reached. |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 295 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 296 | void |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 297 | onFetchLsaError(uint32_t errorCode, const std::string& msg, |
| 298 | const ndn::Name& interestName, uint32_t retransmitNo, |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 299 | const ndn::time::steady_clock::time_point& deadline, |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 300 | ndn::Name lsaName, uint64_t seqNo); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 301 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 302 | /*! |
| 303 | \brief Success callback when SegmentFetcher returns a valid LSA |
| 304 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 305 | \param interestName The base Interest used to fetch the LSA in the format: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 306 | /<network>/NLSR/LSA/<site>/%C1.Router/<router>/<lsa-type>/<seqNo> |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 307 | */ |
| 308 | void |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 309 | afterFetchLsa(const ndn::ConstBufferPtr& bufferPtr, const ndn::Name& interestName); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 310 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 311 | void |
| 312 | emitSegmentValidatedSignal(const ndn::Data& data) |
| 313 | { |
| 314 | afterSegmentValidatedSignal(data); |
| 315 | } |
| 316 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 317 | ndn::time::system_clock::time_point |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 318 | getLsaExpirationTimePoint() const |
| 319 | { |
| 320 | return ndn::time::system_clock::now() + ndn::time::seconds(m_confParam.getRouterDeadInterval()); |
| 321 | } |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 322 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 323 | public: |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 324 | ndn::util::Signal<Lsdb, Statistics::PacketType> lsaIncrementSignal; |
| 325 | ndn::util::Signal<Lsdb, ndn::Data> afterSegmentValidatedSignal; |
| 326 | using AfterLsdbModified = ndn::util::Signal<Lsdb, std::shared_ptr<Lsa>, LsdbUpdate, |
| 327 | std::list<ndn::Name>, std::list<ndn::Name>>; |
| 328 | AfterLsdbModified onLsdbModified; |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 329 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 330 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 331 | ndn::Face& m_face; |
| 332 | ndn::Scheduler m_scheduler; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 333 | ConfParameter& m_confParam; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 334 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 335 | SyncLogicHandler m_sync; |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 336 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 337 | LsaContainer m_lsdb; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 338 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 339 | ndn::time::seconds m_lsaRefreshTime; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 340 | ndn::time::seconds m_adjLsaBuildInterval; |
| 341 | const ndn::Name& m_thisRouterPrefix; |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 342 | |
| 343 | // Maps the name of an LSA to its highest known sequence number from sync; |
| 344 | // Used to stop NLSR from trying to fetch outdated LSAs |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 345 | std::map<ndn::Name, uint64_t> m_highestSeqNo; |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 346 | |
| 347 | SequencingManager m_sequencingManager; |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 348 | |
| 349 | ndn::util::signal::ScopedConnection m_onNewLsaConnection; |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 350 | |
| 351 | std::set<std::shared_ptr<ndn::util::SegmentFetcher>> m_fetchers; |
Davide Pesavento | 65ee992 | 2022-11-16 00:21:43 -0500 | [diff] [blame^] | 352 | ndn::util::Segmenter m_segmenter; |
| 353 | ndn::InMemoryStorageFifo m_segmentFifo; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 354 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 355 | bool m_isBuildAdjLsaScheduled; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 356 | int64_t m_adjBuildCount; |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 357 | ndn::scheduler::ScopedEventId m_scheduledAdjLsaBuild; |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 358 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 359 | ndn::InMemoryStoragePersistent m_lsaStorage; |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 360 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 361 | static inline const ndn::time::steady_clock::time_point DEFAULT_LSA_RETRIEVAL_DEADLINE = |
| 362 | ndn::time::steady_clock::time_point::min(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 363 | }; |
| 364 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 365 | } // namespace nlsr |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 366 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 367 | #endif // NLSR_LSDB_HPP |