NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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-2019, 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 
37 
38 namespace nfd {
39 
40 namespace rib {
41 class Rib;
42 class RibUpdate;
43 } // namespace rib
44 
49 class RibManager : public ManagerBase
50 {
51 public:
52  RibManager(rib::Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
53  ndn::nfd::Controller& nfdController, Dispatcher& dispatcher);
54 
58  void
59  applyLocalhostConfig(const ConfigSection& section, const std::string& filename);
60 
65  void
66  enableLocalhop(const ConfigSection& section, const std::string& filename);
67 
71  void
73 
77  void
78  applyPaConfig(const ConfigSection& section, const std::string& filename);
79 
83  void
85 
89  void
91 
92 public: // self-learning support
93  enum class SlAnnounceResult {
94  OK,
95  ERROR,
97  EXPIRED,
98  NOT_FOUND,
99  };
100 
101  using SlAnnounceCallback = std::function<void(SlAnnounceResult res)>;
102  using SlFindAnnCallback = std::function<void(optional<ndn::PrefixAnnouncement>)>;
103 
121  void
122  slAnnounce(const ndn::PrefixAnnouncement& pa, uint64_t faceId, time::milliseconds maxLifetime,
123  const SlAnnounceCallback& cb);
124 
143  void
144  slRenew(const Name& name, uint64_t faceId, time::milliseconds maxLifetime,
145  const SlAnnounceCallback& cb);
146 
158  void
159  slFindAnn(const Name& name, const SlFindAnnCallback& cb) const;
160 
161 private: // RIB and FibUpdater actions
162  enum class RibUpdateResult
163  {
164  OK,
165  ERROR,
166  EXPIRED,
167  };
168 
169  static SlAnnounceResult
170  getSlAnnounceResultFromRibUpdateResult(RibUpdateResult r);
171 
178  void
179  beginAddRoute(const Name& name, rib::Route route, optional<time::nanoseconds> expires,
180  const std::function<void(RibUpdateResult)>& done);
181 
187  void
188  beginRemoveRoute(const Name& name, const rib::Route& route,
189  const std::function<void(RibUpdateResult)>& done);
190 
191  void
192  beginRibUpdate(const rib::RibUpdate& update,
193  const std::function<void(RibUpdateResult)>& done);
194 
195 private: // management Dispatcher related
196  void
197  registerTopPrefix(const Name& topPrefix);
198 
201  void
202  registerEntry(const Name& topPrefix, const Interest& interest,
203  ControlParameters parameters,
204  const ndn::mgmt::CommandContinuation& done);
205 
208  void
209  unregisterEntry(const Name& topPrefix, const Interest& interest,
210  ControlParameters parameters,
211  const ndn::mgmt::CommandContinuation& done);
212 
215  void
216  listEntries(const Name& topPrefix, const Interest& interest,
218 
219  void
220  setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
221 
223  makeAuthorization(const std::string& verb) override;
224 
225 private: // Face monitor
226  void
227  fetchActiveFaces();
228 
229  void
230  onFetchActiveFacesFailure(uint32_t code, const std::string& reason);
231 
233  void
234  scheduleActiveFaceFetch(const time::seconds& timeToWait);
235 
236  void
237  removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces);
238 
239  void
240  onNotification(const ndn::nfd::FaceEventNotification& notification);
241 
242 public:
243  static const Name LOCALHOP_TOP_PREFIX;
244 
245 private:
246  rib::Rib& m_rib;
247  ndn::KeyChain& m_keyChain;
248  ndn::nfd::Controller& m_nfdController;
249  Dispatcher& m_dispatcher;
250 
251  ndn::nfd::FaceMonitor m_faceMonitor;
252  ndn::ValidatorConfig m_localhostValidator;
253  ndn::ValidatorConfig m_localhopValidator;
254  ndn::ValidatorConfig m_paValidator;
255  bool m_isLocalhopEnabled;
256 
257  scheduler::ScopedEventId m_activeFaceFetchEvent;
258 };
259 
260 std::ostream&
261 operator<<(std::ostream& os, RibManager::SlAnnounceResult res);
262 
263 } // namespace nfd
264 
265 #endif // NFD_DAEMON_MGMT_RIB_MANAGER_HPP
PUBLIC_WITH_TESTS_ELSE_PRIVATE
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
nfd::RibManager::SlAnnounceResult::ERROR
@ ERROR
unspecified error
nfd::RibManager::slRenew
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.
Definition: rib-manager.cpp:382
nfd::RibManager::SlAnnounceCallback
std::function< void(SlAnnounceResult res)> SlAnnounceCallback
Definition: rib-manager.hpp:101
face-monitor.hpp
nfd::RibManager::SlAnnounceResult::VALIDATION_FAILURE
@ VALIDATION_FAILURE
the announcement cannot be verified against the trust schema
nfd::RibManager::slAnnounce
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.
Definition: rib-manager.cpp:357
ndn::mgmt::CommandContinuation
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
Definition: dispatcher.hpp:95
nfd::RibManager::registerWithNfd
void registerWithNfd()
Start accepting commands and dataset requests.
Definition: rib-manager.cpp:98
nfd::RibManager::RibManager
RibManager(rib::Rib &rib, ndn::Face &face, ndn::KeyChain &keyChain, ndn::nfd::Controller &nfdController, Dispatcher &dispatcher)
Definition: rib-manager.cpp:51
controller.hpp
ndn::nfd::Controller
NFD Management protocol client.
Definition: controller.hpp:52
ndn::Face
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:90
scheduler.hpp
ndn::PrefixAnnouncement
A prefix announcement object that represents an application's intent of registering a prefix toward i...
Definition: prefix-announcement.hpp:34
nfd::RibManager::enableLocalhop
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
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
route.hpp
ndn::nfd::FaceEventNotification
represents a Face status change notification
Definition: face-event-notification.hpp:36
nfd::rib::RibUpdate
RibUpdate.
Definition: rib-update.hpp:41
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
nfd::RibManager::SlAnnounceResult::OK
@ OK
RIB and FIB have been updated.
nfd::RibManager::SlAnnounceResult::NOT_FOUND
@ NOT_FOUND
route does not exist (slRenew only)
nfd::RibManager::enableLocalFields
void enableLocalFields()
Enable NDNLP IncomingFaceId field in order to support self-registration commands.
Definition: rib-manager.cpp:114
ndn::security::v2::KeyChain
The interface of signing key management.
Definition: key-chain.hpp:47
nfd::RibManager::disableLocalhop
void disableLocalhop()
Disallow accepting commands on /localhop/nfd/rib prefix.
Definition: rib-manager.cpp:86
ndn::mgmt::StatusDatasetContext
provides a context for generating response to a StatusDataset request
Definition: status-dataset-context.hpp:37
nfd::rib::Rib
represents the Routing Information Base
Definition: rib.hpp:60
validator-config.hpp
nfd::RibManager::SlAnnounceResult
SlAnnounceResult
Definition: rib-manager.hpp:93
ndn::mgmt::Authorization
std::function< void(const Name &prefix, const Interest &interest, const ControlParameters *params, const AcceptContinuation &accept, const RejectContinuation &reject)> Authorization
a function that performs authorization
Definition: dispatcher.hpp:77
nfd::operator<<
std::ostream & operator<<(std::ostream &os, const Network &network)
Definition: network.cpp:79
manager-base.hpp
ndn::Interest
Represents an Interest packet.
Definition: interest.hpp:44
nfd::RibManager::SlAnnounceResult::EXPIRED
@ EXPIRED
the announcement has expired
ndn::security::ValidatorConfig
Helper for validator that uses CommandInterest + Config policy and NetworkFetcher.
Definition: validator-config.hpp:36
nfd::RibManager::slFindAnn
void slFindAnn(const Name &name, const SlFindAnnCallback &cb) const
Retrieve an outgoing prefix announcement for self-learning strategy.
Definition: rib-manager.cpp:407
nfd::RibManager
Implements the RIB Management of NFD Management Protocol.
Definition: rib-manager.hpp:50
nfd::ConfigSection
boost::property_tree::ptree ConfigSection
a config file section
Definition: ndn-l3-protocol.hpp:39
nfd::RibManager::LOCALHOP_TOP_PREFIX
static const Name LOCALHOP_TOP_PREFIX
Definition: rib-manager.hpp:243
ndn::nfd::FaceMonitor
A subscriber for Face status change notification stream.
Definition: face-monitor.hpp:41
nfd::ManagerBase
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
Definition: manager-base.hpp:48
ndn::nfd::ControlParameters
represents parameters in a ControlCommand request or response
Definition: control-parameters.hpp:82
face-event-notification.hpp
ndn::mgmt::Dispatcher
represents a dispatcher on server side of NFD Management protocol
Definition: dispatcher.hpp:131
nfd::rib::Rib
Rib
Definition: rib.cpp:33
ndn::name
Definition: name-component-types.hpp:33
nfd::rib::Route
represents a route for a name prefix
Definition: route.hpp:44
nfd::RibManager::applyLocalhostConfig
void applyLocalhostConfig(const ConfigSection &section, const std::string &filename)
Apply localhost_security configuration.
Definition: rib-manager.cpp:73
ndn::detail::ScopedCancelHandle< EventId >
nfd::RibManager::applyPaConfig
void applyPaConfig(const ConfigSection &section, const std::string &filename)
Apply prefix_announcement_validation configuration.
Definition: rib-manager.cpp:92
nfd::RibManager::SlFindAnnCallback
std::function< void(optional< ndn::PrefixAnnouncement >)> SlFindAnnCallback
Definition: rib-manager.hpp:102