control-command.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2023 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_CXX_MGMT_NFD_CONTROL_COMMAND_HPP
23 #define NDN_CXX_MGMT_NFD_CONTROL_COMMAND_HPP
24 
26 
27 namespace ndn::nfd {
28 
34 class ControlCommand : noncopyable
35 {
36 public:
39  class ArgumentError : public std::invalid_argument
40  {
41  public:
42  using std::invalid_argument::invalid_argument;
43  };
44 
45  virtual
47 
51  virtual void
52  validateRequest(const ControlParameters& parameters) const;
53 
56  virtual void
57  applyDefaultsToRequest(ControlParameters& parameters) const;
58 
62  virtual void
63  validateResponse(const ControlParameters& parameters) const;
64 
67  virtual void
68  applyDefaultsToResponse(ControlParameters& parameters) const;
69 
73  Name
74  getRequestName(const Name& commandPrefix, const ControlParameters& parameters) const;
75 
76 protected:
77  ControlCommand(const std::string& module, const std::string& verb);
78 
80  {
81  public:
83 
88  {
89  m_required[field] = true;
90  return *this;
91  }
92 
97  {
98  m_optional[field] = true;
99  return *this;
100  }
101 
106  void
107  validate(const ControlParameters& parameters) const;
108 
109  private:
110  std::vector<bool> m_required;
111  std::vector<bool> m_optional;
112  };
113 
114 protected:
125 
126 private:
127  name::Component m_module;
128  name::Component m_verb;
129 };
130 
131 
138 {
139 public:
141 
142  void
143  applyDefaultsToRequest(ControlParameters& parameters) const override;
144 
145  void
146  validateResponse(const ControlParameters& parameters) const override;
147 };
148 
149 
156 {
157 public:
159 
160  void
161  applyDefaultsToRequest(ControlParameters& parameters) const override;
162 
167  void
168  validateResponse(const ControlParameters& parameters) const override;
169 };
170 
171 
178 {
179 public:
181 
182  void
183  validateRequest(const ControlParameters& parameters) const override;
184 
185  void
186  validateResponse(const ControlParameters& parameters) const override;
187 };
188 
189 
196 {
197 public:
199 
200  void
201  applyDefaultsToRequest(ControlParameters& parameters) const override;
202 
203  void
204  validateResponse(const ControlParameters& parameters) const override;
205 };
206 
207 
214 {
215 public:
217 
218  void
219  applyDefaultsToRequest(ControlParameters& parameters) const override;
220 
221  void
222  validateResponse(const ControlParameters& parameters) const override;
223 };
224 
225 
232 {
233 public:
234  CsConfigCommand();
235 };
236 
237 
244 {
245 public:
246  CsEraseCommand();
247 
248  void
249  validateRequest(const ControlParameters& parameters) const override;
250 
251  void
252  validateResponse(const ControlParameters& parameters) const override;
253 };
254 
255 
262 {
263 public:
265 };
266 
267 
274 {
275 public:
277 
278  void
279  validateRequest(const ControlParameters& parameters) const override;
280 
281  void
282  validateResponse(const ControlParameters& parameters) const override;
283 };
284 
285 
292 {
293 public:
295 
296  void
297  applyDefaultsToRequest(ControlParameters& parameters) const override;
298 
299  void
300  validateResponse(const ControlParameters& parameters) const override;
301 };
302 
303 
310 {
311 public:
313 
314  void
315  applyDefaultsToRequest(ControlParameters& parameters) const override;
316 
317  void
318  validateResponse(const ControlParameters& parameters) const override;
319 };
320 
321 } // namespace ndn::nfd
322 
323 #endif // NDN_CXX_MGMT_NFD_CONTROL_COMMAND_HPP
Represents an absolute name.
Definition: name.hpp:45
Represents a name component.
Represents an error in ControlParameters.
FieldValidator & required(ControlParameterField field)
Declare a required field.
FieldValidator & optional(ControlParameterField field)
Declare an optional field.
void validate(const ControlParameters &parameters) const
Verify that all required fields are present, and all present fields are either required or optional.
Base class of NFD ControlCommand.
ControlCommand(const std::string &module, const std::string &verb)
Name getRequestName(const Name &commandPrefix, const ControlParameters &parameters) const
Construct the Name for a request Interest.
virtual void validateResponse(const ControlParameters &parameters) const
Validate response parameters.
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
Apply default values to missing fields in request.
virtual void validateRequest(const ControlParameters &parameters) const
Validate request parameters.
virtual void applyDefaultsToResponse(ControlParameters &parameters) const
Apply default values to missing fields in response.
FieldValidator m_responseValidator
FieldValidator for response ControlParameters.
FieldValidator m_requestValidator
FieldValidator for request ControlParameters.
Represents parameters in a ControlCommand request or response.
Represents a cs/config command.
Represents a cs/erase command.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
void validateRequest(const ControlParameters &parameters) const override
Validate request parameters.
Represents a faces/create command.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
Represents a faces/destroy command.
void validateRequest(const ControlParameters &parameters) const override
Validate request parameters.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
Represents a faces/update command.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
void validateResponse(const ControlParameters &parameters) const override
Represents a fib/add-nexthop command.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
Represents a fib/remove-nexthop command.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
Represents a rib/register command.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
Represents a rib/unregister command.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
void applyDefaultsToRequest(ControlParameters &parameters) const override
Apply default values to missing fields in request.
Represents a strategy-choice/set command.
Represents a strategy-choice/set command.
void validateRequest(const ControlParameters &parameters) const override
Validate request parameters.
void validateResponse(const ControlParameters &parameters) const override
Validate response parameters.
Contains classes and functions related to the NFD Management protocol.