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