NFD: Named Data Networking Forwarding Daemon 24.07-28-gdcc0e6e0
Loading...
Searching...
No Matches
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-2025, 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
31#include <ndn-cxx/mgmt/nfd/controller.hpp>
32#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
33#include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
34#include <ndn-cxx/mgmt/nfd/face-status.hpp>
35#include <ndn-cxx/security/validator-config.hpp>
36#include <ndn-cxx/util/scheduler.hpp>
37
38namespace nfd {
39
40namespace rib {
41class Route;
42class Rib;
43struct RibUpdate;
44} // namespace rib
45
50class RibManager final : public ManagerBase
51{
52public:
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
93public: // 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
162private: // RIB update actions
163 enum class RibUpdateResult
164 {
165 OK,
166 ERROR,
167 EXPIRED,
168 };
169
170 static SlAnnounceResult
171 getSlAnnounceResultFromRibUpdateResult(RibUpdateResult r);
172
176 void
177 addRoute(const Name& name, rib::Route route, const time::steady_clock::time_point& now,
178 const std::function<void(RibUpdateResult)>& done = nullptr);
179
180 void
181 beginRibUpdate(const rib::RibUpdate& update,
182 const std::function<void(RibUpdateResult)>& done);
183
184private: // management Dispatcher related
185 void
186 registerTopPrefix(const Name& topPrefix);
187
191 void
192 registerEntry(const Interest& interest, ControlParameters parameters,
193 const CommandContinuation& done);
194
198 void
199 unregisterEntry(const Interest& interest, ControlParameters parameters,
200 const CommandContinuation& done);
201
205 void
206 announceEntry(const Interest& interest, const ndn::nfd::RibAnnounceParameters& parameters,
207 const CommandContinuation& done);
208
212 void
213 listEntries(ndn::mgmt::StatusDatasetContext& context) const;
214
215 ndn::mgmt::Authorization
216 makeAuthorization(const std::string& verb) final;
217
218private: // Face monitor
219 void
220 fetchActiveFaces();
221
223 void
224 scheduleActiveFaceFetch(time::seconds timeToWait);
225
226 void
227 removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces);
228
229 void
230 onNotification(const ndn::nfd::FaceEventNotification& notification);
231
232public:
233 static inline const Name LOCALHOP_TOP_PREFIX{"/localhop/nfd"};
234
235private:
236 rib::Rib& m_rib;
237 ndn::KeyChain& m_keyChain;
238 ndn::nfd::Controller& m_nfdController;
239 Dispatcher& m_dispatcher;
240
241 ndn::nfd::FaceMonitor m_faceMonitor;
242 ndn::ValidatorConfig m_localhostValidator;
243 ndn::ValidatorConfig m_localhopValidator;
244 ndn::ValidatorConfig m_paValidator;
245 bool m_isLocalhopEnabled;
246
247 ndn::scheduler::ScopedEventId m_activeFaceFetchEvent;
248};
249
250std::ostream&
251operator<<(std::ostream& os, RibManager::SlAnnounceResult res);
252
253} // namespace nfd
254
255#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.
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.
void disableLocalhop()
Disallow accepting commands on /localhop/nfd/rib prefix.
static const Name LOCALHOP_TOP_PREFIX
void applyLocalhostConfig(const ConfigSection &section, const std::string &filename)
Apply localhost_security configuration.
void enableLocalhop(const ConfigSection &section, const std::string &filename)
Apply localhop_security configuration and allow accepting commands on /localhop/nfd/rib prefix.
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.
Represents the Routing Information Base.
Definition rib.hpp:70
Represents a route for a name prefix.
Definition route.hpp:44
#define NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition common.hpp:41
Definition common.hpp:71
boost::property_tree::ptree ConfigSection
A configuration file section.
std::ostream & operator<<(std::ostream &os, const Network &network)
Definition network.cpp:83
Represents a route that will be added to or removed from a namespace.