NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
manager-base.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_CORE_MANAGER_BASE_HPP
27 #define NFD_CORE_MANAGER_BASE_HPP
28 
29 #include "common.hpp"
30 
31 #include <ndn-cxx/mgmt/dispatcher.hpp>
32 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
33 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
34 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
35 
36 namespace nfd {
37 
39 
43 
48 class ManagerBase : noncopyable
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  ManagerBase(Dispatcher& dispatcher,
63  const std::string& module);
64 
65  const std::string&
66  getModule() const
67  {
68  return m_module;
69  }
70 
71 PUBLIC_WITH_TESTS_ELSE_PROTECTED: // registrations to the dispatcher
72 
73  // difference from mgmt::ControlCommand: accepts nfd::ControlParameters
74  typedef function<void(const ControlCommand& command,
75  const Name& prefix, const Interest& interest,
76  const ControlParameters& parameters,
78 
79  template<typename Command>
80  void
81  registerCommandHandler(const std::string& verb,
82  const ControlCommandHandler& handler);
83 
84  void
85  registerStatusDatasetHandler(const std::string& verb,
86  const ndn::mgmt::StatusDatasetHandler& handler);
87 
89  registerNotificationStream(const std::string& verb);
90 
100  void
101  extractRequester(const Interest& interest,
103 
109  makeAuthorization(const std::string& verb) = 0;
110 
118  static bool
119  validateParameters(const nfd::ControlCommand& command,
120  const ndn::mgmt::ControlParameters& parameters);
121 
124  static void
125  handleCommand(shared_ptr<nfd::ControlCommand> command,
126  const ControlCommandHandler& handler,
127  const Name& prefix, const Interest& interest,
128  const ndn::mgmt::ControlParameters& params,
130 
140  makeRelPrefix(const std::string& verb);
141 
142 private:
143  Dispatcher& m_dispatcher;
144  std::string m_module;
145 };
146 
147 inline PartialName
148 ManagerBase::makeRelPrefix(const std::string& verb)
149 {
150  return PartialName(m_module).append(verb);
151 }
152 
153 template<typename Command>
154 inline void
155 ManagerBase::registerCommandHandler(const std::string& verb,
156  const ControlCommandHandler& handler)
157 {
158  auto command = make_shared<Command>();
159 
160  m_dispatcher.addControlCommand<ControlParameters>(
161  makeRelPrefix(verb),
162  makeAuthorization(verb),
163  bind(&ManagerBase::validateParameters, cref(*command), _1),
164  bind(&ManagerBase::handleCommand, command, handler, _1, _2, _3, _4));
165 }
166 
167 } // namespace nfd
168 
169 #endif // NFD_CORE_MANAGER_BASE_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
a collection of common functions shared by all NFD managers and RIB manager, such as communicating wi...
represents parameters in a ControlCommand request or response
std::function< void(const Block &notification)> PostNotification
a function to post a notification
Definition: dispatcher.hpp:123
represents a dispatcher on server side of NFD Management protocol
Definition: dispatcher.hpp:129
void extractRequester(const Interest &interest, ndn::mgmt::AcceptContinuation accept)
extract a requester from a ControlCommand request
Error(const std::string &what)
base class of NFD ControlCommand
STL namespace.
ManagerBase(Dispatcher &dispatcher, const std::string &module)
represents an Interest packet
Definition: interest.hpp:42
std::function< void(const std::string &requester)> AcceptContinuation
a function to be called if authorization is successful
Definition: dispatcher.hpp:45
ndn mgmt Dispatcher
Copyright (c) 2013-2016 Regents of the University of California.
Definition: dispatcher.cpp:28
const std::string & getModule() const
ndn::mgmt::ControlResponse ControlResponse
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
Name abstraction to represent an absolute name.
Definition: name.hpp:46
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
Definition: dispatcher.hpp:95
base class for a struct that contains ControlCommand parameters
Name & append(const uint8_t *value, size_t valueLength)
Append a new component, copying from value of length valueLength.
Definition: name.hpp:140
void registerCommandHandler(const std::string &verb, const ControlCommandHandler &handler)
Name PartialName
Partial name abstraction to represent an arbitrary sequence of name components.
Definition: name.hpp:36
ndn::mgmt::PostNotification registerNotificationStream(const std::string &verb)
std::function< void(const Name &prefix, const Interest &interest, const ControlParameters *params, const AcceptContinuation &accept, const RejectContinuation &reject)> Authorization
a function that performs authorization
Definition: dispatcher.hpp:77
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:39
function< void(const ControlCommand &command, const Name &prefix, const Interest &interest, const ControlParameters &parameters, const ndn::mgmt::CommandContinuation done)> ControlCommandHandler
std::function< void(const Name &prefix, const Interest &interest, StatusDatasetContext &context)> StatusDatasetHandler
a function to handle a StatusDataset request
Definition: dispatcher.hpp:117