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