blob: e4355932d15336663be7d3f54635e8cf17a6d085 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -04002/*
Davide Pesavento070ee3b2023-03-16 22:36:36 -04003 * Copyright (c) 2014-2023, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
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 Afanasyev0ad01f32020-06-03 14:12:58 -040020 */
Vince Lehmanc2e51f62015-01-20 15:03:11 -060021
dmcoomes9f936662017-03-02 10:33:09 -060022#ifndef NLSR_NLSR_HPP
23#define NLSR_NLSR_HPP
akmhoque298385a2014-02-13 14:13:09 -060024
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050025#include "adjacency-list.hpp"
akmhoque53353462014-04-22 08:43:45 -050026#include "conf-parameter.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050027#include "hello-protocol.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050028#include "lsdb.hpp"
29#include "name-prefix-list.hpp"
Vince Lehman7b616582014-10-17 16:25:39 -050030#include "test-access-control.hpp"
laqinfan35731852017-08-08 06:17:39 -050031#include "publisher/dataset-interest-handler.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050032#include "route/fib.hpp"
33#include "route/name-prefix-table.hpp"
34#include "route/routing-table.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050035#include "update/prefix-update-processor.hpp"
Nick Gordon4d2c6c02017-01-20 13:18:46 -060036#include "update/nfd-rib-command-processor.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050037#include "utility/name-helper.hpp"
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060038#include "stats-collector.hpp"
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070039
Laqin Fan54a43f02017-03-08 12:31:30 -060040#include <ndn-cxx/face.hpp>
Davide Pesavento070ee3b2023-03-16 22:36:36 -040041#include <ndn-cxx/encoding/nfd-constants.hpp>
42#include <ndn-cxx/mgmt/dispatcher.hpp>
Laqin Fan54a43f02017-03-08 12:31:30 -060043#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
44#include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
Laqin Fan54a43f02017-03-08 12:31:30 -060045#include <ndn-cxx/mgmt/nfd/face-status.hpp>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050046#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
47#include <ndn-cxx/mgmt/nfd/control-response.hpp>
Davide Pesavento070ee3b2023-03-16 22:36:36 -040048#include <ndn-cxx/security/key-chain.hpp>
49#include <ndn-cxx/util/scheduler.hpp>
Laqin Fan54a43f02017-03-08 12:31:30 -060050
akmhoque53353462014-04-22 08:43:45 -050051namespace nlsr {
52
akmhoque53353462014-04-22 08:43:45 -050053class Nlsr
54{
Nick Gordond5c1a372016-10-31 13:56:23 -050055public:
56 using FetchDatasetCallback = std::function<void(const std::vector<ndn::nfd::FaceStatus>&)>;
57 using FetchDatasetTimeoutCallback = std::function<void(uint32_t, const std::string&)>;
Nick Gordon9461afb2017-04-25 15:54:50 -050058
akmhoquefdbddb12014-05-02 18:35:19 -050059 class Error : public std::runtime_error
60 {
61 public:
Davide Pesaventod90338d2021-01-07 17:50:05 -050062 using std::runtime_error::runtime_error;
akmhoquefdbddb12014-05-02 18:35:19 -050063 };
64
Ashlesh Gawande85998a12017-12-07 22:22:13 -060065 Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam);
akmhoque298385a2014-02-13 14:13:09 -060066
Saurab Dulal427e0122019-11-28 11:58:02 -060067 Lsdb&
68 getLsdb()
69 {
70 return m_lsdb;
71 }
72
akmhoque53353462014-04-22 08:43:45 -050073 Fib&
74 getFib()
75 {
76 return m_fib;
77 }
akmhoque298385a2014-02-13 14:13:09 -060078
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070079private:
akmhoque53353462014-04-22 08:43:45 -050080 void
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070081 registerStrategyForCerts(const ndn::Name& originRouter);
akmhoque1fd8c1e2014-02-19 19:41:49 -060082
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070083 /*! \brief Add top level prefixes for Dispatcher
84 *
85 * All dispatcher-related sub-prefixes *must* be registered before sub-prefixes
86 * must be added before adding top
87 */
88 void
89 addDispatcherTopPrefix(const ndn::Name& topPrefix);
90
91PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Nick Gordond5c1a372016-10-31 13:56:23 -050092 /*! \brief Initializes neighbors' Faces using information from NFD.
93 * \sa Nlsr::initialize()
94 * \sa Nlsr::processFaceDataset()
95 *
96 * This function serves as the entry-point for initializing the
97 * neighbors listed in nlsr.conf during Nlsr::initialize(). NLSR
98 * will attempt to fetch a dataset of Faces from NFD, and configure
99 * each of its neighbors using information from that dataset. The
100 * explicit callbacks allow for better testability.
101 */
102 void
103 initializeFaces(const FetchDatasetCallback& onFetchSuccess,
104 const FetchDatasetTimeoutCallback& onFetchFailure);
105
106 void
107 onFaceDatasetFetchTimeout(uint32_t code,
108 const std::string& reason,
109 uint32_t nRetriesSoFar);
110
111 /*! \brief Consumes a Face StatusDataset to configure NLSR neighbors.
112 * \sa Nlsr::initializeFaces
113 * \param faces A Face Dataset that should conform to FaceMgmt specifications.
114 *
115 * This function processes a Face StatusDataset that should conform
116 * to the FaceMgmt specifications listed
117 * [here](https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Face-Dataset).
118 * Any newly configured neighbors will have prefixes registered with NFD
119 * and be sent Hello Interests as well.
120 */
121 void
122 processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces);
123
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700124private:
Nick Gordond5c1a372016-10-31 13:56:23 -0500125 /*! \brief Registers NLSR-specific prefixes for a neighbor (Adjacent)
126 * \sa Nlsr::initializeFaces
127 * \param adj A reference to the neighbor to register prefixes for
128 * \param timeout The amount of time to give NFD to respond to *each* registration request.
129 *
130 * Registers the prefixes in NFD that NLSR needs to route with a
131 * neighbor. The timeout given is how long to set the timeout for
132 * *each* registration request that is made.
133 */
134 void
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700135 registerAdjacencyPrefixes(const Adjacent& adj, ndn::time::milliseconds timeout);
Nick Gordond5c1a372016-10-31 13:56:23 -0500136
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700137 /*! \brief Registers the prefix
Nick Gordond0a7df32017-05-30 16:44:34 -0500138 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700139 void
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700140 registerPrefix(const ndn::Name& prefix);
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500141
Nick Gordond0a7df32017-05-30 16:44:34 -0500142 /*! \brief Do nothing.
143 */
akmhoquee1765152014-06-30 11:32:01 -0500144 void
akmhoquec04e7272014-07-02 11:00:14 -0500145 onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
akmhoquee1765152014-06-30 11:32:01 -0500146
Vince Lehman7b616582014-10-17 16:25:39 -0500147 void
Nick Gordond5c1a372016-10-31 13:56:23 -0500148 scheduleDatasetFetch();
149
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500150 /*! \brief Enables NextHopFaceId indication in NFD for incoming data packet.
151 *
152 * After enabling, when NFD gets a data packet, it will put the incoming face id
153 * of the data in NextHopFaceId field of the packet. The NextHopFaceId will be used
154 * by DirectFetcher to fetch the certificates needed to validate the data packet.
155 * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2#Consumer-Controlled-Forwarding
156 */
157 void
158 enableIncomingFaceIdIndication();
159
alvy297f4162015-03-03 17:15:33 -0600160public:
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400161 static inline const ndn::Name LOCALHOST_PREFIX{"/localhost/nlsr"};
alvy297f4162015-03-03 17:15:33 -0600162
akmhoque157b0a42014-05-13 00:26:37 -0500163private:
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600164 ndn::Face& m_face;
165 ndn::Scheduler m_scheduler;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600166 ConfParameter& m_confParam;
167 AdjacencyList& m_adjacencyList;
168 NamePrefixList& m_namePrefixList;
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500169 std::vector<ndn::Name> m_strategySetOnRouters;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700170
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500171PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600172 Fib m_fib;
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700173 Lsdb m_lsdb;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600174 RoutingTable m_routingTable;
175 NamePrefixTable m_namePrefixTable;
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500176 HelloProtocol m_helloProtocol;
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500177
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600178private:
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500179 ndn::util::signal::ScopedConnection m_onNewLsaConnection;
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500180 ndn::util::signal::ScopedConnection m_onPrefixRegistrationSuccess;
Ashlesh Gawandee63b7fa2021-04-06 21:43:17 -0700181 ndn::util::signal::ScopedConnection m_onInitialHelloDataValidated;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600182
183PUBLIC_WITH_TESTS_ELSE_PRIVATE:
184 ndn::mgmt::Dispatcher m_dispatcher;
185 DatasetInterestHandler m_datasetHandler;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500186
Vince Lehman7b616582014-10-17 16:25:39 -0500187private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500188 /*! \brief Where NLSR stores certificates it claims to be
189 * authoritative for. Usually the router certificate.
190 */
Nick Gordond5c1a372016-10-31 13:56:23 -0500191
Nick Gordond5c1a372016-10-31 13:56:23 -0500192 ndn::nfd::Controller m_controller;
193 ndn::nfd::Controller m_faceDatasetController;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600194
195PUBLIC_WITH_TESTS_ELSE_PRIVATE:
alvy297f4162015-03-03 17:15:33 -0600196 update::PrefixUpdateProcessor m_prefixUpdateProcessor;
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600197 update::NfdRibCommandProcessor m_nfdRibCommandProcessor;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600198
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600199 StatsCollector m_statsCollector;
akmhoquee1765152014-06-30 11:32:01 -0500200
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600201private:
akmhoque060d3022014-08-12 13:35:06 -0500202 ndn::nfd::FaceMonitor m_faceMonitor;
akmhoque53353462014-04-22 08:43:45 -0500203};
akmhoque298385a2014-02-13 14:13:09 -0600204
Nick Gordonfad8e252016-08-11 14:21:38 -0500205} // namespace nlsr
akmhoqueb1710aa2014-02-19 17:13:36 -0600206
dmcoomes9f936662017-03-02 10:33:09 -0600207#endif // NLSR_NLSR_HPP