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 | /* |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2025 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" |
jaczhi | 82d8ed0 | 2025-01-07 15:51:02 -0800 | [diff] [blame] | 25 | #include "tests/key-chain-fixture.hpp" |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 26 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 27 | namespace ndn::tests { |
| 28 | |
| 29 | using namespace ndn::nfd; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 30 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 31 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 32 | BOOST_AUTO_TEST_SUITE(Nfd) |
| 33 | BOOST_AUTO_TEST_SUITE(TestControlCommand) |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 35 | BOOST_AUTO_TEST_CASE(FaceCreateRequest) |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 36 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 37 | using Command = FaceCreateCommand; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 38 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 39 | // good with required fields only |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 40 | ControlParameters p1; |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 41 | p1.setUri("tcp4://192.0.2.1:6363"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 42 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
| 43 | Name n1 = Command::createRequest("/PREFIX", p1).getName(); |
| 44 | BOOST_CHECK(Name("/PREFIX/faces/create").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 45 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 46 | // good with optional fields |
| 47 | ControlParameters p2(p1); |
| 48 | p2.setLocalUri("tcp4://192.0.2.2:32114") |
| 49 | .setFacePersistency(FACE_PERSISTENCY_PERMANENT) |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 50 | .setBaseCongestionMarkingInterval(100_ms) |
| 51 | .setDefaultCongestionThreshold(10000) |
Eric Newberry | 3c9bc04 | 2018-06-02 17:58:10 -0700 | [diff] [blame] | 52 | .setMtu(8192) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 53 | .setFlags(0x3) |
| 54 | .setMask(0x1); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 55 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 56 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 57 | // Uri is required |
| 58 | ControlParameters p3; |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 59 | BOOST_CHECK_THROW(Command::validateRequest(p3), ArgumentError); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 60 | |
| 61 | // Name is forbidden |
| 62 | ControlParameters p4(p1); |
| 63 | p4.setName("/example"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 64 | BOOST_CHECK_THROW(Command::validateRequest(p4), ArgumentError); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 65 | |
| 66 | // Flags and Mask must be specified together |
| 67 | ControlParameters p5(p1); |
| 68 | p5.setFlags(0x3); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 69 | BOOST_CHECK_THROW(Command::validateRequest(p5), ArgumentError); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 70 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 71 | // Flags and Mask must be specified together |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 72 | ControlParameters p6(p1); |
| 73 | p6.setMask(0x1); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 74 | BOOST_CHECK_THROW(Command::validateRequest(p6), ArgumentError); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | BOOST_AUTO_TEST_CASE(FaceCreateResponse) |
| 78 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 79 | using Command = FaceCreateCommand; |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 80 | |
| 81 | // good |
| 82 | ControlParameters p1; |
| 83 | p1.setFaceId(3208) |
Junxiao Shi | 144c7e3 | 2017-04-20 01:04:06 +0000 | [diff] [blame] | 84 | .setUri("tcp4://192.0.2.1:6363") |
| 85 | .setLocalUri("tcp4://192.0.2.2:32114") |
| 86 | .setFacePersistency(FACE_PERSISTENCY_PERMANENT) |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 87 | .setBaseCongestionMarkingInterval(500_ns) |
| 88 | .setDefaultCongestionThreshold(12345) |
Eric Newberry | 3c9bc04 | 2018-06-02 17:58:10 -0700 | [diff] [blame] | 89 | .setMtu(2048) |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 90 | .setFlags(0x3); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 91 | BOOST_CHECK_NO_THROW(Command::validateResponse(p1)); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 92 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 93 | // Name is forbidden |
| 94 | ControlParameters p2(p1); |
| 95 | p2.setName("/example"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 96 | BOOST_CHECK_THROW(Command::validateResponse(p2), ArgumentError); |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 97 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 98 | // Mask is forbidden |
| 99 | ControlParameters p3(p1); |
| 100 | p3.setMask(0x1); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 101 | BOOST_CHECK_THROW(Command::validateResponse(p3), 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 | // FaceId must be valid |
| 104 | ControlParameters p4(p1); |
| 105 | p4.setFaceId(INVALID_FACE_ID); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 106 | BOOST_CHECK_THROW(Command::validateResponse(p4), ArgumentError); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 107 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 108 | // LocalUri is required |
| 109 | ControlParameters p5(p1); |
| 110 | p5.unsetLocalUri(); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 111 | BOOST_CHECK_THROW(Command::validateResponse(p5), ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 114 | BOOST_AUTO_TEST_CASE(FaceUpdate) |
| 115 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 116 | using Command = FaceUpdateCommand; |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 117 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 118 | // FaceId must be valid |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 119 | ControlParameters p1; |
| 120 | p1.setFaceId(0); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 121 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 122 | p1.setFaceId(INVALID_FACE_ID); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 123 | BOOST_CHECK_THROW(Command::validateResponse(p1), ArgumentError); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 124 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 125 | // Persistency and Flags are required in response |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 126 | p1.setFaceId(1); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 127 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
| 128 | BOOST_CHECK_THROW(Command::validateResponse(p1), ArgumentError); |
| 129 | Command::applyDefaultsToRequest(p1); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 130 | BOOST_CHECK_EQUAL(p1.getFaceId(), 1); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 131 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 132 | // Good request, bad response (Mask is forbidden but present) |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 133 | ControlParameters p2; |
| 134 | p2.setFaceId(1) |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 135 | .setFacePersistency(FACE_PERSISTENCY_PERSISTENT) |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 136 | .setBaseCongestionMarkingInterval(765_ns) |
| 137 | .setDefaultCongestionThreshold(54321) |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 138 | .setMtu(8192) |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 139 | .setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 140 | BOOST_CHECK_NO_THROW(Command::validateRequest(p2)); |
| 141 | BOOST_CHECK_THROW(Command::validateResponse(p2), ArgumentError); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 142 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 143 | // Flags without Mask (good response, bad request) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 144 | p2.unsetMask(); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 145 | BOOST_CHECK_THROW(Command::validateRequest(p2), ArgumentError); |
| 146 | BOOST_CHECK_NO_THROW(Command::validateResponse(p2)); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 147 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 148 | // FaceId is optional in request |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 149 | p2.setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false); |
| 150 | p2.unsetFaceId(); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 151 | BOOST_CHECK_NO_THROW(Command::validateRequest(p2)); |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 152 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 153 | // Name is forbidden |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 154 | ControlParameters p3; |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 155 | p3.setFaceId(1) |
| 156 | .setName("/ndn/name"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 157 | BOOST_CHECK_THROW(Command::validateRequest(p3), ArgumentError); |
| 158 | BOOST_CHECK_THROW(Command::validateResponse(p3), ArgumentError); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 159 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 160 | // Uri is forbidden |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 161 | ControlParameters p4; |
| 162 | p4.setFaceId(1) |
Eric Newberry | da916d6 | 2016-08-11 23:04:34 -0700 | [diff] [blame] | 163 | .setUri("tcp4://192.0.2.1"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 164 | BOOST_CHECK_THROW(Command::validateRequest(p4), ArgumentError); |
| 165 | BOOST_CHECK_THROW(Command::validateResponse(p4), ArgumentError); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 166 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 167 | // Empty request is valid, empty response is invalid |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 168 | ControlParameters p5; |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 169 | BOOST_CHECK_NO_THROW(Command::validateRequest(p5)); |
| 170 | BOOST_CHECK_THROW(Command::validateResponse(p5), ArgumentError); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 171 | BOOST_CHECK(!p5.hasFaceId()); |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 172 | |
| 173 | // Default request, not valid response due to missing FacePersistency and Flags |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 174 | Command::applyDefaultsToRequest(p5); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 175 | BOOST_REQUIRE(p5.hasFaceId()); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 176 | BOOST_CHECK_NO_THROW(Command::validateRequest(p5)); |
| 177 | BOOST_CHECK_THROW(Command::validateResponse(p5), ArgumentError); |
Eric Newberry | 138ef2c | 2016-08-15 20:29:03 -0700 | [diff] [blame] | 178 | BOOST_CHECK_EQUAL(p5.getFaceId(), 0); |
Yanbiao Li | cbdacb2 | 2016-08-02 16:02:35 +0800 | [diff] [blame] | 179 | } |
| 180 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 181 | BOOST_AUTO_TEST_CASE(FaceDestroy) |
| 182 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 183 | using Command = FaceDestroyCommand; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 184 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 185 | // Uri is forbidden |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 186 | ControlParameters p1; |
| 187 | p1.setUri("tcp4://192.0.2.1") |
| 188 | .setFaceId(4); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 189 | BOOST_CHECK_THROW(Command::validateRequest(p1), ArgumentError); |
| 190 | BOOST_CHECK_THROW(Command::validateResponse(p1), ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 191 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 192 | // FaceId must be valid |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 193 | ControlParameters p2; |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 194 | p2.setFaceId(INVALID_FACE_ID); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 195 | BOOST_CHECK_THROW(Command::validateRequest(p2), ArgumentError); |
| 196 | BOOST_CHECK_THROW(Command::validateResponse(p2), ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 197 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 198 | // Good request, good response |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 199 | ControlParameters p3; |
| 200 | p3.setFaceId(6); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 201 | BOOST_CHECK_NO_THROW(Command::validateRequest(p3)); |
| 202 | BOOST_CHECK_NO_THROW(Command::validateResponse(p3)); |
| 203 | Name n3 = Command::createRequest("/PREFIX", p3).getName(); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 204 | BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 207 | BOOST_AUTO_TEST_CASE(FibAddNextHop) |
| 208 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 209 | using Command = FibAddNextHopCommand; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 210 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 211 | // Cost required in response |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 212 | ControlParameters p1; |
| 213 | p1.setName("ndn:/") |
| 214 | .setFaceId(22); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 215 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
| 216 | BOOST_CHECK_THROW(Command::validateResponse(p1), ArgumentError); |
| 217 | Name n1 = Command::createRequest("/PREFIX", p1).getName(); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 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); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 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); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 227 | BOOST_CHECK_THROW(Command::validateResponse(p2), ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 228 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 229 | // Default request |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 230 | Command::applyDefaultsToRequest(p1); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 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(); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 236 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
| 237 | Command::applyDefaultsToRequest(p1); |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 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 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 244 | using Command = FibRemoveNextHopCommand; |
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); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 250 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
| 251 | BOOST_CHECK_NO_THROW(Command::validateResponse(p1)); |
| 252 | Name n1 = Command::createRequest("/PREFIX", p1).getName(); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 253 | BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 254 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 255 | // Good request, bad response (FaceId must be valid) |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 256 | ControlParameters p2; |
| 257 | p2.setName("ndn:/example") |
| 258 | .setFaceId(0); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 259 | BOOST_CHECK_NO_THROW(Command::validateRequest(p2)); |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 260 | p2.setFaceId(INVALID_FACE_ID); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 261 | BOOST_CHECK_THROW(Command::validateResponse(p2), ArgumentError); |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 262 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 263 | // FaceId is optional in request |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 264 | p1.unsetFaceId(); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 265 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
| 266 | Command::applyDefaultsToRequest(p1); |
Junxiao Shi | caac54e | 2014-05-20 15:27:01 -0700 | [diff] [blame] | 267 | BOOST_REQUIRE(p1.hasFaceId()); |
| 268 | BOOST_CHECK_EQUAL(p1.getFaceId(), 0); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 271 | BOOST_AUTO_TEST_CASE(CsConfigRequest) |
| 272 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 273 | using Command = CsConfigCommand; |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 274 | |
| 275 | // good empty request |
| 276 | ControlParameters p1; |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 277 | Command::validateRequest(p1); |
| 278 | Name n1 = Command::createRequest("/PREFIX", p1).getName(); |
| 279 | BOOST_CHECK(Name("/PREFIX/cs/config").isPrefixOf(n1)); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 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); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 286 | Command::validateRequest(p2); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 287 | |
| 288 | // bad request: Flags but no Mask |
| 289 | ControlParameters p3(p2); |
| 290 | p3.unsetMask(); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 291 | BOOST_CHECK_THROW(Command::validateRequest(p3), ArgumentError); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 292 | |
| 293 | // bad request: Mask but no Flags |
| 294 | ControlParameters p4(p2); |
| 295 | p4.unsetFlags(); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 296 | BOOST_CHECK_THROW(Command::validateRequest(p4), ArgumentError); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 297 | |
| 298 | // bad request: forbidden field |
| 299 | ControlParameters p5(p2); |
| 300 | p5.setName("/example"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 301 | BOOST_CHECK_THROW(Command::validateRequest(p5), ArgumentError); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | BOOST_AUTO_TEST_CASE(CsConfigResponse) |
| 305 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 306 | using Command = CsConfigCommand; |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 307 | |
| 308 | // bad empty response |
| 309 | ControlParameters p1; |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 310 | BOOST_CHECK_THROW(Command::validateResponse(p1), ArgumentError); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 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); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 317 | BOOST_CHECK_THROW(Command::validateResponse(p2), ArgumentError); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 318 | |
| 319 | // good response |
| 320 | ControlParameters p3(p2); |
| 321 | p3.unsetMask(); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 322 | Command::validateResponse(p3); |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 325 | BOOST_AUTO_TEST_CASE(CsEraseRequest) |
| 326 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 327 | using Command = CsEraseCommand; |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 328 | |
| 329 | // good no-limit request |
| 330 | ControlParameters p1; |
| 331 | p1.setName("/u4LYPNU8Q"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 332 | Command::validateRequest(p1); |
| 333 | Name n1 = Command::createRequest("/PREFIX", p1).getName(); |
| 334 | BOOST_CHECK(Name("/PREFIX/cs/erase").isPrefixOf(n1)); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 335 | |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 336 | // good limited request |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 337 | ControlParameters p2; |
| 338 | p2.setName("/IMw1RaLF"); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 339 | p2.setCount(177); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 340 | Command::validateRequest(p2); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 341 | |
| 342 | // bad request: zero entry |
| 343 | ControlParameters p3; |
| 344 | p3.setName("/ahMID1jcib"); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 345 | p3.setCount(0); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 346 | BOOST_CHECK_THROW(Command::validateRequest(p3), ArgumentError); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 347 | |
| 348 | // bad request: forbidden field |
| 349 | ControlParameters p4(p2); |
| 350 | p4.setCapacity(278); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 351 | BOOST_CHECK_THROW(Command::validateRequest(p3), ArgumentError); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | BOOST_AUTO_TEST_CASE(CsEraseResponse) |
| 355 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 356 | using Command = CsEraseCommand; |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 357 | |
| 358 | // good normal response |
| 359 | ControlParameters p1; |
| 360 | p1.setName("/TwiIwCdR"); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 361 | p1.setCount(1); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 362 | Command::validateResponse(p1); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 363 | |
| 364 | // good limit exceeded request |
| 365 | ControlParameters p2; |
| 366 | p2.setName("/NMsiy44pr"); |
| 367 | p2.setCapacity(360); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 368 | p2.setCount(360); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 369 | Command::validateResponse(p2); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 370 | |
| 371 | // good zero-entry response |
| 372 | ControlParameters p3; |
| 373 | p3.setName("/5f1LRPh1L"); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 374 | p3.setCount(0); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 375 | Command::validateResponse(p3); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 376 | |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 377 | // bad request: missing Count |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 378 | ControlParameters p4(p1); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 379 | p4.unsetCount(); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 380 | BOOST_CHECK_THROW(Command::validateResponse(p4), ArgumentError); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 381 | |
| 382 | // bad request: zero capacity |
| 383 | ControlParameters p5(p1); |
| 384 | p5.setCapacity(0); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 385 | BOOST_CHECK_THROW(Command::validateResponse(p5), ArgumentError); |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 388 | BOOST_AUTO_TEST_CASE(StrategyChoiceSet) |
| 389 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 390 | using Command = StrategyChoiceSetCommand; |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 391 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 392 | // Good request, good response |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 393 | ControlParameters p1; |
| 394 | p1.setName("ndn:/") |
| 395 | .setStrategy("ndn:/strategy/P"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 396 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
| 397 | BOOST_CHECK_NO_THROW(Command::validateResponse(p1)); |
| 398 | Name n1 = Command::createRequest("/PREFIX", p1).getName(); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 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"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 404 | BOOST_CHECK_THROW(Command::validateRequest(p2), ArgumentError); |
| 405 | BOOST_CHECK_THROW(Command::validateResponse(p2), ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | BOOST_AUTO_TEST_CASE(StrategyChoiceUnset) |
| 409 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 410 | using Command = StrategyChoiceUnsetCommand; |
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"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 415 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
| 416 | BOOST_CHECK_NO_THROW(Command::validateResponse(p1)); |
| 417 | Name n1 = Command::createRequest("/PREFIX", p1).getName(); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 418 | BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/unset").isPrefixOf(n1)); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 419 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 420 | // Strategy is forbidden |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 421 | ControlParameters p2; |
| 422 | p2.setName("ndn:/example") |
| 423 | .setStrategy("ndn:/strategy/P"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 424 | BOOST_CHECK_THROW(Command::validateRequest(p2), ArgumentError); |
| 425 | BOOST_CHECK_THROW(Command::validateResponse(p2), ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 426 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 427 | // Name must have at least one component |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 428 | ControlParameters p3; |
| 429 | p3.setName("ndn:/"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 430 | BOOST_CHECK_THROW(Command::validateRequest(p3), ArgumentError); |
| 431 | BOOST_CHECK_THROW(Command::validateResponse(p3), ArgumentError); |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 434 | BOOST_AUTO_TEST_CASE(RibRegister) |
| 435 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 436 | using Command = RibRegisterCommand; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 437 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 438 | // Good request, response missing many fields |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 439 | ControlParameters p1; |
| 440 | p1.setName("ndn:/"); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 441 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
| 442 | BOOST_CHECK_THROW(Command::validateResponse(p1), ArgumentError); |
| 443 | Name n1 = Command::createRequest("/PREFIX", p1).getName(); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 444 | BOOST_CHECK(Name("ndn:/PREFIX/rib/register").isPrefixOf(n1)); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 445 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 446 | // Default request |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 447 | Command::applyDefaultsToRequest(p1); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 448 | BOOST_REQUIRE(p1.hasOrigin()); |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 449 | BOOST_CHECK_EQUAL(p1.getOrigin(), ROUTE_ORIGIN_APP); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 450 | BOOST_REQUIRE(p1.hasCost()); |
| 451 | BOOST_CHECK_EQUAL(p1.getCost(), 0); |
| 452 | BOOST_REQUIRE(p1.hasFlags()); |
| 453 | 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] | 454 | BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 455 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 456 | // Good request, good response |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 457 | ControlParameters p2; |
| 458 | p2.setName("ndn:/example") |
| 459 | .setFaceId(2) |
| 460 | .setCost(6); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 461 | BOOST_CHECK_NO_THROW(Command::validateRequest(p2)); |
| 462 | Command::applyDefaultsToRequest(p2); |
Alexander Afanasyev | 21f13b0 | 2014-07-17 16:17:34 -0700 | [diff] [blame] | 463 | BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 464 | BOOST_CHECK_NO_THROW(Command::validateResponse(p2)); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | BOOST_AUTO_TEST_CASE(RibUnregister) |
| 468 | { |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 469 | using Command = RibUnregisterCommand; |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 470 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 471 | // Good request, good response |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 472 | ControlParameters p1; |
| 473 | p1.setName("ndn:/") |
| 474 | .setFaceId(22) |
| 475 | .setOrigin(ROUTE_ORIGIN_STATIC); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 476 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
| 477 | BOOST_CHECK_NO_THROW(Command::validateResponse(p1)); |
| 478 | Name n1 = Command::createRequest("/PREFIX", p1).getName(); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 479 | BOOST_CHECK(Name("ndn:/PREFIX/rib/unregister").isPrefixOf(n1)); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 480 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 481 | // Good request, bad response (FaceId must be valid) |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 482 | ControlParameters p2; |
| 483 | p2.setName("ndn:/example") |
| 484 | .setFaceId(0) |
| 485 | .setOrigin(ROUTE_ORIGIN_APP); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 486 | BOOST_CHECK_NO_THROW(Command::validateRequest(p2)); |
Davide Pesavento | f8503d2 | 2017-02-17 01:19:10 -0500 | [diff] [blame] | 487 | p2.setFaceId(INVALID_FACE_ID); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 488 | BOOST_CHECK_THROW(Command::validateResponse(p2), ArgumentError); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 489 | |
Eric Newberry | ce9c195 | 2020-02-15 15:10:59 -0800 | [diff] [blame] | 490 | // FaceId is optional in request, required in response |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 491 | p2.unsetFaceId(); |
Davide Pesavento | aebf5d7 | 2024-12-26 16:04:12 -0500 | [diff] [blame] | 492 | BOOST_CHECK_NO_THROW(Command::validateRequest(p2)); |
| 493 | BOOST_CHECK_THROW(Command::validateResponse(p2), ArgumentError); |
Junxiao Shi | 5f6c74f | 2014-04-18 16:29:44 -0700 | [diff] [blame] | 494 | } |
| 495 | |
jaczhi | 82d8ed0 | 2025-01-07 15:51:02 -0800 | [diff] [blame] | 496 | BOOST_FIXTURE_TEST_CASE(RibAnnounce, KeyChainFixture) |
| 497 | { |
| 498 | using Command = RibAnnounceCommand; |
| 499 | |
| 500 | // Good request |
| 501 | PrefixAnnouncement pa1; |
| 502 | pa1.setAnnouncedName("ndn:/"); |
| 503 | pa1.setExpiration(1_min); |
| 504 | pa1.toData(m_keyChain); |
| 505 | RibAnnounceParameters p1; |
| 506 | p1.setPrefixAnnouncement(pa1); |
| 507 | BOOST_CHECK_NO_THROW(Command::validateRequest(p1)); |
| 508 | Name n1 = Command::createRequest("/PREFIX", p1).getName(); |
| 509 | BOOST_CHECK(Name("ndn:/PREFIX/rib/announce").isPrefixOf(n1)); |
| 510 | |
| 511 | // Good response |
| 512 | ControlParameters p2; |
| 513 | p2.setName("ndn:/") |
| 514 | .setFaceId(22) |
| 515 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_PREFIXANN) |
| 516 | .setCost(2048) |
| 517 | .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT) |
| 518 | .setExpirationPeriod(1_min); |
| 519 | BOOST_CHECK_NO_THROW(Command::validateResponse(p2)); |
| 520 | |
| 521 | // Bad request (PrefixAnnouncement must be signed) |
| 522 | PrefixAnnouncement pa2; |
| 523 | pa2.setAnnouncedName("ndn:/"); |
| 524 | pa2.setExpiration(1_min); |
| 525 | RibAnnounceParameters p3; |
| 526 | BOOST_CHECK_THROW(Command::validateRequest(p3), ArgumentError); |
| 527 | p3.setPrefixAnnouncement(pa2); |
| 528 | BOOST_CHECK_THROW(Command::validateRequest(p3), ArgumentError); |
| 529 | |
| 530 | // Bad response (FaceId must be valid) |
| 531 | ControlParameters p4; |
| 532 | p4.setName("ndn:/") |
| 533 | .setFaceId(0) |
| 534 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_PREFIXANN) |
| 535 | .setCost(2048) |
| 536 | .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT) |
| 537 | .setExpirationPeriod(1_min); |
| 538 | BOOST_CHECK_THROW(Command::validateResponse(p4), ArgumentError); |
| 539 | } |
| 540 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 541 | BOOST_AUTO_TEST_SUITE_END() // TestControlCommand |
| 542 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 543 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | 5ec8022 | 2014-03-25 20:08:05 -0700 | [diff] [blame] | 544 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 545 | } // namespace ndn::tests |