blob: 48a05ee13d7c0745c20dae6e47813d906f066af6 [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
Junxiao Shi5ec80222014-03-25 20:08:05 -070050 /** \brief validate request parameters
Junxiao Shi5de006b2014-10-26 20:20:52 -070051 * \throw ArgumentError if parameters are invalid
Junxiao Shi5ec80222014-03-25 20:08:05 -070052 */
53 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070054 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -070055
56 /** \brief apply default values to missing fields in request
57 */
58 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070059 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -070060
61 /** \brief validate response parameters
Junxiao Shi5de006b2014-10-26 20:20:52 -070062 * \throw ArgumentError if parameters are invalid
Junxiao Shi5ec80222014-03-25 20:08:05 -070063 */
64 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070065 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -070066
67 /** \brief apply default values to missing fields in response
68 */
69 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070070 applyDefaultsToResponse(ControlParameters& parameters) const;
71
72 /** \brief construct the Name for a request Interest
Junxiao Shi5de006b2014-10-26 20:20:52 -070073 * \throw ArgumentError if parameters are invalid
74 */
75 Name
76 getRequestName(const Name& commandPrefix, const ControlParameters& parameters) const;
77
Junxiao Shi5ec80222014-03-25 20:08:05 -070078protected:
Junxiao Shi70911652014-08-12 10:14:24 -070079 ControlCommand(const std::string& module, const std::string& verb);
Junxiao Shi5ec80222014-03-25 20:08:05 -070080
81 class FieldValidator
82 {
83 public:
Junxiao Shi70911652014-08-12 10:14:24 -070084 FieldValidator();
Junxiao Shi5ec80222014-03-25 20:08:05 -070085
86 /** \brief declare a required field
87 */
88 FieldValidator&
89 required(ControlParameterField field)
90 {
91 m_required[field] = true;
92 return *this;
93 }
94
95 /** \brief declare an optional field
96 */
97 FieldValidator&
98 optional(ControlParameterField field)
99 {
100 m_optional[field] = true;
101 return *this;
102 }
103
104 /** \brief verify that all required fields are present,
105 * and all present fields are either required or optional
106 * \throw ArgumentError
107 */
108 void
Junxiao Shi70911652014-08-12 10:14:24 -0700109 validate(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700110
111 private:
112 std::vector<bool> m_required;
113 std::vector<bool> m_optional;
114 };
115
116protected:
117 /** \brief FieldValidator for request ControlParameters
118 *
119 * Constructor of subclass should populate this validator.
120 */
121 FieldValidator m_requestValidator;
122 /** \brief FieldValidator for response ControlParameters
123 *
124 * Constructor of subclass should populate this validator.
125 */
126 FieldValidator m_responseValidator;
127
128private:
Junxiao Shi5de006b2014-10-26 20:20:52 -0700129 name::Component m_module;
130 name::Component m_verb;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700131};
132
133
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400134/**
135 * \ingroup management
136 * \brief represents a faces/create command
137 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Create-a-face
Junxiao Shi5ec80222014-03-25 20:08:05 -0700138 */
139class FaceCreateCommand : public ControlCommand
140{
141public:
Junxiao Shi70911652014-08-12 10:14:24 -0700142 FaceCreateCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700143
144 virtual void
Yukai Tud93c5fc2015-08-25 11:37:16 +0800145 applyDefaultsToRequest(ControlParameters& parameters) const;
146
147 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700148 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700149};
150
Yanbiao Licbdacb22016-08-02 16:02:35 +0800151/**
152 * \ingroup management
153 * \brief represents a faces/update command
154 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Update-a-face
155 */
156class FaceUpdateCommand : public ControlCommand
157{
158public:
159 FaceUpdateCommand();
160
161 virtual void
162 validateRequest(const ControlParameters& parameters) const;
163
164 virtual void
165 validateResponse(const ControlParameters& parameters) const;
166};
Junxiao Shi5ec80222014-03-25 20:08:05 -0700167
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400168/**
169 * \ingroup management
170 * \brief represents a faces/destroy command
171 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Destroy-a-face
Junxiao Shi5ec80222014-03-25 20:08:05 -0700172 */
173class FaceDestroyCommand : public ControlCommand
174{
175public:
Junxiao Shi70911652014-08-12 10:14:24 -0700176 FaceDestroyCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700177
178 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700179 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700180
181 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700182 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700183};
184
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400185/**
186 * \ingroup management
187 * \brief Base class for faces/[*]-local-control commands
188 */
Junxiao Shi5ec80222014-03-25 20:08:05 -0700189class FaceLocalControlCommand : public ControlCommand
190{
Junxiao Shi6888bc12014-03-29 23:01:41 -0700191public:
192 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700193 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi6888bc12014-03-29 23:01:41 -0700194
195 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700196 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi6888bc12014-03-29 23:01:41 -0700197
Junxiao Shi5ec80222014-03-25 20:08:05 -0700198protected:
199 explicit
Junxiao Shi70911652014-08-12 10:14:24 -0700200 FaceLocalControlCommand(const std::string& verb);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700201};
202
203
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400204/**
205 * \ingroup management
206 * \brief represents a faces/enable-local-control command
207 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature
Junxiao Shi5ec80222014-03-25 20:08:05 -0700208 */
209class FaceEnableLocalControlCommand : public FaceLocalControlCommand
210{
211public:
Junxiao Shi70911652014-08-12 10:14:24 -0700212 FaceEnableLocalControlCommand();
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/disable-local-control command
219 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Disable-a-LocalControlHeader-feature
Junxiao Shi5ec80222014-03-25 20:08:05 -0700220 */
221class FaceDisableLocalControlCommand : public FaceLocalControlCommand
222{
223public:
Junxiao Shi70911652014-08-12 10:14:24 -0700224 FaceDisableLocalControlCommand();
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 fib/add-nexthop command
231 * \sa http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#Add-a-nexthop
Junxiao Shi5ec80222014-03-25 20:08:05 -0700232 */
233class FibAddNextHopCommand : public ControlCommand
234{
235public:
Junxiao Shi70911652014-08-12 10:14:24 -0700236 FibAddNextHopCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700237
238 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700239 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700240
241 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700242 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700243};
244
245
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400246/**
247 * \ingroup management
248 * \brief represents a fib/remove-nexthop command
249 * \sa http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#Remove-a-nexthop
Junxiao Shi5ec80222014-03-25 20:08:05 -0700250 */
251class FibRemoveNextHopCommand : public ControlCommand
252{
253public:
Junxiao Shi70911652014-08-12 10:14:24 -0700254 FibRemoveNextHopCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700255
256 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700257 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shicaac54e2014-05-20 15:27:01 -0700258
259 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700260 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700261};
262
263
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400264/**
265 * \ingroup management
266 * \brief represents a strategy-choice/set command
267 * \sa http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Set-the-strategy-for-a-namespace
Junxiao Shi5ec80222014-03-25 20:08:05 -0700268 */
269class StrategyChoiceSetCommand : public ControlCommand
270{
271public:
Junxiao Shi70911652014-08-12 10:14:24 -0700272 StrategyChoiceSetCommand();
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#Unset-the-strategy-for-a-namespace
Junxiao Shi5ec80222014-03-25 20:08:05 -0700280 */
281class StrategyChoiceUnsetCommand : public ControlCommand
282{
283public:
Junxiao Shi70911652014-08-12 10:14:24 -0700284 StrategyChoiceUnsetCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700285
286 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700287 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700288
289 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700290 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700291};
292
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700293
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400294/**
295 * \ingroup management
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400296 * \brief represents a rib/register command
297 * \sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Register-a-route
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700298 */
299class RibRegisterCommand : public ControlCommand
300{
301public:
Junxiao Shi70911652014-08-12 10:14:24 -0700302 RibRegisterCommand();
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700303
304 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700305 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700306
307 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700308 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700309};
310
311
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400312/**
313 * \ingroup management
314 * \brief represents a rib/unregister command
315 * \sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Unregister-a-route
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700316 */
317class RibUnregisterCommand : public ControlCommand
318{
319public:
Junxiao Shi70911652014-08-12 10:14:24 -0700320 RibUnregisterCommand();
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700321
322 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700323 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700324
325 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700326 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700327};
328
Junxiao Shi5ec80222014-03-25 20:08:05 -0700329} // namespace nfd
330} // namespace ndn
331
332#endif // NDN_MANAGEMENT_NFD_CONTROL_COMMAND_HPP