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 | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 34 | #include <thread> |
| 35 | |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 36 | #include <boost/logic/tribool.hpp> |
| 37 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 38 | namespace nfd { |
| 39 | namespace tests { |
| 40 | |
| 41 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 42 | BOOST_AUTO_TEST_SUITE(TestFaceManager) |
| 43 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 44 | namespace mpl = boost::mpl; |
| 45 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 46 | class FaceManagerUpdateFixture : public FaceManagerCommandFixture |
| 47 | { |
| 48 | public: |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 49 | ~FaceManagerUpdateFixture() |
| 50 | { |
| 51 | destroyFace(); |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | createFace(const std::string& uri = "tcp4://127.0.0.1:26363", |
| 56 | ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 57 | optional<time::nanoseconds> baseCongestionMarkingInterval = {}, |
| 58 | optional<uint64_t> defaultCongestionThreshold = {}, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 59 | bool enableLocalFields = false, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 60 | bool enableReliability = false, |
| 61 | boost::logic::tribool enableCongestionMarking = boost::logic::indeterminate) |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 62 | { |
| 63 | ControlParameters params; |
| 64 | params.setUri(uri); |
| 65 | params.setFacePersistency(persistency); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 66 | |
| 67 | if (baseCongestionMarkingInterval) { |
| 68 | params.setBaseCongestionMarkingInterval(*baseCongestionMarkingInterval); |
| 69 | } |
| 70 | |
| 71 | if (defaultCongestionThreshold) { |
| 72 | params.setDefaultCongestionThreshold(*defaultCongestionThreshold); |
| 73 | } |
| 74 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 75 | params.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, enableLocalFields); |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 76 | params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, enableReliability); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 77 | |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 78 | if (!boost::logic::indeterminate(enableCongestionMarking)) { |
Davide Pesavento | fa2aa50 | 2019-03-22 13:30:02 -0400 | [diff] [blame] | 79 | params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, bool(enableCongestionMarking)); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 82 | createFace(params); |
| 83 | } |
| 84 | |
| 85 | void |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 86 | createFace(const ControlParameters& createParams, bool isForOnDemandFace = false) |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 87 | { |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 88 | Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", createParams); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 89 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 90 | // if this creation if for on-demand face then create it on node2 |
| 91 | FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1; |
| 92 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 93 | bool hasCallbackFired = false; |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 94 | signal::ScopedConnection connection = target.face.onSendData.connect( |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 95 | [&, req, isForOnDemandFace, this] (const Data& response) { |
| 96 | if (!req.getName().isPrefixOf(response.getName())) { |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 97 | return; |
| 98 | } |
| 99 | |
| 100 | ControlResponse create(response.getContent().blockFromValue()); |
| 101 | BOOST_REQUIRE_EQUAL(create.getCode(), 200); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 102 | BOOST_REQUIRE(create.getBody().hasWire()); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 103 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 104 | ControlParameters faceParams(create.getBody()); |
| 105 | BOOST_REQUIRE(faceParams.hasFaceId()); |
| 106 | this->faceId = faceParams.getFaceId(); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 107 | |
| 108 | hasCallbackFired = true; |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 109 | |
| 110 | if (isForOnDemandFace) { |
| 111 | auto face = target.faceTable.get(static_cast<FaceId>(this->faceId)); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 112 | // to force creation of on-demand face |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 113 | face->sendInterest(*make_shared<Interest>("/hello/world"), 0); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 114 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 115 | }); |
| 116 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 117 | target.face.receive(req); |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 118 | advanceClocks(1_ms, 5); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 119 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 120 | if (isForOnDemandFace) { |
| 121 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 122 | advanceClocks(1_ms, 5); // let node1 accept Interest and create on-demand face |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 125 | BOOST_REQUIRE(hasCallbackFired); |
| 126 | } |
| 127 | |
| 128 | void |
| 129 | updateFace(const ControlParameters& requestParams, |
| 130 | bool isSelfUpdating, |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 131 | const std::function<void(const ControlResponse& resp)>& checkResp) |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 132 | { |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 133 | Interest req = makeControlCommandRequest("/localhost/nfd/faces/update", requestParams); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 134 | if (isSelfUpdating) { |
| 135 | // Attach IncomingFaceIdTag to interest |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 136 | req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId)); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 137 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 138 | |
| 139 | bool hasCallbackFired = false; |
| 140 | signal::ScopedConnection connection = this->node1.face.onSendData.connect( |
Davide Pesavento | ac238f2 | 2017-09-12 15:19:40 -0400 | [diff] [blame] | 141 | [req, &hasCallbackFired, &checkResp] (const Data& response) { |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 142 | if (!req.getName().isPrefixOf(response.getName())) { |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 143 | return; |
| 144 | } |
| 145 | |
| 146 | ControlResponse actual(response.getContent().blockFromValue()); |
| 147 | checkResp(actual); |
| 148 | |
| 149 | hasCallbackFired = true; |
| 150 | }); |
| 151 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 152 | this->node1.face.receive(req); |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 153 | advanceClocks(1_ms, 5); |
| 154 | BOOST_REQUIRE(hasCallbackFired); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | private: |
| 158 | void |
| 159 | destroyFace() |
| 160 | { |
| 161 | if (faceId == 0) { |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | ControlParameters params; |
| 166 | params.setFaceId(faceId); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 167 | Interest req = makeControlCommandRequest("/localhost/nfd/faces/destroy", params); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 168 | |
| 169 | bool hasCallbackFired = false; |
| 170 | signal::ScopedConnection connection = this->node1.face.onSendData.connect( |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 171 | [this, req, &hasCallbackFired] (const Data& response) { |
| 172 | if (!req.getName().isPrefixOf(response.getName())) { |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 173 | return; |
| 174 | } |
| 175 | |
| 176 | ControlResponse destroy(response.getContent().blockFromValue()); |
| 177 | BOOST_CHECK_EQUAL(destroy.getCode(), 200); |
| 178 | |
| 179 | faceId = 0; |
| 180 | hasCallbackFired = true; |
| 181 | }); |
| 182 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 183 | this->node1.face.receive(req); |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 184 | advanceClocks(1_ms, 5); |
| 185 | BOOST_REQUIRE(hasCallbackFired); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 188 | protected: |
| 189 | FaceId faceId = 0; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | BOOST_FIXTURE_TEST_SUITE(UpdateFace, FaceManagerUpdateFixture) |
| 193 | |
| 194 | BOOST_AUTO_TEST_CASE(FaceDoesNotExist) |
| 195 | { |
| 196 | ControlParameters requestParams; |
| 197 | requestParams.setFaceId(65535); |
| 198 | |
| 199 | updateFace(requestParams, false, [] (const ControlResponse& actual) { |
| 200 | ControlResponse expected(404, "Specified face does not exist"); |
| 201 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
| 202 | BOOST_TEST_MESSAGE(actual.getText()); |
| 203 | }); |
| 204 | } |
| 205 | |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 206 | using nfd::face::tests::DummyTransportBase; |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 207 | using UpdatePersistencyTests = mpl::vector< |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 208 | mpl::pair<DummyTransportBase<true>, CommandSuccess>, |
| 209 | mpl::pair<DummyTransportBase<false>, CommandFailure<409>> |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 210 | >; |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 211 | |
| 212 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, FaceManagerUpdateFixture) |
| 213 | { |
| 214 | using TransportType = typename T::first; |
| 215 | using ResultType = typename T::second; |
| 216 | |
| 217 | auto face = make_shared<face::Face>(make_unique<face::GenericLinkService>(), |
| 218 | make_unique<TransportType>()); |
| 219 | this->node1.faceTable.add(face); |
| 220 | |
| 221 | auto parameters = ControlParameters() |
| 222 | .setFaceId(face->getId()) |
| 223 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT); |
| 224 | |
| 225 | updateFace(parameters, false, [] (const ControlResponse& actual) { |
| 226 | BOOST_TEST_MESSAGE(actual.getText()); |
| 227 | BOOST_CHECK_EQUAL(actual.getCode(), ResultType::getExpected().getCode()); |
| 228 | |
| 229 | // the response for either 200 or 409 will have a content body |
| 230 | BOOST_REQUIRE(actual.getBody().hasWire()); |
| 231 | |
| 232 | ControlParameters resp; |
| 233 | resp.wireDecode(actual.getBody()); |
| 234 | BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 235 | }); |
| 236 | } |
| 237 | |
| 238 | class TcpLocalFieldsEnable |
| 239 | { |
| 240 | public: |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 241 | static std::string |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 242 | getUri() |
| 243 | { |
| 244 | return "tcp4://127.0.0.1:26363"; |
| 245 | } |
| 246 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 247 | static constexpr ndn::nfd::FacePersistency |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 248 | getPersistency() |
| 249 | { |
| 250 | return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; |
| 251 | } |
| 252 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 253 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 254 | getInitLocalFieldsEnabled() |
| 255 | { |
| 256 | return false; |
| 257 | } |
| 258 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 259 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 260 | getLocalFieldsEnabled() |
| 261 | { |
| 262 | return true; |
| 263 | } |
| 264 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 265 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 266 | getLocalFieldsEnabledMask() |
| 267 | { |
| 268 | return true; |
| 269 | } |
| 270 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 271 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 272 | shouldHaveWire() |
| 273 | { |
| 274 | return false; |
| 275 | } |
| 276 | }; |
| 277 | |
| 278 | class TcpLocalFieldsDisable |
| 279 | { |
| 280 | public: |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 281 | static std::string |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 282 | getUri() |
| 283 | { |
| 284 | return "tcp4://127.0.0.1:26363"; |
| 285 | } |
| 286 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 287 | static constexpr ndn::nfd::FacePersistency |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 288 | getPersistency() |
| 289 | { |
| 290 | return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; |
| 291 | } |
| 292 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 293 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 294 | getInitLocalFieldsEnabled() |
| 295 | { |
| 296 | return true; |
| 297 | } |
| 298 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 299 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 300 | getLocalFieldsEnabled() |
| 301 | { |
| 302 | return false; |
| 303 | } |
| 304 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 305 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 306 | getLocalFieldsEnabledMask() |
| 307 | { |
| 308 | return true; |
| 309 | } |
| 310 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 311 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 312 | shouldHaveWire() |
| 313 | { |
| 314 | return false; |
| 315 | } |
| 316 | }; |
| 317 | |
| 318 | // UDP faces are non-local by definition |
| 319 | class UdpLocalFieldsEnable |
| 320 | { |
| 321 | public: |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 322 | static std::string |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 323 | getUri() |
| 324 | { |
| 325 | return "udp4://127.0.0.1:26363"; |
| 326 | } |
| 327 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 328 | static constexpr ndn::nfd::FacePersistency |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 329 | getPersistency() |
| 330 | { |
| 331 | return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; |
| 332 | } |
| 333 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 334 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 335 | getInitLocalFieldsEnabled() |
| 336 | { |
| 337 | return false; |
| 338 | } |
| 339 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 340 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 341 | getLocalFieldsEnabled() |
| 342 | { |
| 343 | return true; |
| 344 | } |
| 345 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 346 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 347 | getLocalFieldsEnabledMask() |
| 348 | { |
| 349 | return true; |
| 350 | } |
| 351 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 352 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 353 | shouldHaveWire() |
| 354 | { |
| 355 | return true; |
| 356 | } |
| 357 | }; |
| 358 | |
| 359 | // UDP faces are non-local by definition |
| 360 | // In this test case, attempt to disable local fields on face with local fields already disabled |
| 361 | class UdpLocalFieldsDisable |
| 362 | { |
| 363 | public: |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 364 | static std::string |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 365 | getUri() |
| 366 | { |
| 367 | return "udp4://127.0.0.1:26363"; |
| 368 | } |
| 369 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 370 | static constexpr ndn::nfd::FacePersistency |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 371 | getPersistency() |
| 372 | { |
| 373 | return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; |
| 374 | } |
| 375 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 376 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 377 | getInitLocalFieldsEnabled() |
| 378 | { |
| 379 | return false; |
| 380 | } |
| 381 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 382 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 383 | getLocalFieldsEnabled() |
| 384 | { |
| 385 | return false; |
| 386 | } |
| 387 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 388 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 389 | getLocalFieldsEnabledMask() |
| 390 | { |
| 391 | return true; |
| 392 | } |
| 393 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 394 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 395 | shouldHaveWire() |
| 396 | { |
| 397 | return false; |
| 398 | } |
| 399 | }; |
| 400 | |
| 401 | // In this test case, set Flags to enable local fields on non-local face, but exclude local fields |
| 402 | // from Mask. This test case will pass as no action is taken due to the missing Mask bit. |
| 403 | class UdpLocalFieldsEnableNoMaskBit |
| 404 | { |
| 405 | public: |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 406 | static std::string |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 407 | getUri() |
| 408 | { |
| 409 | return "udp4://127.0.0.1:26363"; |
| 410 | } |
| 411 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 412 | static constexpr ndn::nfd::FacePersistency |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 413 | getPersistency() |
| 414 | { |
| 415 | return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; |
| 416 | } |
| 417 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 418 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 419 | getInitLocalFieldsEnabled() |
| 420 | { |
| 421 | return false; |
| 422 | } |
| 423 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 424 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 425 | getLocalFieldsEnabled() |
| 426 | { |
| 427 | return true; |
| 428 | } |
| 429 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 430 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 431 | getLocalFieldsEnabledMask() |
| 432 | { |
| 433 | return false; |
| 434 | } |
| 435 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 436 | static constexpr bool |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 437 | shouldHaveWire() |
| 438 | { |
| 439 | return false; |
| 440 | } |
| 441 | }; |
| 442 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 443 | using LocalFieldFaces = mpl::vector< |
| 444 | mpl::pair<TcpLocalFieldsEnable, CommandSuccess>, |
| 445 | mpl::pair<TcpLocalFieldsDisable, CommandSuccess>, |
| 446 | mpl::pair<UdpLocalFieldsEnable, CommandFailure<409>>, |
| 447 | mpl::pair<UdpLocalFieldsDisable, CommandSuccess>, |
| 448 | mpl::pair<UdpLocalFieldsEnableNoMaskBit, CommandSuccess> |
| 449 | >; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 450 | |
| 451 | BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces) |
| 452 | { |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 453 | using TestType = typename T::first; |
| 454 | using ResultType = typename T::second; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 455 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 456 | createFace(TestType::getUri(), TestType::getPersistency(), {}, {}, |
| 457 | TestType::getInitLocalFieldsEnabled()); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 458 | |
| 459 | ControlParameters requestParams; |
| 460 | requestParams.setFaceId(faceId); |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 461 | requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType::getLocalFieldsEnabled()); |
| 462 | if (!TestType::getLocalFieldsEnabledMask()) { |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 463 | requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED); |
| 464 | } |
| 465 | |
| 466 | updateFace(requestParams, false, [] (const ControlResponse& actual) { |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 467 | ControlResponse expected(ResultType::getExpected()); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 468 | BOOST_TEST_MESSAGE(actual.getText()); |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 469 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 470 | |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 471 | if (TestType::shouldHaveWire() && actual.getBody().hasWire()) { |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 472 | ControlParameters actualParams(actual.getBody()); |
| 473 | |
| 474 | BOOST_CHECK(!actualParams.hasFacePersistency()); |
| 475 | BOOST_CHECK(actualParams.hasFlags()); |
| 476 | BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 477 | BOOST_CHECK(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 478 | } |
| 479 | }); |
| 480 | } |
| 481 | |
| 482 | BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable) |
| 483 | { |
| 484 | createFace(); |
| 485 | |
| 486 | ControlParameters enableParams; |
| 487 | enableParams.setFaceId(faceId); |
| 488 | enableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true); |
| 489 | |
| 490 | ControlParameters disableParams; |
| 491 | disableParams.setFaceId(faceId); |
| 492 | disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false); |
| 493 | |
| 494 | updateFace(enableParams, false, [] (const ControlResponse& actual) { |
| 495 | ControlResponse expected(200, "OK"); |
| 496 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
| 497 | BOOST_TEST_MESSAGE(actual.getText()); |
| 498 | |
| 499 | if (actual.getBody().hasWire()) { |
| 500 | ControlParameters actualParams(actual.getBody()); |
| 501 | |
| 502 | BOOST_CHECK(actualParams.hasFaceId()); |
| 503 | BOOST_CHECK(actualParams.hasFacePersistency()); |
| 504 | BOOST_REQUIRE(actualParams.hasFlags()); |
| 505 | // Check if flags indicate local fields enabled |
| 506 | BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 507 | } |
| 508 | else { |
| 509 | BOOST_ERROR("Enable: Response does not contain ControlParameters"); |
| 510 | } |
| 511 | }); |
| 512 | |
| 513 | updateFace(disableParams, false, [] (const ControlResponse& actual) { |
| 514 | ControlResponse expected(200, "OK"); |
| 515 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
| 516 | BOOST_TEST_MESSAGE(actual.getText()); |
| 517 | |
| 518 | if (actual.getBody().hasWire()) { |
| 519 | ControlParameters actualParams(actual.getBody()); |
| 520 | |
| 521 | BOOST_CHECK(actualParams.hasFaceId()); |
| 522 | BOOST_CHECK(actualParams.hasFacePersistency()); |
| 523 | BOOST_REQUIRE(actualParams.hasFlags()); |
| 524 | // Check if flags indicate local fields disabled |
| 525 | BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 526 | } |
| 527 | else { |
| 528 | BOOST_ERROR("Disable: Response does not contain ControlParameters"); |
| 529 | } |
| 530 | }); |
| 531 | } |
| 532 | |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 533 | BOOST_AUTO_TEST_CASE(UpdateReliabilityEnableDisable) |
| 534 | { |
| 535 | createFace("udp4://127.0.0.1:26363"); |
| 536 | |
| 537 | ControlParameters enableParams; |
| 538 | enableParams.setFaceId(faceId); |
| 539 | enableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true); |
| 540 | |
| 541 | ControlParameters disableParams; |
| 542 | disableParams.setFaceId(faceId); |
| 543 | disableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false); |
| 544 | |
| 545 | updateFace(enableParams, false, [] (const ControlResponse& actual) { |
| 546 | ControlResponse expected(200, "OK"); |
| 547 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
| 548 | BOOST_TEST_MESSAGE(actual.getText()); |
| 549 | |
| 550 | if (actual.getBody().hasWire()) { |
| 551 | ControlParameters actualParams(actual.getBody()); |
| 552 | |
| 553 | BOOST_CHECK(actualParams.hasFaceId()); |
| 554 | BOOST_CHECK(actualParams.hasFacePersistency()); |
| 555 | BOOST_REQUIRE(actualParams.hasFlags()); |
| 556 | // Check if flags indicate reliability enabled |
| 557 | BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); |
| 558 | } |
| 559 | else { |
| 560 | BOOST_ERROR("Enable: Response does not contain ControlParameters"); |
| 561 | } |
| 562 | }); |
| 563 | |
| 564 | updateFace(disableParams, false, [] (const ControlResponse& actual) { |
| 565 | ControlResponse expected(200, "OK"); |
| 566 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
| 567 | BOOST_TEST_MESSAGE(actual.getText()); |
| 568 | |
| 569 | if (actual.getBody().hasWire()) { |
| 570 | ControlParameters actualParams(actual.getBody()); |
| 571 | |
| 572 | BOOST_CHECK(actualParams.hasFaceId()); |
| 573 | BOOST_CHECK(actualParams.hasFacePersistency()); |
| 574 | BOOST_REQUIRE(actualParams.hasFlags()); |
| 575 | // Check if flags indicate reliability disabled |
| 576 | BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); |
| 577 | } |
| 578 | else { |
| 579 | BOOST_ERROR("Disable: Response does not contain ControlParameters"); |
| 580 | } |
| 581 | }); |
| 582 | } |
| 583 | |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 584 | BOOST_AUTO_TEST_CASE(UpdateCongestionMarkingEnableDisable) |
| 585 | { |
| 586 | createFace("udp4://127.0.0.1:26363"); |
| 587 | |
| 588 | ControlParameters enableParams; |
| 589 | enableParams.setFaceId(faceId); |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 590 | enableParams.setBaseCongestionMarkingInterval(50_ms); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 591 | enableParams.setDefaultCongestionThreshold(10000); |
| 592 | enableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true); |
| 593 | |
| 594 | ControlParameters disableParams; |
| 595 | disableParams.setFaceId(faceId); |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 596 | disableParams.setBaseCongestionMarkingInterval(70_ms); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 597 | disableParams.setDefaultCongestionThreshold(5000); |
| 598 | disableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false); |
| 599 | |
| 600 | updateFace(enableParams, false, [] (const ControlResponse& actual) { |
| 601 | ControlResponse expected(200, "OK"); |
| 602 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
| 603 | BOOST_TEST_MESSAGE(actual.getText()); |
| 604 | |
| 605 | if (actual.getBody().hasWire()) { |
| 606 | ControlParameters actualParams(actual.getBody()); |
| 607 | |
| 608 | BOOST_CHECK(actualParams.hasFaceId()); |
| 609 | BOOST_CHECK(actualParams.hasFacePersistency()); |
| 610 | // Check that congestion marking parameters changed |
| 611 | BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval()); |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 612 | BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 50_ms); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 613 | BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold()); |
| 614 | BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000); |
| 615 | BOOST_REQUIRE(actualParams.hasFlags()); |
| 616 | // Check if flags indicate congestion marking enabled |
| 617 | BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); |
| 618 | } |
| 619 | else { |
| 620 | BOOST_ERROR("Enable: Response does not contain ControlParameters"); |
| 621 | } |
| 622 | }); |
| 623 | |
| 624 | updateFace(disableParams, false, [] (const ControlResponse& actual) { |
| 625 | ControlResponse expected(200, "OK"); |
| 626 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
| 627 | BOOST_TEST_MESSAGE(actual.getText()); |
| 628 | |
| 629 | if (actual.getBody().hasWire()) { |
| 630 | ControlParameters actualParams(actual.getBody()); |
| 631 | |
| 632 | BOOST_CHECK(actualParams.hasFaceId()); |
| 633 | BOOST_CHECK(actualParams.hasFacePersistency()); |
| 634 | // Check that congestion marking parameters changed, even though feature disabled |
| 635 | BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval()); |
Davide Pesavento | 3cf75dc | 2018-03-17 00:38:03 -0400 | [diff] [blame] | 636 | BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 70_ms); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 637 | BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold()); |
| 638 | BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000); |
| 639 | BOOST_REQUIRE(actualParams.hasFlags()); |
| 640 | // Check if flags indicate marking disabled |
| 641 | BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); |
| 642 | } |
| 643 | else { |
| 644 | BOOST_ERROR("Disable: Response does not contain ControlParameters"); |
| 645 | } |
| 646 | }); |
| 647 | } |
| 648 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 649 | BOOST_AUTO_TEST_CASE(SelfUpdating) |
| 650 | { |
| 651 | createFace(); |
| 652 | |
| 653 | // Send a command that does nothing (will return 200) and does not contain a FaceId |
| 654 | ControlParameters sentParams; |
| 655 | |
| 656 | updateFace(sentParams, true, [] (const ControlResponse& actual) { |
| 657 | ControlResponse expected(200, "OK"); |
| 658 | BOOST_REQUIRE_EQUAL(actual.getCode(), expected.getCode()); |
| 659 | BOOST_TEST_MESSAGE(actual.getText()); |
| 660 | }); |
| 661 | } |
| 662 | |
| 663 | BOOST_AUTO_TEST_SUITE_END() // UpdateFace |
| 664 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 665 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 666 | |
| 667 | } // namespace tests |
| 668 | } // namespace nfd |