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" |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace nfd { |
| 29 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 30 | /** |
| 31 | * \ingroup management |
| 32 | * \brief base class of NFD ControlCommand |
| 33 | * \sa http://redmine.named-data.net/projects/nfd/wiki/ControlCommand |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 34 | */ |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 35 | class ControlCommand : noncopyable |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 36 | { |
| 37 | public: |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 58 | /** \brief validate request parameters |
| 59 | * \throw ArgumentError |
| 60 | */ |
| 61 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 62 | validateRequest(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 63 | |
| 64 | /** \brief apply default values to missing fields in request |
| 65 | */ |
| 66 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 67 | applyDefaultsToRequest(ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 68 | |
| 69 | /** \brief validate response parameters |
| 70 | * \throw ArgumentError |
| 71 | */ |
| 72 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 73 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 74 | |
| 75 | /** \brief apply default values to missing fields in response |
| 76 | */ |
| 77 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 78 | 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 85 | protected: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 86 | ControlCommand(const std::string& module, const std::string& verb); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 87 | |
| 88 | class FieldValidator |
| 89 | { |
| 90 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 91 | FieldValidator(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 92 | |
| 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 Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 116 | validate(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 117 | |
| 118 | private: |
| 119 | std::vector<bool> m_required; |
| 120 | std::vector<bool> m_optional; |
| 121 | }; |
| 122 | |
| 123 | protected: |
| 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 | |
| 135 | private: |
| 136 | Name m_prefix; |
| 137 | }; |
| 138 | |
| 139 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 140 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 144 | */ |
| 145 | class FaceCreateCommand : public ControlCommand |
| 146 | { |
| 147 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 148 | FaceCreateCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 149 | |
| 150 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 151 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 155 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 159 | */ |
| 160 | class FaceDestroyCommand : public ControlCommand |
| 161 | { |
| 162 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 163 | FaceDestroyCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 164 | |
| 165 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 166 | validateRequest(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 167 | |
| 168 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 169 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 172 | /** |
| 173 | * \ingroup management |
| 174 | * \brief Base class for faces/[*]-local-control commands |
| 175 | */ |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 176 | class FaceLocalControlCommand : public ControlCommand |
| 177 | { |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 178 | public: |
| 179 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 180 | validateRequest(const ControlParameters& parameters) const; |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 181 | |
| 182 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 183 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 184 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 185 | protected: |
| 186 | explicit |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 187 | FaceLocalControlCommand(const std::string& verb); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 191 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 195 | */ |
| 196 | class FaceEnableLocalControlCommand : public FaceLocalControlCommand |
| 197 | { |
| 198 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 199 | FaceEnableLocalControlCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 203 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 207 | */ |
| 208 | class FaceDisableLocalControlCommand : public FaceLocalControlCommand |
| 209 | { |
| 210 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 211 | FaceDisableLocalControlCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 215 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 219 | */ |
| 220 | class FibAddNextHopCommand : public ControlCommand |
| 221 | { |
| 222 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 223 | FibAddNextHopCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 224 | |
| 225 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 226 | applyDefaultsToRequest(ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 227 | |
| 228 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 229 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 233 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 237 | */ |
| 238 | class FibRemoveNextHopCommand : public ControlCommand |
| 239 | { |
| 240 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 241 | FibRemoveNextHopCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 242 | |
| 243 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 244 | applyDefaultsToRequest(ControlParameters& parameters) const; |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 245 | |
| 246 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 247 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 251 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 255 | */ |
| 256 | class StrategyChoiceSetCommand : public ControlCommand |
| 257 | { |
| 258 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 259 | StrategyChoiceSetCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 263 | /** |
| 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 Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 267 | */ |
| 268 | class StrategyChoiceUnsetCommand : public ControlCommand |
| 269 | { |
| 270 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 271 | StrategyChoiceUnsetCommand(); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 272 | |
| 273 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 274 | validateRequest(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 275 | |
| 276 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 277 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 278 | }; |
| 279 | |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 280 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 281 | /** |
| 282 | * \ingroup management |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 283 | * \brief represents a rib/register command |
| 284 | * \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] | 285 | */ |
| 286 | class RibRegisterCommand : public ControlCommand |
| 287 | { |
| 288 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 289 | RibRegisterCommand(); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 290 | |
| 291 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 292 | applyDefaultsToRequest(ControlParameters& parameters) const; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 293 | |
| 294 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 295 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 299 | /** |
| 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 Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 303 | */ |
| 304 | class RibUnregisterCommand : public ControlCommand |
| 305 | { |
| 306 | public: |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 307 | RibUnregisterCommand(); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 308 | |
| 309 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 310 | applyDefaultsToRequest(ControlParameters& parameters) const; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 311 | |
| 312 | virtual void |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 313 | validateResponse(const ControlParameters& parameters) const; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
| 316 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 317 | } // namespace nfd |
| 318 | } // namespace ndn |
| 319 | |
| 320 | #endif // NDN_MANAGEMENT_NFD_CONTROL_COMMAND_HPP |