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 | #include "management/nfd-control-command.hpp" |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 24 | #include "boost-test.hpp" |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace nfd { |
| 28 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 29 | BOOST_AUTO_TEST_SUITE(ManagementTestNfdControlCommand) |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 30 | |
| 31 | BOOST_AUTO_TEST_CASE(FaceCreate) |
| 32 | { |
| 33 | FaceCreateCommand command; |
| 34 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/create"); |
| 35 | |
| 36 | ControlParameters p1; |
| 37 | p1.setUri("tcp4://192.0.2.1") |
| 38 | .setFaceId(4); |
| 39 | BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError); |
| 40 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 41 | |
| 42 | ControlParameters p2; |
| 43 | p2.setName("ndn:/example"); |
| 44 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 45 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 46 | |
| 47 | ControlParameters p3; |
| 48 | p3.setUri("tcp4://192.0.2.1") |
| 49 | .setFaceId(0); |
| 50 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 51 | } |
| 52 | |
| 53 | BOOST_AUTO_TEST_CASE(FaceDestroy) |
| 54 | { |
| 55 | FaceDestroyCommand command; |
| 56 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/destroy"); |
| 57 | |
| 58 | ControlParameters p1; |
| 59 | p1.setUri("tcp4://192.0.2.1") |
| 60 | .setFaceId(4); |
| 61 | BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError); |
| 62 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 63 | |
| 64 | ControlParameters p2; |
| 65 | p2.setFaceId(0); |
| 66 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 67 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 68 | |
| 69 | ControlParameters p3; |
| 70 | p3.setFaceId(6); |
| 71 | BOOST_CHECK_NO_THROW(command.validateRequest(p3)); |
| 72 | BOOST_CHECK_NO_THROW(command.validateResponse(p3)); |
| 73 | } |
| 74 | |
| 75 | BOOST_AUTO_TEST_CASE(FaceEnableLocalControl) |
| 76 | { |
| 77 | FaceEnableLocalControlCommand command; |
| 78 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/enable-local-control"); |
| 79 | |
| 80 | ControlParameters p1; |
| 81 | p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 82 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 83 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 84 | |
| 85 | ControlParameters p2; |
| 86 | p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID) |
| 87 | .setFaceId(9); |
| 88 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 89 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 90 | |
| 91 | ControlParameters p3; |
| 92 | p3.setLocalControlFeature(static_cast<LocalControlFeature>(666)); |
| 93 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 94 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | BOOST_AUTO_TEST_CASE(FaceDisableLocalControl) |
| 98 | { |
| 99 | FaceDisableLocalControlCommand command; |
| 100 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/disable-local-control"); |
| 101 | |
| 102 | ControlParameters p1; |
| 103 | p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 104 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 105 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 106 | |
| 107 | ControlParameters p2; |
| 108 | p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID) |
| 109 | .setFaceId(9); |
| 110 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 111 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 112 | |
| 113 | ControlParameters p3; |
| 114 | p3.setLocalControlFeature(static_cast<LocalControlFeature>(666)); |
| 115 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 116 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | BOOST_AUTO_TEST_CASE(FibAddNextHop) |
| 120 | { |
| 121 | FibAddNextHopCommand command; |
| 122 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/add-nexthop"); |
| 123 | |
| 124 | ControlParameters p1; |
| 125 | p1.setName("ndn:/") |
| 126 | .setFaceId(22); |
| 127 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 128 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 129 | |
| 130 | ControlParameters p2; |
| 131 | p2.setName("ndn:/example") |
| 132 | .setFaceId(0) |
| 133 | .setCost(6); |
| 134 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 135 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 136 | |
| 137 | command.applyDefaultsToRequest(p1); |
| 138 | BOOST_REQUIRE(p1.hasCost()); |
| 139 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 140 | |
| 141 | p1.unsetFaceId(); |
| 142 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 143 | command.applyDefaultsToRequest(p1); |
| 144 | BOOST_REQUIRE(p1.hasFaceId()); |
| 145 | BOOST_CHECK_EQUAL(p1.getFaceId(), 0); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | BOOST_AUTO_TEST_CASE(FibRemoveNextHop) |
| 149 | { |
| 150 | FibRemoveNextHopCommand command; |
| 151 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/remove-nexthop"); |
| 152 | |
| 153 | ControlParameters p1; |
| 154 | p1.setName("ndn:/") |
| 155 | .setFaceId(22); |
| 156 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 157 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 158 | |
| 159 | ControlParameters p2; |
| 160 | p2.setName("ndn:/example") |
| 161 | .setFaceId(0); |
| 162 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 163 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 164 | |
| 165 | p1.unsetFaceId(); |
| 166 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 167 | command.applyDefaultsToRequest(p1); |
| 168 | BOOST_REQUIRE(p1.hasFaceId()); |
| 169 | BOOST_CHECK_EQUAL(p1.getFaceId(), 0); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | BOOST_AUTO_TEST_CASE(StrategyChoiceSet) |
| 173 | { |
| 174 | StrategyChoiceSetCommand command; |
| 175 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/set"); |
| 176 | |
| 177 | ControlParameters p1; |
| 178 | p1.setName("ndn:/") |
| 179 | .setStrategy("ndn:/strategy/P"); |
| 180 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 181 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 182 | |
| 183 | ControlParameters p2; |
| 184 | p2.setName("ndn:/example"); |
| 185 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 186 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 187 | } |
| 188 | |
| 189 | BOOST_AUTO_TEST_CASE(StrategyChoiceUnset) |
| 190 | { |
| 191 | StrategyChoiceUnsetCommand command; |
| 192 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/unset"); |
| 193 | |
| 194 | ControlParameters p1; |
| 195 | p1.setName("ndn:/example"); |
| 196 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 197 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 198 | |
| 199 | ControlParameters p2; |
| 200 | p2.setName("ndn:/example") |
| 201 | .setStrategy("ndn:/strategy/P"); |
| 202 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 203 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 204 | |
| 205 | ControlParameters p3; |
| 206 | p3.setName("ndn:/"); |
| 207 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 208 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 209 | } |
| 210 | |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 211 | BOOST_AUTO_TEST_CASE(RibRegister) |
| 212 | { |
| 213 | RibRegisterCommand command; |
| 214 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/rib/register"); |
| 215 | |
| 216 | ControlParameters p1; |
| 217 | p1.setName("ndn:/"); |
| 218 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 219 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 220 | |
| 221 | command.applyDefaultsToRequest(p1); |
| 222 | BOOST_REQUIRE(p1.hasOrigin()); |
| 223 | BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP)); |
| 224 | BOOST_REQUIRE(p1.hasCost()); |
| 225 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
| 226 | BOOST_REQUIRE(p1.hasFlags()); |
| 227 | BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT)); |
Alexander Afanasyev | 21f13b0 | 2014-07-17 16:17:34 -0700 | [diff] [blame] | 228 | BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 229 | |
| 230 | ControlParameters p2; |
| 231 | p2.setName("ndn:/example") |
| 232 | .setFaceId(2) |
| 233 | .setCost(6); |
| 234 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 235 | command.applyDefaultsToRequest(p2); |
Alexander Afanasyev | 21f13b0 | 2014-07-17 16:17:34 -0700 | [diff] [blame] | 236 | BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 237 | BOOST_CHECK_NO_THROW(command.validateResponse(p2)); |
| 238 | } |
| 239 | |
| 240 | BOOST_AUTO_TEST_CASE(RibUnregister) |
| 241 | { |
| 242 | RibUnregisterCommand command; |
| 243 | BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/rib/unregister"); |
| 244 | |
| 245 | ControlParameters p1; |
| 246 | p1.setName("ndn:/") |
| 247 | .setFaceId(22) |
| 248 | .setOrigin(ROUTE_ORIGIN_STATIC); |
| 249 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 250 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
| 251 | |
| 252 | ControlParameters p2; |
| 253 | p2.setName("ndn:/example") |
| 254 | .setFaceId(0) |
| 255 | .setOrigin(ROUTE_ORIGIN_APP); |
| 256 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 257 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 258 | |
| 259 | p2.unsetFaceId(); |
| 260 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 261 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 262 | } |
| 263 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 264 | BOOST_AUTO_TEST_SUITE_END() |
| 265 | |
| 266 | } // namespace nfd |
| 267 | } // namespace ndn |