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