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