NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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  CommandValidator& validator,
35  const std::string& module)
36  : m_dispatcher(dispatcher)
37  , m_validator(validator)
38  , m_mgmtModuleName(module)
39 {
40  m_validator.addSupportedPrivilege(module);
41 }
42 
43 void
45  const ndn::mgmt::StatusDatasetHandler& handler)
46 {
47  m_dispatcher.addStatusDataset(makeRelPrefix(verb),
49  handler);
50 }
51 
54 {
55  return m_dispatcher.addNotificationStream(makeRelPrefix(verb));
56 }
57 
58 void
59 ManagerBase::authorize(const Name& prefix, const Interest& interest,
60  const ndn::mgmt::ControlParameters* params,
63 {
64  BOOST_ASSERT(params != nullptr);
65  BOOST_ASSERT(typeid(*params) == typeid(ndn::nfd::ControlParameters));
66 
67  m_validator.validate(interest,
68  bind(&ManagerBase::extractRequester, this, interest, accept),
69  bind([&] { reject(ndn::mgmt::RejectReply::STATUS403); }));
70 }
71 
72 void
73 ManagerBase::extractRequester(const Interest& interest,
75 {
76  const Name& interestName = interest.getName();
77 
78  try {
80  if (!sigInfo.hasKeyLocator() ||
81  sigInfo.getKeyLocator().getType() != ndn::KeyLocator::KeyLocator_Name) {
82  return accept("");
83  }
84 
85  accept(sigInfo.getKeyLocator().getName().toUri());
86  }
87  catch (const tlv::Error&) {
88  accept("");
89  }
90 }
91 
92 bool
93 ManagerBase::validateParameters(const nfd::ControlCommand& command, const ndn::mgmt::ControlParameters& parameters)
94 {
95  BOOST_ASSERT(dynamic_cast<const ControlParameters*>(&parameters) != nullptr);
96 
97  try {
98  command.validateRequest(static_cast<const ControlParameters&>(parameters));
99  }
100  catch (const ControlCommand::ArgumentError&) {
101  return false;
102  }
103  return true;
104 }
105 
106 void
107 ManagerBase::handleCommand(shared_ptr<nfd::ControlCommand> command,
108  const ControlCommandHandler& handler,
109  const Name& prefix, const Interest& interest,
110  const ndn::mgmt::ControlParameters& params,
112 {
113  BOOST_ASSERT(dynamic_cast<const ControlParameters*>(&params) != nullptr);
114  ControlParameters parameters = static_cast<const ControlParameters&>(params);
115  command->applyDefaultsToRequest(parameters);
116  handler(*command, prefix, interest, parameters, done);
117 }
118 
119 
120 } // namespace nfd
const Component & at(ssize_t i) const
Get component at the specified index.
Definition: name.hpp:442
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
reply with a ControlResponse where StatusCode is 403
base class of NFD ControlCommand
represents an Interest packet
Definition: interest.hpp:45
virtual void validateRequest(const ControlParameters &parameters) const
validate request parameters
std::function< void(RejectReply act)> RejectContinuation
a function to be called if authorization is rejected
Definition: dispatcher.hpp:60
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:34
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
ManagerBase(Dispatcher &dispatcher, CommandValidator &validator, const std::string &module)
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
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
void validate(const Interest &interest, const ndn::OnInterestValidated &onValidated, const ndn::OnInterestValidationFailed &onValidationFailed)
void addSupportedPrivilege(const std::string &privilege)
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:218
std::function< void(const Name &prefix, const Interest &interest, StatusDatasetContext &context)> StatusDatasetHandler
a function to handle a StatusDataset request
Definition: dispatcher.hpp:117