blob: 8285a6d6252850b2d23a2a3fed8733b52296a79e [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
50 /** \return Name prefix of this ControlCommand
51 */
52 const Name&
53 getPrefix() const
54 {
55 return m_prefix;
56 }
57
Junxiao Shi5ec80222014-03-25 20:08:05 -070058 /** \brief validate request parameters
59 * \throw ArgumentError
60 */
61 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070062 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -070063
64 /** \brief apply default values to missing fields in request
65 */
66 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070067 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -070068
69 /** \brief validate response parameters
70 * \throw ArgumentError
71 */
72 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070073 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -070074
75 /** \brief apply default values to missing fields in response
76 */
77 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -070078 applyDefaultsToResponse(ControlParameters& parameters) const;
79
80 /** \brief construct the Name for a request Interest
81 */
82 Name
83 getRequestName(const ControlParameters& parameters) const;
84
Junxiao Shi5ec80222014-03-25 20:08:05 -070085protected:
Junxiao Shi70911652014-08-12 10:14:24 -070086 ControlCommand(const std::string& module, const std::string& verb);
Junxiao Shi5ec80222014-03-25 20:08:05 -070087
88 class FieldValidator
89 {
90 public:
Junxiao Shi70911652014-08-12 10:14:24 -070091 FieldValidator();
Junxiao Shi5ec80222014-03-25 20:08:05 -070092
93 /** \brief declare a required field
94 */
95 FieldValidator&
96 required(ControlParameterField field)
97 {
98 m_required[field] = true;
99 return *this;
100 }
101
102 /** \brief declare an optional field
103 */
104 FieldValidator&
105 optional(ControlParameterField field)
106 {
107 m_optional[field] = true;
108 return *this;
109 }
110
111 /** \brief verify that all required fields are present,
112 * and all present fields are either required or optional
113 * \throw ArgumentError
114 */
115 void
Junxiao Shi70911652014-08-12 10:14:24 -0700116 validate(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700117
118 private:
119 std::vector<bool> m_required;
120 std::vector<bool> m_optional;
121 };
122
123protected:
124 /** \brief FieldValidator for request ControlParameters
125 *
126 * Constructor of subclass should populate this validator.
127 */
128 FieldValidator m_requestValidator;
129 /** \brief FieldValidator for response ControlParameters
130 *
131 * Constructor of subclass should populate this validator.
132 */
133 FieldValidator m_responseValidator;
134
135private:
136 Name m_prefix;
137};
138
139
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400140/**
141 * \ingroup management
142 * \brief represents a faces/create command
143 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Create-a-face
Junxiao Shi5ec80222014-03-25 20:08:05 -0700144 */
145class FaceCreateCommand : public ControlCommand
146{
147public:
Junxiao Shi70911652014-08-12 10:14:24 -0700148 FaceCreateCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700149
150 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700151 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700152};
153
154
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400155/**
156 * \ingroup management
157 * \brief represents a faces/destroy command
158 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Destroy-a-face
Junxiao Shi5ec80222014-03-25 20:08:05 -0700159 */
160class FaceDestroyCommand : public ControlCommand
161{
162public:
Junxiao Shi70911652014-08-12 10:14:24 -0700163 FaceDestroyCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700164
165 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700166 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700167
168 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700169 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700170};
171
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400172/**
173 * \ingroup management
174 * \brief Base class for faces/[*]-local-control commands
175 */
Junxiao Shi5ec80222014-03-25 20:08:05 -0700176class FaceLocalControlCommand : public ControlCommand
177{
Junxiao Shi6888bc12014-03-29 23:01:41 -0700178public:
179 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700180 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi6888bc12014-03-29 23:01:41 -0700181
182 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700183 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi6888bc12014-03-29 23:01:41 -0700184
Junxiao Shi5ec80222014-03-25 20:08:05 -0700185protected:
186 explicit
Junxiao Shi70911652014-08-12 10:14:24 -0700187 FaceLocalControlCommand(const std::string& verb);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700188};
189
190
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400191/**
192 * \ingroup management
193 * \brief represents a faces/enable-local-control command
194 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature
Junxiao Shi5ec80222014-03-25 20:08:05 -0700195 */
196class FaceEnableLocalControlCommand : public FaceLocalControlCommand
197{
198public:
Junxiao Shi70911652014-08-12 10:14:24 -0700199 FaceEnableLocalControlCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700200};
201
202
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400203/**
204 * \ingroup management
205 * \brief represents a faces/disable-local-control command
206 * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Disable-a-LocalControlHeader-feature
Junxiao Shi5ec80222014-03-25 20:08:05 -0700207 */
208class FaceDisableLocalControlCommand : public FaceLocalControlCommand
209{
210public:
Junxiao Shi70911652014-08-12 10:14:24 -0700211 FaceDisableLocalControlCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700212};
213
214
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400215/**
216 * \ingroup management
217 * \brief represents a fib/add-nexthop command
218 * \sa http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#Add-a-nexthop
Junxiao Shi5ec80222014-03-25 20:08:05 -0700219 */
220class FibAddNextHopCommand : public ControlCommand
221{
222public:
Junxiao Shi70911652014-08-12 10:14:24 -0700223 FibAddNextHopCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700224
225 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700226 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700227
228 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700229 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700230};
231
232
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400233/**
234 * \ingroup management
235 * \brief represents a fib/remove-nexthop command
236 * \sa http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#Remove-a-nexthop
Junxiao Shi5ec80222014-03-25 20:08:05 -0700237 */
238class FibRemoveNextHopCommand : public ControlCommand
239{
240public:
Junxiao Shi70911652014-08-12 10:14:24 -0700241 FibRemoveNextHopCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700242
243 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700244 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shicaac54e2014-05-20 15:27:01 -0700245
246 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700247 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700248};
249
250
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400251/**
252 * \ingroup management
253 * \brief represents a strategy-choice/set command
254 * \sa http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Set-the-strategy-for-a-namespace
Junxiao Shi5ec80222014-03-25 20:08:05 -0700255 */
256class StrategyChoiceSetCommand : public ControlCommand
257{
258public:
Junxiao Shi70911652014-08-12 10:14:24 -0700259 StrategyChoiceSetCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700260};
261
262
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400263/**
264 * \ingroup management
265 * \brief represents a strategy-choice/set command
266 * \sa http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Unset-the-strategy-for-a-namespace
Junxiao Shi5ec80222014-03-25 20:08:05 -0700267 */
268class StrategyChoiceUnsetCommand : public ControlCommand
269{
270public:
Junxiao Shi70911652014-08-12 10:14:24 -0700271 StrategyChoiceUnsetCommand();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700272
273 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700274 validateRequest(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700275
276 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700277 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700278};
279
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700280
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400281/**
282 * \ingroup management
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400283 * \brief represents a rib/register command
284 * \sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Register-a-route
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700285 */
286class RibRegisterCommand : public ControlCommand
287{
288public:
Junxiao Shi70911652014-08-12 10:14:24 -0700289 RibRegisterCommand();
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700290
291 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700292 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700293
294 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700295 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700296};
297
298
Alexander Afanasyev4671bf72014-05-19 09:01:37 -0400299/**
300 * \ingroup management
301 * \brief represents a rib/unregister command
302 * \sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Unregister-a-route
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700303 */
304class RibUnregisterCommand : public ControlCommand
305{
306public:
Junxiao Shi70911652014-08-12 10:14:24 -0700307 RibUnregisterCommand();
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700308
309 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700310 applyDefaultsToRequest(ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700311
312 virtual void
Junxiao Shi70911652014-08-12 10:14:24 -0700313 validateResponse(const ControlParameters& parameters) const;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700314};
315
316
Junxiao Shi5ec80222014-03-25 20:08:05 -0700317} // namespace nfd
318} // namespace ndn
319
320#endif // NDN_MANAGEMENT_NFD_CONTROL_COMMAND_HPP