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  registerStrategyForCerts(const ndn::Name& originRouter);
87 
88  void
89  registrationFailed(const ndn::Name& name);
90 
91  void
92  onRegistrationSuccess(const ndn::Name& name);
93 
94  void
96 
97  void
99 
105  void
106  addDispatcherTopPrefix(const ndn::Name& topPrefix);
107 
108  Fib&
110  {
111  return m_fib;
112  }
113 
114  void
115  initialize();
116 
127  void
128  initializeFaces(const FetchDatasetCallback& onFetchSuccess,
129  const FetchDatasetTimeoutCallback& onFetchFailure);
130 
131  void
132  onFaceDatasetFetchTimeout(uint32_t code,
133  const std::string& reason,
134  uint32_t nRetriesSoFar);
135 
146  void
147  processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces);
148 
158  void
160  const ndn::time::milliseconds& timeout);
161 
166  void
167  loadCertToPublish(const ndn::security::v2::Certificate& certificate);
168 
171  void
172  afterFetcherSignalEmitted(const ndn::Data& lsaSegment);
173 
178  void
179  publishCertFromCache(const ndn::Name& keyName);
180 
181  void
182  initializeKey();
183 
192  const ndn::security::v2::Certificate*
193  getCertificate(const ndn::Name& certificateKeyName)
194  {
195  const ndn::security::v2::Certificate* cert =
196  m_certStore.find(certificateKeyName);
197 
198  return cert;
199  }
200 
201  void
202  setStrategies();
203 
205 
207  getCertificateStore()
208  {
209  return m_certStore;
210  }
211 
212 private:
215  void
216  registerKeyPrefix();
217 
220  void
221  registerLocalhostPrefix();
222 
225  void
226  registerRouterPrefix();
227 
230  void
231  onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
232 
235  void
236  onKeyPrefixRegSuccess(const ndn::Name& name);
237 
240  void
241  onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
242 
243  void
244  scheduleDatasetFetch();
245 
253  void
254  enableIncomingFaceIdIndication();
255 
256  void
257  onFaceIdIndicationSuccess(const ndn::nfd::ControlParameters& cp);
258 
259  void
260  onFaceIdIndicationFailure(const ndn::nfd::ControlResponse& cr);
261 
262 public:
263  static const ndn::Name LOCALHOST_PREFIX;
264 
265 private:
266  ndn::Face& m_face;
267  ndn::Scheduler m_scheduler;
268  ndn::security::v2::KeyChain& m_keyChain;
269  ConfParameter& m_confParam;
270  AdjacencyList& m_adjacencyList;
271  NamePrefixList& m_namePrefixList;
272  bool m_isDaemonProcess;
273  ndn::security::ValidatorConfig& m_validator;
274  std::vector<ndn::Name> m_strategySetOnRouters;
275  uint16_t m_numSyncPrefixRegistered = 0;
276 
278  Fib m_fib;
279  RoutingTable m_routingTable;
280  NamePrefixTable m_namePrefixTable;
281  Lsdb m_lsdb;
282  HelloProtocol m_helloProtocol;
283 
284 private:
285  ndn::util::signal::ScopedConnection m_afterSegmentValidatedConnection;
286  ndn::util::signal::ScopedConnection m_onNewLsaConnection;
287  ndn::util::signal::ScopedConnection m_onPrefixRegistrationSuccess;
288  ndn::util::signal::ScopedConnection m_onHelloDataValidated;
289 
291  ndn::mgmt::Dispatcher m_dispatcher;
292  DatasetInterestHandler m_datasetHandler;
293 
294 private:
298  security::CertificateStore& m_certStore;
299 
300  ndn::nfd::Controller m_controller;
301  ndn::nfd::Controller m_faceDatasetController;
302 
304  ndn::security::SigningInfo m_signingInfo;
305  update::PrefixUpdateProcessor m_prefixUpdateProcessor;
306  update::NfdRibCommandProcessor m_nfdRibCommandProcessor;
307 
308  StatsCollector m_statsCollector;
309 
310 private:
311  ndn::nfd::FaceMonitor m_faceMonitor;
312 
313  friend class NlsrRunner;
314 };
315 
316 } // namespace nlsr
317 
318 #endif // NLSR_NLSR_HPP
void initializeFaces(const FetchDatasetCallback &onFetchSuccess, const FetchDatasetTimeoutCallback &onFetchFailure)
Initializes neighbors&#39; Faces using information from NFD.
Definition: nlsr.cpp:531
void onFaceDatasetFetchTimeout(uint32_t code, const std::string &reason, uint32_t nRetriesSoFar)
Definition: nlsr.cpp:591
A class to house all the configuration parameters for NLSR.
Class to publish all dataset.
void initialize()
Definition: nlsr.cpp:276
std::function< void(uint32_t, const std::string &)> FetchDatasetTimeoutCallback
Definition: nlsr.hpp:71
Store certificates for names.
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
void setStrategies()
Definition: nlsr.cpp:217
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:52
void setLsaInterestFilter()
Definition: nlsr.cpp:191
void addDispatcherTopPrefix(const ndn::Name &topPrefix)
Add top level prefixes for Dispatcher.
Definition: nlsr.cpp:205
static const ndn::Name LOCALHOST_PREFIX
Definition: nlsr.hpp:263
void registerAdjacencyPrefixes(const Adjacent &adj, const ndn::time::milliseconds &timeout)
Registers NLSR-specific prefixes for a neighbor (Adjacent)
Definition: nlsr.cpp:575
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
void onRegistrationSuccess(const ndn::Name &name)
Definition: nlsr.cpp:169
void loadCertToPublish(const ndn::security::v2::Certificate &certificate)
Add a certificate NLSR claims to be authoritative for to the certificate store.
Definition: nlsr.cpp:224
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:249
void setInfoInterestFilter()
Definition: nlsr.cpp:175
void afterFetcherSignalEmitted(const ndn::Data &lsaSegment)
Callback when SegmentFetcher retrieves a segment.
Definition: nlsr.cpp:236
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:127
void registrationFailed(const ndn::Name &name)
Definition: nlsr.cpp:162
Copyright (c) 2014-2019, 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:193
friend class NlsrRunner
Definition: nlsr.hpp:313
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:541
Fib & getFib()
Definition: nlsr.hpp:109
void initializeKey()
Definition: nlsr.cpp:298