NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
40 using ndn::nfd::ControlCommand;
41 using ndn::nfd::ControlResponse;
42 using ndn::nfd::ControlParameters;
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
125 ManagerBase::setResponse(ControlResponse& response,
126  uint32_t code,
127  const std::string& text)
128 {
129  response.setCode(code);
130  response.setText(text);
131 }
132 
133 inline void
134 ManagerBase::setResponse(ControlResponse& response,
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
159 ManagerBase::validate(const Interest& interest,
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
ndn::KeyChain & m_keyChain
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:38
void sendResponse(const Name &name, const ControlResponse &response)
static bool extractParameters(const Name::Component &parameterComponent, ControlParameters &extractedParameters)
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()
void sendNack(const Name &name)
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)
Error(const std::string &what)