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 | /* |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, 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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [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 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 25 | #include "conf-parameter.hpp" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 26 | #include "lsa/lsa.hpp" |
| 27 | #include "lsa/name-lsa.hpp" |
| 28 | #include "lsa/coordinate-lsa.hpp" |
| 29 | #include "lsa/adj-lsa.hpp" |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 30 | #include "sequencing-manager.hpp" |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 31 | #include "test-access-control.hpp" |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 32 | #include "communication/sync-logic-handler.hpp" |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 33 | #include "statistics.hpp" |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 34 | #include "route/name-prefix-table.hpp" |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 35 | |
| 36 | #include <ndn-cxx/security/key-chain.hpp> |
| 37 | #include <ndn-cxx/util/signal.hpp> |
| 38 | #include <ndn-cxx/util/time.hpp> |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 39 | #include <ndn-cxx/util/segment-fetcher.hpp> |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 40 | #include <ndn-cxx/ims/in-memory-storage-persistent.hpp> |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 41 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 42 | #include <PSync/segment-publisher.hpp> |
| 43 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 44 | #include <utility> |
| 45 | #include <boost/cstdint.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [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 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 49 | class Lsdb |
| 50 | { |
| 51 | public: |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 52 | Lsdb(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam, |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 53 | NamePrefixTable& namePrefixTable, RoutingTable& routingTable); |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 54 | |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 55 | ~Lsdb(); |
| 56 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 57 | bool |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 58 | isLsaNew(const ndn::Name& routerName, const Lsa::Type& lsaType, const uint64_t& sequenceNumber); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 59 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 60 | bool |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 61 | doesLsaExist(const ndn::Name& key, const Lsa::Type& lsType); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 62 | |
| 63 | /*! \brief Builds a name LSA for this router and then installs it |
| 64 | into the LSDB. |
| 65 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 66 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 67 | buildAndInstallOwnNameLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 68 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 69 | /*! \brief Returns the name LSA with the given key. |
| 70 | \param key The name of the router that the desired LSA comes from. |
| 71 | */ |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 72 | NameLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 73 | findNameLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 74 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 75 | /*! \brief Installs a name LSA into the LSDB |
| 76 | \param nlsa The name LSA to install into the LSDB. |
| 77 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 78 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 79 | installNameLsa(NameLsa& nlsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 80 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 81 | /*! \brief Remove a name LSA from the LSDB. |
| 82 | \param key The name of the router that published the LSA to remove. |
| 83 | |
| 84 | This function will remove a name LSA from the LSDB by finding an |
| 85 | LSA whose name matches key. This removal also causes the NPT to |
| 86 | remove those name prefixes if no more LSAs advertise them. |
| 87 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 88 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 89 | removeNameLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 90 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 91 | /*! Returns whether a seq. no. from a certain router signals a new LSA. |
| 92 | \param key The name of the originating router. |
| 93 | \param seqNo The sequence number to check. |
| 94 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 95 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 96 | isNameLsaNew(const ndn::Name& key, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 97 | |
| 98 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 99 | writeNameLsdbLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 100 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 101 | const std::list<NameLsa>& |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 102 | getNameLsdb() const; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 103 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 104 | /*! \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] | 105 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 106 | buildAndInstallOwnCoordinateLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 107 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 108 | /*! \brief Finds a cor. LSA in the LSDB. |
| 109 | \param key The name of the originating router that published the LSA. |
| 110 | */ |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 111 | CoordinateLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 112 | findCoordinateLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 113 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 114 | /*! \brief Installs a cor. LSA into the LSDB. |
| 115 | \param clsa The cor. LSA to install. |
| 116 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 117 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 118 | installCoordinateLsa(CoordinateLsa& clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 119 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 120 | /*! \brief Removes a cor. LSA from the LSDB. |
| 121 | \param key The name of the router that published the LSA to remove. |
| 122 | |
| 123 | Removes the coordinate LSA whose origin router name matches that |
| 124 | given by key. Additionally, ask the NPT to remove the prefix, |
| 125 | which will occur if no other LSAs point there. |
| 126 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 127 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 128 | removeCoordinateLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 129 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 130 | /*! \brief Returns whether a cor. LSA from a router is new or not. |
| 131 | \param key The name prefix of the originating router. |
| 132 | \param seqNo The sequence number of the candidate LSA. |
| 133 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 134 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 135 | isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 136 | |
| 137 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 138 | writeCorLsdbLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 139 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 140 | const std::list<CoordinateLsa>& |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 141 | getCoordinateLsdb() const; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 142 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 143 | //function related to Adj LSDB |
| 144 | |
| 145 | /*! \brief Schedules a build of this router's LSA. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 146 | void |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 147 | scheduleAdjLsaBuild(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 148 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 149 | /*! \brief Wrapper event to build and install an adj. LSA for this router. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 150 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 151 | buildAndInstallOwnAdjLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 152 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 153 | /*! \brief Removes an adj. LSA from the LSDB. |
| 154 | \param key The name of the publishing router whose LSA to remove. |
| 155 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 156 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 157 | removeAdjLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 158 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 159 | /*! \brief Returns whether an LSA is new. |
| 160 | \param key The name of the publishing router. |
| 161 | \param seqNo The seq. no. of the candidate LSA. |
| 162 | |
| 163 | This function determines whether the LSA with the name key and |
| 164 | seq. no. seqNo would be new to this LSDB. |
| 165 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 166 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 167 | isAdjLsaNew(const ndn::Name& key, uint64_t seqNo); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 168 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 169 | /*! \brief Installs an adj. LSA into the LSDB. |
| 170 | \param alsa The adj. LSA to add to the LSDB. |
| 171 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 172 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 173 | installAdjLsa(AdjLsa& alsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 174 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 175 | /*! \brief Finds an adj. LSA in the LSDB. |
| 176 | \param key The name of the publishing router whose LSA to find. |
| 177 | */ |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 178 | AdjLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 179 | findAdjLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 180 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 181 | const std::list<AdjLsa>& |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 182 | getAdjLsdb() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 183 | |
| 184 | void |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 185 | setAdjLsaBuildInterval(uint32_t interval) |
| 186 | { |
| 187 | m_adjLsaBuildInterval = ndn::time::seconds(interval); |
| 188 | } |
| 189 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 190 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 191 | writeAdjLsdbLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 192 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 193 | void |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 194 | expressInterest(const ndn::Name& interestName, uint32_t timeoutCount, |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 195 | ndn::time::steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 196 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 197 | /* \brief Process interest which can be either: |
| 198 | * 1) Discovery interest from segment fetcher: |
| 199 | * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo> |
| 200 | * 2) Interest containing segment number: |
| 201 | * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>/<version>/<segmentNo> |
| 202 | */ |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 203 | void |
| 204 | processInterest(const ndn::Name& name, const ndn::Interest& interest); |
| 205 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 206 | bool |
| 207 | getIsBuildAdjLsaSheduled() |
| 208 | { |
| 209 | return m_isBuildAdjLsaSheduled; |
| 210 | } |
| 211 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 212 | SyncLogicHandler& |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 213 | getSync() { |
| 214 | return m_sync; |
| 215 | } |
| 216 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 217 | private: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 218 | /* \brief Add a name LSA to the LSDB if it isn't already there. |
| 219 | \param nlsa The candidade name LSA. |
| 220 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 221 | bool |
| 222 | addNameLsa(NameLsa& nlsa); |
| 223 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 224 | /*! \brief Returns whether the LSDB contains some LSA. |
| 225 | \param key The name of the publishing router whose LSA to check for. |
| 226 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 227 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 228 | doesNameLsaExist(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 229 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 230 | /*! \brief Adds a cor. LSA to the LSDB if it isn't already there. |
| 231 | \param clsa The candidate cor. LSA. |
| 232 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 233 | bool |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 234 | addCoordinateLsa(CoordinateLsa& clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 235 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 236 | /*! \brief Returns whether a cor. LSA is in the LSDB. |
| 237 | \param key The name of the router that published the queried LSA. |
| 238 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 239 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 240 | doesCoordinateLsaExist(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 241 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 242 | /*! \brief Attempts to construct an adj. LSA. |
| 243 | |
| 244 | This function will attempt to construct an adjacency LSA. An LSA |
| 245 | can only be built when the status of all of the router's neighbors |
| 246 | is known. That is, when we are not currently trying to contact any |
| 247 | neighbor. |
| 248 | */ |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 249 | void |
| 250 | buildAdjLsa(); |
| 251 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 252 | /*! \brief Adds an adj. LSA to the LSDB if it isn't already there. |
| 253 | \param alsa The candidate adj. LSA to add to the LSDB. |
| 254 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 255 | bool |
| 256 | addAdjLsa(AdjLsa& alsa); |
| 257 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 258 | /*! \brief Returns whether the LSDB contains an LSA. |
| 259 | \param key The name of a router whose LSA to check for in the LSDB. |
| 260 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 261 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 262 | doesAdjLsaExist(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 263 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 264 | /*! \brief Schedules a refresh/expire event in the scheduler. |
| 265 | \param key The name of the router that published the LSA. |
| 266 | \param seqNo The seq. no. associated with the LSA. |
| 267 | \param expTime How many seconds to wait before triggering the event. |
| 268 | */ |
Davide Pesavento | af7a211 | 2019-03-19 14:55:20 -0400 | [diff] [blame] | 269 | ndn::scheduler::EventId |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 270 | scheduleNameLsaExpiration(const ndn::Name& key, int seqNo, |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 271 | const ndn::time::seconds& expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 272 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 273 | /*! \brief Either allow to expire, or refresh a name LSA. |
| 274 | \param lsaKey The name of the router that published the LSA. |
| 275 | \param seqNo The seq. no. of the LSA to check. |
| 276 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 277 | void |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 278 | expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 279 | |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 280 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 281 | /*! \brief Schedules an expire/refresh event in the LSA. |
| 282 | \param key The name of the router whose LSA is in question. |
| 283 | \param seqNo The sequence number of the LSA to check. |
| 284 | \param expTime The number of seconds to wait before triggering the event. |
| 285 | */ |
Davide Pesavento | af7a211 | 2019-03-19 14:55:20 -0400 | [diff] [blame] | 286 | ndn::scheduler::EventId |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 287 | scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo, |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 288 | const ndn::time::seconds& expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 289 | |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 290 | private: |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 291 | void |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 292 | expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 293 | |
Davide Pesavento | af7a211 | 2019-03-19 14:55:20 -0400 | [diff] [blame] | 294 | ndn::scheduler::EventId |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 295 | scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo, |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 296 | const ndn::time::seconds& expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 297 | |
| 298 | void |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 299 | expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey, |
Davide Pesavento | af7a211 | 2019-03-19 14:55:20 -0400 | [diff] [blame] | 300 | uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 301 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 302 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 303 | processInterestForNameLsa(const ndn::Interest& interest, |
| 304 | const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 305 | uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 306 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 307 | void |
| 308 | processInterestForAdjacencyLsa(const ndn::Interest& interest, |
| 309 | const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 310 | uint64_t seqNo); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 311 | |
| 312 | void |
| 313 | processInterestForCoordinateLsa(const ndn::Interest& interest, |
| 314 | const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 315 | uint64_t seqNo); |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 316 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 317 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 318 | processContentNameLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 319 | uint64_t lsSeqNo, const ndn::Block& block); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 320 | |
| 321 | void |
| 322 | processContentAdjacencyLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 323 | uint64_t lsSeqNo, const ndn::Block& block); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 324 | |
| 325 | void |
| 326 | processContentCoordinateLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 327 | uint64_t lsSeqNo, const ndn::Block& block); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 328 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 329 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 330 | /*! |
| 331 | \brief Error callback when SegmentFetcher fails to return an LSA |
| 332 | |
| 333 | In all error cases, a reattempt to fetch the LSA will be made. |
| 334 | |
| 335 | Segment validation can fail either because the packet does not have a |
| 336 | valid signature (fatal) or because some of the certificates in the trust chain |
| 337 | could not be fetched (non-fatal). |
| 338 | |
| 339 | Currently, the library does not provide clear indication (besides a plain-text message |
| 340 | in the error callback) of the reason for the failure nor the segment that failed |
| 341 | to be validated, thus we will continue to try to fetch the LSA until the deadline |
| 342 | is reached. |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 343 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 344 | void |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 345 | onFetchLsaError(uint32_t errorCode, |
| 346 | const std::string& msg, |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 347 | const ndn::Name& interestName, |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 348 | uint32_t retransmitNo, |
| 349 | const ndn::time::steady_clock::TimePoint& deadline, |
| 350 | ndn::Name lsaName, |
| 351 | uint64_t seqNo); |
| 352 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 353 | /*! |
| 354 | \brief Success callback when SegmentFetcher returns a valid LSA |
| 355 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 356 | \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] | 357 | /<network>/NLSR/LSA/<site>/%C1.Router/<router>/<lsa-type>/<seqNo> |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 358 | */ |
| 359 | void |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 360 | afterFetchLsa(const ndn::ConstBufferPtr& bufferPtr, const ndn::Name& interestName); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 361 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 362 | void |
| 363 | emitSegmentValidatedSignal(const ndn::Data& data) |
| 364 | { |
| 365 | afterSegmentValidatedSignal(data); |
| 366 | } |
| 367 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 368 | private: |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 369 | ndn::time::system_clock::TimePoint |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 370 | getLsaExpirationTimePoint(); |
| 371 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 372 | public: |
| 373 | static const ndn::Name::Component NAME_COMPONENT; |
| 374 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 375 | ndn::util::signal::Signal<Lsdb, Statistics::PacketType> lsaIncrementSignal; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 376 | ndn::util::signal::Signal<Lsdb, const ndn::Data&> afterSegmentValidatedSignal; |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 377 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 378 | private: |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 379 | ndn::Face& m_face; |
| 380 | ndn::Scheduler m_scheduler; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 381 | |
| 382 | ConfParameter& m_confParam; |
| 383 | NamePrefixTable& m_namePrefixTable; |
| 384 | RoutingTable& m_routingTable; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 385 | |
| 386 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 387 | SyncLogicHandler m_sync; |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 388 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 389 | private: |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 390 | std::list<NameLsa> m_nameLsdb; |
| 391 | std::list<AdjLsa> m_adjLsdb; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 392 | std::list<CoordinateLsa> m_corLsdb; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 393 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 394 | ndn::time::seconds m_lsaRefreshTime; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 395 | std::string m_thisRouterPrefix; |
| 396 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 397 | typedef std::map<ndn::Name, uint64_t> SequenceNumberMap; |
| 398 | |
| 399 | // Maps the name of an LSA to its highest known sequence number from sync; |
| 400 | // Used to stop NLSR from trying to fetch outdated LSAs |
| 401 | SequenceNumberMap m_highestSeqNo; |
| 402 | |
Vince Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 403 | static const ndn::time::seconds GRACE_PERIOD; |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 404 | static const ndn::time::steady_clock::TimePoint DEFAULT_LSA_RETRIEVAL_DEADLINE; |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 405 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 406 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 407 | ndn::time::seconds m_adjLsaBuildInterval; |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 408 | |
| 409 | SequencingManager m_sequencingManager; |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 410 | |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 411 | private: |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 412 | ndn::util::signal::ScopedConnection m_onNewLsaConnection; |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 413 | |
| 414 | std::set<std::shared_ptr<ndn::util::SegmentFetcher>> m_fetchers; |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame] | 415 | psync::SegmentPublisher m_segmentPublisher; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 416 | |
| 417 | bool m_isBuildAdjLsaSheduled; |
| 418 | int64_t m_adjBuildCount; |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 419 | ndn::scheduler::ScopedEventId m_scheduledAdjLsaBuild; |
Ashlesh Gawande | 1505240 | 2018-12-12 20:20:00 -0600 | [diff] [blame] | 420 | |
| 421 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 422 | ndn::InMemoryStoragePersistent m_lsaStorage; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 423 | }; |
| 424 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 425 | } // namespace nlsr |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 426 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 427 | #endif // NLSR_LSDB_HPP |