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-2018, 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 
30 #include "fib-updater.hpp"
31 #include "rib.hpp"
32 
33 #include "core/config-file.hpp"
34 #include "core/manager-base.hpp"
35 
36 #include <ndn-cxx/security/validator-config.hpp>
37 #include <ndn-cxx/mgmt/nfd/controller.hpp>
38 #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
39 #include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
40 #include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
41 
42 namespace nfd {
43 namespace rib {
44 
49 {
50 public:
51  class Error : public std::runtime_error
52  {
53  public:
54  using std::runtime_error::runtime_error;
55  };
56 
57  RibManager(Rib& rib, ndn::Face& face, ndn::nfd::Controller& nfdController, Dispatcher& dispatcher);
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 private: // RIB and FibUpdater actions
91  enum class RibUpdateResult
92  {
93  OK,
94  ERROR,
95  EXPIRED,
96  };
97 
104  void
105  beginAddRoute(const Name& name, Route route, optional<time::nanoseconds> expires,
106  const std::function<void(RibUpdateResult)>& done);
107 
113  void
114  beginRemoveRoute(const Name& name, const Route& route,
115  const std::function<void(RibUpdateResult)>& done);
116 
117  void
118  beginRibUpdate(const RibUpdate& update, const std::function<void(RibUpdateResult)>& done);
119 
120 private: // management Dispatcher related
121  void
122  registerTopPrefix(const Name& topPrefix);
123 
126  void
127  registerEntry(const Name& topPrefix, const Interest& interest,
128  ControlParameters parameters,
129  const ndn::mgmt::CommandContinuation& done);
130 
133  void
134  unregisterEntry(const Name& topPrefix, const Interest& interest,
135  ControlParameters parameters,
136  const ndn::mgmt::CommandContinuation& done);
137 
140  void
141  listEntries(const Name& topPrefix, const Interest& interest,
142  ndn::mgmt::StatusDatasetContext& context);
143 
144  void
145  setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
146 
147  ndn::mgmt::Authorization
148  makeAuthorization(const std::string& verb) override;
149 
150 private: // Face monitor
151  void
152  fetchActiveFaces();
153 
154  void
155  onFetchActiveFacesFailure(uint32_t code, const std::string& reason);
156 
157  void
158  onFaceDestroyedEvent(uint64_t faceId);
159 
161  void
162  scheduleActiveFaceFetch(const time::seconds& timeToWait);
163 
169  void
170  removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces);
171 
177  void
178  onNotification(const ndn::nfd::FaceEventNotification& notification);
179 
180 private:
181  Rib& m_rib;
182  ndn::nfd::Controller& m_nfdController;
183  Dispatcher& m_dispatcher;
184 
185  ndn::nfd::FaceMonitor m_faceMonitor;
186  ndn::ValidatorConfig m_localhostValidator;
187  ndn::ValidatorConfig m_localhopValidator;
188  bool m_isLocalhopEnabled;
189 
190 private:
191  scheduler::ScopedEventId m_activeFaceFetchEvent;
192 
193  typedef std::set<uint64_t> FaceIdSet;
196  FaceIdSet m_registeredFaces;
197 };
198 
199 } // namespace rib
200 } // namespace nfd
201 
202 #endif // NFD_RIB_RIB_MANAGER_HPP
Serve commands and datasets in NFD RIB management protocol.
Definition: rib-manager.hpp:48
represents the Routing Information Base
Definition: rib.hpp:59
RibManager(Rib &rib, ndn::Face &face, ndn::nfd::Controller &nfdController, Dispatcher &dispatcher)
Definition: rib-manager.cpp:49
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:74
void registerWithNfd()
Start accepting commands and dataset requests.
Definition: rib-manager.cpp:87
Cancels an event automatically upon destruction.
Definition: scheduler.hpp:57
void applyLocalhostConfig(const ConfigSection &section, const std::string &filename)
Apply localhost_security configuration.
Definition: rib-manager.cpp:68
void enableLocalFields()
Enable NDNLP IncomingFaceId field in order to support self-registration commands. ...
a collection of common functions shared by all NFD managers and RIB manager, such as communicating wi...
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:42
void disableLocalhop()
Disallow accepting commands on /localhop/nfd/rib prefix.
Definition: rib-manager.cpp:81
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40