akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [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" |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 36 | #include "update/prefix-update-processor.hpp" |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 37 | #include "update/nfd-rib-command-processor.hpp" |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 38 | #include "utility/name-helper.hpp" |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 39 | #include "stats-collector.hpp" |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 40 | |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 41 | #include <ndn-cxx/face.hpp> |
| 42 | #include <ndn-cxx/security/key-chain.hpp> |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 43 | #include <ndn-cxx/util/scheduler.hpp> |
| 44 | #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp> |
| 45 | #include <ndn-cxx/mgmt/nfd/face-monitor.hpp> |
| 46 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
| 47 | #include <ndn-cxx/mgmt/nfd/face-status.hpp> |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 48 | #include <ndn-cxx/encoding/nfd-constants.hpp> |
| 49 | #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> |
| 50 | #include <ndn-cxx/mgmt/nfd/control-response.hpp> |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 51 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 52 | namespace nlsr { |
| 53 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 54 | class Nlsr |
| 55 | { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 56 | public: |
| 57 | using FetchDatasetCallback = std::function<void(const std::vector<ndn::nfd::FaceStatus>&)>; |
| 58 | using FetchDatasetTimeoutCallback = std::function<void(uint32_t, const std::string&)>; |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 59 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 60 | class Error : public std::runtime_error |
| 61 | { |
| 62 | public: |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 63 | using std::runtime_error::runtime_error; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 64 | }; |
| 65 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 66 | Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam); |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 67 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 68 | Lsdb& |
| 69 | getLsdb() |
| 70 | { |
| 71 | return m_lsdb; |
| 72 | } |
| 73 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 74 | Fib& |
| 75 | getFib() |
| 76 | { |
| 77 | return m_fib; |
| 78 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 79 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 80 | private: |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 81 | void |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 82 | registerStrategyForCerts(const ndn::Name& originRouter); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 83 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 84 | /*! \brief Add top level prefixes for Dispatcher |
| 85 | * |
| 86 | * All dispatcher-related sub-prefixes *must* be registered before sub-prefixes |
| 87 | * must be added before adding top |
| 88 | */ |
| 89 | void |
| 90 | addDispatcherTopPrefix(const ndn::Name& topPrefix); |
| 91 | |
| 92 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 93 | /*! \brief Initializes neighbors' Faces using information from NFD. |
| 94 | * \sa Nlsr::initialize() |
| 95 | * \sa Nlsr::processFaceDataset() |
| 96 | * |
| 97 | * This function serves as the entry-point for initializing the |
| 98 | * neighbors listed in nlsr.conf during Nlsr::initialize(). NLSR |
| 99 | * will attempt to fetch a dataset of Faces from NFD, and configure |
| 100 | * each of its neighbors using information from that dataset. The |
| 101 | * explicit callbacks allow for better testability. |
| 102 | */ |
| 103 | void |
| 104 | initializeFaces(const FetchDatasetCallback& onFetchSuccess, |
| 105 | const FetchDatasetTimeoutCallback& onFetchFailure); |
| 106 | |
| 107 | void |
| 108 | onFaceDatasetFetchTimeout(uint32_t code, |
| 109 | const std::string& reason, |
| 110 | uint32_t nRetriesSoFar); |
| 111 | |
| 112 | /*! \brief Consumes a Face StatusDataset to configure NLSR neighbors. |
| 113 | * \sa Nlsr::initializeFaces |
| 114 | * \param faces A Face Dataset that should conform to FaceMgmt specifications. |
| 115 | * |
| 116 | * This function processes a Face StatusDataset that should conform |
| 117 | * to the FaceMgmt specifications listed |
| 118 | * [here](https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Face-Dataset). |
| 119 | * Any newly configured neighbors will have prefixes registered with NFD |
| 120 | * and be sent Hello Interests as well. |
| 121 | */ |
| 122 | void |
| 123 | processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces); |
| 124 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 125 | private: |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 126 | /*! \brief Registers NLSR-specific prefixes for a neighbor (Adjacent) |
| 127 | * \sa Nlsr::initializeFaces |
| 128 | * \param adj A reference to the neighbor to register prefixes for |
| 129 | * \param timeout The amount of time to give NFD to respond to *each* registration request. |
| 130 | * |
| 131 | * Registers the prefixes in NFD that NLSR needs to route with a |
| 132 | * neighbor. The timeout given is how long to set the timeout for |
| 133 | * *each* registration request that is made. |
| 134 | */ |
| 135 | void |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 136 | registerAdjacencyPrefixes(const Adjacent& adj, ndn::time::milliseconds timeout); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 137 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 138 | /*! \brief Registers the prefix |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 139 | */ |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 140 | void |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 141 | registerPrefix(const ndn::Name& prefix); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 142 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 143 | /*! \brief Do nothing. |
| 144 | */ |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 145 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 146 | onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification); |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 147 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 148 | void |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 149 | scheduleDatasetFetch(); |
| 150 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 151 | /*! \brief Enables NextHopFaceId indication in NFD for incoming data packet. |
| 152 | * |
| 153 | * After enabling, when NFD gets a data packet, it will put the incoming face id |
| 154 | * of the data in NextHopFaceId field of the packet. The NextHopFaceId will be used |
| 155 | * by DirectFetcher to fetch the certificates needed to validate the data packet. |
| 156 | * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2#Consumer-Controlled-Forwarding |
| 157 | */ |
| 158 | void |
| 159 | enableIncomingFaceIdIndication(); |
| 160 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 161 | public: |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 162 | static inline const ndn::Name LOCALHOST_PREFIX{"/localhost/nlsr"}; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 163 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 164 | private: |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 165 | ndn::Face& m_face; |
| 166 | ndn::Scheduler m_scheduler; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 167 | ConfParameter& m_confParam; |
| 168 | AdjacencyList& m_adjacencyList; |
| 169 | NamePrefixList& m_namePrefixList; |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 170 | std::vector<ndn::Name> m_strategySetOnRouters; |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 171 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 172 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 173 | Fib m_fib; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 174 | Lsdb m_lsdb; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 175 | RoutingTable m_routingTable; |
| 176 | NamePrefixTable m_namePrefixTable; |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 177 | HelloProtocol m_helloProtocol; |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 178 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 179 | private: |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 180 | ndn::util::signal::ScopedConnection m_onNewLsaConnection; |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 181 | ndn::util::signal::ScopedConnection m_onPrefixRegistrationSuccess; |
Ashlesh Gawande | e63b7fa | 2021-04-06 21:43:17 -0700 | [diff] [blame] | 182 | ndn::util::signal::ScopedConnection m_onInitialHelloDataValidated; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 183 | |
| 184 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 185 | ndn::mgmt::Dispatcher m_dispatcher; |
| 186 | DatasetInterestHandler m_datasetHandler; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 187 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 188 | private: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 189 | /*! \brief Where NLSR stores certificates it claims to be |
| 190 | * authoritative for. Usually the router certificate. |
| 191 | */ |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 192 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 193 | ndn::nfd::Controller m_controller; |
| 194 | ndn::nfd::Controller m_faceDatasetController; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 195 | |
| 196 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 197 | update::PrefixUpdateProcessor m_prefixUpdateProcessor; |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 198 | update::NfdRibCommandProcessor m_nfdRibCommandProcessor; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 199 | |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 200 | StatsCollector m_statsCollector; |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 201 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 202 | private: |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 203 | ndn::nfd::FaceMonitor m_faceMonitor; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 204 | }; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 205 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 206 | } // namespace nlsr |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 207 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 208 | #endif // NLSR_NLSR_HPP |