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