blob: 2f1c4e0821796a61d71261f3c1318a0c9672b9b1 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi5ec80222014-03-25 20:08:05 -07002/**
Yanbiao Licbdacb22016-08-02 16:02:35 +08003 * Copyright (c) 2013-2016 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Junxiao Shi5ec80222014-03-25 20:08:05 -070020 */
21
22#ifndef NDN_MANAGEMENT_NFD_CONTROL_COMMAND_HPP
23#define NDN_MANAGEMENT_NFD_CONTROL_COMMAND_HPP
24
25#include "nfd-control-parameters.hpp"
Junxiao Shi5ec80222014-03-25 20:08:05 -070026
27namespace ndn {
28namespace nfd {
29
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040030/**
31 * \ingroup management
32 * \brief base class of NFD ControlCommand
33 * \sa http://redmine.named-data.net/projects/nfd/wiki/ControlCommand
Junxiao Shi5ec80222014-03-25 20:08:05 -070034 */
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070035class ControlCommand : noncopyable
Junxiao Shi5ec80222014-03-25 20:08:05 -070036{
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
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +020050 virtual
51 ~ControlCommand();
52
Junxiao Shi5ec80222014-03-25 20:08:05 -070053 /** \brief validate request parameters
Junxiao Shi5de006b2014-10-26 20:20:52 -070054 * \throw ArgumentError if parameters are invalid
Junxiao Shi5ec80222014-03-25 20:08:05 -070055 */
56 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070057 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -070058
59 /** \brief apply default values to missing fields in request
60 */
61 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070062 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -070063
64 /** \brief validate response parameters
Junxiao Shi5de006b2014-10-26 20:20:52 -070065 * \throw ArgumentError if parameters are invalid
Junxiao Shi5ec80222014-03-25 20:08:05 -070066 */
67 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070068 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -070069
70 /** \brief apply default values to missing fields in response
71 */
72 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070073 applyDefaultsToResponse(ControlParameters& parameters) const;
74
75 /** \brief construct the Name for a request Interest
Junxiao Shi5de006b2014-10-26 20:20:52 -070076 * \throw ArgumentError if parameters are invalid
77 */
78 Name
79 getRequestName(const Name& commandPrefix, const ControlParameters& parameters) const;
80
Junxiao Shi5ec80222014-03-25 20:08:05 -070081protected:
Junxiao Shi70911652014-08-12 10:14:24 -070082 ControlCommand(const std::string& module, const std::string& verb);
Junxiao Shi5ec80222014-03-25 20:08:05 -070083
84 class FieldValidator
85 {
86 public:
Junxiao Shi70911652014-08-12 10:14:24 -070087 FieldValidator();
Junxiao Shi5ec80222014-03-25 20:08:05 -070088
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
Junxiao Shi70911652014-08-12 10:14:24 -0700112 validate(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700113
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:
Junxiao Shi5de006b2014-10-26 20:20:52 -0700132 name::Component m_module;
133 name::Component m_verb;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700134};
135
136
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400137/**
138 * \ingroup management
139 * \brief represents a faces/create command
140 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Create-a-face
Junxiao Shi5ec80222014-03-25 20:08:05 -0700141 */
142class FaceCreateCommand : public ControlCommand
143{
144public:
Junxiao Shi70911652014-08-12 10:14:24 -0700145 FaceCreateCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700146
147 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200148 applyDefaultsToRequest(ControlParameters& parameters) const override;
Yukai Tud93c5fc2015-08-25 11:37:16 +0800149
150 virtual void
Eric Newberryda916d62016-08-11 23:04:34 -0700151 validateRequest(const ControlParameters& parameters) const override;
152
153 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200154 validateResponse(const ControlParameters& parameters) const override;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700155};
156
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200157
Yanbiao Licbdacb22016-08-02 16:02:35 +0800158/**
159 * \ingroup management
160 * \brief represents a faces/update command
161 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Update-a-face
162 */
163class FaceUpdateCommand : public ControlCommand
164{
165public:
166 FaceUpdateCommand();
167
168 virtual void
Eric Newberryda916d62016-08-11 23:04:34 -0700169 applyDefaultsToRequest(ControlParameters& parameters) const override;
170
171 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200172 validateRequest(const ControlParameters& parameters) const override;
Yanbiao Licbdacb22016-08-02 16:02:35 +0800173
174 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200175 validateResponse(const ControlParameters& parameters) const override;
Yanbiao Licbdacb22016-08-02 16:02:35 +0800176};
Junxiao Shi5ec80222014-03-25 20:08:05 -0700177
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200178
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400179/**
180 * \ingroup management
181 * \brief represents a faces/destroy command
182 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Destroy-a-face
Junxiao Shi5ec80222014-03-25 20:08:05 -0700183 */
184class FaceDestroyCommand : public ControlCommand
185{
186public:
Junxiao Shi70911652014-08-12 10:14:24 -0700187 FaceDestroyCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700188
189 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200190 validateRequest(const ControlParameters& parameters) const override;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700191
192 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200193 validateResponse(const ControlParameters& parameters) const override;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700194};
195
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200196
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400197/**
198 * \ingroup management
199 * \brief Base class for faces/[*]-local-control commands
200 */
Junxiao Shi5ec80222014-03-25 20:08:05 -0700201class FaceLocalControlCommand : public ControlCommand
202{
Junxiao Shi6888bc12014-03-29 23:01:41 -0700203public:
204 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200205 validateRequest(const ControlParameters& parameters) const override;
Junxiao Shi6888bc12014-03-29 23:01:41 -0700206
207 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200208 validateResponse(const ControlParameters& parameters) const override;
Junxiao Shi6888bc12014-03-29 23:01:41 -0700209
Junxiao Shi5ec80222014-03-25 20:08:05 -0700210protected:
211 explicit
Junxiao Shi70911652014-08-12 10:14:24 -0700212 FaceLocalControlCommand(const std::string& verb);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700213};
214
215
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400216/**
217 * \ingroup management
218 * \brief represents a faces/enable-local-control command
219 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature
Junxiao Shi5ec80222014-03-25 20:08:05 -0700220 */
221class FaceEnableLocalControlCommand : public FaceLocalControlCommand
222{
223public:
Junxiao Shi70911652014-08-12 10:14:24 -0700224 FaceEnableLocalControlCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700225};
226
227
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400228/**
229 * \ingroup management
230 * \brief represents a faces/disable-local-control command
231 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Disable-a-LocalControlHeader-feature
Junxiao Shi5ec80222014-03-25 20:08:05 -0700232 */
233class FaceDisableLocalControlCommand : public FaceLocalControlCommand
234{
235public:
Junxiao Shi70911652014-08-12 10:14:24 -0700236 FaceDisableLocalControlCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700237};
238
239
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400240/**
241 * \ingroup management
242 * \brief represents a fib/add-nexthop command
243 * \sa http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#Add-a-nexthop
Junxiao Shi5ec80222014-03-25 20:08:05 -0700244 */
245class FibAddNextHopCommand : public ControlCommand
246{
247public:
Junxiao Shi70911652014-08-12 10:14:24 -0700248 FibAddNextHopCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700249
250 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200251 applyDefaultsToRequest(ControlParameters& parameters) const override;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700252
253 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200254 validateResponse(const ControlParameters& parameters) const override;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700255};
256
257
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400258/**
259 * \ingroup management
260 * \brief represents a fib/remove-nexthop command
261 * \sa http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#Remove-a-nexthop
Junxiao Shi5ec80222014-03-25 20:08:05 -0700262 */
263class FibRemoveNextHopCommand : public ControlCommand
264{
265public:
Junxiao Shi70911652014-08-12 10:14:24 -0700266 FibRemoveNextHopCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700267
268 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200269 applyDefaultsToRequest(ControlParameters& parameters) const override;
Junxiao Shicaac54e2014-05-20 15:27:01 -0700270
271 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200272 validateResponse(const ControlParameters& parameters) const override;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700273};
274
275
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400276/**
277 * \ingroup management
278 * \brief represents a strategy-choice/set command
279 * \sa http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Set-the-strategy-for-a-namespace
Junxiao Shi5ec80222014-03-25 20:08:05 -0700280 */
281class StrategyChoiceSetCommand : public ControlCommand
282{
283public:
Junxiao Shi70911652014-08-12 10:14:24 -0700284 StrategyChoiceSetCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700285};
286
287
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400288/**
289 * \ingroup management
290 * \brief represents a strategy-choice/set command
291 * \sa http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Unset-the-strategy-for-a-namespace
Junxiao Shi5ec80222014-03-25 20:08:05 -0700292 */
293class StrategyChoiceUnsetCommand : public ControlCommand
294{
295public:
Junxiao Shi70911652014-08-12 10:14:24 -0700296 StrategyChoiceUnsetCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700297
298 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200299 validateRequest(const ControlParameters& parameters) const override;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700300
301 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200302 validateResponse(const ControlParameters& parameters) const override;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700303};
304
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700305
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400306/**
307 * \ingroup management
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400308 * \brief represents a rib/register command
309 * \sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Register-a-route
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700310 */
311class RibRegisterCommand : public ControlCommand
312{
313public:
Junxiao Shi70911652014-08-12 10:14:24 -0700314 RibRegisterCommand();
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700315
316 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200317 applyDefaultsToRequest(ControlParameters& parameters) const override;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700318
319 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200320 validateResponse(const ControlParameters& parameters) const override;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700321};
322
323
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400324/**
325 * \ingroup management
326 * \brief represents a rib/unregister command
327 * \sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Unregister-a-route
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700328 */
329class RibUnregisterCommand : public ControlCommand
330{
331public:
Junxiao Shi70911652014-08-12 10:14:24 -0700332 RibUnregisterCommand();
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700333
334 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200335 applyDefaultsToRequest(ControlParameters& parameters) const override;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700336
337 virtual void
Davide Pesaventoaeeb3fc2016-08-14 03:40:02 +0200338 validateResponse(const ControlParameters& parameters) const override;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700339};
340
Junxiao Shi5ec80222014-03-25 20:08:05 -0700341} // namespace nfd
342} // namespace ndn
343
344#endif // NDN_MANAGEMENT_NFD_CONTROL_COMMAND_HPP