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