NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
manager-base.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "manager-base.hpp"
27 
28 namespace nfd {
29 
32 
34  const std::string& module)
35  : m_dispatcher(dispatcher)
36  , m_module(module)
37 {
38 }
39 
40 void
42  const ndn::mgmt::StatusDatasetHandler& handler)
43 {
44  m_dispatcher.addStatusDataset(makeRelPrefix(verb),
46  handler);
47 }
48 
51 {
52  return m_dispatcher.addNotificationStream(makeRelPrefix(verb));
53 }
54 
55 void
58 {
59  const Name& interestName = interest.getName();
60 
61  try {
63  if (!sigInfo.hasKeyLocator() ||
64  sigInfo.getKeyLocator().getType() != ndn::KeyLocator::KeyLocator_Name) {
65  return accept("");
66  }
67 
68  accept(sigInfo.getKeyLocator().getName().toUri());
69  }
70  catch (const tlv::Error&) {
71  accept("");
72  }
73 }
74 
75 bool
76 ManagerBase::validateParameters(const nfd::ControlCommand& command, const ndn::mgmt::ControlParameters& parameters)
77 {
78  BOOST_ASSERT(dynamic_cast<const ControlParameters*>(&parameters) != nullptr);
79 
80  try {
81  command.validateRequest(static_cast<const ControlParameters&>(parameters));
82  }
83  catch (const ControlCommand::ArgumentError&) {
84  return false;
85  }
86  return true;
87 }
88 
89 void
90 ManagerBase::handleCommand(shared_ptr<nfd::ControlCommand> command,
91  const ControlCommandHandler& handler,
92  const Name& prefix, const Interest& interest,
93  const ndn::mgmt::ControlParameters& params,
95 {
96  BOOST_ASSERT(dynamic_cast<const ControlParameters*>(&params) != nullptr);
97  ControlParameters parameters = static_cast<const ControlParameters&>(params);
98  command->applyDefaultsToRequest(parameters);
99  handler(*command, prefix, interest, parameters, done);
100 }
101 
102 } // namespace nfd
const Component & at(ssize_t i) const
Get component at the specified index.
Definition: name.hpp:434
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
base class of NFD ControlCommand
ManagerBase(Dispatcher &dispatcher, const std::string &module)
represents an Interest packet
Definition: interest.hpp:42
virtual void validateRequest(const ControlParameters &parameters) const
validate request parameters
std::function< void(const std::string &requester)> AcceptContinuation
a function to be called if authorization is successful
Definition: dispatcher.hpp:45
indicates KeyLocator contains a Name
Definition: key-locator.hpp:49
Authorization makeAcceptAllAuthorization()
Definition: dispatcher.cpp:36
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
void addStatusDataset(const PartialName &relPrefix, const Authorization &authorization, const StatusDatasetHandler &handler)
register a StatusDataset or a prefix under which StatusDatasets can be requested
Definition: dispatcher.cpp:259
Block blockFromValue() const
Definition: block.cpp:437
const ssize_t POS_SIG_INFO
std::function< bool(const ControlParameters &params)> ValidateParameters
a function to validate input ControlParameters
Definition: dispatcher.hpp:90
ndn::mgmt::PostNotification registerNotificationStream(const std::string &verb)
represents an error in ControlParameters
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)
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
PostNotification addNotificationStream(const PartialName &relPrefix)
register a NotificationStream
Definition: dispatcher.cpp:334
function< void(const ControlCommand &command, const Name &prefix, const Interest &interest, const ControlParameters &parameters, const ndn::mgmt::CommandContinuation done)> ControlCommandHandler
const Name & getName() const
Definition: interest.hpp:215
std::function< void(const Name &prefix, const Interest &interest, StatusDatasetContext &context)> StatusDatasetHandler
a function to handle a StatusDataset request
Definition: dispatcher.hpp:117