rib-manager.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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 
45 class AutoPrefixPropagator;
46 class Readvertise;
47 
49 {
50 public:
51  class Error : public std::runtime_error
52  {
53  public:
54  explicit
55  Error(const std::string& what)
56  : std::runtime_error(what)
57  {
58  }
59  };
60 
61 public:
62  RibManager(Dispatcher& dispatcher, ndn::Face& face, ndn::KeyChain& keyChain);
63 
64  ~RibManager() override;
65 
66  void
68 
69  void
71 
72  void
73  setConfigFile(ConfigFile& configFile);
74 
75  void
76  onRibUpdateSuccess(const RibUpdate& update);
77 
78  void
79  onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error);
80 
81 private: // initialization helpers
82  void
83  onConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename);
84 
85  void
86  registerTopPrefix(const Name& topPrefix);
87 
88 private: // ControlCommand and StatusDataset
89  void
90  registerEntry(const Name& topPrefix, const Interest& interest,
91  ControlParameters parameters,
92  const ndn::mgmt::CommandContinuation& done);
93 
94  void
95  unregisterEntry(const Name& topPrefix, const Interest& interest,
96  ControlParameters parameters,
97  const ndn::mgmt::CommandContinuation& done);
98 
99  void
100  listEntries(const Name& topPrefix, const Interest& interest,
101  ndn::mgmt::StatusDatasetContext& context);
102 
103  void
104  setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
105 
106  ndn::mgmt::Authorization
107  makeAuthorization(const std::string& verb) override;
108 
109 private: // Face monitor
110  void
111  fetchActiveFaces();
112 
113  void
114  onFetchActiveFacesFailure(uint32_t code, const std::string& reason);
115 
116  void
117  onFaceDestroyedEvent(uint64_t faceId);
118 
120  void
121  scheduleActiveFaceFetch(const time::seconds& timeToWait);
122 
128  void
129  removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces);
130 
136  void
137  onNotification(const ndn::nfd::FaceEventNotification& notification);
138 
139 private:
140  void
141  onCommandPrefixAddNextHopSuccess(const Name& prefix, const ControlParameters& result);
142 
143  void
144  onCommandPrefixAddNextHopError(const Name& name, const ControlResponse& response);
145 
146  void
147  onEnableLocalFieldsSuccess();
148 
149  void
150  onEnableLocalFieldsError(const ControlResponse& response);
151 
152 private:
153  ndn::Face& m_face;
154  ndn::KeyChain& m_keyChain;
155  ndn::nfd::Controller m_nfdController;
156  ndn::nfd::FaceMonitor m_faceMonitor;
157  ndn::ValidatorConfig m_localhostValidator;
158  ndn::ValidatorConfig m_localhopValidator;
159  bool m_isLocalhopEnabled;
160  AutoPrefixPropagator m_prefixPropagator;
161  unique_ptr<Readvertise> m_readvertiseNlsr;
162 
164  Rib m_rib;
165  FibUpdater m_fibUpdater;
166 
167 private:
168  static const Name LOCAL_HOST_TOP_PREFIX;
169  static const Name LOCAL_HOP_TOP_PREFIX;
170  static const std::string MGMT_MODULE_NAME;
171  static const Name FACES_LIST_DATASET_PREFIX;
172  static const time::seconds ACTIVE_FACE_FETCH_INTERVAL;
173  scheduler::ScopedEventId m_activeFaceFetchEvent;
174  static const Name READVERTISE_NLSR_PREFIX;
175 
176  typedef std::set<uint64_t> FaceIdSet;
179  FaceIdSet m_registeredFaces;
180 
181  std::function<void(const Name& topPrefix)> m_addTopPrefix;
182 };
183 
184 } // namespace rib
185 } // namespace nfd
186 
187 #endif // NFD_RIB_RIB_MANAGER_HPP
~RibManager() override
represents the Routing Information Base
Definition: rib.hpp:59
configuration file parsing utility
Definition: config-file.hpp:58
computes FibUpdates based on updates to the RIB and sends them to NFD
Definition: fib-updater.hpp:41
provides automatic prefix propagation feature
STL namespace.
cancels an event automatically upon destruction
Definition: scheduler.hpp:56
a collection of common functions shared by all NFD managers and RIB manager, such as communicating wi...
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
void onRibUpdateFailure(const RibUpdate &update, uint32_t code, const std::string &error)
boost::property_tree::ptree ConfigSection
a config file section
Definition: config-file.hpp:37
void setConfigFile(ConfigFile &configFile)
Error(const std::string &what)
Definition: rib-manager.hpp:55
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
void onRibUpdateSuccess(const RibUpdate &update)
RibManager(Dispatcher &dispatcher, ndn::Face &face, ndn::KeyChain &keyChain)
Definition: rib-manager.cpp:53