nlsr.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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 <boost/cstdint.hpp>
42 #include <stdexcept>
43 #include <boost/throw_exception.hpp>
44 
45 #include <ndn-cxx/face.hpp>
46 #include <ndn-cxx/security/key-chain.hpp>
47 #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>
51 #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>
58 #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>
61 
62 namespace nlsr {
63 
64 static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast");
65 
66 class Nlsr
67 {
68 public:
69  using FetchDatasetCallback = std::function<void(const std::vector<ndn::nfd::FaceStatus>&)>;
70  using FetchDatasetTimeoutCallback = std::function<void(uint32_t, const std::string&)>;
71 
72  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 
82  Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam);
83 
84  void
85  registerStrategyForCerts(const ndn::Name& originRouter);
86 
87  void
88  registrationFailed(const ndn::Name& name);
89 
90  void
91  onRegistrationSuccess(const ndn::Name& name);
92 
93  void
95 
96  void
98 
104  void
105  addDispatcherTopPrefix(const ndn::Name& topPrefix);
106 
107  Lsdb&
109  {
110  return m_lsdb;
111  }
112 
113  Fib&
115  {
116  return m_fib;
117  }
118 
119  void
120  initialize();
121 
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 
151  void
152  processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces);
153 
163  void
165  const ndn::time::milliseconds& timeout);
166 
167  void
168  setStrategies();
169 
170 private:
173  void
174  registerLocalhostPrefix();
175 
178  void
179  registerRouterPrefix();
180 
183  void
184  onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
185 
186  void
187  scheduleDatasetFetch();
188 
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 
205 public:
206  static const ndn::Name LOCALHOST_PREFIX;
207 
208 private:
209  ndn::Face& m_face;
210  ndn::Scheduler m_scheduler;
211  ndn::security::v2::KeyChain& m_keyChain;
212  ConfParameter& m_confParam;
213  AdjacencyList& m_adjacencyList;
214  NamePrefixList& m_namePrefixList;
215  bool m_isDaemonProcess;
216  ndn::security::ValidatorConfig& m_validator;
217  std::vector<ndn::Name> m_strategySetOnRouters;
218 
220  Fib m_fib;
221  RoutingTable m_routingTable;
222  NamePrefixTable m_namePrefixTable;
223  Lsdb m_lsdb;
224  HelloProtocol m_helloProtocol;
225 
226 private:
227  ndn::util::signal::ScopedConnection m_onNewLsaConnection;
228  ndn::util::signal::ScopedConnection m_onPrefixRegistrationSuccess;
229  ndn::util::signal::ScopedConnection m_onHelloDataValidated;
230 
232  ndn::mgmt::Dispatcher m_dispatcher;
233  DatasetInterestHandler m_datasetHandler;
234 
235 private:
240  ndn::nfd::Controller m_controller;
241  ndn::nfd::Controller m_faceDatasetController;
242 
244  update::PrefixUpdateProcessor m_prefixUpdateProcessor;
245  update::NfdRibCommandProcessor m_nfdRibCommandProcessor;
246 
247  StatsCollector m_statsCollector;
248 
249 private:
250  ndn::nfd::FaceMonitor m_faceMonitor;
251 
252  friend class NlsrRunner;
253 };
254 
255 } // namespace nlsr
256 
257 #endif // NLSR_NLSR_HPP
void initializeFaces(const FetchDatasetCallback &onFetchSuccess, const FetchDatasetTimeoutCallback &onFetchFailure)
Initializes neighbors&#39; Faces using information from NFD.
Definition: nlsr.cpp:342
void onFaceDatasetFetchTimeout(uint32_t code, const std::string &reason, uint32_t nRetriesSoFar)
Definition: nlsr.cpp:402
A class to house all the configuration parameters for NLSR.
Class to publish all dataset.
void initialize()
Definition: nlsr.cpp:218
std::function< void(uint32_t, const std::string &)> FetchDatasetTimeoutCallback
Definition: nlsr.hpp:70
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
void setStrategies()
Definition: nlsr.cpp:211
Error(const std::string &what)
Definition: nlsr.hpp:76
STL namespace.
std::function< void(const std::vector< ndn::nfd::FaceStatus > &)> FetchDatasetCallback
Definition: nlsr.hpp:69
Nlsr(ndn::Face &face, ndn::KeyChain &keyChain, ConfParameter &confParam)
Definition: nlsr.cpp:42
Maps names to lists of next hops, and exports this information to NFD.
Definition: fib.hpp:52
void setLsaInterestFilter()
Definition: nlsr.cpp:185
void addDispatcherTopPrefix(const ndn::Name &topPrefix)
Add top level prefixes for Dispatcher.
Definition: nlsr.cpp:199
static const ndn::Name LOCALHOST_PREFIX
Definition: nlsr.hpp:206
void registerAdjacencyPrefixes(const Adjacent &adj, const ndn::time::milliseconds &timeout)
Registers NLSR-specific prefixes for a neighbor (Adjacent)
Definition: nlsr.cpp:386
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
void onRegistrationSuccess(const ndn::Name &name)
Definition: nlsr.cpp:163
void setInfoInterestFilter()
Definition: nlsr.cpp:169
A neighbor reachable over a Face.
Definition: adjacent.hpp:38
Copyright (c) 2014-2019, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
void registerStrategyForCerts(const ndn::Name &originRouter)
Definition: nlsr.cpp:121
void registrationFailed(const ndn::Name &name)
Definition: nlsr.cpp:156
Copyright (c) 2014-2019, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Lsdb & getLsdb()
Definition: nlsr.hpp:108
friend class NlsrRunner
Definition: nlsr.hpp:252
static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast")
void processFaceDataset(const std::vector< ndn::nfd::FaceStatus > &faces)
Consumes a Face StatusDataset to configure NLSR neighbors.
Definition: nlsr.cpp:352
Fib & getFib()
Definition: nlsr.hpp:114