NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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; -*- */
26 #ifndef NFD_DAEMON_MGMT_MANAGER_BASE_HPP
27 #define NFD_DAEMON_MGMT_MANAGER_BASE_HPP
28 
29 #include "common.hpp"
30 
32 #include "mgmt/internal-face.hpp"
33 
34 #include <ndn-cxx/management/nfd-control-command.hpp>
35 #include <ndn-cxx/management/nfd-control-response.hpp>
36 #include <ndn-cxx/management/nfd-control-parameters.hpp>
37 
38 namespace nfd {
39 
43 
44 class InternalFace;
45 
47 {
48 public:
49 
50  struct Error : public std::runtime_error
51  {
52  Error(const std::string& what) : std::runtime_error(what) {}
53  };
54 
55  ManagerBase(shared_ptr<InternalFace> face,
56  const std::string& privilege,
57  ndn::KeyChain& keyChain);
58 
59  virtual
60  ~ManagerBase();
61 
62  void
63  onCommandValidationFailed(const shared_ptr<const Interest>& command,
64  const std::string& error);
65 
66 protected:
67 
68  static bool
69  extractParameters(const Name::Component& parameterComponent,
70  ControlParameters& extractedParameters);
71 
72  void
73  setResponse(ControlResponse& response,
74  uint32_t code,
75  const std::string& text);
76  void
77  setResponse(ControlResponse& response,
78  uint32_t code,
79  const std::string& text,
80  const Block& body);
81 
82  void
83  sendResponse(const Name& name,
84  const ControlResponse& response);
85 
86  void
87  sendResponse(const Name& name,
88  uint32_t code,
89  const std::string& text);
90 
91  void
92  sendResponse(const Name& name,
93  uint32_t code,
94  const std::string& text,
95  const Block& body);
96 
97  void
98  sendNack(const Name& name);
99 
100  virtual bool
101  validateParameters(const ControlCommand& command,
102  ControlParameters& parameters);
103 
105  void
106  addInterestRule(const std::string& regex,
107  const ndn::IdentityCertificate& certificate);
108 
109  void
110  addInterestRule(const std::string& regex,
111  const Name& keyName,
112  const ndn::PublicKey& publicKey);
113 
114  void
115  validate(const Interest& interest,
116  const ndn::OnInterestValidated& onValidated,
117  const ndn::OnInterestValidationFailed& onValidationFailed);
118 
119 protected:
120  shared_ptr<InternalFace> m_face;
121  ndn::KeyChain& m_keyChain;
122 };
123 
124 inline void
126  uint32_t code,
127  const std::string& text)
128 {
129  response.setCode(code);
130  response.setText(text);
131 }
132 
133 inline void
135  uint32_t code,
136  const std::string& text,
137  const Block& body)
138 {
139  setResponse(response, code, text);
140  response.setBody(body);
141 }
142 
143 inline void
144 ManagerBase::addInterestRule(const std::string& regex,
145  const ndn::IdentityCertificate& certificate)
146 {
147  m_face->getValidator().addInterestRule(regex, certificate);
148 }
149 
150 inline void
151 ManagerBase::addInterestRule(const std::string& regex,
152  const Name& keyName,
153  const ndn::PublicKey& publicKey)
154 {
155  m_face->getValidator().addInterestRule(regex, keyName, publicKey);
156 }
157 
158 inline void
160  const ndn::OnInterestValidated& onValidated,
161  const ndn::OnInterestValidationFailed& onValidationFailed)
162 {
163  m_face->getValidator().validate(interest, onValidated, onValidationFailed);
164 }
165 
166 
167 } // namespace nfd
168 
169 #endif // NFD_DAEMON_MGMT_MANAGER_BASE_HPP
shared_ptr< InternalFace > m_face
represents parameters in a ControlCommand request or response
ndn::KeyChain & m_keyChain
void sendResponse(const Name &name, const ControlResponse &response)
base class of NFD ControlCommand
STL namespace.
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
represents an Interest packet
Definition: interest.hpp:45
static bool extractParameters(const Name::Component &parameterComponent, ControlParameters &extractedParameters)
ndn::mgmt::ControlResponse ControlResponse
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
void onCommandValidationFailed(const shared_ptr< const Interest > &command, const std::string &error)
ManagerBase(shared_ptr< InternalFace > face, const std::string &privilege, ndn::KeyChain &keyChain)
virtual ~ManagerBase()
Name abstraction to represent an absolute name.
Definition: name.hpp:46
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:38
void sendNack(const Name &name)
function< void(const shared_ptr< const Interest > &, const std::string &)> OnInterestValidationFailed
Callback to report a failed Interest validation.
Component holds a read-only name component value.
void addInterestRule(const std::string &regex, const ndn::IdentityCertificate &certificate)
void setResponse(ControlResponse &response, uint32_t code, const std::string &text)
virtual bool validateParameters(const ControlCommand &command, ControlParameters &parameters)
void validate(const Interest &interest, const ndn::OnInterestValidated &onValidated, const ndn::OnInterestValidationFailed &onValidationFailed)
function< void(const shared_ptr< const Interest > &)> OnInterestValidated
Callback to report a successful Interest validation.
Error(const std::string &what)