Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 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. |
| 20 | */ |
| 21 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 22 | #include "control-command.hpp" |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 23 | |
| 24 | namespace ndn { |
| 25 | namespace nfd { |
| 26 | |
| 27 | ControlCommand::ControlCommand(const std::string& module, const std::string& verb) |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 28 | : m_module(module) |
| 29 | , m_verb(verb) |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 30 | { |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Davide Pesavento | aeeb3fc | 2016-08-14 03:40:02 +0200 | [diff] [blame] | 33 | ControlCommand::~ControlCommand() = default; |
| 34 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 35 | void |
| 36 | ControlCommand::validateRequest(const ControlParameters& parameters) const |
| 37 | { |
| 38 | m_requestValidator.validate(parameters); |
| 39 | } |
| 40 | |
| 41 | void |
| 42 | ControlCommand::applyDefaultsToRequest(ControlParameters& parameters) const |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void |
| 47 | ControlCommand::validateResponse(const ControlParameters& parameters) const |
| 48 | { |
| 49 | m_responseValidator.validate(parameters); |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | ControlCommand::applyDefaultsToResponse(ControlParameters& parameters) const |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | Name |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 58 | ControlCommand::getRequestName(const Name& commandPrefix, |
| 59 | const ControlParameters& parameters) const |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 60 | { |
| 61 | this->validateRequest(parameters); |
| 62 | |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 63 | Name name = commandPrefix; |
| 64 | name.append(m_module).append(m_verb); |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 65 | name.append(parameters.wireEncode()); |
| 66 | return name; |
| 67 | } |
| 68 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 69 | ControlCommand::FieldValidator::FieldValidator() |
| 70 | : m_required(CONTROL_PARAMETER_UBOUND) |
| 71 | , m_optional(CONTROL_PARAMETER_UBOUND) |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | ControlCommand::FieldValidator::validate(const ControlParameters& parameters) const |
| 77 | { |
| 78 | const std::vector<bool>& presentFields = parameters.getPresentFields(); |
| 79 | |
| 80 | for (size_t i = 0; i < CONTROL_PARAMETER_UBOUND; ++i) { |
| 81 | bool isPresent = presentFields[i]; |
| 82 | if (m_required[i]) { |
| 83 | if (!isPresent) { |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 84 | BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is required but missing")); |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | else if (isPresent && !m_optional[i]) { |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 88 | BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is forbidden but present")); |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 89 | } |
| 90 | } |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 91 | |
| 92 | if (m_optional[CONTROL_PARAMETER_FLAGS] && m_optional[CONTROL_PARAMETER_MASK]) { |
| 93 | if (parameters.hasFlags() != parameters.hasMask()) { |
| 94 | BOOST_THROW_EXCEPTION(ArgumentError("Flags must be accompanied by Mask")); |
| 95 | } |
| 96 | } |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | FaceCreateCommand::FaceCreateCommand() |
| 100 | : ControlCommand("faces", "create") |
| 101 | { |
| 102 | m_requestValidator |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 103 | .required(CONTROL_PARAMETER_URI) |
Teng Liang | f4908b1 | 2017-03-29 15:24:03 -0700 | [diff] [blame] | 104 | .optional(CONTROL_PARAMETER_LOCAL_URI) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 105 | .optional(CONTROL_PARAMETER_FACE_PERSISTENCY) |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 106 | .optional(CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL) |
| 107 | .optional(CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 108 | .optional(CONTROL_PARAMETER_FLAGS) |
| 109 | .optional(CONTROL_PARAMETER_MASK); |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 110 | m_responseValidator |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 111 | .required(CONTROL_PARAMETER_FACE_ID) |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 112 | .required(CONTROL_PARAMETER_URI) |
| 113 | .required(CONTROL_PARAMETER_LOCAL_URI) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 114 | .required(CONTROL_PARAMETER_FACE_PERSISTENCY) |
Eric Newberry | d567aab | 2018-01-27 16:38:24 -0700 | [diff] [blame] | 115 | .optional(CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL) |
| 116 | .optional(CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD) |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 117 | .required(CONTROL_PARAMETER_FLAGS); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void |
| 121 | FaceCreateCommand::applyDefaultsToRequest(ControlParameters& parameters) const |
| 122 | { |
| 123 | if (!parameters.hasFacePersistency()) { |
| 124 | parameters.setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 125 | } |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void |
| 129 | FaceCreateCommand::validateResponse(const ControlParameters& parameters) const |
| 130 | { |
| 131 | this->ControlCommand::validateResponse(parameters); |
| 132 | |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 133 | if (parameters.getFaceId() == INVALID_FACE_ID) { |
| 134 | BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid")); |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 138 | FaceUpdateCommand::FaceUpdateCommand() |
| 139 | : ControlCommand("faces", "update") |
| 140 | { |
| 141 | m_requestValidator |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 142 | .optional(CONTROL_PARAMETER_FACE_ID) |
| 143 | .optional(CONTROL_PARAMETER_FACE_PERSISTENCY) |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 144 | .optional(CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL) |
| 145 | .optional(CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 146 | .optional(CONTROL_PARAMETER_FLAGS) |
| 147 | .optional(CONTROL_PARAMETER_MASK); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 148 | m_responseValidator |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 149 | .required(CONTROL_PARAMETER_FACE_ID) |
| 150 | .required(CONTROL_PARAMETER_FACE_PERSISTENCY) |
Eric Newberry | d567aab | 2018-01-27 16:38:24 -0700 | [diff] [blame] | 151 | .optional(CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL) |
| 152 | .optional(CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD) |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 153 | .required(CONTROL_PARAMETER_FLAGS); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void |
| 157 | FaceUpdateCommand::applyDefaultsToRequest(ControlParameters& parameters) const |
| 158 | { |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 159 | if (!parameters.hasFaceId()) { |
| 160 | parameters.setFaceId(0); |
| 161 | } |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | void |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 165 | FaceUpdateCommand::validateResponse(const ControlParameters& parameters) const |
| 166 | { |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 167 | this->ControlCommand::validateResponse(parameters); |
| 168 | |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 169 | if (parameters.getFaceId() == INVALID_FACE_ID) { |
| 170 | BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid")); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 171 | } |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 172 | } |
| 173 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 174 | FaceDestroyCommand::FaceDestroyCommand() |
| 175 | : ControlCommand("faces", "destroy") |
| 176 | { |
| 177 | m_requestValidator |
| 178 | .required(CONTROL_PARAMETER_FACE_ID); |
| 179 | m_responseValidator = m_requestValidator; |
| 180 | } |
| 181 | |
| 182 | void |
| 183 | FaceDestroyCommand::validateRequest(const ControlParameters& parameters) const |
| 184 | { |
| 185 | this->ControlCommand::validateRequest(parameters); |
| 186 | |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 187 | if (parameters.getFaceId() == INVALID_FACE_ID) { |
| 188 | BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid")); |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
| 192 | void |
| 193 | FaceDestroyCommand::validateResponse(const ControlParameters& parameters) const |
| 194 | { |
| 195 | this->validateRequest(parameters); |
| 196 | } |
| 197 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 198 | FibAddNextHopCommand::FibAddNextHopCommand() |
| 199 | : ControlCommand("fib", "add-nexthop") |
| 200 | { |
| 201 | m_requestValidator |
| 202 | .required(CONTROL_PARAMETER_NAME) |
| 203 | .optional(CONTROL_PARAMETER_FACE_ID) |
| 204 | .optional(CONTROL_PARAMETER_COST); |
| 205 | m_responseValidator |
| 206 | .required(CONTROL_PARAMETER_NAME) |
| 207 | .required(CONTROL_PARAMETER_FACE_ID) |
| 208 | .required(CONTROL_PARAMETER_COST); |
| 209 | } |
| 210 | |
| 211 | void |
| 212 | FibAddNextHopCommand::applyDefaultsToRequest(ControlParameters& parameters) const |
| 213 | { |
| 214 | if (!parameters.hasFaceId()) { |
| 215 | parameters.setFaceId(0); |
| 216 | } |
| 217 | if (!parameters.hasCost()) { |
| 218 | parameters.setCost(0); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | void |
| 223 | FibAddNextHopCommand::validateResponse(const ControlParameters& parameters) const |
| 224 | { |
| 225 | this->ControlCommand::validateResponse(parameters); |
| 226 | |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 227 | if (parameters.getFaceId() == INVALID_FACE_ID) { |
| 228 | BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid")); |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
| 232 | FibRemoveNextHopCommand::FibRemoveNextHopCommand() |
| 233 | : ControlCommand("fib", "remove-nexthop") |
| 234 | { |
| 235 | m_requestValidator |
| 236 | .required(CONTROL_PARAMETER_NAME) |
| 237 | .optional(CONTROL_PARAMETER_FACE_ID); |
| 238 | m_responseValidator |
| 239 | .required(CONTROL_PARAMETER_NAME) |
| 240 | .required(CONTROL_PARAMETER_FACE_ID); |
| 241 | } |
| 242 | |
| 243 | void |
| 244 | FibRemoveNextHopCommand::applyDefaultsToRequest(ControlParameters& parameters) const |
| 245 | { |
| 246 | if (!parameters.hasFaceId()) { |
| 247 | parameters.setFaceId(0); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | void |
| 252 | FibRemoveNextHopCommand::validateResponse(const ControlParameters& parameters) const |
| 253 | { |
| 254 | this->ControlCommand::validateResponse(parameters); |
| 255 | |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 256 | if (parameters.getFaceId() == INVALID_FACE_ID) { |
| 257 | BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid")); |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 261 | CsConfigCommand::CsConfigCommand() |
| 262 | : ControlCommand("cs", "config") |
| 263 | { |
| 264 | m_requestValidator |
| 265 | .optional(CONTROL_PARAMETER_CAPACITY) |
| 266 | .optional(CONTROL_PARAMETER_FLAGS) |
| 267 | .optional(CONTROL_PARAMETER_MASK); |
| 268 | m_responseValidator |
| 269 | .required(CONTROL_PARAMETER_CAPACITY) |
| 270 | .required(CONTROL_PARAMETER_FLAGS); |
| 271 | } |
| 272 | |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 273 | CsEraseCommand::CsEraseCommand() |
| 274 | : ControlCommand("cs", "erase") |
| 275 | { |
| 276 | m_requestValidator |
| 277 | .required(CONTROL_PARAMETER_NAME) |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 278 | .optional(CONTROL_PARAMETER_COUNT); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 279 | m_responseValidator |
| 280 | .required(CONTROL_PARAMETER_NAME) |
| 281 | .optional(CONTROL_PARAMETER_CAPACITY) |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 282 | .required(CONTROL_PARAMETER_COUNT); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void |
| 286 | CsEraseCommand::validateRequest(const ControlParameters& parameters) const |
| 287 | { |
| 288 | this->ControlCommand::validateRequest(parameters); |
| 289 | |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 290 | if (parameters.hasCount() && parameters.getCount() == 0) { |
| 291 | BOOST_THROW_EXCEPTION(ArgumentError("Count must be positive")); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
| 295 | void |
| 296 | CsEraseCommand::validateResponse(const ControlParameters& parameters) const |
| 297 | { |
| 298 | this->ControlCommand::validateResponse(parameters); |
| 299 | |
| 300 | if (parameters.hasCapacity() && parameters.getCapacity() == 0) { |
| 301 | BOOST_THROW_EXCEPTION(ArgumentError("Capacity must be positive")); |
| 302 | } |
| 303 | } |
| 304 | |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 305 | StrategyChoiceSetCommand::StrategyChoiceSetCommand() |
| 306 | : ControlCommand("strategy-choice", "set") |
| 307 | { |
| 308 | m_requestValidator |
| 309 | .required(CONTROL_PARAMETER_NAME) |
| 310 | .required(CONTROL_PARAMETER_STRATEGY); |
| 311 | m_responseValidator = m_requestValidator; |
| 312 | } |
| 313 | |
| 314 | StrategyChoiceUnsetCommand::StrategyChoiceUnsetCommand() |
| 315 | : ControlCommand("strategy-choice", "unset") |
| 316 | { |
| 317 | m_requestValidator |
| 318 | .required(CONTROL_PARAMETER_NAME); |
| 319 | m_responseValidator = m_requestValidator; |
| 320 | } |
| 321 | |
| 322 | void |
| 323 | StrategyChoiceUnsetCommand::validateRequest(const ControlParameters& parameters) const |
| 324 | { |
| 325 | this->ControlCommand::validateRequest(parameters); |
| 326 | |
| 327 | if (parameters.getName().size() == 0) { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 328 | BOOST_THROW_EXCEPTION(ArgumentError("Name must not be ndn:/")); |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
| 332 | void |
| 333 | StrategyChoiceUnsetCommand::validateResponse(const ControlParameters& parameters) const |
| 334 | { |
| 335 | this->validateRequest(parameters); |
| 336 | } |
| 337 | |
| 338 | RibRegisterCommand::RibRegisterCommand() |
| 339 | : ControlCommand("rib", "register") |
| 340 | { |
| 341 | m_requestValidator |
| 342 | .required(CONTROL_PARAMETER_NAME) |
| 343 | .optional(CONTROL_PARAMETER_FACE_ID) |
| 344 | .optional(CONTROL_PARAMETER_ORIGIN) |
| 345 | .optional(CONTROL_PARAMETER_COST) |
| 346 | .optional(CONTROL_PARAMETER_FLAGS) |
| 347 | .optional(CONTROL_PARAMETER_EXPIRATION_PERIOD); |
| 348 | m_responseValidator |
| 349 | .required(CONTROL_PARAMETER_NAME) |
| 350 | .required(CONTROL_PARAMETER_FACE_ID) |
| 351 | .required(CONTROL_PARAMETER_ORIGIN) |
| 352 | .required(CONTROL_PARAMETER_COST) |
| 353 | .required(CONTROL_PARAMETER_FLAGS) |
| 354 | .optional(CONTROL_PARAMETER_EXPIRATION_PERIOD); |
| 355 | } |
| 356 | |
| 357 | void |
| 358 | RibRegisterCommand::applyDefaultsToRequest(ControlParameters& parameters) const |
| 359 | { |
| 360 | if (!parameters.hasFaceId()) { |
| 361 | parameters.setFaceId(0); |
| 362 | } |
| 363 | if (!parameters.hasOrigin()) { |
| 364 | parameters.setOrigin(ROUTE_ORIGIN_APP); |
| 365 | } |
| 366 | if (!parameters.hasCost()) { |
| 367 | parameters.setCost(0); |
| 368 | } |
| 369 | if (!parameters.hasFlags()) { |
| 370 | parameters.setFlags(ROUTE_FLAG_CHILD_INHERIT); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | void |
| 375 | RibRegisterCommand::validateResponse(const ControlParameters& parameters) const |
| 376 | { |
| 377 | this->ControlCommand::validateResponse(parameters); |
| 378 | |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 379 | if (parameters.getFaceId() == INVALID_FACE_ID) { |
| 380 | BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid")); |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
| 384 | RibUnregisterCommand::RibUnregisterCommand() |
| 385 | : ControlCommand("rib", "unregister") |
| 386 | { |
| 387 | m_requestValidator |
| 388 | .required(CONTROL_PARAMETER_NAME) |
| 389 | .optional(CONTROL_PARAMETER_FACE_ID) |
| 390 | .optional(CONTROL_PARAMETER_ORIGIN); |
| 391 | m_responseValidator |
| 392 | .required(CONTROL_PARAMETER_NAME) |
| 393 | .required(CONTROL_PARAMETER_FACE_ID) |
| 394 | .required(CONTROL_PARAMETER_ORIGIN); |
| 395 | } |
| 396 | |
| 397 | void |
| 398 | RibUnregisterCommand::applyDefaultsToRequest(ControlParameters& parameters) const |
| 399 | { |
| 400 | if (!parameters.hasFaceId()) { |
| 401 | parameters.setFaceId(0); |
| 402 | } |
| 403 | if (!parameters.hasOrigin()) { |
| 404 | parameters.setOrigin(ROUTE_ORIGIN_APP); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | void |
| 409 | RibUnregisterCommand::validateResponse(const ControlParameters& parameters) const |
| 410 | { |
| 411 | this->ControlCommand::validateResponse(parameters); |
| 412 | |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 413 | if (parameters.getFaceId() == INVALID_FACE_ID) { |
| 414 | BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid")); |
Junxiao Shi | 7091165 | 2014-08-12 10:14:24 -0700 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | |
| 418 | } // namespace nfd |
| 419 | } // namespace ndn |