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-2018, 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_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, const std::string& module);
63 
64  virtual
65  ~ManagerBase();
66 
67  const std::string&
68  getModule() const
69  {
70  return m_module;
71  }
72 
73 PUBLIC_WITH_TESTS_ELSE_PROTECTED: // registrations to the dispatcher
74  // difference from mgmt::ControlCommand: accepts nfd::ControlParameters
75  using ControlCommandHandler = std::function<void(const ControlCommand& command,
76  const Name& prefix, const Interest& interest,
77  const ControlParameters& parameters,
79 
80  template<typename Command>
81  void
82  registerCommandHandler(const std::string& verb,
83  const ControlCommandHandler& handler);
84 
85  void
86  registerStatusDatasetHandler(const std::string& verb,
87  const ndn::mgmt::StatusDatasetHandler& handler);
88 
90  registerNotificationStream(const std::string& verb);
91 
101  void
102  extractRequester(const Interest& interest,
104 
110  makeAuthorization(const std::string& verb) = 0;
111 
119  static bool
120  validateParameters(const nfd::ControlCommand& command,
121  const ndn::mgmt::ControlParameters& parameters);
122 
125  static void
126  handleCommand(shared_ptr<nfd::ControlCommand> command,
127  const ControlCommandHandler& handler,
128  const Name& prefix, const Interest& interest,
129  const ndn::mgmt::ControlParameters& params,
131 
141  makeRelPrefix(const std::string& verb);
142 
143 private:
144  Dispatcher& m_dispatcher;
145  std::string m_module;
146 };
147 
148 inline PartialName
149 ManagerBase::makeRelPrefix(const std::string& verb)
150 {
151  return PartialName(m_module).append(verb);
152 }
153 
154 template<typename Command>
155 inline void
156 ManagerBase::registerCommandHandler(const std::string& verb,
157  const ControlCommandHandler& handler)
158 {
159  auto command = make_shared<Command>();
160 
161  m_dispatcher.addControlCommand<ControlParameters>(
162  makeRelPrefix(verb),
163  makeAuthorization(verb),
164  bind(&ManagerBase::validateParameters, cref(*command), _1),
165  bind(&ManagerBase::handleCommand, command, handler, _1, _2, _3, _4));
166 }
167 
168 } // namespace nfd
169 
170 #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:124
represents a dispatcher on server side of NFD Management protocol
Definition: dispatcher.hpp:130
void extractRequester(const Interest &interest, ndn::mgmt::AcceptContinuation accept)
extract a requester from a ControlCommand request
std::function< void(const ControlCommand &command, const Name &prefix, const Interest &interest, const ControlParameters &parameters, const ndn::mgmt::CommandContinuation done)> ControlCommandHandler
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
Name & append(const Component &component)
Append a component.
Definition: name.hpp:256
ndn mgmt Dispatcher
Definition: dispatcher.cpp:26
const std::string & getModule() const
mgmt::ControlResponse ControlResponse
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
Name PartialName
Represents an arbitrary sequence of name components.
Definition: name.hpp:38
virtual ~ManagerBase()
Represents an absolute name.
Definition: name.hpp:42
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
void addControlCommand(const PartialName &relPrefix, const Authorization &authorization, const ValidateParameters &validateParams, const ControlCommandHandler &handler)
register a ControlCommand
Definition: dispatcher.hpp:463
void registerCommandHandler(const std::string &verb, const ControlCommandHandler &handler)
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
std::function< void(const Name &prefix, const Interest &interest, StatusDatasetContext &context)> StatusDatasetHandler
a function to handle a StatusDataset request
Definition: dispatcher.hpp:118