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"
39 #include "utility/name-helper.hpp"
40 #include "stats-collector.hpp"
41 
42 #include <boost/cstdint.hpp>
43 #include <stdexcept>
44 #include <boost/throw_exception.hpp>
45 
46 #include <ndn-cxx/face.hpp>
47 #include <ndn-cxx/security/key-chain.hpp>
48 #include <ndn-cxx/security/validator-config.hpp>
49 #include <ndn-cxx/security/v2/certificate-fetcher-direct-fetch.hpp>
50 #include <ndn-cxx/security/signing-helpers.hpp>
51 #include <ndn-cxx/security/signing-info.hpp>
52 #include <ndn-cxx/util/scheduler.hpp>
53 #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
54 #include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
55 #include <ndn-cxx/mgmt/dispatcher.hpp>
56 #include <ndn-cxx/mgmt/nfd/face-status.hpp>
57 #include <ndn-cxx/data.hpp>
58 #include <ndn-cxx/encoding/block.hpp>
59 #include <ndn-cxx/encoding/nfd-constants.hpp>
60 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
61 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
62 
63 namespace nlsr {
64 
65 static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast");
66 
67 class Nlsr
68 {
69 public:
70  using FetchDatasetCallback = std::function<void(const std::vector<ndn::nfd::FaceStatus>&)>;
71  using FetchDatasetTimeoutCallback = std::function<void(uint32_t, const std::string&)>;
72 
73  class Error : public std::runtime_error
74  {
75  public:
76  explicit
77  Error(const std::string& what)
78  : std::runtime_error(what)
79  {
80  }
81  };
82 
83  Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam);
84 
85  void
86  registrationFailed(const ndn::Name& name);
87 
88  void
89  onRegistrationSuccess(const ndn::Name& name);
90 
91  void
93 
94  void
96 
102  void
103  addDispatcherTopPrefix(const ndn::Name& topPrefix);
104 
105  Fib&
107  {
108  return m_fib;
109  }
110 
111  void
112  initialize();
113 
124  void
125  initializeFaces(const FetchDatasetCallback& onFetchSuccess,
126  const FetchDatasetTimeoutCallback& onFetchFailure);
127 
128  void
129  onFaceDatasetFetchTimeout(uint32_t code,
130  const std::string& reason,
131  uint32_t nRetriesSoFar);
132 
143  void
144  processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces);
145 
155  void
157  const ndn::time::milliseconds& timeout);
158 
163  void
164  loadCertToPublish(const ndn::security::v2::Certificate& certificate);
165 
168  void
169  afterFetcherSignalEmitted(const ndn::Data& lsaSegment);
170 
175  void
176  publishCertFromCache(const ndn::Name& keyName);
177 
178  void
179  initializeKey();
180 
189  const ndn::security::v2::Certificate*
190  getCertificate(const ndn::Name& certificateKeyName)
191  {
192  const ndn::security::v2::Certificate* cert =
193  m_certStore.find(certificateKeyName);
194 
195  return cert;
196  }
197 
198  void
199  setStrategies();
200 
202 
204  getCertificateStore()
205  {
206  return m_certStore;
207  }
208 
209 private:
212  void
213  registerKeyPrefix();
214 
217  void
218  registerLocalhostPrefix();
219 
222  void
223  registerRouterPrefix();
224 
227  void
228  onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
229 
232  void
233  onKeyPrefixRegSuccess(const ndn::Name& name);
234 
237  void
238  onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
239 
240  void
241  scheduleDatasetFetch();
242 
250  void
251  enableIncomingFaceIdIndication();
252 
253  void
254  onFaceIdIndicationSuccess(const ndn::nfd::ControlParameters& cp);
255 
256  void
257  onFaceIdIndicationFailure(const ndn::nfd::ControlResponse& cr);
258 
259 public:
260  static const ndn::Name LOCALHOST_PREFIX;
261 
262 private:
263  ndn::Face& m_face;
264  ndn::Scheduler m_scheduler;
265  ndn::security::v2::KeyChain& m_keyChain;
266  ConfParameter& m_confParam;
267  AdjacencyList& m_adjacencyList;
268  NamePrefixList& m_namePrefixList;
269  bool m_isDaemonProcess;
270  ndn::security::ValidatorConfig& m_validator;
271 
273  Fib m_fib;
274  RoutingTable m_routingTable;
275  NamePrefixTable m_namePrefixTable;
276  Lsdb m_lsdb;
277 
278 private:
279  ndn::util::signal::ScopedConnection m_afterSegmentValidatedConnection;
280 
282  ndn::mgmt::Dispatcher m_dispatcher;
283  DatasetInterestHandler m_datasetHandler;
284  HelloProtocol m_helloProtocol;
285 
286 private:
290  security::CertificateStore& m_certStore;
291 
292  ndn::nfd::Controller m_controller;
293  ndn::nfd::Controller m_faceDatasetController;
294 
296  ndn::security::SigningInfo m_signingInfo;
297  update::PrefixUpdateProcessor m_prefixUpdateProcessor;
298  update::NfdRibCommandProcessor m_nfdRibCommandProcessor;
299 
300  StatsCollector m_statsCollector;
301 
302 private:
303  ndn::nfd::FaceMonitor m_faceMonitor;
304 
305  friend class NlsrRunner;
306 };
307 
308 } // namespace nlsr
309 
310 #endif // NLSR_NLSR_HPP
void initializeFaces(const FetchDatasetCallback &onFetchSuccess, const FetchDatasetTimeoutCallback &onFetchFailure)
Initializes neighbors&#39; Faces using information from NFD.
Definition: nlsr.cpp:472
void onFaceDatasetFetchTimeout(uint32_t code, const std::string &reason, uint32_t nRetriesSoFar)
Definition: nlsr.cpp:536
A class to house all the configuration parameters for NLSR.
Class to publish all dataset.
void initialize()
Definition: nlsr.cpp:195
std::function< void(uint32_t, const std::string &)> FetchDatasetTimeoutCallback
Definition: nlsr.hpp:71
Store certificates for names.
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
A wrapper class to instantiate and configure an NLSR object.
Definition: nlsr-runner.hpp:41
void setStrategies()
Definition: nlsr.cpp:136
Error(const std::string &what)
Definition: nlsr.hpp:77
STL namespace.
std::function< void(const std::vector< ndn::nfd::FaceStatus > &)> FetchDatasetCallback
Definition: nlsr.hpp:70
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:53
void setLsaInterestFilter()
Definition: nlsr.cpp:110
void addDispatcherTopPrefix(const ndn::Name &topPrefix)
Add top level prefixes for Dispatcher.
Definition: nlsr.cpp:124
static const ndn::Name LOCALHOST_PREFIX
Definition: nlsr.hpp:260
void registerAdjacencyPrefixes(const Adjacent &adj, const ndn::time::milliseconds &timeout)
Registers NLSR-specific prefixes for a neighbor (Adjacent)
Definition: nlsr.cpp:516
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
void onRegistrationSuccess(const ndn::Name &name)
Definition: nlsr.cpp:88
void loadCertToPublish(const ndn::security::v2::Certificate &certificate)
Add a certificate NLSR claims to be authoritative for to the certificate store.
Definition: nlsr.cpp:145
void publishCertFromCache(const ndn::Name &keyName)
Retrieves the chain of certificates from Validator&#39;s cache and store them in Nlsr&#39;s own CertificateSt...
Definition: nlsr.cpp:170
void setInfoInterestFilter()
Definition: nlsr.cpp:94
void afterFetcherSignalEmitted(const ndn::Data &lsaSegment)
Callback when SegmentFetcher retrieves a segment.
Definition: nlsr.cpp:157
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 registrationFailed(const ndn::Name &name)
Definition: nlsr.cpp:81
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
const ndn::security::v2::Certificate * getCertificate(const ndn::Name &certificateKeyName)
Find a certificate.
Definition: nlsr.hpp:190
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:482
Fib & getFib()
Definition: nlsr.hpp:106
void initializeKey()
Definition: nlsr.cpp:246