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 | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2018 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 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 34 | BOOST_AUTO_TEST_CASE(FaceCreateRequest) |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 35 | { |
| 36 | FaceCreateCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 37 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 38 | // good with required fields only |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 39 | ControlParameters p1; |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 40 | p1.setUri("tcp4://192.0.2.1:6363"); |
| 41 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 42 | BOOST_CHECK(Name("/PREFIX/faces/create").isPrefixOf(command.getRequestName("/PREFIX", p1))); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 43 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 44 | // good with optional fields |
| 45 | ControlParameters p2(p1); |
| 46 | p2.setLocalUri("tcp4://192.0.2.2:32114") |
| 47 | .setFacePersistency(FACE_PERSISTENCY_PERMANENT) |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 48 | .setBaseCongestionMarkingInterval(100_ms) |
| 49 | .setDefaultCongestionThreshold(10000) |
Eric Newberry | 3c9bc04 | 2018-06-02 17:58:10 -0700 | [diff] [blame^] | 50 | .setMtu(8192) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 51 | .setFlags(0x3) |
| 52 | .setMask(0x1); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 53 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 54 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 55 | // Uri is required |
| 56 | ControlParameters p3; |
| 57 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 58 | |
| 59 | // Name is forbidden |
| 60 | ControlParameters p4(p1); |
| 61 | p4.setName("/example"); |
| 62 | BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError); |
| 63 | |
| 64 | // Flags and Mask must be specified together |
| 65 | ControlParameters p5(p1); |
| 66 | p5.setFlags(0x3); |
| 67 | BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError); |
| 68 | |
| 69 | ControlParameters p6(p1); |
| 70 | p6.setMask(0x1); |
| 71 | BOOST_CHECK_THROW(command.validateRequest(p6), ControlCommand::ArgumentError); |
| 72 | } |
| 73 | |
| 74 | BOOST_AUTO_TEST_CASE(FaceCreateResponse) |
| 75 | { |
| 76 | FaceCreateCommand command; |
| 77 | |
| 78 | // good |
| 79 | ControlParameters p1; |
| 80 | p1.setFaceId(3208) |
Junxiao Shi | 144c7e3 | 2017-04-20 01:04:06 +0000 | [diff] [blame] | 81 | .setUri("tcp4://192.0.2.1:6363") |
| 82 | .setLocalUri("tcp4://192.0.2.2:32114") |
| 83 | .setFacePersistency(FACE_PERSISTENCY_PERMANENT) |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 84 | .setBaseCongestionMarkingInterval(500_ns) |
| 85 | .setDefaultCongestionThreshold(12345) |
Eric Newberry | 3c9bc04 | 2018-06-02 17:58:10 -0700 | [diff] [blame^] | 86 | .setMtu(2048) |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 87 | .setFlags(0x3); |
| 88 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 89 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 90 | // Name is forbidden |
| 91 | ControlParameters p2(p1); |
| 92 | p2.setName("/example"); |
| 93 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 94 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 95 | // Mask is forbidden |
| 96 | ControlParameters p3(p1); |
| 97 | p3.setMask(0x1); |
| 98 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 99 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 100 | // FaceId must be valid |
| 101 | ControlParameters p4(p1); |
| 102 | p4.setFaceId(INVALID_FACE_ID); |
| 103 | BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 104 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 105 | // LocalUri is required |
| 106 | ControlParameters p5(p1); |
| 107 | p5.unsetLocalUri(); |
| 108 | BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 111 | BOOST_AUTO_TEST_CASE(FaceUpdate) |
| 112 | { |
| 113 | FaceUpdateCommand command; |
| 114 | |
| 115 | ControlParameters p1; |
| 116 | p1.setFaceId(0); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 117 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 118 | p1.setFaceId(INVALID_FACE_ID); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 119 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 120 | |
| 121 | p1.setFaceId(1); |
| 122 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 123 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 124 | command.applyDefaultsToRequest(p1); |
| 125 | BOOST_CHECK_EQUAL(p1.getFaceId(), 1); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 126 | |
| 127 | ControlParameters p2; |
| 128 | p2.setFaceId(1) |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 129 | .setFacePersistency(FACE_PERSISTENCY_PERSISTENT) |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 130 | .setBaseCongestionMarkingInterval(765_ns) |
| 131 | .setDefaultCongestionThreshold(54321) |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 132 | .setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 133 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 134 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); // Mask forbidden but present |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 135 | |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 136 | // Flags without Mask |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 137 | p2.unsetMask(); |
| 138 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 139 | BOOST_CHECK_NO_THROW(command.validateResponse(p2)); |
| 140 | |
| 141 | p2.setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false); |
| 142 | p2.unsetFaceId(); |
| 143 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 144 | |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 145 | ControlParameters p3; |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 146 | p3.setFaceId(1) |
| 147 | .setName("/ndn/name"); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 148 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 149 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 150 | |
| 151 | ControlParameters p4; |
| 152 | p4.setFaceId(1) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 153 | .setUri("tcp4://192.0.2.1"); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 154 | BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError); |
| 155 | BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError); |
| 156 | |
| 157 | ControlParameters p5; |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 158 | BOOST_CHECK_NO_THROW(command.validateRequest(p5)); |
| 159 | BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError); |
| 160 | BOOST_CHECK(!p5.hasFaceId()); |
| 161 | command.applyDefaultsToRequest(p5); |
| 162 | BOOST_REQUIRE(p5.hasFaceId()); |
| 163 | BOOST_CHECK_NO_THROW(command.validateRequest(p5)); |
| 164 | BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError); |
| 165 | BOOST_CHECK_EQUAL(p5.getFaceId(), 0); |
Eric Newberry | 3c9bc04 | 2018-06-02 17:58:10 -0700 | [diff] [blame^] | 166 | |
| 167 | ControlParameters p6; |
| 168 | p6.setFaceId(1) |
| 169 | .setMtu(1024); |
| 170 | BOOST_CHECK_THROW(command.validateRequest(p6), ControlCommand::ArgumentError); |
| 171 | BOOST_CHECK_THROW(command.validateResponse(p6), ControlCommand::ArgumentError); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 172 | } |
| 173 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 174 | BOOST_AUTO_TEST_CASE(FaceDestroy) |
| 175 | { |
| 176 | FaceDestroyCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 177 | |
| 178 | ControlParameters p1; |
| 179 | p1.setUri("tcp4://192.0.2.1") |
| 180 | .setFaceId(4); |
| 181 | BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError); |
| 182 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 183 | |
| 184 | ControlParameters p2; |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 185 | p2.setFaceId(INVALID_FACE_ID); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 186 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 187 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 188 | |
| 189 | ControlParameters p3; |
| 190 | p3.setFaceId(6); |
| 191 | BOOST_CHECK_NO_THROW(command.validateRequest(p3)); |
| 192 | BOOST_CHECK_NO_THROW(command.validateResponse(p3)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 193 | Name n3; |
| 194 | BOOST_CHECK_NO_THROW(n3 = command.getRequestName("/PREFIX", p3)); |
| 195 | BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 198 | BOOST_AUTO_TEST_CASE(FibAddNextHop) |
| 199 | { |
| 200 | FibAddNextHopCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 201 | |
| 202 | ControlParameters p1; |
| 203 | p1.setName("ndn:/") |
| 204 | .setFaceId(22); |
| 205 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 206 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 207 | Name n1; |
| 208 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 209 | BOOST_CHECK(Name("ndn:/PREFIX/fib/add-nexthop").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 210 | |
| 211 | ControlParameters p2; |
| 212 | p2.setName("ndn:/example") |
| 213 | .setFaceId(0) |
| 214 | .setCost(6); |
| 215 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 216 | p2.setFaceId(INVALID_FACE_ID); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 217 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 218 | |
| 219 | command.applyDefaultsToRequest(p1); |
| 220 | BOOST_REQUIRE(p1.hasCost()); |
| 221 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 222 | |
| 223 | p1.unsetFaceId(); |
| 224 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 225 | command.applyDefaultsToRequest(p1); |
| 226 | BOOST_REQUIRE(p1.hasFaceId()); |
| 227 | BOOST_CHECK_EQUAL(p1.getFaceId(), 0); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | BOOST_AUTO_TEST_CASE(FibRemoveNextHop) |
| 231 | { |
| 232 | FibRemoveNextHopCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 233 | |
| 234 | ControlParameters p1; |
| 235 | p1.setName("ndn:/") |
| 236 | .setFaceId(22); |
| 237 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 238 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 239 | Name n1; |
| 240 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 241 | BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 242 | |
| 243 | ControlParameters p2; |
| 244 | p2.setName("ndn:/example") |
| 245 | .setFaceId(0); |
| 246 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 247 | p2.setFaceId(INVALID_FACE_ID); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 248 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 249 | |
| 250 | p1.unsetFaceId(); |
| 251 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 252 | command.applyDefaultsToRequest(p1); |
| 253 | BOOST_REQUIRE(p1.hasFaceId()); |
| 254 | BOOST_CHECK_EQUAL(p1.getFaceId(), 0); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 257 | BOOST_AUTO_TEST_CASE(CsConfigRequest) |
| 258 | { |
| 259 | CsConfigCommand command; |
| 260 | |
| 261 | // good empty request |
| 262 | ControlParameters p1; |
| 263 | command.validateRequest(p1); |
| 264 | BOOST_CHECK(Name("/PREFIX/cs/config").isPrefixOf(command.getRequestName("/PREFIX", p1))); |
| 265 | |
| 266 | // good full request |
| 267 | ControlParameters p2; |
| 268 | p2.setCapacity(1574); |
| 269 | p2.setFlagBit(BIT_CS_ENABLE_ADMIT, true); |
| 270 | p2.setFlagBit(BIT_CS_ENABLE_SERVE, true); |
| 271 | command.validateRequest(p2); |
| 272 | |
| 273 | // bad request: Flags but no Mask |
| 274 | ControlParameters p3(p2); |
| 275 | p3.unsetMask(); |
| 276 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 277 | |
| 278 | // bad request: Mask but no Flags |
| 279 | ControlParameters p4(p2); |
| 280 | p4.unsetFlags(); |
| 281 | BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError); |
| 282 | |
| 283 | // bad request: forbidden field |
| 284 | ControlParameters p5(p2); |
| 285 | p5.setName("/example"); |
| 286 | BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError); |
| 287 | } |
| 288 | |
| 289 | BOOST_AUTO_TEST_CASE(CsConfigResponse) |
| 290 | { |
| 291 | CsConfigCommand command; |
| 292 | |
| 293 | // bad empty response |
| 294 | ControlParameters p1; |
| 295 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
| 296 | |
| 297 | // bad response: Mask not allowed |
| 298 | ControlParameters p2; |
| 299 | p2.setCapacity(1574); |
| 300 | p2.setFlagBit(BIT_CS_ENABLE_ADMIT, true); |
| 301 | p2.setFlagBit(BIT_CS_ENABLE_SERVE, true); |
| 302 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 303 | |
| 304 | // good response |
| 305 | ControlParameters p3(p2); |
| 306 | p3.unsetMask(); |
| 307 | command.validateResponse(p3); |
| 308 | } |
| 309 | |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 310 | BOOST_AUTO_TEST_CASE(CsEraseRequest) |
| 311 | { |
| 312 | CsEraseCommand command; |
| 313 | |
| 314 | // good no-limit request |
| 315 | ControlParameters p1; |
| 316 | p1.setName("/u4LYPNU8Q"); |
| 317 | command.validateRequest(p1); |
| 318 | BOOST_CHECK(Name("/PREFIX/cs/erase").isPrefixOf(command.getRequestName("/PREFIX", p1))); |
| 319 | |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 320 | // good limited request |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 321 | ControlParameters p2; |
| 322 | p2.setName("/IMw1RaLF"); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 323 | p2.setCount(177); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 324 | command.validateRequest(p2); |
| 325 | |
| 326 | // bad request: zero entry |
| 327 | ControlParameters p3; |
| 328 | p3.setName("/ahMID1jcib"); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 329 | p3.setCount(0); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 330 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 331 | |
| 332 | // bad request: forbidden field |
| 333 | ControlParameters p4(p2); |
| 334 | p4.setCapacity(278); |
| 335 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 336 | } |
| 337 | |
| 338 | BOOST_AUTO_TEST_CASE(CsEraseResponse) |
| 339 | { |
| 340 | CsEraseCommand command; |
| 341 | |
| 342 | // good normal response |
| 343 | ControlParameters p1; |
| 344 | p1.setName("/TwiIwCdR"); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 345 | p1.setCount(1); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 346 | command.validateResponse(p1); |
| 347 | |
| 348 | // good limit exceeded request |
| 349 | ControlParameters p2; |
| 350 | p2.setName("/NMsiy44pr"); |
| 351 | p2.setCapacity(360); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 352 | p2.setCount(360); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 353 | command.validateResponse(p2); |
| 354 | |
| 355 | // good zero-entry response |
| 356 | ControlParameters p3; |
| 357 | p3.setName("/5f1LRPh1L"); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 358 | p3.setCount(0); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 359 | command.validateResponse(p3); |
| 360 | |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 361 | // bad request: missing Count |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 362 | ControlParameters p4(p1); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 363 | p4.unsetCount(); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 364 | BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError); |
| 365 | |
| 366 | // bad request: zero capacity |
| 367 | ControlParameters p5(p1); |
| 368 | p5.setCapacity(0); |
| 369 | BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 372 | BOOST_AUTO_TEST_CASE(StrategyChoiceSet) |
| 373 | { |
| 374 | StrategyChoiceSetCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 375 | |
| 376 | ControlParameters p1; |
| 377 | p1.setName("ndn:/") |
| 378 | .setStrategy("ndn:/strategy/P"); |
| 379 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 380 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 381 | Name n1; |
| 382 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 383 | BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/set").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 384 | |
| 385 | ControlParameters p2; |
| 386 | p2.setName("ndn:/example"); |
| 387 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 388 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 389 | } |
| 390 | |
| 391 | BOOST_AUTO_TEST_CASE(StrategyChoiceUnset) |
| 392 | { |
| 393 | StrategyChoiceUnsetCommand command; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 394 | |
| 395 | ControlParameters p1; |
| 396 | p1.setName("ndn:/example"); |
| 397 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 398 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 399 | Name n1; |
| 400 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 401 | BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/unset").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 402 | |
| 403 | ControlParameters p2; |
| 404 | p2.setName("ndn:/example") |
| 405 | .setStrategy("ndn:/strategy/P"); |
| 406 | BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError); |
| 407 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 408 | |
| 409 | ControlParameters p3; |
| 410 | p3.setName("ndn:/"); |
| 411 | BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError); |
| 412 | BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError); |
| 413 | } |
| 414 | |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 415 | BOOST_AUTO_TEST_CASE(RibRegister) |
| 416 | { |
| 417 | RibRegisterCommand command; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 418 | |
| 419 | ControlParameters p1; |
| 420 | p1.setName("ndn:/"); |
| 421 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 422 | BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 423 | Name n1; |
| 424 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 425 | BOOST_CHECK(Name("ndn:/PREFIX/rib/register").isPrefixOf(n1)); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 426 | |
| 427 | command.applyDefaultsToRequest(p1); |
| 428 | BOOST_REQUIRE(p1.hasOrigin()); |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 429 | BOOST_CHECK_EQUAL(p1.getOrigin(), ROUTE_ORIGIN_APP); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 430 | BOOST_REQUIRE(p1.hasCost()); |
| 431 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
| 432 | BOOST_REQUIRE(p1.hasFlags()); |
| 433 | 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] | 434 | BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 435 | |
| 436 | ControlParameters p2; |
| 437 | p2.setName("ndn:/example") |
| 438 | .setFaceId(2) |
| 439 | .setCost(6); |
| 440 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 441 | command.applyDefaultsToRequest(p2); |
Alexander Afanasyev | 21f13b0 | 2014-07-17 16:17:34 -0700 | [diff] [blame] | 442 | BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 443 | BOOST_CHECK_NO_THROW(command.validateResponse(p2)); |
| 444 | } |
| 445 | |
| 446 | BOOST_AUTO_TEST_CASE(RibUnregister) |
| 447 | { |
| 448 | RibUnregisterCommand command; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 449 | |
| 450 | ControlParameters p1; |
| 451 | p1.setName("ndn:/") |
| 452 | .setFaceId(22) |
| 453 | .setOrigin(ROUTE_ORIGIN_STATIC); |
| 454 | BOOST_CHECK_NO_THROW(command.validateRequest(p1)); |
| 455 | BOOST_CHECK_NO_THROW(command.validateResponse(p1)); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 456 | Name n1; |
| 457 | BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1)); |
| 458 | BOOST_CHECK(Name("ndn:/PREFIX/rib/unregister").isPrefixOf(n1)); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 459 | |
| 460 | ControlParameters p2; |
| 461 | p2.setName("ndn:/example") |
| 462 | .setFaceId(0) |
| 463 | .setOrigin(ROUTE_ORIGIN_APP); |
| 464 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 465 | p2.setFaceId(INVALID_FACE_ID); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 466 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 467 | |
| 468 | p2.unsetFaceId(); |
| 469 | BOOST_CHECK_NO_THROW(command.validateRequest(p2)); |
| 470 | BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); |
| 471 | } |
| 472 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 473 | BOOST_AUTO_TEST_SUITE_END() // TestControlCommand |
| 474 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 475 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 476 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 477 | } // namespace tests |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 478 | } // namespace nfd |
| 479 | } // namespace ndn |