blob: 9c1d2eaa55425bf8c0e859ecb8405ad8e2ed30cc [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/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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
78public: // deprecated
79 /** \return Name prefix of this ControlCommand
80 * \deprecated use getRequestName
81 */
Junxiao Shi415b17c2014-11-12 00:43:25 -070082 DEPRECATED(
Junxiao Shi5de006b2014-10-26 20:20:52 -070083 const Name&
Junxiao Shi415b17c2014-11-12 00:43:25 -070084 getPrefix() const);
Junxiao Shi5de006b2014-10-26 20:20:52 -070085
86 /** \brief construct the Name for a request Interest
87 * \throw ArgumentError if parameters are invalid
88 * \deprecated use the two-argument overload
Junxiao Shi70911652014-08-12 10:14:24 -070089 */
Junxiao Shi415b17c2014-11-12 00:43:25 -070090 DEPRECATED(
Junxiao Shi70911652014-08-12 10:14:24 -070091 Name
Junxiao Shi415b17c2014-11-12 00:43:25 -070092 getRequestName(const ControlParameters& parameters) const);
Junxiao Shi70911652014-08-12 10:14:24 -070093
Junxiao Shi5ec80222014-03-25 20:08:05 -070094protected:
Junxiao Shi70911652014-08-12 10:14:24 -070095 ControlCommand(const std::string& module, const std::string& verb);
Junxiao Shi5ec80222014-03-25 20:08:05 -070096
97 class FieldValidator
98 {
99 public:
Junxiao Shi70911652014-08-12 10:14:24 -0700100 FieldValidator();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700101
102 /** \brief declare a required field
103 */
104 FieldValidator&
105 required(ControlParameterField field)
106 {
107 m_required[field] = true;
108 return *this;
109 }
110
111 /** \brief declare an optional field
112 */
113 FieldValidator&
114 optional(ControlParameterField field)
115 {
116 m_optional[field] = true;
117 return *this;
118 }
119
120 /** \brief verify that all required fields are present,
121 * and all present fields are either required or optional
122 * \throw ArgumentError
123 */
124 void
Junxiao Shi70911652014-08-12 10:14:24 -0700125 validate(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700126
127 private:
128 std::vector<bool> m_required;
129 std::vector<bool> m_optional;
130 };
131
132protected:
133 /** \brief FieldValidator for request ControlParameters
134 *
135 * Constructor of subclass should populate this validator.
136 */
137 FieldValidator m_requestValidator;
138 /** \brief FieldValidator for response ControlParameters
139 *
140 * Constructor of subclass should populate this validator.
141 */
142 FieldValidator m_responseValidator;
143
144private:
Junxiao Shi5de006b2014-10-26 20:20:52 -0700145 name::Component m_module;
146 name::Component m_verb;
147
148 /** \deprecated kept to support getPrefix
149 */
150 mutable Name m_prefix;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700151};
152
153
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400154/**
155 * \ingroup management
156 * \brief represents a faces/create command
157 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Create-a-face
Junxiao Shi5ec80222014-03-25 20:08:05 -0700158 */
159class FaceCreateCommand : public ControlCommand
160{
161public:
Junxiao Shi70911652014-08-12 10:14:24 -0700162 FaceCreateCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700163
164 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700165 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700166};
167
168
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400169/**
170 * \ingroup management
171 * \brief represents a faces/destroy command
172 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Destroy-a-face
Junxiao Shi5ec80222014-03-25 20:08:05 -0700173 */
174class FaceDestroyCommand : public ControlCommand
175{
176public:
Junxiao Shi70911652014-08-12 10:14:24 -0700177 FaceDestroyCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700178
179 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700180 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700181
182 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700183 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700184};
185
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400186/**
187 * \ingroup management
188 * \brief Base class for faces/[*]-local-control commands
189 */
Junxiao Shi5ec80222014-03-25 20:08:05 -0700190class FaceLocalControlCommand : public ControlCommand
191{
Junxiao Shi6888bc12014-03-29 23:01:41 -0700192public:
193 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700194 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi6888bc12014-03-29 23:01:41 -0700195
196 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700197 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi6888bc12014-03-29 23:01:41 -0700198
Junxiao Shi5ec80222014-03-25 20:08:05 -0700199protected:
200 explicit
Junxiao Shi70911652014-08-12 10:14:24 -0700201 FaceLocalControlCommand(const std::string& verb);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700202};
203
204
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400205/**
206 * \ingroup management
207 * \brief represents a faces/enable-local-control command
208 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature
Junxiao Shi5ec80222014-03-25 20:08:05 -0700209 */
210class FaceEnableLocalControlCommand : public FaceLocalControlCommand
211{
212public:
Junxiao Shi70911652014-08-12 10:14:24 -0700213 FaceEnableLocalControlCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700214};
215
216
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400217/**
218 * \ingroup management
219 * \brief represents a faces/disable-local-control command
220 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Disable-a-LocalControlHeader-feature
Junxiao Shi5ec80222014-03-25 20:08:05 -0700221 */
222class FaceDisableLocalControlCommand : public FaceLocalControlCommand
223{
224public:
Junxiao Shi70911652014-08-12 10:14:24 -0700225 FaceDisableLocalControlCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700226};
227
228
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400229/**
230 * \ingroup management
231 * \brief represents a fib/add-nexthop command
232 * \sa http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#Add-a-nexthop
Junxiao Shi5ec80222014-03-25 20:08:05 -0700233 */
234class FibAddNextHopCommand : public ControlCommand
235{
236public:
Junxiao Shi70911652014-08-12 10:14:24 -0700237 FibAddNextHopCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700238
239 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700240 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700241
242 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700243 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700244};
245
246
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400247/**
248 * \ingroup management
249 * \brief represents a fib/remove-nexthop command
250 * \sa http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#Remove-a-nexthop
Junxiao Shi5ec80222014-03-25 20:08:05 -0700251 */
252class FibRemoveNextHopCommand : public ControlCommand
253{
254public:
Junxiao Shi70911652014-08-12 10:14:24 -0700255 FibRemoveNextHopCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700256
257 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700258 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shicaac54e2014-05-20 15:27:01 -0700259
260 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700261 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700262};
263
264
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400265/**
266 * \ingroup management
267 * \brief represents a strategy-choice/set command
268 * \sa http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Set-the-strategy-for-a-namespace
Junxiao Shi5ec80222014-03-25 20:08:05 -0700269 */
270class StrategyChoiceSetCommand : public ControlCommand
271{
272public:
Junxiao Shi70911652014-08-12 10:14:24 -0700273 StrategyChoiceSetCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700274};
275
276
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400277/**
278 * \ingroup management
279 * \brief represents a strategy-choice/set command
280 * \sa http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Unset-the-strategy-for-a-namespace
Junxiao Shi5ec80222014-03-25 20:08:05 -0700281 */
282class StrategyChoiceUnsetCommand : public ControlCommand
283{
284public:
Junxiao Shi70911652014-08-12 10:14:24 -0700285 StrategyChoiceUnsetCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700286
287 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700288 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700289
290 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700291 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700292};
293
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700294
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400295/**
296 * \ingroup management
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400297 * \brief represents a rib/register command
298 * \sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Register-a-route
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700299 */
300class RibRegisterCommand : public ControlCommand
301{
302public:
Junxiao Shi70911652014-08-12 10:14:24 -0700303 RibRegisterCommand();
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700304
305 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700306 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700307
308 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700309 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700310};
311
312
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400313/**
314 * \ingroup management
315 * \brief represents a rib/unregister command
316 * \sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Unregister-a-route
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700317 */
318class RibUnregisterCommand : public ControlCommand
319{
320public:
Junxiao Shi70911652014-08-12 10:14:24 -0700321 RibUnregisterCommand();
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700322
323 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700324 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700325
326 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700327 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700328};
329
330
Junxiao Shi5ec80222014-03-25 20:08:05 -0700331} // namespace nfd
332} // namespace ndn
333
334#endif // NDN_MANAGEMENT_NFD_CONTROL_COMMAND_HPP