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_RIB_RIB_MANAGER_HPP
27 #define NFD_RIB_RIB_MANAGER_HPP
28 
29 #include "fib-updater.hpp"
30 #include "rib.hpp"
31 
32 #include "core/config-file.hpp"
33 #include "core/manager-base.hpp"
34 
40 
41 namespace nfd {
42 namespace rib {
43 
48 {
49 public:
50  class Error : public std::runtime_error
51  {
52  public:
53  using std::runtime_error::runtime_error;
54  };
55 
56  RibManager(Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain, ndn::nfd::Controller& nfdController,
57  Dispatcher& dispatcher, ndn::util::Scheduler& scheduler);
58 
62  void
63  applyLocalhostConfig(const ConfigSection& section, const std::string& filename);
64 
69  void
70  enableLocalhop(const ConfigSection& section, const std::string& filename);
71 
75  void
77 
81  void
83 
87  void
89 
90 public: // self-learning support
91  enum class SlAnnounceResult {
92  OK,
93  ERROR,
95  EXPIRED,
96  NOT_FOUND,
97  };
98 
99  using SlAnnounceCallback = std::function<void(SlAnnounceResult res)>;
100  using SlFindAnnCallback = std::function<void(optional<ndn::PrefixAnnouncement>)>;
101 
119  void
120  slAnnounce(const ndn::PrefixAnnouncement& pa, uint64_t faceId, time::milliseconds maxLifetime,
121  const SlAnnounceCallback& cb);
122 
141  void
142  slRenew(const Name& name, uint64_t faceId, time::milliseconds maxLifetime,
143  const SlAnnounceCallback& cb);
144 
156  void
157  slFindAnn(const Name& name, const SlFindAnnCallback& cb) const;
158 
159 private: // RIB and FibUpdater actions
160  enum class RibUpdateResult
161  {
162  OK,
163  ERROR,
164  EXPIRED,
165  };
166 
167  static SlAnnounceResult
168  getSlAnnounceResultFromRibUpdateResult(RibUpdateResult r);
169 
176  void
177  beginAddRoute(const Name& name, Route route, optional<time::nanoseconds> expires,
178  const std::function<void(RibUpdateResult)>& done);
179 
185  void
186  beginRemoveRoute(const Name& name, const Route& route,
187  const std::function<void(RibUpdateResult)>& done);
188 
189  void
190  beginRibUpdate(const RibUpdate& update, const std::function<void(RibUpdateResult)>& done);
191 
192 private: // management Dispatcher related
193  void
194  registerTopPrefix(const Name& topPrefix);
195 
198  void
199  registerEntry(const Name& topPrefix, const Interest& interest,
200  ControlParameters parameters,
201  const ndn::mgmt::CommandContinuation& done);
202 
205  void
206  unregisterEntry(const Name& topPrefix, const Interest& interest,
207  ControlParameters parameters,
208  const ndn::mgmt::CommandContinuation& done);
209 
212  void
213  listEntries(const Name& topPrefix, const Interest& interest,
215 
216  void
217  setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
218 
220  makeAuthorization(const std::string& verb) override;
221 
222 private: // Face monitor
223  void
224  fetchActiveFaces();
225 
226  void
227  onFetchActiveFacesFailure(uint32_t code, const std::string& reason);
228 
229  void
230  onFaceDestroyedEvent(uint64_t faceId);
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& m_rib;
247  ndn::KeyChain& m_keyChain;
248  ndn::nfd::Controller& m_nfdController;
249  Dispatcher& m_dispatcher;
250  ndn::util::Scheduler& m_scheduler;
251 
252  ndn::nfd::FaceMonitor m_faceMonitor;
253  ndn::ValidatorConfig m_localhostValidator;
254  ndn::ValidatorConfig m_localhopValidator;
255  bool m_isLocalhopEnabled;
256 
257  ndn::util::scheduler::ScopedEventId m_activeFaceFetchEvent;
258  using FaceIdSet = std::set<uint64_t>;
259  FaceIdSet m_registeredFaces;
260 };
261 
262 std::ostream&
263 operator<<(std::ostream& os, RibManager::SlAnnounceResult res);
264 
265 } // namespace rib
266 } // namespace nfd
267 
268 #endif // NFD_RIB_RIB_MANAGER_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
void disableLocalhop()
Disallow accepting commands on /localhop/nfd/rib prefix.
Definition: rib-manager.cpp:85
a collection of common functions shared by all NFD managers and RIB manager, such as communicating wi...
represents the Routing Information Base
Definition: rib.hpp:59
void applyLocalhostConfig(const ConfigSection &section, const std::string &filename)
Apply localhost_security configuration.
Definition: rib-manager.cpp:72
The interface of signing key management.
Definition: key-chain.hpp:46
Serve commands and datasets in NFD RIB management protocol.
Definition: rib-manager.hpp:47
represents parameters in a ControlCommand request or response
represents a dispatcher on server side of NFD Management protocol
Definition: dispatcher.hpp:130
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
Definition: fib-update.hpp:74
Helper for validator that uses CommandInterest + Config policy and NetworkFetcher.
RIB and FIB have been updated.
represents a Face status change notification
Represents an Interest packet.
Definition: interest.hpp:44
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:78
A subscriber for Face status change notification stream.
A prefix announcement object that represents an application's intent of registering a prefix toward i...
std::function< void(SlAnnounceResult res)> SlAnnounceCallback
Definition: rib-manager.hpp:99
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
route does not exist (slRenew only)
represents a route for a name prefix
Definition: route.hpp:43
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:93
NFD Management protocol client.
Definition: controller.hpp:51
RibManager(Rib &rib, ndn::Face &face, ndn::KeyChain &keyChain, ndn::nfd::Controller &nfdController, Dispatcher &dispatcher, ndn::util::Scheduler &scheduler)
Definition: rib-manager.cpp:49
boost::property_tree::ptree ConfigSection
a config file section
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.
Represents an absolute name.
Definition: name.hpp:43
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
Definition: dispatcher.hpp:95
A scoped handle of scheduled event.
Definition: scheduler.hpp:123
void slFindAnn(const Name &name, const SlFindAnnCallback &cb) const
Retrieve an outgoing prefix announcement for self-learning strategy.
std::function< void(optional< ndn::PrefixAnnouncement >)> SlFindAnnCallback
provides a context for generating response to a StatusDataset request
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.
static const Name LOCALHOP_TOP_PREFIX
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
the announcement cannot be verified against the trust schema
void enableLocalFields()
Enable NDNLP IncomingFaceId field in order to support self-registration commands.
void registerWithNfd()
Start accepting commands and dataset requests.
Definition: rib-manager.cpp:91