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 
29 #include "rib.hpp"
30 #include "core/config-file.hpp"
31 #include "core/manager-base.hpp"
33 #include "fib-updater.hpp"
34 
35 #include <ndn-cxx/encoding/buffer-stream.hpp>
36 #include <ndn-cxx/security/validator-config.hpp>
37 #include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
38 #include <ndn-cxx/mgmt/nfd/controller.hpp>
39 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
40 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
41 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
42 
43 namespace nfd {
44 namespace rib {
45 
46 using ndn::nfd::ControlCommand;
47 using ndn::nfd::ControlResponse;
48 using ndn::nfd::ControlParameters;
49 
50 using ndn::nfd::FaceEventNotification;
51 
53 {
54 public:
55  class Error : public std::runtime_error
56  {
57  public:
58  explicit
59  Error(const std::string& what)
60  : std::runtime_error(what)
61  {
62  }
63  };
64 
65 public:
66  RibManager(Dispatcher& dispatcher, ndn::Face& face, ndn::KeyChain& keyChain);
67 
68  ~RibManager();
69 
70  void
72 
73  void
75 
76  void
77  setConfigFile(ConfigFile& configFile);
78 
79  void
80  onRibUpdateSuccess(const RibUpdate& update);
81 
82  void
83  onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error);
84 
85 private: // initialization helpers
86  void
87  onConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename);
88 
89  void
90  registerTopPrefix(const Name& topPrefix);
91 
92 private: // ControlCommand and StatusDataset
93  void
94  registerEntry(const Name& topPrefix, const Interest& interest,
95  ControlParameters parameters,
96  const ndn::mgmt::CommandContinuation& done);
97 
98  void
99  unregisterEntry(const Name& topPrefix, const Interest& interest,
100  ControlParameters parameters,
101  const ndn::mgmt::CommandContinuation& done);
102 
103  void
104  listEntries(const Name& topPrefix, const Interest& interest,
105  ndn::mgmt::StatusDatasetContext& context);
106 
107  void
108  setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
109 
110  virtual ndn::mgmt::Authorization
111  makeAuthorization(const std::string& verb) override;
112 
113 private: // Face monitor
114  void
115  fetchActiveFaces();
116 
117  void
118  fetchSegments(const Data& data, shared_ptr<ndn::OBufferStream> buffer);
119 
120  void
121  onFetchFaceStatusTimeout();
122 
123  void
124  onFaceDestroyedEvent(uint64_t faceId);
125 
127  void
128  scheduleActiveFaceFetch(const time::seconds& timeToWait);
129 
135  void
136  removeInvalidFaces(shared_ptr<ndn::OBufferStream> buffer);
137 
143  void
144  onNotification(const FaceEventNotification& notification);
145 
146 private:
147  void
148  onCommandPrefixAddNextHopSuccess(const Name& prefix,
149  const ndn::nfd::ControlParameters& result);
150 
151  void
152  onCommandPrefixAddNextHopError(const Name& name, const ndn::nfd::ControlResponse& response);
153 
154  void
155  onControlHeaderSuccess();
156 
157  void
158  onControlHeaderError(const ndn::nfd::ControlResponse& response);
159 
160 private:
161  ndn::Face& m_face;
162  ndn::KeyChain& m_keyChain;
163  ndn::nfd::Controller m_nfdController;
164  ndn::nfd::FaceMonitor m_faceMonitor;
165  ndn::ValidatorConfig m_localhostValidator;
166  ndn::ValidatorConfig m_localhopValidator;
167  bool m_isLocalhopEnabled;
168  AutoPrefixPropagator m_prefixPropagator;
169 
171  Rib m_rib;
172  FibUpdater m_fibUpdater;
173 
174 private:
175  static const Name LOCAL_HOST_TOP_PREFIX;
176  static const Name LOCAL_HOP_TOP_PREFIX;
177  static const std::string MGMT_MODULE_NAME;
178  static const Name FACES_LIST_DATASET_PREFIX;
179  static const time::seconds ACTIVE_FACE_FETCH_INTERVAL;
180  scheduler::EventId m_activeFaceFetchEvent;
181 
182  typedef std::set<uint64_t> FaceIdSet;
185  FaceIdSet m_registeredFaces;
186 
187  std::function<void(const Name& topPrefix)> m_addTopPrefix;
188 };
189 
190 } // namespace rib
191 } // namespace nfd
192 
193 #endif // NFD_RIB_RIB_MANAGER_HPP
represents the RIB
Definition: rib.hpp:43
configuration file parsing utility
Definition: config-file.hpp:50
computes FibUpdates based on updates to the RIB and sends them to NFD
Definition: fib-updater.hpp:41
provides automatic prefix propagation feature
void enableLocalControlHeader()
Definition: rib-manager.cpp:92
STL namespace.
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
Definition: config-file.hpp:35
void setConfigFile(ConfigFile &configFile)
Error(const std::string &what)
Definition: rib-manager.hpp:59
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:39
void onRibUpdateSuccess(const RibUpdate &update)
RibManager(Dispatcher &dispatcher, ndn::Face &face, ndn::KeyChain &keyChain)
Definition: rib-manager.cpp:45