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-2023, 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 "conf-parameter.hpp"
27 #include "hello-protocol.hpp"
28 #include "lsdb.hpp"
29 #include "name-prefix-list.hpp"
30 #include "test-access-control.hpp"
32 #include "route/fib.hpp"
34 #include "route/routing-table.hpp"
37 #include "utility/name-helper.hpp"
38 #include "stats-collector.hpp"
39 
40 #include <ndn-cxx/face.hpp>
41 #include <ndn-cxx/encoding/nfd-constants.hpp>
42 #include <ndn-cxx/mgmt/dispatcher.hpp>
43 #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
44 #include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
45 #include <ndn-cxx/mgmt/nfd/face-status.hpp>
46 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
47 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
48 #include <ndn-cxx/security/key-chain.hpp>
49 #include <ndn-cxx/util/scheduler.hpp>
50 
51 namespace nlsr {
52 
53 class Nlsr
54 {
55 public:
56  using FetchDatasetCallback = std::function<void(const std::vector<ndn::nfd::FaceStatus>&)>;
57  using FetchDatasetTimeoutCallback = std::function<void(uint32_t, const std::string&)>;
58 
59  class Error : public std::runtime_error
60  {
61  public:
62  using std::runtime_error::runtime_error;
63  };
64 
65  Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam);
66 
67  Lsdb&
69  {
70  return m_lsdb;
71  }
72 
73  Fib&
75  {
76  return m_fib;
77  }
78 
79 private:
80  void
81  registerStrategyForCerts(const ndn::Name& originRouter);
82 
88  void
89  addDispatcherTopPrefix(const ndn::Name& topPrefix);
90 
102  void
103  initializeFaces(const FetchDatasetCallback& onFetchSuccess,
104  const FetchDatasetTimeoutCallback& onFetchFailure);
105 
106  void
107  onFaceDatasetFetchTimeout(uint32_t code,
108  const std::string& reason,
109  uint32_t nRetriesSoFar);
110 
121  void
122  processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces);
123 
124 private:
134  void
135  registerAdjacencyPrefixes(const Adjacent& adj, ndn::time::milliseconds timeout);
136 
139  void
140  registerPrefix(const ndn::Name& prefix);
141 
144  void
145  onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
146 
147  void
148  scheduleDatasetFetch();
149 
157  void
158  enableIncomingFaceIdIndication();
159 
160 public:
161  static inline const ndn::Name LOCALHOST_PREFIX{"/localhost/nlsr"};
162 
163 private:
164  ndn::Face& m_face;
165  ndn::Scheduler m_scheduler;
166  ConfParameter& m_confParam;
167  AdjacencyList& m_adjacencyList;
168  NamePrefixList& m_namePrefixList;
169  std::vector<ndn::Name> m_strategySetOnRouters;
170 
172  Fib m_fib;
173  Lsdb m_lsdb;
174  RoutingTable m_routingTable;
175  NamePrefixTable m_namePrefixTable;
176  HelloProtocol m_helloProtocol;
177 
178 private:
179  ndn::signal::ScopedConnection m_onNewLsaConnection;
180  ndn::signal::ScopedConnection m_onPrefixRegistrationSuccess;
181  ndn::signal::ScopedConnection m_onInitialHelloDataValidated;
182 
184  ndn::mgmt::Dispatcher m_dispatcher;
185  DatasetInterestHandler m_datasetHandler;
186 
187 private:
192  ndn::nfd::Controller m_controller;
193  ndn::nfd::Controller m_faceDatasetController;
194 
196  update::PrefixUpdateProcessor m_prefixUpdateProcessor;
197  update::NfdRibCommandProcessor m_nfdRibCommandProcessor;
198 
199  StatsCollector m_statsCollector;
200 
201 private:
202  ndn::nfd::FaceMonitor m_faceMonitor;
203 };
204 
205 } // namespace nlsr
206 
207 #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:63
Fib & getFib()
Definition: nlsr.hpp:74
Nlsr(ndn::Face &face, ndn::KeyChain &keyChain, ConfParameter &confParam)
Definition: nlsr.cpp:37
static const ndn::Name LOCALHOST_PREFIX
Definition: nlsr.hpp:161
Lsdb & getLsdb()
Definition: nlsr.hpp:68
std::function< void(const std::vector< ndn::nfd::FaceStatus > &)> FetchDatasetCallback
Definition: nlsr.hpp:56
std::function< void(uint32_t, const std::string &)> FetchDatasetTimeoutCallback
Definition: nlsr.hpp:57
a class designed to handle statistical signals in nlsr
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE