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 | /** |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 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 { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 28 | namespace tests { |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 29 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 30 | BOOST_AUTO_TEST_SUITE(ManagementNfdControlCommand) |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 31 | |
| 32 | BOOST_AUTO_TEST_CASE(FaceCreate) |
| 33 | { |
| 34 | FaceCreateCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 35 | |
| 36 | ControlParameters p1; |
| 37 | p1.setUri("tcp4://192.0.2.1") |
| 38 | .setFaceId(4); |
| 39 | BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 40 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 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); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 51 | |
| 52 | ControlParameters p4; |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 53 | p4.setUri("tcp4://192.0.2.1") |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 54 | .setFacePersistency(FACE_PERSISTENCY_PERSISTENT) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 55 | .setFlags(0x3) |
| 56 | .setMask(0x1); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 57 | BOOST_CHECK_NO_THROW(command.validateRequest(p4)); |
| 58 | |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 59 | ControlParameters p5; |
| 60 | p5.setUri("tcp4://192.0.2.1") |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 61 | .setFacePersistency(FACE_PERSISTENCY_PERSISTENT) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 62 | .setFlags(0x1); |
| 63 | BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError); |
| 64 | |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 65 | p4.unsetFacePersistency(); |
| 66 | BOOST_CHECK_NO_THROW(command.validateRequest(p4)); |
| 67 | command.applyDefaultsToRequest(p4); |
| 68 | BOOST_REQUIRE(p4.hasFacePersistency()); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(p4.getFacePersistency(), FACE_PERSISTENCY_PERSISTENT); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 70 | |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 71 | ControlParameters p6; |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 72 | p6.setFaceId(4) |
| 73 | .setUri("tcp4://192.0.2.1") |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 74 | .setFacePersistency(FACE_PERSISTENCY_PERSISTENT); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 75 | BOOST_CHECK_NO_THROW(command.validateResponse(p6)); |
| 76 | |
| 77 | ControlParameters p7; |
| 78 | p7.setUri("tcp4://192.0.2.1:6363"); |
| 79 | Name n7; |
| 80 | BOOST_CHECK_NO_THROW(n7 = command.getRequestName("/PREFIX", p7)); |
| 81 | BOOST_CHECK(Name("ndn:/PREFIX/faces/create").isPrefixOf(n7)); |
| 82 | |
| 83 | ControlParameters p8; |
| 84 | p8.setFaceId(5) |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 85 | .setFacePersistency(FACE_PERSISTENCY_PERMANENT) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 86 | .setFlags(0x2); |
| 87 | BOOST_CHECK_NO_THROW(command.validateResponse(p8)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 90 | BOOST_AUTO_TEST_CASE(FaceUpdate) |
| 91 | { |
| 92 | FaceUpdateCommand command; |
| 93 | |
| 94 | ControlParameters p1; |
| 95 | p1.setFaceId(0); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 96 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 97 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 98 | |
| 99 | p1.setFaceId(1); |
| 100 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 101 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 102 | command.applyDefaultsToRequest(p1); |
| 103 | BOOST_CHECK_EQUAL(p1.getFaceId(), 1); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 104 | |
| 105 | ControlParameters p2; |
| 106 | p2.setFaceId(1) |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 107 | .setFacePersistency(FACE_PERSISTENCY_PERSISTENT) |
| 108 | .setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 109 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 110 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); // Mask forbidden but present |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 111 | |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 112 | // Flags without Mask |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 113 | p2.unsetMask(); |
| 114 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 115 | BOOST_CHECK_NO_THROW(command.validateResponse(p2)); |
| 116 | |
| 117 | p2.setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false); |
| 118 | p2.unsetFaceId(); |
| 119 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 120 | |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 121 | ControlParameters p3; |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 122 | p3.setFaceId(1) |
| 123 | .setName("/ndn/name"); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 124 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 125 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 126 | |
| 127 | ControlParameters p4; |
| 128 | p4.setFaceId(1) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 129 | .setUri("tcp4://192.0.2.1"); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 130 | BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError); |
| 131 | BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError); |
| 132 | |
| 133 | ControlParameters p5; |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 134 | BOOST_CHECK_NO_THROW(command.validateRequest(p5)); |
| 135 | BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError); |
| 136 | BOOST_CHECK(!p5.hasFaceId()); |
| 137 | command.applyDefaultsToRequest(p5); |
| 138 | BOOST_REQUIRE(p5.hasFaceId()); |
| 139 | BOOST_CHECK_NO_THROW(command.validateRequest(p5)); |
| 140 | BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError); |
| 141 | BOOST_CHECK_EQUAL(p5.getFaceId(), 0); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 142 | } |
| 143 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 144 | BOOST_AUTO_TEST_CASE(FaceDestroy) |
| 145 | { |
| 146 | FaceDestroyCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 147 | |
| 148 | ControlParameters p1; |
| 149 | p1.setUri("tcp4://192.0.2.1") |
| 150 | .setFaceId(4); |
| 151 | BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError); |
| 152 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 153 | |
| 154 | ControlParameters p2; |
| 155 | p2.setFaceId(0); |
| 156 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 157 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 158 | |
| 159 | ControlParameters p3; |
| 160 | p3.setFaceId(6); |
| 161 | BOOST_CHECK_NO_THROW(command.validateRequest(p3)); |
| 162 | BOOST_CHECK_NO_THROW(command.validateResponse(p3)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 163 | Name n3; |
| 164 | BOOST_CHECK_NO_THROW(n3 = command.getRequestName("/PREFIX", p3)); |
| 165 | BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | BOOST_AUTO_TEST_CASE(FaceEnableLocalControl) |
| 169 | { |
| 170 | FaceEnableLocalControlCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 171 | |
| 172 | ControlParameters p1; |
| 173 | p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 174 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 175 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 176 | Name n1; |
| 177 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 178 | BOOST_CHECK(Name("ndn:/PREFIX/faces/enable-local-control").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 179 | |
| 180 | ControlParameters p2; |
| 181 | p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID) |
| 182 | .setFaceId(9); |
| 183 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 184 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 185 | |
| 186 | ControlParameters p3; |
| 187 | p3.setLocalControlFeature(static_cast<LocalControlFeature>(666)); |
| 188 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 189 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | BOOST_AUTO_TEST_CASE(FaceDisableLocalControl) |
| 193 | { |
| 194 | FaceDisableLocalControlCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 195 | |
| 196 | ControlParameters p1; |
| 197 | p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 198 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 199 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 200 | Name n1; |
| 201 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 202 | BOOST_CHECK(Name("ndn:/PREFIX/faces/disable-local-control").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 203 | |
| 204 | ControlParameters p2; |
| 205 | p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID) |
| 206 | .setFaceId(9); |
| 207 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 208 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | 6888bc1 | 2014-03-29 23:01:41 -0700 | [diff] [blame] | 209 | |
| 210 | ControlParameters p3; |
| 211 | p3.setLocalControlFeature(static_cast<LocalControlFeature>(666)); |
| 212 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 213 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | BOOST_AUTO_TEST_CASE(FibAddNextHop) |
| 217 | { |
| 218 | FibAddNextHopCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 219 | |
| 220 | ControlParameters p1; |
| 221 | p1.setName("ndn:/") |
| 222 | .setFaceId(22); |
| 223 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 224 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 225 | Name n1; |
| 226 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 227 | BOOST_CHECK(Name("ndn:/PREFIX/fib/add-nexthop").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 228 | |
| 229 | ControlParameters p2; |
| 230 | p2.setName("ndn:/example") |
| 231 | .setFaceId(0) |
| 232 | .setCost(6); |
| 233 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 234 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 235 | |
| 236 | command.applyDefaultsToRequest(p1); |
| 237 | BOOST_REQUIRE(p1.hasCost()); |
| 238 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 239 | |
| 240 | p1.unsetFaceId(); |
| 241 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 242 | command.applyDefaultsToRequest(p1); |
| 243 | BOOST_REQUIRE(p1.hasFaceId()); |
| 244 | BOOST_CHECK_EQUAL(p1.getFaceId(), 0); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | BOOST_AUTO_TEST_CASE(FibRemoveNextHop) |
| 248 | { |
| 249 | FibRemoveNextHopCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 250 | |
| 251 | ControlParameters p1; |
| 252 | p1.setName("ndn:/") |
| 253 | .setFaceId(22); |
| 254 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 255 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 256 | Name n1; |
| 257 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 258 | BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 259 | |
| 260 | ControlParameters p2; |
| 261 | p2.setName("ndn:/example") |
| 262 | .setFaceId(0); |
| 263 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 264 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 265 | |
| 266 | p1.unsetFaceId(); |
| 267 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 268 | command.applyDefaultsToRequest(p1); |
| 269 | BOOST_REQUIRE(p1.hasFaceId()); |
| 270 | BOOST_CHECK_EQUAL(p1.getFaceId(), 0); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | BOOST_AUTO_TEST_CASE(StrategyChoiceSet) |
| 274 | { |
| 275 | StrategyChoiceSetCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 276 | |
| 277 | ControlParameters p1; |
| 278 | p1.setName("ndn:/") |
| 279 | .setStrategy("ndn:/strategy/P"); |
| 280 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 281 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 282 | Name n1; |
| 283 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 284 | BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/set").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 285 | |
| 286 | ControlParameters p2; |
| 287 | p2.setName("ndn:/example"); |
| 288 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 289 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 290 | } |
| 291 | |
| 292 | BOOST_AUTO_TEST_CASE(StrategyChoiceUnset) |
| 293 | { |
| 294 | StrategyChoiceUnsetCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 295 | |
| 296 | ControlParameters p1; |
| 297 | p1.setName("ndn:/example"); |
| 298 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 299 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 300 | Name n1; |
| 301 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 302 | BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/unset").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 303 | |
| 304 | ControlParameters p2; |
| 305 | p2.setName("ndn:/example") |
| 306 | .setStrategy("ndn:/strategy/P"); |
| 307 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 308 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 309 | |
| 310 | ControlParameters p3; |
| 311 | p3.setName("ndn:/"); |
| 312 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 313 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 314 | } |
| 315 | |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 316 | BOOST_AUTO_TEST_CASE(RibRegister) |
| 317 | { |
| 318 | RibRegisterCommand command; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 319 | |
| 320 | ControlParameters p1; |
| 321 | p1.setName("ndn:/"); |
| 322 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 323 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 324 | Name n1; |
| 325 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 326 | BOOST_CHECK(Name("ndn:/PREFIX/rib/register").isPrefixOf(n1)); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 327 | |
| 328 | command.applyDefaultsToRequest(p1); |
| 329 | BOOST_REQUIRE(p1.hasOrigin()); |
| 330 | BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP)); |
| 331 | BOOST_REQUIRE(p1.hasCost()); |
| 332 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
| 333 | BOOST_REQUIRE(p1.hasFlags()); |
| 334 | 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] | 335 | BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 336 | |
| 337 | ControlParameters p2; |
| 338 | p2.setName("ndn:/example") |
| 339 | .setFaceId(2) |
| 340 | .setCost(6); |
| 341 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 342 | command.applyDefaultsToRequest(p2); |
Alexander Afanasyev | 21f13b0 | 2014-07-17 16:17:34 -0700 | [diff] [blame] | 343 | BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 344 | BOOST_CHECK_NO_THROW(command.validateResponse(p2)); |
| 345 | } |
| 346 | |
| 347 | BOOST_AUTO_TEST_CASE(RibUnregister) |
| 348 | { |
| 349 | RibUnregisterCommand command; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 350 | |
| 351 | ControlParameters p1; |
| 352 | p1.setName("ndn:/") |
| 353 | .setFaceId(22) |
| 354 | .setOrigin(ROUTE_ORIGIN_STATIC); |
| 355 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 356 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 357 | Name n1; |
| 358 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 359 | BOOST_CHECK(Name("ndn:/PREFIX/rib/unregister").isPrefixOf(n1)); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 360 | |
| 361 | ControlParameters p2; |
| 362 | p2.setName("ndn:/example") |
| 363 | .setFaceId(0) |
| 364 | .setOrigin(ROUTE_ORIGIN_APP); |
| 365 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 366 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 367 | |
| 368 | p2.unsetFaceId(); |
| 369 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 370 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 371 | } |
| 372 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 373 | BOOST_AUTO_TEST_SUITE_END() |
| 374 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 375 | } // namespace tests |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 376 | } // namespace nfd |
| 377 | } // namespace ndn |