akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [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 | **/ |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 21 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 22 | #ifndef NLSR_NLSR_HPP |
| 23 | #define NLSR_NLSR_HPP |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 24 | |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 25 | #include "adjacency-list.hpp" |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 26 | #include "common.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 27 | #include "conf-parameter.hpp" |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 28 | #include "hello-protocol.hpp" |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 29 | #include "lsdb.hpp" |
| 30 | #include "name-prefix-list.hpp" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 31 | #include "test-access-control.hpp" |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 32 | #include "publisher/dataset-interest-handler.hpp" |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 33 | #include "route/fib.hpp" |
| 34 | #include "route/name-prefix-table.hpp" |
| 35 | #include "route/routing-table.hpp" |
| 36 | #include "security/certificate-store.hpp" |
| 37 | #include "update/prefix-update-processor.hpp" |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 38 | #include "update/nfd-rib-command-processor.hpp" |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 39 | #include "utility/name-helper.hpp" |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 40 | #include "stats-collector.hpp" |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 41 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 42 | #include <boost/cstdint.hpp> |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 43 | #include <stdexcept> |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 44 | #include <boost/throw_exception.hpp> |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 45 | |
| 46 | #include <ndn-cxx/face.hpp> |
| 47 | #include <ndn-cxx/security/key-chain.hpp> |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 48 | #include <ndn-cxx/security/validator-config.hpp> |
| 49 | #include <ndn-cxx/security/v2/certificate-fetcher-direct-fetch.hpp> |
| 50 | #include <ndn-cxx/security/signing-helpers.hpp> |
| 51 | #include <ndn-cxx/security/signing-info.hpp> |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 52 | #include <ndn-cxx/util/scheduler.hpp> |
| 53 | #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp> |
| 54 | #include <ndn-cxx/mgmt/nfd/face-monitor.hpp> |
| 55 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
| 56 | #include <ndn-cxx/mgmt/nfd/face-status.hpp> |
| 57 | #include <ndn-cxx/data.hpp> |
| 58 | #include <ndn-cxx/encoding/block.hpp> |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 59 | #include <ndn-cxx/encoding/nfd-constants.hpp> |
| 60 | #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> |
| 61 | #include <ndn-cxx/mgmt/nfd/control-response.hpp> |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 62 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 63 | namespace nlsr { |
| 64 | |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 65 | static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast"); |
| 66 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 67 | class Nlsr |
| 68 | { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 69 | public: |
| 70 | using FetchDatasetCallback = std::function<void(const std::vector<ndn::nfd::FaceStatus>&)>; |
| 71 | using FetchDatasetTimeoutCallback = std::function<void(uint32_t, const std::string&)>; |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 72 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 73 | class Error : public std::runtime_error |
| 74 | { |
| 75 | public: |
| 76 | explicit |
| 77 | Error(const std::string& what) |
| 78 | : std::runtime_error(what) |
| 79 | { |
| 80 | } |
| 81 | }; |
| 82 | |
Laqin Fan | a4cf402 | 2017-01-03 18:57:35 +0000 | [diff] [blame] | 83 | Nlsr(boost::asio::io_service& ioService, ndn::Scheduler& scheduler, ndn::Face& face, ndn::KeyChain& keyChain); |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 84 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 85 | void |
| 86 | registrationFailed(const ndn::Name& name); |
| 87 | |
| 88 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 89 | onRegistrationSuccess(const ndn::Name& name); |
| 90 | |
| 91 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 92 | setInfoInterestFilter(); |
| 93 | |
| 94 | void |
| 95 | setLsaInterestFilter(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 96 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 97 | /*! \brief Add top level prefixes for Dispatcher |
| 98 | * |
| 99 | * All dispatcher-related sub-prefixes *must* be registered before sub-prefixes |
| 100 | * must be added before adding top |
| 101 | */ |
| 102 | void |
| 103 | addDispatcherTopPrefix(const ndn::Name& topPrefix); |
| 104 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 105 | void |
| 106 | startEventLoop(); |
| 107 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 108 | std::string |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 109 | getConfFileName() const |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 110 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 111 | return m_configFileName; |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 112 | } |
| 113 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 114 | void |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 115 | setConfFileName(const std::string& fileName) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 116 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 117 | m_configFileName = fileName; |
| 118 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 119 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 120 | ConfParameter& |
| 121 | getConfParameter() |
| 122 | { |
| 123 | return m_confParam; |
| 124 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 125 | |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 126 | const ConfParameter& |
| 127 | getConfParameter() const |
| 128 | { |
| 129 | return m_confParam; |
| 130 | } |
| 131 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 132 | AdjacencyList& |
| 133 | getAdjacencyList() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 134 | { |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 135 | return m_adjacencyList; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 136 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 137 | |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 138 | const AdjacencyList& |
| 139 | getAdjacencyList() const |
| 140 | { |
| 141 | return m_adjacencyList; |
| 142 | } |
| 143 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 144 | NamePrefixList& |
| 145 | getNamePrefixList() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 146 | { |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 147 | return m_namePrefixList; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 148 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 149 | |
Nick Gordon | 4964870 | 2018-01-22 11:57:33 -0600 | [diff] [blame] | 150 | const NamePrefixList& |
| 151 | getNamePrefixList() const |
| 152 | { |
| 153 | return m_namePrefixList; |
| 154 | } |
| 155 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 156 | ndn::Face& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 157 | getNlsrFace() |
| 158 | { |
| 159 | return m_nlsrFace; |
| 160 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 161 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 162 | Lsdb& |
| 163 | getLsdb() |
| 164 | { |
| 165 | return m_nlsrLsdb; |
| 166 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 167 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 168 | RoutingTable& |
| 169 | getRoutingTable() |
| 170 | { |
| 171 | return m_routingTable; |
| 172 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 173 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 174 | NamePrefixTable& |
| 175 | getNamePrefixTable() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 176 | { |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 177 | return m_namePrefixTable; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 178 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 179 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 180 | Fib& |
| 181 | getFib() |
| 182 | { |
| 183 | return m_fib; |
| 184 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 185 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 186 | long int |
| 187 | getAdjBuildCount() |
| 188 | { |
| 189 | return m_adjBuildCount; |
| 190 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 191 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 192 | void |
| 193 | incrementAdjBuildCount() |
| 194 | { |
| 195 | m_adjBuildCount++; |
| 196 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 197 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 198 | void |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 199 | setAdjBuildCount(int64_t abc) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 200 | { |
| 201 | m_adjBuildCount = abc; |
| 202 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 203 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 204 | bool |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 205 | getIsBuildAdjLsaSheduled() |
| 206 | { |
| 207 | return m_isBuildAdjLsaSheduled; |
| 208 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 209 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 210 | void |
| 211 | setIsBuildAdjLsaSheduled(bool iabls) |
| 212 | { |
| 213 | m_isBuildAdjLsaSheduled = iabls; |
| 214 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 215 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 216 | bool |
| 217 | getIsRoutingTableCalculating() |
| 218 | { |
| 219 | return m_isRoutingTableCalculating; |
| 220 | } |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 221 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 222 | void |
| 223 | setIsRoutingTableCalculating(bool irtc) |
| 224 | { |
| 225 | m_isRoutingTableCalculating = irtc; |
| 226 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 227 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 228 | bool |
| 229 | getIsRouteCalculationScheduled() |
| 230 | { |
| 231 | return m_isRouteCalculationScheduled; |
| 232 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 233 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 234 | void |
| 235 | setIsRouteCalculationScheduled(bool ircs) |
| 236 | { |
| 237 | m_isRouteCalculationScheduled = ircs; |
| 238 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 239 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 240 | DatasetInterestHandler& |
| 241 | getDatasetHandler() |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 242 | { |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 243 | return m_datasetHandler; |
Muktadir R Chowdhury | 3ac0728 | 2016-06-17 16:30:29 -0500 | [diff] [blame] | 244 | } |
| 245 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 246 | void |
| 247 | initialize(); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 248 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 249 | /*! \brief Initializes neighbors' Faces using information from NFD. |
| 250 | * \sa Nlsr::initialize() |
| 251 | * \sa Nlsr::processFaceDataset() |
| 252 | * |
| 253 | * This function serves as the entry-point for initializing the |
| 254 | * neighbors listed in nlsr.conf during Nlsr::initialize(). NLSR |
| 255 | * will attempt to fetch a dataset of Faces from NFD, and configure |
| 256 | * each of its neighbors using information from that dataset. The |
| 257 | * explicit callbacks allow for better testability. |
| 258 | */ |
| 259 | void |
| 260 | initializeFaces(const FetchDatasetCallback& onFetchSuccess, |
| 261 | const FetchDatasetTimeoutCallback& onFetchFailure); |
| 262 | |
| 263 | void |
| 264 | onFaceDatasetFetchTimeout(uint32_t code, |
| 265 | const std::string& reason, |
| 266 | uint32_t nRetriesSoFar); |
| 267 | |
| 268 | /*! \brief Consumes a Face StatusDataset to configure NLSR neighbors. |
| 269 | * \sa Nlsr::initializeFaces |
| 270 | * \param faces A Face Dataset that should conform to FaceMgmt specifications. |
| 271 | * |
| 272 | * This function processes a Face StatusDataset that should conform |
| 273 | * to the FaceMgmt specifications listed |
| 274 | * [here](https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Face-Dataset). |
| 275 | * Any newly configured neighbors will have prefixes registered with NFD |
| 276 | * and be sent Hello Interests as well. |
| 277 | */ |
| 278 | void |
| 279 | processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces); |
| 280 | |
| 281 | /*! \brief Registers NLSR-specific prefixes for a neighbor (Adjacent) |
| 282 | * \sa Nlsr::initializeFaces |
| 283 | * \param adj A reference to the neighbor to register prefixes for |
| 284 | * \param timeout The amount of time to give NFD to respond to *each* registration request. |
| 285 | * |
| 286 | * Registers the prefixes in NFD that NLSR needs to route with a |
| 287 | * neighbor. The timeout given is how long to set the timeout for |
| 288 | * *each* registration request that is made. |
| 289 | */ |
| 290 | void |
| 291 | registerAdjacencyPrefixes(const Adjacent& adj, |
| 292 | const ndn::time::milliseconds& timeout); |
| 293 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 294 | /*! \brief Add a certificate NLSR claims to be authoritative for to the certificate store. |
| 295 | * |
| 296 | * \sa CertificateStore |
| 297 | */ |
| 298 | void |
| 299 | loadCertToPublish(const ndn::security::v2::Certificate& certificate); |
| 300 | |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 301 | void |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 302 | connectToFetcher(ndn::util::SegmentFetcher& fetcher); |
| 303 | |
| 304 | /*! \brief Callback when SegmentFetcher retrieves a segment. |
| 305 | */ |
| 306 | void |
| 307 | afterFetcherSignalEmitted(const ndn::Data& lsaSegment); |
| 308 | |
| 309 | /*! \brief Retrieves the chain of certificates from Validator's cache and |
| 310 | * store them in Nlsr's own CertificateStore. |
| 311 | * \param keyName Name of the first key in the certificate chain. |
| 312 | */ |
| 313 | void |
| 314 | publishCertFromCache(const ndn::Name& keyName); |
| 315 | |
| 316 | void |
akmhoque | 443ad81 | 2014-07-29 10:26:56 -0500 | [diff] [blame] | 317 | initializeKey(); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 318 | |
| 319 | void |
| 320 | loadValidator(boost::property_tree::ptree section, |
| 321 | const std::string& filename) |
| 322 | { |
| 323 | m_validator.load(section, filename); |
| 324 | } |
| 325 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 326 | ndn::security::ValidatorConfig& |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 327 | getValidator() |
| 328 | { |
| 329 | return m_validator; |
| 330 | } |
| 331 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 332 | /*! \brief Find a certificate |
| 333 | * |
| 334 | * Find a certificate that NLSR has. First it checks against the |
| 335 | * certificates this NLSR claims to be authoritative for, usually |
| 336 | * something like this specific router's certificate, and then |
| 337 | * checks the cache of certficates it has already fetched. If none |
| 338 | * can be found, it will return an empty pointer. |
| 339 | */ |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 340 | const ndn::security::v2::Certificate* |
| 341 | getCertificate(const ndn::Name& certificateKeyName) |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 342 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 343 | const ndn::security::v2::Certificate* cert = |
| 344 | m_certStore.find(certificateKeyName); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 345 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 346 | return cert; |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 349 | ndn::security::v2::KeyChain& |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 350 | getKeyChain() |
| 351 | { |
| 352 | return m_keyChain; |
| 353 | } |
| 354 | |
| 355 | const ndn::Name& |
| 356 | getDefaultCertName() |
| 357 | { |
| 358 | return m_defaultCertName; |
| 359 | } |
| 360 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 361 | const ndn::security::SigningInfo& |
| 362 | getSigningInfo() |
| 363 | { |
| 364 | return m_signingInfo; |
| 365 | } |
| 366 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 367 | update::PrefixUpdateProcessor& |
| 368 | getPrefixUpdateProcessor() |
| 369 | { |
| 370 | return m_prefixUpdateProcessor; |
| 371 | } |
| 372 | |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 373 | update::NfdRibCommandProcessor& |
| 374 | getNfdRibCommandProcessor() |
| 375 | { |
| 376 | return m_nfdRibCommandProcessor; |
| 377 | } |
| 378 | |
Nick Gordon | d1f4f33 | 2017-01-20 13:40:57 -0600 | [diff] [blame] | 379 | ndn::mgmt::Dispatcher& |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 380 | getDispatcher() |
Nick Gordon | d1f4f33 | 2017-01-20 13:40:57 -0600 | [diff] [blame] | 381 | { |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 382 | return m_dispatcher; |
Nick Gordon | d1f4f33 | 2017-01-20 13:40:57 -0600 | [diff] [blame] | 383 | } |
| 384 | |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 385 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 386 | setStrategies(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 387 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 388 | uint32_t |
| 389 | getFirstHelloInterval() const |
| 390 | { |
| 391 | return m_firstHelloInterval; |
| 392 | } |
| 393 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 394 | /*! \brief Canonize the URI for this and all proceeding neighbors in a list. |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 395 | * |
| 396 | * This function canonizes the URI of the Adjacent object pointed to |
| 397 | * by currentNeighbor. It then executes the then callback, providing |
| 398 | * the next iterator in the list to the callback. A standard |
| 399 | * invocation would be to pass the begin() iterator of NLSR's |
| 400 | * adjacency list, and to provide Nlsr::canonizeContinuation as the |
| 401 | * callback. Because every URI must be canonical before we begin |
Nick Gordon | 922714a | 2017-06-13 14:12:02 -0500 | [diff] [blame] | 402 | * operations, the canonize function provides a finally() function |
| 403 | * to resume whatever needs to occur. |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 404 | * |
| 405 | * \sa Nlsr::canonizeContinuation |
| 406 | * \sa Nlsr::initialize |
| 407 | * \sa NlsrRunner::run |
| 408 | */ |
| 409 | void |
| 410 | canonizeNeighborUris(std::list<Adjacent>::iterator currentNeighbor, |
Nick Gordon | 922714a | 2017-06-13 14:12:02 -0500 | [diff] [blame] | 411 | std::function<void(std::list<Adjacent>::iterator)> then, |
| 412 | std::function<void(void)> finally); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 413 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 414 | StatsCollector& |
| 415 | getStatsCollector() |
| 416 | { |
| 417 | return m_statsCollector; |
| 418 | } |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 419 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 420 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 421 | |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 422 | security::CertificateStore& |
| 423 | getCertificateStore() |
| 424 | { |
| 425 | return m_certStore; |
| 426 | } |
| 427 | |
akmhoque | 393d4ff | 2014-07-16 14:27:03 -0500 | [diff] [blame] | 428 | private: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 429 | /*! \brief Registers the prefix that NLSR will use for key/certificate interests. |
| 430 | */ |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 431 | void |
| 432 | registerKeyPrefix(); |
| 433 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 434 | /*! \brief Registers the prefix that NLSR will consider to be the machine-local, secure prefix. |
| 435 | */ |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 436 | void |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 437 | registerLocalhostPrefix(); |
| 438 | |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame^] | 439 | /*! \brief Registers the <router-prefix>/nlsr so that NLSR can respond to status requests from remote routers. |
| 440 | */ |
| 441 | void |
| 442 | registerRouterPrefix(); |
| 443 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 444 | /*! \brief Attempts to satisfy an Interest for a certificate, and send it back. |
| 445 | */ |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 446 | void |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 447 | onKeyInterest(const ndn::Name& name, const ndn::Interest& interest); |
| 448 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 449 | /*! \brief Do nothing. |
| 450 | */ |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 451 | void |
| 452 | onKeyPrefixRegSuccess(const ndn::Name& name); |
| 453 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 454 | /*! \brief Do nothing. |
| 455 | */ |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 456 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 457 | onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification); |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 458 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 459 | void |
| 460 | setFirstHelloInterval(uint32_t interval) |
| 461 | { |
| 462 | m_firstHelloInterval = interval; |
| 463 | } |
| 464 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 465 | /*! \brief Continues canonizing neighbor URIs. |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 466 | * |
| 467 | * For testability reasons, we want what each instance of |
| 468 | * canonization does after completion to be controllable. The best |
| 469 | * way to do this is to control that by simply passing a |
| 470 | * continuation function. |
| 471 | */ |
| 472 | void |
Nick Gordon | 922714a | 2017-06-13 14:12:02 -0500 | [diff] [blame] | 473 | canonizeContinuation(std::list<Adjacent>::iterator iterator, |
| 474 | std::function<void(void)> finally); |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 475 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 476 | void |
| 477 | scheduleDatasetFetch(); |
| 478 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 479 | /*! \brief Enables NextHopFaceId indication in NFD for incoming data packet. |
| 480 | * |
| 481 | * After enabling, when NFD gets a data packet, it will put the incoming face id |
| 482 | * of the data in NextHopFaceId field of the packet. The NextHopFaceId will be used |
| 483 | * by DirectFetcher to fetch the certificates needed to validate the data packet. |
| 484 | * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2#Consumer-Controlled-Forwarding |
| 485 | */ |
| 486 | void |
| 487 | enableIncomingFaceIdIndication(); |
| 488 | |
| 489 | void |
| 490 | onFaceIdIndicationSuccess(const ndn::nfd::ControlParameters& cp); |
| 491 | |
| 492 | void |
| 493 | onFaceIdIndicationFailure(const ndn::nfd::ControlResponse& cr); |
| 494 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 495 | public: |
| 496 | static const ndn::Name LOCALHOST_PREFIX; |
| 497 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 498 | private: |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 499 | ndn::Face& m_nlsrFace; |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 500 | ndn::Scheduler& m_scheduler; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 501 | ndn::security::v2::KeyChain& m_keyChain; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 502 | ConfParameter m_confParam; |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 503 | AdjacencyList m_adjacencyList; |
| 504 | NamePrefixList m_namePrefixList; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 505 | std::string m_configFileName; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 506 | Lsdb m_nlsrLsdb; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 507 | int64_t m_adjBuildCount; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 508 | bool m_isBuildAdjLsaSheduled; |
| 509 | bool m_isRouteCalculationScheduled; |
| 510 | bool m_isRoutingTableCalculating; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 511 | RoutingTable m_routingTable; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 512 | Fib m_fib; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 513 | NamePrefixTable m_namePrefixTable; |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 514 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 515 | ndn::mgmt::Dispatcher m_dispatcher; |
laqinfan | d22da51 | 2017-05-25 17:29:53 -0500 | [diff] [blame] | 516 | |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 517 | DatasetInterestHandler m_datasetHandler; |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 518 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 519 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 520 | HelloProtocol m_helloProtocol; |
| 521 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 522 | ndn::security::ValidatorConfig m_validator; |
| 523 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 524 | private: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 525 | /*! \brief Where NLSR stores certificates it claims to be |
| 526 | * authoritative for. Usually the router certificate. |
| 527 | */ |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 528 | security::CertificateStore m_certStore; |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 529 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 530 | ndn::nfd::Controller m_controller; |
| 531 | ndn::nfd::Controller m_faceDatasetController; |
Joao Pereira | 97473d4 | 2015-07-03 16:57:27 -0400 | [diff] [blame] | 532 | ndn::security::SigningInfo m_signingInfo; |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 533 | ndn::Name m_defaultCertName; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 534 | update::PrefixUpdateProcessor m_prefixUpdateProcessor; |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 535 | update::NfdRibCommandProcessor m_nfdRibCommandProcessor; |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 536 | StatsCollector m_statsCollector; |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 537 | |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 538 | ndn::nfd::FaceMonitor m_faceMonitor; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 539 | |
| 540 | uint32_t m_firstHelloInterval; |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 541 | |
| 542 | friend class NlsrRunner; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 543 | }; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 544 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 545 | } // namespace nlsr |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 546 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 547 | #endif // NLSR_NLSR_HPP |