Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef NDN_MANAGEMENT_NFD_CONTROL_COMMAND_HPP |
| 23 | #define NDN_MANAGEMENT_NFD_CONTROL_COMMAND_HPP |
| 24 | |
| 25 | #include "nfd-control-parameters.hpp" |
| 26 | #include "../util/command-interest-generator.hpp" |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace nfd { |
| 30 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 31 | /** |
| 32 | * \ingroup management |
| 33 | * \brief base class of NFD ControlCommand |
| 34 | * \sa http://redmine.named-data.net/projects/nfd/wiki/ControlCommand |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 35 | */ |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 36 | class ControlCommand : noncopyable |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | /** \brief represents an error in ControlParameters |
| 40 | */ |
| 41 | class ArgumentError : public std::invalid_argument |
| 42 | { |
| 43 | public: |
| 44 | explicit |
| 45 | ArgumentError(const std::string& what) |
| 46 | : std::invalid_argument(what) |
| 47 | { |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | /** \return Name prefix of this ControlCommand |
| 52 | */ |
| 53 | const Name& |
| 54 | getPrefix() const |
| 55 | { |
| 56 | return m_prefix; |
| 57 | } |
| 58 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 59 | /** \brief validate request parameters |
| 60 | * \throw ArgumentError |
| 61 | */ |
| 62 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 63 | validateRequest(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 64 | |
| 65 | /** \brief apply default values to missing fields in request |
| 66 | */ |
| 67 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 68 | applyDefaultsToRequest(ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 69 | |
| 70 | /** \brief validate response parameters |
| 71 | * \throw ArgumentError |
| 72 | */ |
| 73 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 74 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 75 | |
| 76 | /** \brief apply default values to missing fields in response |
| 77 | */ |
| 78 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 79 | applyDefaultsToResponse(ControlParameters& parameters) const; |
| 80 | |
| 81 | /** \brief construct the Name for a request Interest |
| 82 | */ |
| 83 | Name |
| 84 | getRequestName(const ControlParameters& parameters) const; |
| 85 | |
| 86 | public: // deprecated |
| 87 | /** \brief a callback on signing command interest |
| 88 | */ |
| 89 | typedef function<void(Interest&)> Sign; |
| 90 | |
| 91 | /** \brief make a Command Interest from parameters |
| 92 | * \deprecated use .getCommandName and sign with KeyChain |
| 93 | */ |
| 94 | Interest |
| 95 | makeCommandInterest(const ControlParameters& parameters, |
| 96 | const Sign& sign) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 97 | |
| 98 | protected: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 99 | ControlCommand(const std::string& module, const std::string& verb); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 100 | |
| 101 | class FieldValidator |
| 102 | { |
| 103 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 104 | FieldValidator(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 105 | |
| 106 | /** \brief declare a required field |
| 107 | */ |
| 108 | FieldValidator& |
| 109 | required(ControlParameterField field) |
| 110 | { |
| 111 | m_required[field] = true; |
| 112 | return *this; |
| 113 | } |
| 114 | |
| 115 | /** \brief declare an optional field |
| 116 | */ |
| 117 | FieldValidator& |
| 118 | optional(ControlParameterField field) |
| 119 | { |
| 120 | m_optional[field] = true; |
| 121 | return *this; |
| 122 | } |
| 123 | |
| 124 | /** \brief verify that all required fields are present, |
| 125 | * and all present fields are either required or optional |
| 126 | * \throw ArgumentError |
| 127 | */ |
| 128 | void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 129 | validate(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 130 | |
| 131 | private: |
| 132 | std::vector<bool> m_required; |
| 133 | std::vector<bool> m_optional; |
| 134 | }; |
| 135 | |
| 136 | protected: |
| 137 | /** \brief FieldValidator for request ControlParameters |
| 138 | * |
| 139 | * Constructor of subclass should populate this validator. |
| 140 | */ |
| 141 | FieldValidator m_requestValidator; |
| 142 | /** \brief FieldValidator for response ControlParameters |
| 143 | * |
| 144 | * Constructor of subclass should populate this validator. |
| 145 | */ |
| 146 | FieldValidator m_responseValidator; |
| 147 | |
| 148 | private: |
| 149 | Name m_prefix; |
| 150 | }; |
| 151 | |
| 152 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 153 | /** |
| 154 | * \ingroup management |
| 155 | * \brief represents a faces/create command |
| 156 | * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Create-a-face |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 157 | */ |
| 158 | class FaceCreateCommand : public ControlCommand |
| 159 | { |
| 160 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 161 | FaceCreateCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 162 | |
| 163 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 164 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 168 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 172 | */ |
| 173 | class FaceDestroyCommand : public ControlCommand |
| 174 | { |
| 175 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 176 | FaceDestroyCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 177 | |
| 178 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 179 | validateRequest(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 180 | |
| 181 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 182 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 185 | /** |
| 186 | * \ingroup management |
| 187 | * \brief Base class for faces/[*]-local-control commands |
| 188 | */ |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 189 | class FaceLocalControlCommand : public ControlCommand |
| 190 | { |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 191 | public: |
| 192 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 193 | validateRequest(const ControlParameters& parameters) const; |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 194 | |
| 195 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 196 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 197 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 198 | protected: |
| 199 | explicit |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 200 | FaceLocalControlCommand(const std::string& verb); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 204 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 208 | */ |
| 209 | class FaceEnableLocalControlCommand : public FaceLocalControlCommand |
| 210 | { |
| 211 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 212 | FaceEnableLocalControlCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 216 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 220 | */ |
| 221 | class FaceDisableLocalControlCommand : public FaceLocalControlCommand |
| 222 | { |
| 223 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 224 | FaceDisableLocalControlCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 228 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 232 | */ |
| 233 | class FibAddNextHopCommand : public ControlCommand |
| 234 | { |
| 235 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 236 | FibAddNextHopCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 237 | |
| 238 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 239 | applyDefaultsToRequest(ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 240 | |
| 241 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 242 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 246 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 250 | */ |
| 251 | class FibRemoveNextHopCommand : public ControlCommand |
| 252 | { |
| 253 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 254 | FibRemoveNextHopCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 255 | |
| 256 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 257 | applyDefaultsToRequest(ControlParameters& parameters) const; |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 258 | |
| 259 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 260 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 264 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 268 | */ |
| 269 | class StrategyChoiceSetCommand : public ControlCommand |
| 270 | { |
| 271 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 272 | StrategyChoiceSetCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 276 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 280 | */ |
| 281 | class StrategyChoiceUnsetCommand : public ControlCommand |
| 282 | { |
| 283 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 284 | StrategyChoiceUnsetCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 285 | |
| 286 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 287 | validateRequest(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 288 | |
| 289 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 290 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 293 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 294 | /** |
| 295 | * \ingroup management |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 296 | * \brief represents a rib/register command |
| 297 | * \sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Register-a-route |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 298 | */ |
| 299 | class RibRegisterCommand : public ControlCommand |
| 300 | { |
| 301 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 302 | RibRegisterCommand(); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 303 | |
| 304 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 305 | applyDefaultsToRequest(ControlParameters& parameters) const; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 306 | |
| 307 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 308 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 309 | }; |
| 310 | |
| 311 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 312 | /** |
| 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 Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 316 | */ |
| 317 | class RibUnregisterCommand : public ControlCommand |
| 318 | { |
| 319 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 320 | RibUnregisterCommand(); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 321 | |
| 322 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 323 | applyDefaultsToRequest(ControlParameters& parameters) const; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 324 | |
| 325 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 326 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 330 | } // namespace nfd |
| 331 | } // namespace ndn |
| 332 | |
| 333 | #endif // NDN_MANAGEMENT_NFD_CONTROL_COMMAND_HPP |