nlsr.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2021, The University of Memphis,
4  * Regents of the University of California,
5  * Arizona Board of Regents.
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/>.
20  */
21 
22 #ifndef NLSR_NLSR_HPP
23 #define NLSR_NLSR_HPP
24 
25 #include "adjacency-list.hpp"
26 #include "common.hpp"
27 #include "conf-parameter.hpp"
28 #include "hello-protocol.hpp"
29 #include "lsdb.hpp"
30 #include "name-prefix-list.hpp"
31 #include "test-access-control.hpp"
33 #include "route/fib.hpp"
35 #include "route/routing-table.hpp"
38 #include "utility/name-helper.hpp"
39 #include "stats-collector.hpp"
40 
41 #include <ndn-cxx/face.hpp>
42 #include <ndn-cxx/security/key-chain.hpp>
43 #include <ndn-cxx/security/certificate-fetcher-direct-fetch.hpp>
44 #include <ndn-cxx/security/signing-helpers.hpp>
45 #include <ndn-cxx/security/signing-info.hpp>
46 #include <ndn-cxx/util/scheduler.hpp>
47 #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
48 #include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
49 #include <ndn-cxx/mgmt/dispatcher.hpp>
50 #include <ndn-cxx/mgmt/nfd/face-status.hpp>
51 #include <ndn-cxx/data.hpp>
52 #include <ndn-cxx/encoding/block.hpp>
53 #include <ndn-cxx/encoding/nfd-constants.hpp>
54 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
55 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
56 
57 namespace nlsr {
58 
59 class Nlsr
60 {
61 public:
62  using FetchDatasetCallback = std::function<void(const std::vector<ndn::nfd::FaceStatus>&)>;
63  using FetchDatasetTimeoutCallback = std::function<void(uint32_t, const std::string&)>;
64 
65  class Error : public std::runtime_error
66  {
67  public:
68  using std::runtime_error::runtime_error;
69  };
70 
71  Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam);
72 
73  void
74  registerStrategyForCerts(const ndn::Name& originRouter);
75 
76  void
77  registrationFailed(const ndn::Name& name);
78 
79  void
80  onRegistrationSuccess(const ndn::Name& name);
81 
82  void
84 
90  void
91  addDispatcherTopPrefix(const ndn::Name& topPrefix);
92 
93  Lsdb&
95  {
96  return m_lsdb;
97  }
98 
99  Fib&
101  {
102  return m_fib;
103  }
104 
105  void
106  initialize();
107 
118  void
119  initializeFaces(const FetchDatasetCallback& onFetchSuccess,
120  const FetchDatasetTimeoutCallback& onFetchFailure);
121 
122  void
123  onFaceDatasetFetchTimeout(uint32_t code,
124  const std::string& reason,
125  uint32_t nRetriesSoFar);
126 
137  void
138  processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces);
139 
149  void
151  const ndn::time::milliseconds& timeout);
152 
153  void
154  setStrategies();
155 
156 private:
159  void
160  registerLocalhostPrefix();
161 
164  void
165  registerRouterPrefix();
166 
169  void
170  onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
171 
172  void
173  scheduleDatasetFetch();
174 
182  void
183  enableIncomingFaceIdIndication();
184 
185  void
186  onFaceIdIndicationSuccess(const ndn::nfd::ControlParameters& cp);
187 
188  void
189  onFaceIdIndicationFailure(const ndn::nfd::ControlResponse& cr);
190 
191 public:
192  static const ndn::Name LOCALHOST_PREFIX;
193 
194 private:
195  ndn::Face& m_face;
196  ndn::Scheduler m_scheduler;
197  ConfParameter& m_confParam;
198  AdjacencyList& m_adjacencyList;
199  NamePrefixList& m_namePrefixList;
200  std::vector<ndn::Name> m_strategySetOnRouters;
201 
203  Fib m_fib;
204  RoutingTable m_routingTable;
205  NamePrefixTable m_namePrefixTable;
206  Lsdb m_lsdb;
207  HelloProtocol m_helloProtocol;
208 
209 private:
210  ndn::util::signal::ScopedConnection m_onNewLsaConnection;
211  ndn::util::signal::ScopedConnection m_onPrefixRegistrationSuccess;
212  ndn::util::signal::ScopedConnection m_onHelloDataValidated;
213 
215  ndn::mgmt::Dispatcher m_dispatcher;
216  DatasetInterestHandler m_datasetHandler;
217 
218 private:
223  ndn::nfd::Controller m_controller;
224  ndn::nfd::Controller m_faceDatasetController;
225 
227  update::PrefixUpdateProcessor m_prefixUpdateProcessor;
228  update::NfdRibCommandProcessor m_nfdRibCommandProcessor;
229 
230  StatsCollector m_statsCollector;
231 
232 private:
233  ndn::nfd::FaceMonitor m_faceMonitor;
234 };
235 
236 } // namespace nlsr
237 
238 #endif // NLSR_NLSR_HPP
A neighbor reachable over a Face.
Definition: adjacent.hpp:47
A class to house all the configuration parameters for NLSR.
Class to publish all dataset.
Maps names to lists of next hops, and exports this information to NFD.
Definition: fib.hpp:60
void initialize()
Definition: nlsr.cpp:194
void initializeFaces(const FetchDatasetCallback &onFetchSuccess, const FetchDatasetTimeoutCallback &onFetchFailure)
Initializes neighbors' Faces using information from NFD.
Definition: nlsr.cpp:318
void setLsaInterestFilter()
Definition: nlsr.cpp:161
void registerAdjacencyPrefixes(const Adjacent &adj, const ndn::time::milliseconds &timeout)
Registers NLSR-specific prefixes for a neighbor (Adjacent)
Definition: nlsr.cpp:362
void onRegistrationSuccess(const ndn::Name &name)
Definition: nlsr.cpp:155
void processFaceDataset(const std::vector< ndn::nfd::FaceStatus > &faces)
Consumes a Face StatusDataset to configure NLSR neighbors.
Definition: nlsr.cpp:328
Fib & getFib()
Definition: nlsr.hpp:100
Nlsr(ndn::Face &face, ndn::KeyChain &keyChain, ConfParameter &confParam)
Definition: nlsr.cpp:38
static const ndn::Name LOCALHOST_PREFIX
Definition: nlsr.hpp:192
void setStrategies()
Definition: nlsr.cpp:187
Lsdb & getLsdb()
Definition: nlsr.hpp:94
std::function< void(const std::vector< ndn::nfd::FaceStatus > &)> FetchDatasetCallback
Definition: nlsr.hpp:62
void registrationFailed(const ndn::Name &name)
Definition: nlsr.cpp:148
void registerStrategyForCerts(const ndn::Name &originRouter)
Definition: nlsr.cpp:113
std::function< void(uint32_t, const std::string &)> FetchDatasetTimeoutCallback
Definition: nlsr.hpp:63
void addDispatcherTopPrefix(const ndn::Name &topPrefix)
Add top level prefixes for Dispatcher.
Definition: nlsr.cpp:175
void onFaceDatasetFetchTimeout(uint32_t code, const std::string &reason, uint32_t nRetriesSoFar)
Definition: nlsr.cpp:378
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California,...
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE