blob: 4e61bbc8072ba1785830050261cf6376fd18cda6 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Saurab Dulal427e0122019-11-28 11:58:02 -06003 * Copyright (c) 2014-2020, 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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
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"
Vince Lehman0a7da612014-10-29 14:39:29 -050026#include "common.hpp"
akmhoque53353462014-04-22 08:43:45 -050027#include "conf-parameter.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050028#include "hello-protocol.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050029#include "lsdb.hpp"
30#include "name-prefix-list.hpp"
Vince Lehman7b616582014-10-17 16:25:39 -050031#include "test-access-control.hpp"
laqinfan35731852017-08-08 06:17:39 -050032#include "publisher/dataset-interest-handler.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050033#include "route/fib.hpp"
34#include "route/name-prefix-table.hpp"
35#include "route/routing-table.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050036#include "update/prefix-update-processor.hpp"
Nick Gordon4d2c6c02017-01-20 13:18:46 -060037#include "update/nfd-rib-command-processor.hpp"
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050038#include "utility/name-helper.hpp"
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060039#include "stats-collector.hpp"
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070040
Nick Gordond0a7df32017-05-30 16:44:34 -050041#include <boost/cstdint.hpp>
Laqin Fan54a43f02017-03-08 12:31:30 -060042#include <stdexcept>
Nick Gordond0a7df32017-05-30 16:44:34 -050043#include <boost/throw_exception.hpp>
Laqin Fan54a43f02017-03-08 12:31:30 -060044
45#include <ndn-cxx/face.hpp>
46#include <ndn-cxx/security/key-chain.hpp>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050047#include <ndn-cxx/security/validator-config.hpp>
48#include <ndn-cxx/security/v2/certificate-fetcher-direct-fetch.hpp>
49#include <ndn-cxx/security/signing-helpers.hpp>
50#include <ndn-cxx/security/signing-info.hpp>
Laqin Fan54a43f02017-03-08 12:31:30 -060051#include <ndn-cxx/util/scheduler.hpp>
52#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
53#include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
54#include <ndn-cxx/mgmt/dispatcher.hpp>
55#include <ndn-cxx/mgmt/nfd/face-status.hpp>
56#include <ndn-cxx/data.hpp>
57#include <ndn-cxx/encoding/block.hpp>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050058#include <ndn-cxx/encoding/nfd-constants.hpp>
59#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
60#include <ndn-cxx/mgmt/nfd/control-response.hpp>
Laqin Fan54a43f02017-03-08 12:31:30 -060061
akmhoque53353462014-04-22 08:43:45 -050062namespace nlsr {
63
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070064static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast");
65
akmhoque53353462014-04-22 08:43:45 -050066class Nlsr
67{
Nick Gordond5c1a372016-10-31 13:56:23 -050068public:
69 using FetchDatasetCallback = std::function<void(const std::vector<ndn::nfd::FaceStatus>&)>;
70 using FetchDatasetTimeoutCallback = std::function<void(uint32_t, const std::string&)>;
Nick Gordon9461afb2017-04-25 15:54:50 -050071
akmhoquefdbddb12014-05-02 18:35:19 -050072 class Error : public std::runtime_error
73 {
74 public:
75 explicit
76 Error(const std::string& what)
77 : std::runtime_error(what)
78 {
79 }
80 };
81
Ashlesh Gawande85998a12017-12-07 22:22:13 -060082 Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam);
akmhoque298385a2014-02-13 14:13:09 -060083
akmhoque53353462014-04-22 08:43:45 -050084 void
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -050085 registerStrategyForCerts(const ndn::Name& originRouter);
86
87 void
akmhoque53353462014-04-22 08:43:45 -050088 registrationFailed(const ndn::Name& name);
89
90 void
akmhoque157b0a42014-05-13 00:26:37 -050091 onRegistrationSuccess(const ndn::Name& name);
92
93 void
akmhoque31d1d4b2014-05-05 22:08:14 -050094 setInfoInterestFilter();
95
96 void
97 setLsaInterestFilter();
akmhoque53353462014-04-22 08:43:45 -050098
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050099 /*! \brief Add top level prefixes for Dispatcher
100 *
101 * All dispatcher-related sub-prefixes *must* be registered before sub-prefixes
102 * must be added before adding top
103 */
104 void
105 addDispatcherTopPrefix(const ndn::Name& topPrefix);
106
Saurab Dulal427e0122019-11-28 11:58:02 -0600107 Lsdb&
108 getLsdb()
109 {
110 return m_lsdb;
111 }
112
akmhoque53353462014-04-22 08:43:45 -0500113 Fib&
114 getFib()
115 {
116 return m_fib;
117 }
akmhoque298385a2014-02-13 14:13:09 -0600118
akmhoque53353462014-04-22 08:43:45 -0500119 void
120 initialize();
akmhoque1fd8c1e2014-02-19 19:41:49 -0600121
Nick Gordond5c1a372016-10-31 13:56:23 -0500122 /*! \brief Initializes neighbors' Faces using information from NFD.
123 * \sa Nlsr::initialize()
124 * \sa Nlsr::processFaceDataset()
125 *
126 * This function serves as the entry-point for initializing the
127 * neighbors listed in nlsr.conf during Nlsr::initialize(). NLSR
128 * will attempt to fetch a dataset of Faces from NFD, and configure
129 * each of its neighbors using information from that dataset. The
130 * explicit callbacks allow for better testability.
131 */
132 void
133 initializeFaces(const FetchDatasetCallback& onFetchSuccess,
134 const FetchDatasetTimeoutCallback& onFetchFailure);
135
136 void
137 onFaceDatasetFetchTimeout(uint32_t code,
138 const std::string& reason,
139 uint32_t nRetriesSoFar);
140
141 /*! \brief Consumes a Face StatusDataset to configure NLSR neighbors.
142 * \sa Nlsr::initializeFaces
143 * \param faces A Face Dataset that should conform to FaceMgmt specifications.
144 *
145 * This function processes a Face StatusDataset that should conform
146 * to the FaceMgmt specifications listed
147 * [here](https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Face-Dataset).
148 * Any newly configured neighbors will have prefixes registered with NFD
149 * and be sent Hello Interests as well.
150 */
151 void
152 processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces);
153
154 /*! \brief Registers NLSR-specific prefixes for a neighbor (Adjacent)
155 * \sa Nlsr::initializeFaces
156 * \param adj A reference to the neighbor to register prefixes for
157 * \param timeout The amount of time to give NFD to respond to *each* registration request.
158 *
159 * Registers the prefixes in NFD that NLSR needs to route with a
160 * neighbor. The timeout given is how long to set the timeout for
161 * *each* registration request that is made.
162 */
163 void
164 registerAdjacencyPrefixes(const Adjacent& adj,
165 const ndn::time::milliseconds& timeout);
166
akmhoquee1765152014-06-30 11:32:01 -0500167 void
akmhoquec04e7272014-07-02 11:00:14 -0500168 setStrategies();
akmhoque157b0a42014-05-13 00:26:37 -0500169
akmhoque393d4ff2014-07-16 14:27:03 -0500170private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500171 /*! \brief Registers the prefix that NLSR will consider to be the machine-local, secure prefix.
172 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700173 void
alvy297f4162015-03-03 17:15:33 -0600174 registerLocalhostPrefix();
175
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500176 /*! \brief Registers the <router-prefix>/nlsr so that NLSR can respond to status requests from remote routers.
177 */
178 void
179 registerRouterPrefix();
180
Nick Gordond0a7df32017-05-30 16:44:34 -0500181 /*! \brief Do nothing.
182 */
akmhoquee1765152014-06-30 11:32:01 -0500183 void
akmhoquec04e7272014-07-02 11:00:14 -0500184 onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
akmhoquee1765152014-06-30 11:32:01 -0500185
Vince Lehman7b616582014-10-17 16:25:39 -0500186 void
Nick Gordond5c1a372016-10-31 13:56:23 -0500187 scheduleDatasetFetch();
188
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500189 /*! \brief Enables NextHopFaceId indication in NFD for incoming data packet.
190 *
191 * After enabling, when NFD gets a data packet, it will put the incoming face id
192 * of the data in NextHopFaceId field of the packet. The NextHopFaceId will be used
193 * by DirectFetcher to fetch the certificates needed to validate the data packet.
194 * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2#Consumer-Controlled-Forwarding
195 */
196 void
197 enableIncomingFaceIdIndication();
198
199 void
200 onFaceIdIndicationSuccess(const ndn::nfd::ControlParameters& cp);
201
202 void
203 onFaceIdIndicationFailure(const ndn::nfd::ControlResponse& cr);
204
alvy297f4162015-03-03 17:15:33 -0600205public:
206 static const ndn::Name LOCALHOST_PREFIX;
207
akmhoque157b0a42014-05-13 00:26:37 -0500208private:
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600209 ndn::Face& m_face;
210 ndn::Scheduler m_scheduler;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500211 ndn::security::v2::KeyChain& m_keyChain;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600212 ConfParameter& m_confParam;
213 AdjacencyList& m_adjacencyList;
214 NamePrefixList& m_namePrefixList;
215 bool m_isDaemonProcess;
216 ndn::security::ValidatorConfig& m_validator;
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500217 std::vector<ndn::Name> m_strategySetOnRouters;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700218
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500219PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600220 Fib m_fib;
221 RoutingTable m_routingTable;
222 NamePrefixTable m_namePrefixTable;
223 Lsdb m_lsdb;
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500224 HelloProtocol m_helloProtocol;
Vince Lehmanf7eec4f2015-05-08 19:02:31 -0500225
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600226private:
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500227 ndn::util::signal::ScopedConnection m_onNewLsaConnection;
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500228 ndn::util::signal::ScopedConnection m_onPrefixRegistrationSuccess;
229 ndn::util::signal::ScopedConnection m_onHelloDataValidated;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600230
231PUBLIC_WITH_TESTS_ELSE_PRIVATE:
232 ndn::mgmt::Dispatcher m_dispatcher;
233 DatasetInterestHandler m_datasetHandler;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500234
Vince Lehman7b616582014-10-17 16:25:39 -0500235private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500236 /*! \brief Where NLSR stores certificates it claims to be
237 * authoritative for. Usually the router certificate.
238 */
Nick Gordond5c1a372016-10-31 13:56:23 -0500239
Nick Gordond5c1a372016-10-31 13:56:23 -0500240 ndn::nfd::Controller m_controller;
241 ndn::nfd::Controller m_faceDatasetController;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600242
243PUBLIC_WITH_TESTS_ELSE_PRIVATE:
alvy297f4162015-03-03 17:15:33 -0600244 update::PrefixUpdateProcessor m_prefixUpdateProcessor;
Nick Gordon4d2c6c02017-01-20 13:18:46 -0600245 update::NfdRibCommandProcessor m_nfdRibCommandProcessor;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600246
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -0600247 StatsCollector m_statsCollector;
akmhoquee1765152014-06-30 11:32:01 -0500248
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600249private:
akmhoque060d3022014-08-12 13:35:06 -0500250 ndn::nfd::FaceMonitor m_faceMonitor;
Vince Lehman7b616582014-10-17 16:25:39 -0500251
Nick Gordond5c1a372016-10-31 13:56:23 -0500252 friend class NlsrRunner;
akmhoque53353462014-04-22 08:43:45 -0500253};
akmhoque298385a2014-02-13 14:13:09 -0600254
Nick Gordonfad8e252016-08-11 14:21:38 -0500255} // namespace nlsr
akmhoqueb1710aa2014-02-19 17:13:36 -0600256
dmcoomes9f936662017-03-02 10:33:09 -0600257#endif // NLSR_NLSR_HPP