NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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 
33 ManagerBase::ManagerBase(Dispatcher& dispatcher, const std::string& module)
34  : m_dispatcher(dispatcher)
35  , m_module(module)
36 {
37 }
38 
39 ManagerBase::~ManagerBase() = default;
40 
41 void
43  const ndn::mgmt::StatusDatasetHandler& handler)
44 {
45  m_dispatcher.addStatusDataset(makeRelPrefix(verb),
47  handler);
48 }
49 
52 {
53  return m_dispatcher.addNotificationStream(makeRelPrefix(verb));
54 }
55 
56 void
59 {
60  const Name& interestName = interest.getName();
61 
62  try {
64  if (!sigInfo.hasKeyLocator() ||
65  sigInfo.getKeyLocator().getType() != ndn::KeyLocator::KeyLocator_Name) {
66  return accept("");
67  }
68 
69  accept(sigInfo.getKeyLocator().getName().toUri());
70  }
71  catch (const tlv::Error&) {
72  accept("");
73  }
74 }
75 
76 bool
77 ManagerBase::validateParameters(const nfd::ControlCommand& command, const ndn::mgmt::ControlParameters& parameters)
78 {
79  BOOST_ASSERT(dynamic_cast<const ControlParameters*>(&parameters) != nullptr);
80 
81  try {
82  command.validateRequest(static_cast<const ControlParameters&>(parameters));
83  }
84  catch (const ControlCommand::ArgumentError&) {
85  return false;
86  }
87  return true;
88 }
89 
90 void
91 ManagerBase::handleCommand(shared_ptr<nfd::ControlCommand> command,
92  const ControlCommandHandler& handler,
93  const Name& prefix, const Interest& interest,
94  const ndn::mgmt::ControlParameters& params,
96 {
97  BOOST_ASSERT(dynamic_cast<const ControlParameters*>(&params) != nullptr);
98  ControlParameters parameters = static_cast<const ControlParameters&>(params);
99  command->applyDefaultsToRequest(parameters);
100  handler(*command, prefix, interest, parameters, done);
101 }
102 
103 } // namespace nfd
Represents a SignatureInfo TLV element.
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
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()
return an Authorization that accepts all Interests, with empty string as requester ...
Definition: dispatcher.cpp:34
const Component & at(ssize_t i) const
Get the component at the given index.
Definition: name.cpp:180
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
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
std::function< void(const Name &prefix, const Interest &interest, const ControlParameters &params, const CommandContinuation &done)> ControlCommandHandler
a function to handle an authorized ControlCommand
Definition: dispatcher.hpp:106
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:249
Block blockFromValue() const
Definition: block.cpp:325
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)
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:323
const Name & getName() const
Definition: interest.hpp:137
std::function< void(const Name &prefix, const Interest &interest, StatusDatasetContext &context)> StatusDatasetHandler
a function to handle a StatusDataset request
Definition: dispatcher.hpp:118