rib-manager.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2024, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef NFD_DAEMON_MGMT_RIB_MANAGER_HPP
27 #define NFD_DAEMON_MGMT_RIB_MANAGER_HPP
28 
29 #include "manager-base.hpp"
30 #include "rib/route.hpp"
31 
32 #include <ndn-cxx/mgmt/nfd/controller.hpp>
33 #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
34 #include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
35 #include <ndn-cxx/mgmt/nfd/face-status.hpp>
36 #include <ndn-cxx/security/validator-config.hpp>
37 #include <ndn-cxx/util/scheduler.hpp>
38 
39 namespace nfd {
40 
41 namespace rib {
42 class Rib;
43 class RibUpdate;
44 } // namespace rib
45 
50 class RibManager final : public ManagerBase
51 {
52 public:
53  RibManager(rib::Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
54  ndn::nfd::Controller& nfdController, Dispatcher& dispatcher);
55 
59  void
60  applyLocalhostConfig(const ConfigSection& section, const std::string& filename);
61 
66  void
67  enableLocalhop(const ConfigSection& section, const std::string& filename);
68 
72  void
74 
78  void
79  applyPaConfig(const ConfigSection& section, const std::string& filename);
80 
84  void
86 
90  void
92 
93 public: // self-learning support
94  enum class SlAnnounceResult {
95  OK,
96  ERROR,
98  EXPIRED,
99  NOT_FOUND,
100  };
101 
102  using SlAnnounceCallback = std::function<void(SlAnnounceResult res)>;
103  using SlFindAnnCallback = std::function<void(std::optional<ndn::PrefixAnnouncement>)>;
104 
122  void
123  slAnnounce(const ndn::PrefixAnnouncement& pa, uint64_t faceId, time::milliseconds maxLifetime,
124  const SlAnnounceCallback& cb);
125 
144  void
145  slRenew(const Name& name, uint64_t faceId, time::milliseconds maxLifetime,
146  const SlAnnounceCallback& cb);
147 
159  void
160  slFindAnn(const Name& name, const SlFindAnnCallback& cb) const;
161 
162 private: // RIB and FibUpdater actions
163  enum class RibUpdateResult
164  {
165  OK,
166  ERROR,
167  EXPIRED,
168  };
169 
170  static SlAnnounceResult
171  getSlAnnounceResultFromRibUpdateResult(RibUpdateResult r);
172 
179  void
180  beginAddRoute(const Name& name, rib::Route route, std::optional<time::nanoseconds> expires,
181  const std::function<void(RibUpdateResult)>& done);
182 
188  void
189  beginRemoveRoute(const Name& name, const rib::Route& route,
190  const std::function<void(RibUpdateResult)>& done);
191 
192  void
193  beginRibUpdate(const rib::RibUpdate& update,
194  const std::function<void(RibUpdateResult)>& done);
195 
196 private: // management Dispatcher related
197  void
198  registerTopPrefix(const Name& topPrefix);
199 
202  void
203  registerEntry(const Interest& interest, ControlParameters parameters,
204  const ndn::mgmt::CommandContinuation& done);
205 
208  void
209  unregisterEntry(const Interest& interest, ControlParameters parameters,
210  const ndn::mgmt::CommandContinuation& done);
211 
214  void
215  listEntries(ndn::mgmt::StatusDatasetContext& context);
216 
217  void
218  setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
219 
220  ndn::mgmt::Authorization
221  makeAuthorization(const std::string& verb) final;
222 
223 private: // Face monitor
224  void
225  fetchActiveFaces();
226 
227  void
228  onFetchActiveFacesFailure(uint32_t code, const std::string& reason);
229 
231  void
232  scheduleActiveFaceFetch(const time::seconds& timeToWait);
233 
234  void
235  removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces);
236 
237  void
238  onNotification(const ndn::nfd::FaceEventNotification& notification);
239 
240 public:
241  static inline const Name LOCALHOP_TOP_PREFIX{"/localhop/nfd"};
242 
243 private:
244  rib::Rib& m_rib;
245  ndn::KeyChain& m_keyChain;
246  ndn::nfd::Controller& m_nfdController;
247  Dispatcher& m_dispatcher;
248 
249  ndn::nfd::FaceMonitor m_faceMonitor;
250  ndn::ValidatorConfig m_localhostValidator;
251  ndn::ValidatorConfig m_localhopValidator;
252  ndn::ValidatorConfig m_paValidator;
253  bool m_isLocalhopEnabled;
254 
255  ndn::scheduler::ScopedEventId m_activeFaceFetchEvent;
256 };
257 
258 std::ostream&
259 operator<<(std::ostream& os, RibManager::SlAnnounceResult res);
260 
261 } // namespace nfd
262 
263 #endif // NFD_DAEMON_MGMT_RIB_MANAGER_HPP
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
Implements the RIB Management of NFD Management Protocol.
Definition: rib-manager.hpp:51
void slRenew(const Name &name, uint64_t faceId, time::milliseconds maxLifetime, const SlAnnounceCallback &cb)
Renew a route created by prefix announcement from self-learning strategy.
std::function< void(SlAnnounceResult res)> SlAnnounceCallback
void registerWithNfd()
Start accepting commands and dataset requests.
Definition: rib-manager.cpp:98
void disableLocalhop()
Disallow accepting commands on /localhop/nfd/rib prefix.
Definition: rib-manager.cpp:86
RibManager(rib::Rib &rib, ndn::Face &face, ndn::KeyChain &keyChain, ndn::nfd::Controller &nfdController, Dispatcher &dispatcher)
Definition: rib-manager.cpp:51
static const Name LOCALHOP_TOP_PREFIX
void applyLocalhostConfig(const ConfigSection &section, const std::string &filename)
Apply localhost_security configuration.
Definition: rib-manager.cpp:73
void enableLocalhop(const ConfigSection &section, const std::string &filename)
Apply localhop_security configuration and allow accepting commands on /localhop/nfd/rib prefix.
Definition: rib-manager.cpp:79
void slAnnounce(const ndn::PrefixAnnouncement &pa, uint64_t faceId, time::milliseconds maxLifetime, const SlAnnounceCallback &cb)
Insert a route by prefix announcement from self-learning strategy.
std::function< void(std::optional< ndn::PrefixAnnouncement >)> SlFindAnnCallback
@ VALIDATION_FAILURE
the announcement cannot be verified against the trust schema
@ EXPIRED
the announcement has expired
@ NOT_FOUND
route does not exist (slRenew only)
@ OK
RIB and FIB have been updated.
void enableLocalFields()
Enable NDNLP IncomingFaceId field in order to support self-registration commands.
void slFindAnn(const Name &name, const SlFindAnnCallback &cb) const
Retrieve an outgoing prefix announcement for self-learning strategy.
void applyPaConfig(const ConfigSection &section, const std::string &filename)
Apply prefix_announcement_validation configuration.
Definition: rib-manager.cpp:92
Represents the Routing Information Base.
Definition: rib.hpp:70
Represents a route that will be added to or removed from a namespace.
Definition: rib-update.hpp:39
Represents a route for a name prefix.
Definition: route.hpp:44
#define NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
-status-http-server
Definition: common.hpp:71
boost::property_tree::ptree ConfigSection
A configuration file section.
Definition: config-file.hpp:41
std::ostream & operator<<(std::ostream &os, const Network &network)
Definition: network.cpp:83