NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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; -*- */
2 /*
3  * Copyright (c) 2014-2019, 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_DAEMON_MGMT_MANAGER_BASE_HPP
27 #define NFD_DAEMON_MGMT_MANAGER_BASE_HPP
28 
30 
35 
36 namespace nfd {
37 
42 
47 class ManagerBase : noncopyable
48 {
49 public:
50  class Error : public std::runtime_error
51  {
52  public:
53  using std::runtime_error::runtime_error;
54  };
55 
56  virtual
58 
59  const std::string&
60  getModule() const
61  {
62  return m_module;
63  }
64 
65 protected:
69  ManagerBase(const std::string& module, Dispatcher& dispatcher);
70 
71  ManagerBase(const std::string& module, Dispatcher& dispatcher,
72  CommandAuthenticator& authenticator);
73 
74 PUBLIC_WITH_TESTS_ELSE_PROTECTED: // registrations to the dispatcher
75  // difference from mgmt::ControlCommand: accepts nfd::ControlParameters
76  using ControlCommandHandler = std::function<void(const ControlCommand& command,
77  const Name& prefix, const Interest& interest,
78  const ControlParameters& parameters,
79  const ndn::mgmt::CommandContinuation done)>;
80 
81  template<typename Command>
82  void
83  registerCommandHandler(const std::string& verb,
84  const ControlCommandHandler& handler);
85 
86  void
87  registerStatusDatasetHandler(const std::string& verb,
88  const ndn::mgmt::StatusDatasetHandler& handler);
89 
91  registerNotificationStream(const std::string& verb);
92 
102  void
104 
110  makeAuthorization(const std::string& verb);
111 
118  static bool
119  validateParameters(const ControlCommand& command,
120  const ndn::mgmt::ControlParameters& parameters);
121 
125  static void
126  handleCommand(shared_ptr<ControlCommand> command,
127  const ControlCommandHandler& handler,
128  const Name& prefix, const Interest& interest,
129  const ndn::mgmt::ControlParameters& params,
131 
139  makeRelPrefix(const std::string& verb)
140  {
141  return PartialName(m_module).append(verb);
142  }
143 
144 private:
145  std::string m_module;
146  Dispatcher& m_dispatcher;
147  CommandAuthenticator* m_authenticator = nullptr;
148 };
149 
150 template<typename Command>
151 inline void
152 ManagerBase::registerCommandHandler(const std::string& verb,
153  const ControlCommandHandler& handler)
154 {
155  auto command = make_shared<Command>();
156 
157  m_dispatcher.addControlCommand<ControlParameters>(
158  makeRelPrefix(verb),
159  makeAuthorization(verb),
160  bind(&ManagerBase::validateParameters, std::cref(*command), _1),
161  bind(&ManagerBase::handleCommand, command, handler, _1, _2, _3, _4));
162 }
163 
164 } // namespace nfd
165 
166 #endif // NFD_DAEMON_MGMT_MANAGER_BASE_HPP
PUBLIC_WITH_TESTS_ELSE_PRIVATE
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
ndn::mgmt::AcceptContinuation
std::function< void(const std::string &requester)> AcceptContinuation
a function to be called if authorization is successful
Definition: dispatcher.hpp:45
ndn::PartialName
Name PartialName
Represents an arbitrary sequence of name components.
Definition: name.hpp:39
control-command.hpp
ndn::mgmt::CommandContinuation
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
Definition: dispatcher.hpp:95
ndn::nfd::ControlResponse
mgmt::ControlResponse ControlResponse
Definition: control-response.hpp:30
nfd::ManagerBase::Error
Definition: manager-base.hpp:51
ndn::mgmt::StatusDatasetHandler
std::function< void(const Name &prefix, const Interest &interest, StatusDatasetContext &context)> StatusDatasetHandler
a function to handle a StatusDataset request
Definition: dispatcher.hpp:118
nfd::ManagerBase::registerStatusDatasetHandler
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
Definition: manager-base.cpp:47
nfd::ManagerBase::getModule
const std::string & getModule() const
Definition: manager-base.hpp:60
ndn::mgmt::PostNotification
std::function< void(const Block &notification)> PostNotification
a function to post a notification
Definition: dispatcher.hpp:124
ndn::mgmt::ControlParameters
base class for a struct that contains ControlCommand parameters
Definition: control-parameters.hpp:33
nfd::ManagerBase::ManagerBase
ManagerBase(const std::string &module, Dispatcher &dispatcher)
Definition: manager-base.cpp:30
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
command-authenticator.hpp
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
dispatcher.hpp
nfd::ManagerBase::registerNotificationStream
ndn::mgmt::PostNotification registerNotificationStream(const std::string &verb)
Definition: manager-base.cpp:56
ndn::Name::append
Name & append(const Component &component)
Append a component.
Definition: name.hpp:277
control-response.hpp
ndn::mgmt::Authorization
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
ndn::tlv::nfd::ControlParameters
@ ControlParameters
Definition: tlv-nfd.hpp:35
ndn::mgmt::Dispatcher::addControlCommand
void addControlCommand(const PartialName &relPrefix, Authorization authorize, ValidateParameters validate, ControlCommandHandler handle)
register a ControlCommand
Definition: dispatcher.hpp:460
nfd::ManagerBase::registerCommandHandler
void registerCommandHandler(const std::string &verb, const ControlCommandHandler &handler)
Definition: manager-base.hpp:152
ndn::Interest
Represents an Interest packet.
Definition: interest.hpp:44
nfd::ManagerBase
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
Definition: manager-base.hpp:48
ndn::nfd::ControlParameters
represents parameters in a ControlCommand request or response
Definition: control-parameters.hpp:82
ndn::nfd::ControlCommand
base class of NFD ControlCommand
Definition: control-command.hpp:36
nfd::ManagerBase::~ManagerBase
virtual ~ManagerBase()
ndn::mgmt::Dispatcher
represents a dispatcher on server side of NFD Management protocol
Definition: dispatcher.hpp:131
nfd::CommandAuthenticator
Provides ControlCommand authorization according to NFD configuration file.
Definition: command-authenticator.hpp:46
PUBLIC_WITH_TESTS_ELSE_PROTECTED
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:40
control-parameters.hpp
nfd::ManagerBase::extractRequester
void extractRequester(const Interest &interest, ndn::mgmt::AcceptContinuation accept)
Extracts the requester from a ControlCommand request.
Definition: manager-base.cpp:62
nfd::ManagerBase::ControlCommandHandler
std::function< void(const ControlCommand &command, const Name &prefix, const Interest &interest, const ControlParameters &parameters, const ndn::mgmt::CommandContinuation done)> ControlCommandHandler
Definition: manager-base.hpp:79
Dispatcher
ndn mgmt Dispatcher
Definition: dispatcher.cpp:26