NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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; -*- */
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 "rib-status-publisher.hpp"
33 #include "fib-updater.hpp"
34 
35 #include <ndn-cxx/security/validator-config.hpp>
36 #include <ndn-cxx/management/nfd-face-monitor.hpp>
37 #include <ndn-cxx/management/nfd-controller.hpp>
38 #include <ndn-cxx/management/nfd-control-command.hpp>
39 #include <ndn-cxx/management/nfd-control-response.hpp>
40 #include <ndn-cxx/management/nfd-control-parameters.hpp>
41 
42 namespace nfd {
43 namespace rib {
44 
48 
50 
51 class RibManager : noncopyable
52 {
53 public:
54  class Error : public std::runtime_error
55  {
56  public:
57  explicit
58  Error(const std::string& what)
59  : std::runtime_error(what)
60  {
61  }
62  };
63 
65 
66  ~RibManager();
67 
68  void
70 
71  void
73 
74  void
75  setConfigFile(ConfigFile& configFile);
76 
77  void
78  onRibUpdateSuccess(const RibUpdate& update);
79 
80  void
81  onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error);
82 
83 private:
84  void
85  onConfig(const ConfigSection& configSection,
86  bool isDryRun,
87  const std::string& filename);
88 
89  void
90  startListening(const Name& commandPrefix, const ndn::OnInterest& onRequest);
91 
92  void
93  onLocalhopRequest(const Interest& request);
94 
95  void
96  onLocalhostRequest(const Interest& request);
97 
98  void
99  sendResponse(const Name& name,
100  const ControlResponse& response);
101 
102  void
103  sendResponse(const Name& name,
104  uint32_t code,
105  const std::string& text);
106 
107  void
108  sendSuccessResponse(const shared_ptr<const Interest>& request,
109  const ControlParameters& parameters);
110 
111  void
112  sendErrorResponse(uint32_t code, const std::string& error,
113  const shared_ptr<const Interest>& request);
114 
115  void
116  registerEntry(const shared_ptr<const Interest>& request,
117  ControlParameters& parameters);
118 
119  void
120  unregisterEntry(const shared_ptr<const Interest>& request,
121  ControlParameters& parameters);
122 
123 private:
124  void
125  onCommandValidated(const shared_ptr<const Interest>& request);
126 
127  void
128  onCommandValidationFailed(const shared_ptr<const Interest>& request,
129  const std::string& failureInfo);
130 
131 
132  void
133  onCommandError(uint32_t code, const std::string& error,
134  const shared_ptr<const Interest>& request,
135  const Route& route);
136 
137  void
138  onRegSuccess(const shared_ptr<const Interest>& request,
139  const ControlParameters& parameters,
140  const Route& route);
141 
142  void
143  onUnRegSuccess(const shared_ptr<const Interest>& request,
144  const ControlParameters& parameters,
145  const Route& route);
146 
148  void
149  onNrdCommandPrefixAddNextHopSuccess(const Name& prefix,
150  const ndn::nfd::ControlParameters& result);
151 
152 private:
153  void
154  onNrdCommandPrefixAddNextHopError(const Name& name, const std::string& msg);
155 
156  void
157  onControlHeaderSuccess();
158 
159  void
160  onControlHeaderError(uint32_t code, const std::string& reason);
161 
162  static bool
163  extractParameters(const Name::Component& parameterComponent,
164  ControlParameters& extractedParameters);
165 
166  bool
167  validateParameters(const ControlCommand& command,
168  ControlParameters& parameters);
169 
170  void
171  onNotification(const FaceEventNotification& notification);
172 
174  void
175  onFaceDestroyedEvent(uint64_t faceId);
176 
177 private:
178  void
179  listEntries(const Interest& request);
180 
181  void
182  scheduleActiveFaceFetch(const time::seconds& timeToWait);
183 
184  void
185  fetchActiveFaces();
186 
187  void
188  fetchSegments(const Data& data, shared_ptr<ndn::OBufferStream> buffer);
189 
190  void
191  onFetchFaceStatusTimeout();
192 
196  void
197  removeInvalidFaces(shared_ptr<ndn::OBufferStream> buffer);
198 
200  Rib m_managedRib;
201 
202 private:
203  ndn::Face& m_face;
204  ndn::KeyChain& m_keyChain;
205  ndn::nfd::Controller m_nfdController;
206  ndn::ValidatorConfig m_localhostValidator;
207  ndn::ValidatorConfig m_localhopValidator;
208  ndn::nfd::FaceMonitor m_faceMonitor;
209  bool m_isLocalhopEnabled;
210  AutoPrefixPropagator m_prefixPropagator;
211 
212  RibStatusPublisher m_ribStatusPublisher;
213 
215  FibUpdater m_fibUpdater;
216 
217 private:
218  typedef function<void(RibManager*,
219  const shared_ptr<const Interest>& request,
220  ControlParameters& parameters)> SignedVerbProcessor;
221 
222  typedef std::map<name::Component, SignedVerbProcessor> SignedVerbDispatchTable;
223 
224  typedef std::pair<name::Component, SignedVerbProcessor> SignedVerbAndProcessor;
225 
226 
227  const SignedVerbDispatchTable m_signedVerbDispatch;
228 
229  static const Name COMMAND_PREFIX; // /localhost/nrd
230 
232  static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
233 
234 private:
235  // number of components in an invalid, but not malformed, unsigned command.
236  // (/localhost/nrd + verb + options) = 4
237  static const size_t COMMAND_UNSIGNED_NCOMPS;
238 
239  // number of components in a valid signed Interest.
240  // 8 with signed Interest support.
241  static const size_t COMMAND_SIGNED_NCOMPS;
242 
243  static const SignedVerbAndProcessor SIGNED_COMMAND_VERBS[];
244 
245  typedef function<void(RibManager*, const Interest&)> UnsignedVerbProcessor;
246  typedef std::map<Name::Component, UnsignedVerbProcessor> UnsignedVerbDispatchTable;
247  typedef std::pair<Name::Component, UnsignedVerbProcessor> UnsignedVerbAndProcessor;
248 
249  const UnsignedVerbDispatchTable m_unsignedVerbDispatch;
250  static const UnsignedVerbAndProcessor UNSIGNED_COMMAND_VERBS[];
251 
252  static const Name LIST_COMMAND_PREFIX;
253  static const size_t LIST_COMMAND_NCOMPS;
254 
255  static const Name FACES_LIST_DATASET_PREFIX;
256 
257  static const time::seconds ACTIVE_FACE_FETCH_INTERVAL;
258  scheduler::EventId m_activeFaceFetchEvent;
259 
260  typedef std::set<uint64_t> FaceIdSet;
263  FaceIdSet m_registeredFaces;
264 };
265 
266 } // namespace rib
267 } // namespace nfd
268 
269 #endif // NFD_RIB_RIB_MANAGER_HPP
Error(const std::string &what)
Definition: rib-manager.hpp:58
represents the RIB
Definition: rib.hpp:45
RibManager(ndn::Face &face, ndn::KeyChain &keyChain)
Definition: rib-manager.cpp:76
represents parameters in a ControlCommand request or response
The packet signing interface.
Definition: key-chain.hpp:48
base class of NFD ControlCommand
STL namespace.
computes FibUpdates based on updates to the RIB and sends them to NFD
Definition: fib-updater.hpp:41
represents a Face status change notification
represents an Interest packet
Definition: interest.hpp:45
A subscriber for Face status change notification stream.
function< void(const InterestFilter &, const Interest &)> OnInterest
Callback called when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:94
void onRibUpdateSuccess(const RibUpdate &update)
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:39
ndn::mgmt::ControlResponse ControlResponse
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
represents a route for a name prefix
Definition: route.hpp:38
Abstraction to communicate with local or remote NDN forwarder.
Definition: face.hpp:119
NFD Management protocol - ControlCommand client.
boost::property_tree::ptree ConfigSection
Name abstraction to represent an absolute name.
Definition: name.hpp:46
Component holds a read-only name component value.
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:39
ControlCommand response.
provides automatic prefix propagation feature
represents a Data packet
Definition: data.hpp:39
void onRibUpdateFailure(const RibUpdate &update, uint32_t code, const std::string &error)
void setConfigFile(ConfigFile &configFile)