Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2025, Regents of the University of California, |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 26 | #include "mgmt/face-manager.hpp" |
| 27 | #include "face/generic-link-service.hpp" |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 28 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 29 | #include "face-manager-command-fixture.hpp" |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 30 | #include "tests/daemon/face/dummy-transport.hpp" |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 31 | |
Junxiao Shi | cbc8e94 | 2016-09-06 03:17:45 +0000 | [diff] [blame] | 32 | #include <ndn-cxx/lp/tags.hpp> |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 33 | |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 34 | #include <boost/logic/tribool.hpp> |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 35 | #include <boost/mp11/list.hpp> |
| 36 | #include <thread> |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 37 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 38 | namespace nfd::tests { |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 39 | |
| 40 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 41 | BOOST_AUTO_TEST_SUITE(TestFaceManager) |
| 42 | |
| 43 | class FaceManagerUpdateFixture : public FaceManagerCommandFixture |
| 44 | { |
| 45 | public: |
Davide Pesavento | 2208536 | 2021-03-18 22:08:03 -0400 | [diff] [blame] | 46 | ~FaceManagerUpdateFixture() override |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 47 | { |
| 48 | destroyFace(); |
| 49 | } |
| 50 | |
| 51 | void |
| 52 | createFace(const std::string& uri = "tcp4://127.0.0.1:26363", |
| 53 | ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 54 | std::optional<time::nanoseconds> baseCongestionMarkingInterval = std::nullopt, |
| 55 | std::optional<uint64_t> defaultCongestionThreshold = std::nullopt, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 56 | bool enableLocalFields = false, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 57 | bool enableReliability = false, |
| 58 | boost::logic::tribool enableCongestionMarking = boost::logic::indeterminate) |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 59 | { |
| 60 | ControlParameters params; |
| 61 | params.setUri(uri); |
| 62 | params.setFacePersistency(persistency); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 63 | |
| 64 | if (baseCongestionMarkingInterval) { |
| 65 | params.setBaseCongestionMarkingInterval(*baseCongestionMarkingInterval); |
| 66 | } |
| 67 | |
| 68 | if (defaultCongestionThreshold) { |
| 69 | params.setDefaultCongestionThreshold(*defaultCongestionThreshold); |
| 70 | } |
| 71 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 72 | params.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, enableLocalFields); |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 73 | params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, enableReliability); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 74 | |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 75 | if (!boost::logic::indeterminate(enableCongestionMarking)) { |
Davide Pesavento | fa2aa50 | 2019-03-22 13:30:02 -0400 | [diff] [blame] | 76 | params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, bool(enableCongestionMarking)); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 79 | createFace(params); |
| 80 | } |
| 81 | |
| 82 | void |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 83 | createFace(const ControlParameters& createParams, bool isForOnDemandFace = false) |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 84 | { |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 85 | Interest req = makeControlCommandRequest(CREATE_REQUEST, createParams); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 86 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 87 | // if this creation if for on-demand face then create it on node2 |
| 88 | FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1; |
| 89 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 90 | bool hasCallbackFired = false; |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 91 | signal::ScopedConnection conn = target.face.onSendData.connect([&] (const Data& response) { |
| 92 | if (!req.getName().isPrefixOf(response.getName())) { |
| 93 | return; |
| 94 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 95 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 96 | ControlResponse create(response.getContent().blockFromValue()); |
| 97 | BOOST_TEST_REQUIRE(create.getCode() == 200); |
| 98 | ControlParameters faceParams(create.getBody()); |
| 99 | BOOST_TEST_REQUIRE(faceParams.hasFaceId()); |
| 100 | this->faceId = faceParams.getFaceId(); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 101 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 102 | hasCallbackFired = true; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 103 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 104 | if (isForOnDemandFace) { |
| 105 | auto face = target.faceTable.get(this->faceId); |
| 106 | // to force creation of on-demand face |
| 107 | face->sendInterest(*makeInterest("/hello/world")); |
| 108 | } |
| 109 | }); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 110 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 111 | target.face.receive(req); |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 112 | advanceClocks(1_ms, 10); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 113 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 114 | if (isForOnDemandFace) { |
| 115 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 116 | advanceClocks(1_ms, 10); // let node1 accept Interest and create on-demand face |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 119 | BOOST_TEST_REQUIRE(hasCallbackFired); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 123 | updateFace(const ControlParameters& requestParams, bool isSelfUpdating, |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 124 | const std::function<void(const ControlResponse& resp)>& checkResp) |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 125 | { |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 126 | Interest req = makeControlCommandRequest(UPDATE_REQUEST, requestParams); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 127 | if (isSelfUpdating) { |
| 128 | // Attach IncomingFaceIdTag to interest |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 129 | req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId)); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 130 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 131 | |
| 132 | bool hasCallbackFired = false; |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 133 | signal::ScopedConnection conn = node1.face.onSendData.connect([&] (const Data& response) { |
| 134 | if (!req.getName().isPrefixOf(response.getName())) { |
| 135 | return; |
| 136 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 137 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 138 | ControlResponse actual(response.getContent().blockFromValue()); |
| 139 | checkResp(actual); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 140 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 141 | hasCallbackFired = true; |
| 142 | }); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 143 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 144 | this->node1.face.receive(req); |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 145 | advanceClocks(1_ms, 10); |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 146 | BOOST_TEST_REQUIRE(hasCallbackFired); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | private: |
| 150 | void |
| 151 | destroyFace() |
| 152 | { |
| 153 | if (faceId == 0) { |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | ControlParameters params; |
| 158 | params.setFaceId(faceId); |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 159 | Interest req = makeControlCommandRequest(DESTROY_REQUEST, params); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 160 | |
| 161 | bool hasCallbackFired = false; |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 162 | signal::ScopedConnection conn = node1.face.onSendData.connect([&] (const Data& response) { |
| 163 | if (!req.getName().isPrefixOf(response.getName())) { |
| 164 | return; |
| 165 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 166 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 167 | ControlResponse destroy(response.getContent().blockFromValue()); |
| 168 | BOOST_CHECK_EQUAL(destroy.getCode(), 200); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 169 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 170 | faceId = 0; |
| 171 | hasCallbackFired = true; |
| 172 | }); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 173 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 174 | this->node1.face.receive(req); |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 175 | advanceClocks(1_ms, 10); |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 176 | BOOST_TEST_REQUIRE(hasCallbackFired); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 179 | protected: |
| 180 | FaceId faceId = 0; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | BOOST_FIXTURE_TEST_SUITE(UpdateFace, FaceManagerUpdateFixture) |
| 184 | |
| 185 | BOOST_AUTO_TEST_CASE(FaceDoesNotExist) |
| 186 | { |
| 187 | ControlParameters requestParams; |
| 188 | requestParams.setFaceId(65535); |
| 189 | |
| 190 | updateFace(requestParams, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 191 | BOOST_TEST(actual.getCode() == 404); |
| 192 | BOOST_TEST(actual.getText() == "Specified face does not exist"); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 193 | }); |
| 194 | } |
| 195 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 196 | using UpdatePersistencyTests = boost::mp11::mp_list< |
| 197 | boost::mp11::mp_list<DummyTransportBase<true>, CommandSuccess>, |
| 198 | boost::mp11::mp_list<DummyTransportBase<false>, CommandFailure<409>> |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 199 | >; |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 200 | |
| 201 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, FaceManagerUpdateFixture) |
| 202 | { |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 203 | using TransportType = boost::mp11::mp_first<T>; |
| 204 | using ResultType = boost::mp11::mp_second<T>; |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 205 | |
| 206 | auto face = make_shared<face::Face>(make_unique<face::GenericLinkService>(), |
| 207 | make_unique<TransportType>()); |
| 208 | this->node1.faceTable.add(face); |
| 209 | |
| 210 | auto parameters = ControlParameters() |
| 211 | .setFaceId(face->getId()) |
| 212 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT); |
| 213 | |
| 214 | updateFace(parameters, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 215 | BOOST_TEST(actual.getCode() == ResultType::getExpected().getCode(), actual.getText()); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 216 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 217 | // the response for either 200 or 409 will have a content body |
| 218 | ControlParameters resp(actual.getBody()); |
| 219 | BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 220 | }); |
| 221 | } |
| 222 | |
Eric Newberry | 13ff259 | 2020-03-06 17:32:29 -0800 | [diff] [blame] | 223 | BOOST_AUTO_TEST_CASE(UpdateMtu) |
| 224 | { |
| 225 | createFace("udp4://127.0.0.1:26363"); |
| 226 | |
| 227 | ControlParameters validParams; |
| 228 | validParams.setFaceId(faceId); |
| 229 | validParams.setMtu(4000); |
| 230 | |
| 231 | ControlParameters mtuTooLow; |
| 232 | mtuTooLow.setFaceId(faceId); |
| 233 | mtuTooLow.setMtu(63); |
| 234 | |
| 235 | updateFace(validParams, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 236 | BOOST_TEST(actual.getCode() == 200, actual.getText()); |
Eric Newberry | 13ff259 | 2020-03-06 17:32:29 -0800 | [diff] [blame] | 237 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 238 | ControlParameters actualParams(actual.getBody()); |
| 239 | BOOST_TEST(actualParams.hasFaceId()); |
| 240 | BOOST_TEST_REQUIRE(actualParams.hasMtu()); |
| 241 | // Check for changed MTU |
| 242 | BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000); |
Eric Newberry | 13ff259 | 2020-03-06 17:32:29 -0800 | [diff] [blame] | 243 | }); |
| 244 | |
| 245 | updateFace(mtuTooLow, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 246 | BOOST_TEST(actual.getCode() == 409); |
| 247 | BOOST_TEST(actual.getText() == "Invalid properties specified"); |
Eric Newberry | 13ff259 | 2020-03-06 17:32:29 -0800 | [diff] [blame] | 248 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 249 | ControlParameters actualParams(actual.getBody()); |
| 250 | BOOST_TEST(!actualParams.hasFaceId()); |
| 251 | BOOST_TEST_REQUIRE(actualParams.hasMtu()); |
| 252 | // Check for returned invalid parameter |
| 253 | BOOST_CHECK_EQUAL(actualParams.getMtu(), 63); |
Eric Newberry | 13ff259 | 2020-03-06 17:32:29 -0800 | [diff] [blame] | 254 | }); |
| 255 | } |
| 256 | |
| 257 | BOOST_AUTO_TEST_CASE(UpdateMtuUnsupportedFace) |
| 258 | { |
| 259 | createFace("tcp4://127.0.0.1:26363"); |
| 260 | |
| 261 | ControlParameters updateParams; |
| 262 | updateParams.setFaceId(faceId); |
| 263 | updateParams.setMtu(4000); |
| 264 | |
| 265 | updateFace(updateParams, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 266 | BOOST_TEST(actual.getCode() == 409); |
| 267 | BOOST_TEST(actual.getText() == "Invalid properties specified"); |
Eric Newberry | 13ff259 | 2020-03-06 17:32:29 -0800 | [diff] [blame] | 268 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 269 | ControlParameters actualParams(actual.getBody()); |
| 270 | BOOST_TEST(!actualParams.hasFaceId()); |
| 271 | BOOST_TEST_REQUIRE(actualParams.hasMtu()); |
| 272 | // Check for returned invalid parameter |
| 273 | BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000); |
Eric Newberry | 13ff259 | 2020-03-06 17:32:29 -0800 | [diff] [blame] | 274 | }); |
| 275 | } |
| 276 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 277 | template<bool EnableLocalFields> |
| 278 | struct TcpLocalFields |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 279 | { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 280 | static inline const std::string uri = "tcp4://127.0.0.1:26363"; |
| 281 | static constexpr bool localFieldsInit = !EnableLocalFields; |
| 282 | static constexpr bool localFieldsEnabled = EnableLocalFields; |
| 283 | static constexpr bool mask = true; |
| 284 | static constexpr bool shouldHaveBody = false; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 287 | // UDP faces are non-local by definition. |
| 288 | struct UdpLocalFieldsEnable |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 289 | { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 290 | static inline const std::string uri = "udp4://127.0.0.1:26363"; |
| 291 | static constexpr bool localFieldsInit = false; |
| 292 | static constexpr bool localFieldsEnabled = true; |
| 293 | static constexpr bool mask = true; |
| 294 | static constexpr bool shouldHaveBody = true; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 295 | }; |
| 296 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 297 | // UDP faces are non-local by definition. |
| 298 | // In this test case, attempt to disable local fields on face with local fields already disabled. |
| 299 | struct UdpLocalFieldsDisable |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 300 | { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 301 | static inline const std::string uri = "udp4://127.0.0.1:26363"; |
| 302 | static constexpr bool localFieldsInit = false; |
| 303 | static constexpr bool localFieldsEnabled = false; |
| 304 | static constexpr bool mask = true; |
| 305 | static constexpr bool shouldHaveBody = false; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 306 | }; |
| 307 | |
| 308 | // In this test case, set Flags to enable local fields on non-local face, but exclude local fields |
| 309 | // from Mask. This test case will pass as no action is taken due to the missing Mask bit. |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 310 | struct UdpLocalFieldsEnableNoMaskBit |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 311 | { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 312 | static inline const std::string uri = "udp4://127.0.0.1:26363"; |
| 313 | static constexpr bool localFieldsInit = false; |
| 314 | static constexpr bool localFieldsEnabled = true; |
| 315 | static constexpr bool mask = false; |
| 316 | static constexpr bool shouldHaveBody = false; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 317 | }; |
| 318 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 319 | using LocalFieldFaces = boost::mp11::mp_list< |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 320 | boost::mp11::mp_list<TcpLocalFields<true>, CommandSuccess>, |
| 321 | boost::mp11::mp_list<TcpLocalFields<false>, CommandSuccess>, |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 322 | boost::mp11::mp_list<UdpLocalFieldsEnable, CommandFailure<409>>, |
| 323 | boost::mp11::mp_list<UdpLocalFieldsDisable, CommandSuccess>, |
| 324 | boost::mp11::mp_list<UdpLocalFieldsEnableNoMaskBit, CommandSuccess> |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 325 | >; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 326 | |
| 327 | BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces) |
| 328 | { |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 329 | using TestType = boost::mp11::mp_first<T>; |
| 330 | using ResultType = boost::mp11::mp_second<T>; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 331 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 332 | createFace(TestType::uri, ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, TestType::localFieldsInit); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 333 | |
| 334 | ControlParameters requestParams; |
| 335 | requestParams.setFaceId(faceId); |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 336 | requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType::localFieldsEnabled); |
| 337 | if constexpr (!TestType::mask) { |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 338 | requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED); |
| 339 | } |
| 340 | |
| 341 | updateFace(requestParams, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 342 | BOOST_TEST(actual.getCode() == ResultType::getExpected().getCode(), actual.getText()); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 343 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 344 | if constexpr (TestType::shouldHaveBody) { |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 345 | ControlParameters actualParams(actual.getBody()); |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 346 | BOOST_TEST(!actualParams.hasFacePersistency()); |
| 347 | BOOST_TEST(actualParams.hasFlags()); |
| 348 | BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 349 | BOOST_TEST(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 350 | } |
| 351 | }); |
| 352 | } |
| 353 | |
| 354 | BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable) |
| 355 | { |
| 356 | createFace(); |
| 357 | |
| 358 | ControlParameters enableParams; |
| 359 | enableParams.setFaceId(faceId); |
| 360 | enableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true); |
| 361 | |
| 362 | ControlParameters disableParams; |
| 363 | disableParams.setFaceId(faceId); |
| 364 | disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false); |
| 365 | |
| 366 | updateFace(enableParams, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 367 | BOOST_TEST(actual.getCode() == 200, actual.getText()); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 368 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 369 | ControlParameters actualParams(actual.getBody()); |
| 370 | BOOST_TEST(actualParams.hasFaceId()); |
| 371 | BOOST_TEST(actualParams.hasFacePersistency()); |
| 372 | BOOST_TEST_REQUIRE(actualParams.hasFlags()); |
| 373 | // Check if flags indicate local fields enabled |
| 374 | BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 375 | }); |
| 376 | |
| 377 | updateFace(disableParams, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 378 | BOOST_TEST(actual.getCode() == 200, actual.getText()); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 379 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 380 | ControlParameters actualParams(actual.getBody()); |
| 381 | BOOST_TEST(actualParams.hasFaceId()); |
| 382 | BOOST_TEST(actualParams.hasFacePersistency()); |
| 383 | BOOST_TEST_REQUIRE(actualParams.hasFlags()); |
| 384 | // Check if flags indicate local fields disabled |
| 385 | BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 386 | }); |
| 387 | } |
| 388 | |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 389 | BOOST_AUTO_TEST_CASE(UpdateReliabilityEnableDisable) |
| 390 | { |
| 391 | createFace("udp4://127.0.0.1:26363"); |
| 392 | |
| 393 | ControlParameters enableParams; |
| 394 | enableParams.setFaceId(faceId); |
| 395 | enableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true); |
| 396 | |
| 397 | ControlParameters disableParams; |
| 398 | disableParams.setFaceId(faceId); |
| 399 | disableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false); |
| 400 | |
| 401 | updateFace(enableParams, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 402 | BOOST_TEST(actual.getCode() == 200, actual.getText()); |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 403 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 404 | ControlParameters actualParams(actual.getBody()); |
| 405 | BOOST_TEST(actualParams.hasFaceId()); |
| 406 | BOOST_TEST(actualParams.hasFacePersistency()); |
| 407 | BOOST_TEST_REQUIRE(actualParams.hasFlags()); |
| 408 | // Check if flags indicate reliability enabled |
| 409 | BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 410 | }); |
| 411 | |
| 412 | updateFace(disableParams, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 413 | BOOST_TEST(actual.getCode() == 200, actual.getText()); |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 414 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 415 | ControlParameters actualParams(actual.getBody()); |
| 416 | BOOST_TEST(actualParams.hasFaceId()); |
| 417 | BOOST_TEST(actualParams.hasFacePersistency()); |
| 418 | BOOST_TEST_REQUIRE(actualParams.hasFlags()); |
| 419 | // Check if flags indicate reliability disabled |
| 420 | BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 421 | }); |
| 422 | } |
| 423 | |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 424 | BOOST_AUTO_TEST_CASE(UpdateCongestionMarkingEnableDisable) |
| 425 | { |
| 426 | createFace("udp4://127.0.0.1:26363"); |
| 427 | |
| 428 | ControlParameters enableParams; |
| 429 | enableParams.setFaceId(faceId); |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 430 | enableParams.setBaseCongestionMarkingInterval(50_ms); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 431 | enableParams.setDefaultCongestionThreshold(10000); |
| 432 | enableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true); |
| 433 | |
| 434 | ControlParameters disableParams; |
| 435 | disableParams.setFaceId(faceId); |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 436 | disableParams.setBaseCongestionMarkingInterval(70_ms); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 437 | disableParams.setDefaultCongestionThreshold(5000); |
| 438 | disableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false); |
| 439 | |
| 440 | updateFace(enableParams, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 441 | BOOST_TEST(actual.getCode() == 200, actual.getText()); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 442 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 443 | ControlParameters actualParams(actual.getBody()); |
| 444 | BOOST_TEST(actualParams.hasFaceId()); |
| 445 | BOOST_TEST(actualParams.hasFacePersistency()); |
| 446 | // Check that congestion marking parameters changed |
| 447 | BOOST_TEST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval()); |
| 448 | BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 50_ms); |
| 449 | BOOST_TEST_REQUIRE(actualParams.hasDefaultCongestionThreshold()); |
| 450 | BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000); |
| 451 | BOOST_TEST_REQUIRE(actualParams.hasFlags()); |
| 452 | // Check if flags indicate congestion marking enabled |
| 453 | BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 454 | }); |
| 455 | |
| 456 | updateFace(disableParams, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 457 | BOOST_TEST(actual.getCode() == 200, actual.getText()); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 458 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 459 | ControlParameters actualParams(actual.getBody()); |
| 460 | BOOST_TEST(actualParams.hasFaceId()); |
| 461 | BOOST_TEST(actualParams.hasFacePersistency()); |
| 462 | // Check that congestion marking parameters changed, even though feature disabled |
| 463 | BOOST_TEST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval()); |
| 464 | BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 70_ms); |
| 465 | BOOST_TEST_REQUIRE(actualParams.hasDefaultCongestionThreshold()); |
| 466 | BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000); |
| 467 | BOOST_TEST_REQUIRE(actualParams.hasFlags()); |
| 468 | // Check if flags indicate marking disabled |
| 469 | BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 470 | }); |
| 471 | } |
| 472 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 473 | BOOST_AUTO_TEST_CASE(SelfUpdating) |
| 474 | { |
| 475 | createFace(); |
| 476 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 477 | // Send a command that does nothing and does not contain a FaceId |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 478 | ControlParameters sentParams; |
| 479 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 480 | // Success case: FaceId is obtained automatically from IncomingFaceIdTag |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 481 | updateFace(sentParams, true, [] (const ControlResponse& actual) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 482 | BOOST_TEST(actual.getCode() == 200, actual.getText()); |
| 483 | }); |
| 484 | |
| 485 | // Error case: IncomingFaceIdTag is missing |
| 486 | updateFace(sentParams, false, [] (const ControlResponse& actual) { |
| 487 | BOOST_TEST(actual.getCode() == 404); |
| 488 | BOOST_TEST(actual.getText() == "No FaceId specified and IncomingFaceId not available"); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 489 | }); |
| 490 | } |
| 491 | |
| 492 | BOOST_AUTO_TEST_SUITE_END() // UpdateFace |
| 493 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 494 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 495 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 496 | } // namespace nfd::tests |