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 
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/security/validator-config.hpp>
36 #include <ndn-cxx/util/scheduler.hpp>
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
72  disableLocalhop();
73 
77  void
78  registerWithNfd();
79 
83  void
84  enableLocalFields();
85 
86 public: // self-learning support
87  enum class SlAnnounceResult {
88  OK,
89  ERROR,
90  VALIDATION_FAILURE,
91  EXPIRED,
92  NOT_FOUND,
93  };
94 
95  using SlAnnounceCallback = std::function<void(SlAnnounceResult res)>;
96  using SlFindAnnCallback = std::function<void(optional<ndn::PrefixAnnouncement>)>;
97 
115  void
116  slAnnounce(const ndn::PrefixAnnouncement& pa, uint64_t faceId, time::milliseconds maxLifetime,
117  const SlAnnounceCallback& cb);
118 
137  void
138  slRenew(const Name& name, uint64_t faceId, time::milliseconds maxLifetime,
139  const SlAnnounceCallback& cb);
140 
152  void
153  slFindAnn(const Name& name, const SlFindAnnCallback& cb) const;
154 
155 private: // RIB and FibUpdater actions
156  enum class RibUpdateResult
157  {
158  OK,
159  ERROR,
160  EXPIRED,
161  };
162 
163  static SlAnnounceResult
164  getSlAnnounceResultFromRibUpdateResult(RibUpdateResult r);
165 
172  void
173  beginAddRoute(const Name& name, rib::Route route, optional<time::nanoseconds> expires,
174  const std::function<void(RibUpdateResult)>& done);
175 
181  void
182  beginRemoveRoute(const Name& name, const rib::Route& route,
183  const std::function<void(RibUpdateResult)>& done);
184 
185  void
186  beginRibUpdate(const rib::RibUpdate& update,
187  const std::function<void(RibUpdateResult)>& done);
188 
189 private: // management Dispatcher related
190  void
191  registerTopPrefix(const Name& topPrefix);
192 
195  void
196  registerEntry(const Name& topPrefix, const Interest& interest,
197  ControlParameters parameters,
198  const ndn::mgmt::CommandContinuation& done);
199 
202  void
203  unregisterEntry(const Name& topPrefix, const Interest& interest,
204  ControlParameters parameters,
205  const ndn::mgmt::CommandContinuation& done);
206 
209  void
210  listEntries(const Name& topPrefix, const Interest& interest,
211  ndn::mgmt::StatusDatasetContext& context);
212 
213  void
214  setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
215 
216  ndn::mgmt::Authorization
217  makeAuthorization(const std::string& verb) override;
218 
219 private: // Face monitor
220  void
221  fetchActiveFaces();
222 
223  void
224  onFetchActiveFacesFailure(uint32_t code, const std::string& reason);
225 
226  void
227  onFaceDestroyedEvent(uint64_t faceId);
228 
230  void
231  scheduleActiveFaceFetch(const time::seconds& timeToWait);
232 
233  void
234  removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces);
235 
236  void
237  onNotification(const ndn::nfd::FaceEventNotification& notification);
238 
239 public:
240  static const Name LOCALHOP_TOP_PREFIX;
241 
242 private:
243  rib::Rib& m_rib;
244  ndn::KeyChain& m_keyChain;
245  ndn::nfd::Controller& m_nfdController;
246  Dispatcher& m_dispatcher;
247 
248  ndn::nfd::FaceMonitor m_faceMonitor;
249  ndn::ValidatorConfig m_localhostValidator;
250  ndn::ValidatorConfig m_localhopValidator;
251  bool m_isLocalhopEnabled;
252 
253  scheduler::ScopedEventId m_activeFaceFetchEvent;
254  using FaceIdSet = std::set<uint64_t>;
255  FaceIdSet m_registeredFaces;
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
represents the Routing Information Base
Definition: rib.hpp:59
std::function< void(SlAnnounceResult res)> SlAnnounceCallback
Definition: rib-manager.hpp:95
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
Definition: fib-update.hpp:74
Implements the RIB Management of NFD Management Protocol.
Definition: rib-manager.hpp:49
std::function< void(optional< ndn::PrefixAnnouncement >)> SlFindAnnCallback
Definition: rib-manager.hpp:96
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
boost::property_tree::ptree ConfigSection
a config file section
Definition: config-file.hpp:37
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
represents a route for a name prefix
Definition: route.hpp:43
static const Name LOCALHOP_TOP_PREFIX
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41