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> |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 36 | #include <ndn-cxx/util/segment-fetcher.hpp> |
| 37 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame^] | 38 | #include <PSync/segment-publisher.hpp> |
| 39 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 40 | #include <utility> |
| 41 | #include <boost/cstdint.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 42 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 43 | namespace nlsr { |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 44 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 45 | class Nlsr; |
| 46 | |
| 47 | class Lsdb |
| 48 | { |
| 49 | public: |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 50 | Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler); |
| 51 | |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 52 | ~Lsdb(); |
| 53 | |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 54 | SyncLogicHandler& |
| 55 | getSyncLogicHandler() |
| 56 | { |
| 57 | return m_sync; |
| 58 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 59 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 60 | bool |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 61 | isLsaNew(const ndn::Name& routerName, const Lsa::Type& lsaType, const uint64_t& sequenceNumber); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 62 | |
Nick Gordon | 8f23b5d | 2017-08-31 17:53:07 -0500 | [diff] [blame] | 63 | bool |
Nick Gordon | 727d483 | 2017-10-13 18:04:25 -0500 | [diff] [blame] | 64 | doesLsaExist(const ndn::Name& key, const Lsa::Type& lsType); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 65 | |
| 66 | /*! \brief Builds a name LSA for this router and then installs it |
| 67 | into the LSDB. |
| 68 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 69 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 70 | buildAndInstallOwnNameLsa(); |
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 Returns the name LSA with the given key. |
| 73 | \param key The name of the router that the desired LSA comes from. |
| 74 | */ |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 75 | NameLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 76 | findNameLsa(const ndn::Name& key); |
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 Installs a name LSA into the LSDB |
| 79 | \param nlsa The name LSA to install into the LSDB. |
| 80 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 81 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 82 | installNameLsa(NameLsa& nlsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 83 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 84 | /*! \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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 91 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 92 | removeNameLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 93 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 94 | /*! 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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 98 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 99 | isNameLsaNew(const ndn::Name& key, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 100 | |
| 101 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 102 | writeNameLsdbLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 103 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 104 | const std::list<NameLsa>& |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 105 | getNameLsdb() const; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 106 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 107 | /*! \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] | 108 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 109 | buildAndInstallOwnCoordinateLsa(); |
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 Finds a cor. LSA in the LSDB. |
| 112 | \param key The name of the originating router that published the LSA. |
| 113 | */ |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 114 | CoordinateLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 115 | findCoordinateLsa(const ndn::Name& key); |
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 Installs a cor. LSA into the LSDB. |
| 118 | \param clsa The cor. LSA to install. |
| 119 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 120 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 121 | installCoordinateLsa(CoordinateLsa& clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 122 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 123 | /*! \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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 130 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 131 | removeCoordinateLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 132 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 133 | /*! \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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 137 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 138 | isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 139 | |
| 140 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 141 | writeCorLsdbLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 142 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 143 | const std::list<CoordinateLsa>& |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 144 | getCoordinateLsdb() const; |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 145 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 146 | //function related to Adj LSDB |
| 147 | |
| 148 | /*! \brief Schedules a build of this router's LSA. */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 149 | void |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 150 | scheduleAdjLsaBuild(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 151 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 152 | /*! \brief Wrapper event to build and install an adj. LSA for this router. */ |
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 | buildAndInstallOwnAdjLsa(); |
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 Removes an adj. LSA from the LSDB. |
| 157 | \param key The name of the publishing router whose LSA to remove. |
| 158 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 159 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 160 | removeAdjLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 161 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 162 | /*! \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 | */ |
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 | isAdjLsaNew(const ndn::Name& key, uint64_t seqNo); |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 171 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 172 | /*! \brief Installs an adj. LSA into the LSDB. |
| 173 | \param alsa The adj. LSA to add to the LSDB. |
| 174 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 175 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 176 | installAdjLsa(AdjLsa& alsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 177 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 178 | /*! \brief Finds an adj. LSA in the LSDB. |
| 179 | \param key The name of the publishing router whose LSA to find. |
| 180 | */ |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 181 | AdjLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 182 | findAdjLsa(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 183 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 184 | const std::list<AdjLsa>& |
Nick Gordon | 114537f | 2017-08-09 14:51:37 -0500 | [diff] [blame] | 185 | getAdjLsdb() const; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 186 | |
| 187 | void |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 188 | 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 Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 199 | SequencingManager& |
| 200 | getSequencingManager() |
| 201 | { |
| 202 | return m_sequencingManager; |
| 203 | } |
| 204 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 205 | LsaSegmentStorage& |
Ashlesh Gawande | 304bebf | 2018-02-07 17:10:35 -0600 | [diff] [blame] | 206 | getLsaStorage() |
| 207 | { |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 208 | return m_lsaStorage; |
| 209 | } |
| 210 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 211 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 212 | writeAdjLsdbLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 213 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 214 | void |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 215 | setLsaRefreshTime(const ndn::time::seconds& lsaRefreshTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 216 | |
| 217 | void |
| 218 | setThisRouterPrefix(std::string trp); |
| 219 | |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 220 | void |
| 221 | expressInterest(const ndn::Name& interestName, uint32_t timeoutCount, |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 222 | ndn::time::steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE); |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 223 | |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame^] | 224 | /* \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 Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 230 | void |
| 231 | processInterest(const ndn::Name& name, const ndn::Interest& interest); |
| 232 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 233 | private: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 234 | /* \brief Add a name LSA to the LSDB if it isn't already there. |
| 235 | \param nlsa The candidade name LSA. |
| 236 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 237 | bool |
| 238 | addNameLsa(NameLsa& nlsa); |
| 239 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 240 | /*! \brief Returns whether the LSDB contains some LSA. |
| 241 | \param key The name of the publishing router whose LSA to check for. |
| 242 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 243 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 244 | doesNameLsaExist(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 245 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 246 | /*! \brief Adds a cor. LSA to the LSDB if it isn't already there. |
| 247 | \param clsa The candidate cor. LSA. |
| 248 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 249 | bool |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 250 | addCoordinateLsa(CoordinateLsa& clsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 251 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 252 | /*! \brief Returns whether a cor. LSA is in the LSDB. |
| 253 | \param key The name of the router that published the queried LSA. |
| 254 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 255 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 256 | doesCoordinateLsaExist(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 257 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 258 | /*! \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 Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 265 | void |
| 266 | buildAdjLsa(); |
| 267 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 268 | /*! \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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 271 | bool |
| 272 | addAdjLsa(AdjLsa& alsa); |
| 273 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 274 | /*! \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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 277 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 278 | doesAdjLsaExist(const ndn::Name& key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 279 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 280 | /*! \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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 285 | ndn::EventId |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 286 | scheduleNameLsaExpiration(const ndn::Name& key, int seqNo, |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 287 | const ndn::time::seconds& expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 288 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 289 | /*! \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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 293 | void |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 294 | expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 295 | |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 296 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 297 | /*! \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 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 302 | ndn::EventId |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 303 | scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo, |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 304 | const ndn::time::seconds& expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 305 | |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 306 | private: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 307 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 308 | void |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 309 | expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 310 | |
| 311 | ndn::EventId |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 312 | scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo, |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 313 | const ndn::time::seconds& expTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 314 | |
| 315 | void |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 316 | expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey, |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 317 | uint64_t seqNo); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 318 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 319 | private: |
| 320 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 321 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 322 | processInterestForNameLsa(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 | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 325 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 326 | void |
| 327 | processInterestForAdjacencyLsa(const ndn::Interest& interest, |
| 328 | const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 329 | uint64_t seqNo); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 330 | |
| 331 | void |
| 332 | processInterestForCoordinateLsa(const ndn::Interest& interest, |
| 333 | const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 334 | uint64_t seqNo); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 335 | void |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 336 | onContentValidated(const std::shared_ptr<const ndn::Data>& data); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 337 | |
| 338 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 339 | processContentNameLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 340 | uint64_t lsSeqNo, std::string& dataContent); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 341 | |
| 342 | void |
| 343 | processContentAdjacencyLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 344 | uint64_t lsSeqNo, std::string& dataContent); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 345 | |
| 346 | void |
| 347 | processContentCoordinateLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 348 | uint64_t lsSeqNo, std::string& dataContent); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 349 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 350 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 351 | /*! |
| 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 Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 364 | */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 365 | void |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 366 | onFetchLsaError(uint32_t errorCode, |
| 367 | const std::string& msg, |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 368 | const ndn::Name& interestName, |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 369 | uint32_t retransmitNo, |
| 370 | const ndn::time::steady_clock::TimePoint& deadline, |
| 371 | ndn::Name lsaName, |
| 372 | uint64_t seqNo); |
| 373 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 374 | /*! |
| 375 | \brief Success callback when SegmentFetcher returns a valid LSA |
| 376 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 377 | \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] | 378 | /<network>/NLSR/LSA/<site>/%C1.Router/<router>/<lsa-type>/<seqNo> |
Muktadir R Chowdhury | aa3b085 | 2015-08-06 13:08:56 -0500 | [diff] [blame] | 379 | */ |
| 380 | void |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 381 | afterFetchLsa(const ndn::ConstBufferPtr& data, const ndn::Name& interestName); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 382 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 383 | private: |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 384 | ndn::time::system_clock::TimePoint |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 385 | getLsaExpirationTimePoint(); |
| 386 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 387 | /*! \brief Cancels an event in the event scheduler. */ |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 388 | void |
| 389 | cancelScheduleLsaExpiringEvent(ndn::EventId eid); |
| 390 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 391 | public: |
| 392 | static const ndn::Name::Component NAME_COMPONENT; |
| 393 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 394 | ndn::util::signal::Signal<Lsdb, Statistics::PacketType> lsaIncrementSignal; |
| 395 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 396 | private: |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 397 | Nlsr& m_nlsr; |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 398 | ndn::Scheduler& m_scheduler; |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 399 | SyncLogicHandler m_sync; |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 400 | LsaSegmentStorage m_lsaStorage; |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 401 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 402 | std::list<NameLsa> m_nameLsdb; |
| 403 | std::list<AdjLsa> m_adjLsdb; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 404 | std::list<CoordinateLsa> m_corLsdb; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 405 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 406 | ndn::time::seconds m_lsaRefreshTime; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 407 | std::string m_thisRouterPrefix; |
| 408 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 409 | 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 Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 415 | static const ndn::time::seconds GRACE_PERIOD; |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 416 | static const ndn::time::steady_clock::TimePoint DEFAULT_LSA_RETRIEVAL_DEADLINE; |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 417 | |
| 418 | ndn::time::seconds m_adjLsaBuildInterval; |
Ashlesh Gawande | 3e105a0 | 2017-05-16 17:36:56 -0500 | [diff] [blame] | 419 | |
| 420 | SequencingManager m_sequencingManager; |
Nick Gordon | 9eac4d9 | 2017-08-29 17:31:29 -0500 | [diff] [blame] | 421 | |
| 422 | ndn::util::signal::ScopedConnection m_onNewLsaConnection; |
Ashlesh Gawande | 744e481 | 2018-08-22 16:26:24 -0500 | [diff] [blame] | 423 | |
| 424 | std::set<std::shared_ptr<ndn::util::SegmentFetcher>> m_fetchers; |
Ashlesh Gawande | 939b6f8 | 2018-12-09 16:51:09 -0600 | [diff] [blame^] | 425 | psync::SegmentPublisher m_segmentPublisher; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 426 | }; |
| 427 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 428 | } // namespace nlsr |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 429 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 430 | #endif // NLSR_LSDB_HPP |