blob: 97b0fa826edf3b57ac73d13f3563a8437c8ca1b7 [file] [log] [blame]
Junxiao Shi7357ef22016-09-07 02:39:37 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -08003 * Copyright (c) 2013-2017 Regents of the University of California.
Junxiao Shi7357ef22016-09-07 02:39:37 +00004 *
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_MGMT_NFD_CONTROL_COMMAND_HPP
23#define NDN_MGMT_NFD_CONTROL_COMMAND_HPP
24
25#include "control-parameters.hpp"
26
27namespace ndn {
28namespace nfd {
29
30/**
31 * \ingroup management
32 * \brief base class of NFD ControlCommand
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -080033 * \sa https://redmine.named-data.net/projects/nfd/wiki/ControlCommand
Junxiao Shi7357ef22016-09-07 02:39:37 +000034 */
35class ControlCommand : noncopyable
36{
37public:
38 /** \brief represents an error in ControlParameters
39 */
40 class ArgumentError : public std::invalid_argument
41 {
42 public:
43 explicit
44 ArgumentError(const std::string& what)
45 : std::invalid_argument(what)
46 {
47 }
48 };
49
50 virtual
51 ~ControlCommand();
52
53 /** \brief validate request parameters
54 * \throw ArgumentError if parameters are invalid
55 */
56 virtual void
57 validateRequest(const ControlParameters& parameters) const;
58
59 /** \brief apply default values to missing fields in request
60 */
61 virtual void
62 applyDefaultsToRequest(ControlParameters& parameters) const;
63
64 /** \brief validate response parameters
65 * \throw ArgumentError if parameters are invalid
66 */
67 virtual void
68 validateResponse(const ControlParameters& parameters) const;
69
70 /** \brief apply default values to missing fields in response
71 */
72 virtual void
73 applyDefaultsToResponse(ControlParameters& parameters) const;
74
75 /** \brief construct the Name for a request Interest
76 * \throw ArgumentError if parameters are invalid
77 */
78 Name
79 getRequestName(const Name& commandPrefix, const ControlParameters& parameters) const;
80
81protected:
82 ControlCommand(const std::string& module, const std::string& verb);
83
84 class FieldValidator
85 {
86 public:
87 FieldValidator();
88
89 /** \brief declare a required field
90 */
91 FieldValidator&
92 required(ControlParameterField field)
93 {
94 m_required[field] = true;
95 return *this;
96 }
97
98 /** \brief declare an optional field
99 */
100 FieldValidator&
101 optional(ControlParameterField field)
102 {
103 m_optional[field] = true;
104 return *this;
105 }
106
107 /** \brief verify that all required fields are present,
108 * and all present fields are either required or optional
109 * \throw ArgumentError
110 */
111 void
112 validate(const ControlParameters& parameters) const;
113
114 private:
115 std::vector<bool> m_required;
116 std::vector<bool> m_optional;
117 };
118
119protected:
120 /** \brief FieldValidator for request ControlParameters
121 *
122 * Constructor of subclass should populate this validator.
123 */
124 FieldValidator m_requestValidator;
125 /** \brief FieldValidator for response ControlParameters
126 *
127 * Constructor of subclass should populate this validator.
128 */
129 FieldValidator m_responseValidator;
130
131private:
132 name::Component m_module;
133 name::Component m_verb;
134};
135
136
137/**
138 * \ingroup management
139 * \brief represents a faces/create command
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -0800140 * \sa https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Create-a-face
Junxiao Shi7357ef22016-09-07 02:39:37 +0000141 */
142class FaceCreateCommand : public ControlCommand
143{
144public:
145 FaceCreateCommand();
146
Davide Pesavento57c07df2016-12-11 18:41:45 -0500147 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000148 applyDefaultsToRequest(ControlParameters& parameters) const override;
149
Davide Pesavento57c07df2016-12-11 18:41:45 -0500150 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000151 validateRequest(const ControlParameters& parameters) const override;
152
Davide Pesavento57c07df2016-12-11 18:41:45 -0500153 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000154 validateResponse(const ControlParameters& parameters) const override;
155};
156
157
158/**
159 * \ingroup management
160 * \brief represents a faces/update command
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -0800161 * \sa https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Update-a-face
Junxiao Shi7357ef22016-09-07 02:39:37 +0000162 */
163class FaceUpdateCommand : public ControlCommand
164{
165public:
166 FaceUpdateCommand();
167
Davide Pesavento57c07df2016-12-11 18:41:45 -0500168 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000169 applyDefaultsToRequest(ControlParameters& parameters) const override;
170
Davide Pesavento57c07df2016-12-11 18:41:45 -0500171 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000172 validateRequest(const ControlParameters& parameters) const override;
173
174 /**
175 * \note This can only validate ControlParameters in a success response.
176 * Failure responses should be validated with validateRequest.
177 */
Davide Pesavento57c07df2016-12-11 18:41:45 -0500178 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000179 validateResponse(const ControlParameters& parameters) const override;
180};
181
182
183/**
184 * \ingroup management
185 * \brief represents a faces/destroy command
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -0800186 * \sa https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Destroy-a-face
Junxiao Shi7357ef22016-09-07 02:39:37 +0000187 */
188class FaceDestroyCommand : public ControlCommand
189{
190public:
191 FaceDestroyCommand();
192
Davide Pesavento57c07df2016-12-11 18:41:45 -0500193 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000194 validateRequest(const ControlParameters& parameters) const override;
195
Davide Pesavento57c07df2016-12-11 18:41:45 -0500196 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000197 validateResponse(const ControlParameters& parameters) const override;
198};
199
200
201/**
202 * \ingroup management
Junxiao Shi7357ef22016-09-07 02:39:37 +0000203 * \brief represents a fib/add-nexthop command
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -0800204 * \sa https://redmine.named-data.net/projects/nfd/wiki/FibMgmt#Add-a-nexthop
Junxiao Shi7357ef22016-09-07 02:39:37 +0000205 */
206class FibAddNextHopCommand : public ControlCommand
207{
208public:
209 FibAddNextHopCommand();
210
Davide Pesavento57c07df2016-12-11 18:41:45 -0500211 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000212 applyDefaultsToRequest(ControlParameters& parameters) const override;
213
Davide Pesavento57c07df2016-12-11 18:41:45 -0500214 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000215 validateResponse(const ControlParameters& parameters) const override;
216};
217
218
219/**
220 * \ingroup management
221 * \brief represents a fib/remove-nexthop command
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -0800222 * \sa https://redmine.named-data.net/projects/nfd/wiki/FibMgmt#Remove-a-nexthop
Junxiao Shi7357ef22016-09-07 02:39:37 +0000223 */
224class FibRemoveNextHopCommand : public ControlCommand
225{
226public:
227 FibRemoveNextHopCommand();
228
Davide Pesavento57c07df2016-12-11 18:41:45 -0500229 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000230 applyDefaultsToRequest(ControlParameters& parameters) const override;
231
Davide Pesavento57c07df2016-12-11 18:41:45 -0500232 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000233 validateResponse(const ControlParameters& parameters) const override;
234};
235
236
237/**
238 * \ingroup management
239 * \brief represents a strategy-choice/set command
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -0800240 * \sa https://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Set-the-strategy-for-a-namespace
Junxiao Shi7357ef22016-09-07 02:39:37 +0000241 */
242class StrategyChoiceSetCommand : public ControlCommand
243{
244public:
245 StrategyChoiceSetCommand();
246};
247
248
249/**
250 * \ingroup management
251 * \brief represents a strategy-choice/set command
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -0800252 * \sa https://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Unset-the-strategy-for-a-namespace
Junxiao Shi7357ef22016-09-07 02:39:37 +0000253 */
254class StrategyChoiceUnsetCommand : public ControlCommand
255{
256public:
257 StrategyChoiceUnsetCommand();
258
Davide Pesavento57c07df2016-12-11 18:41:45 -0500259 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000260 validateRequest(const ControlParameters& parameters) const override;
261
Davide Pesavento57c07df2016-12-11 18:41:45 -0500262 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000263 validateResponse(const ControlParameters& parameters) const override;
264};
265
266
267/**
268 * \ingroup management
269 * \brief represents a rib/register command
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -0800270 * \sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Register-a-route
Junxiao Shi7357ef22016-09-07 02:39:37 +0000271 */
272class RibRegisterCommand : public ControlCommand
273{
274public:
275 RibRegisterCommand();
276
Davide Pesavento57c07df2016-12-11 18:41:45 -0500277 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000278 applyDefaultsToRequest(ControlParameters& parameters) const override;
279
Davide Pesavento57c07df2016-12-11 18:41:45 -0500280 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000281 validateResponse(const ControlParameters& parameters) const override;
282};
283
284
285/**
286 * \ingroup management
287 * \brief represents a rib/unregister command
Alexander Afanasyeve6835fe2017-01-19 20:05:01 -0800288 * \sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Unregister-a-route
Junxiao Shi7357ef22016-09-07 02:39:37 +0000289 */
290class RibUnregisterCommand : public ControlCommand
291{
292public:
293 RibUnregisterCommand();
294
Davide Pesavento57c07df2016-12-11 18:41:45 -0500295 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000296 applyDefaultsToRequest(ControlParameters& parameters) const override;
297
Davide Pesavento57c07df2016-12-11 18:41:45 -0500298 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000299 validateResponse(const ControlParameters& parameters) const override;
300};
301
302} // namespace nfd
303} // namespace ndn
304
305#endif // NDN_MGMT_NFD_CONTROL_COMMAND_HPP