Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, Regents of the University of California, |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -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 | |
| 26 | #include "face/generic-link-service.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 27 | #include "face/face.hpp" |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 28 | |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 30 | #include "tests/key-chain-fixture.hpp" |
| 31 | #include "tests/daemon/global-io-fixture.hpp" |
| 32 | #include "dummy-transport.hpp" |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 33 | |
Davide Pesavento | 9a63bf2 | 2023-11-11 17:12:51 -0500 | [diff] [blame] | 34 | #include <ndn-cxx/lp/fields.hpp> |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 35 | #include <ndn-cxx/lp/tags.hpp> |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 36 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 37 | namespace nfd::tests { |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 38 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 39 | using namespace nfd::face; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 40 | |
| 41 | BOOST_AUTO_TEST_SUITE(Face) |
| 42 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 43 | using nfd::Face; |
| 44 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 45 | class GenericLinkServiceFixture : public GlobalIoTimeFixture, public KeyChainFixture |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 46 | { |
| 47 | protected: |
| 48 | GenericLinkServiceFixture() |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 49 | { |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 50 | // By default, GenericLinkService is created with default options. |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 51 | // Test cases may invoke initialize() with alternate options. |
| 52 | initialize({}); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 56 | initialize(const GenericLinkService::Options& options, |
| 57 | ssize_t mtu = MTU_UNLIMITED, |
| 58 | ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 59 | { |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 60 | face = make_unique<Face>(make_unique<GenericLinkService>(options), |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 61 | make_unique<DummyTransport>("dummy://", "dummy://", |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 62 | ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 63 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 64 | ndn::nfd::LINK_TYPE_POINT_TO_POINT, |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 65 | mtu, sendQueueCapacity)); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 66 | service = static_cast<GenericLinkService*>(face->getLinkService()); |
| 67 | transport = static_cast<DummyTransport*>(face->getTransport()); |
| 68 | |
| 69 | face->afterReceiveInterest.connect( |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 70 | [this] (const Interest& interest, const EndpointId&) { receivedInterests.push_back(interest); }); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 71 | face->afterReceiveData.connect( |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 72 | [this] (const Data& data, const EndpointId&) { receivedData.push_back(data); }); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 73 | face->afterReceiveNack.connect( |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 74 | [this] (const lp::Nack& nack, const EndpointId&) { receivedNacks.push_back(nack); }); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 77 | lp::PrefixAnnouncementHeader |
| 78 | makePrefixAnnHeader(const Name& announcedName) |
| 79 | { |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 80 | return lp::PrefixAnnouncementHeader{signPrefixAnn(makePrefixAnn(announcedName, 1_h), |
| 81 | m_keyChain, ndn::signingWithSha256())}; |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 84 | protected: |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 85 | unique_ptr<Face> face; |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 86 | GenericLinkService* service = nullptr; |
| 87 | DummyTransport* transport = nullptr; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 88 | std::vector<Interest> receivedInterests; |
| 89 | std::vector<Data> receivedData; |
| 90 | std::vector<lp::Nack> receivedNacks; |
| 91 | }; |
| 92 | |
| 93 | BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture) |
| 94 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 95 | BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields |
| 96 | |
| 97 | BOOST_AUTO_TEST_CASE(SendInterest) |
| 98 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 99 | // Initialize with Options that disables all services |
| 100 | GenericLinkService::Options options; |
| 101 | options.allowLocalFields = false; |
| 102 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 103 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 104 | auto interest1 = makeInterest("/localhost/test"); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 105 | face->sendInterest(*interest1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 106 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 107 | BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 108 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 109 | lp::Packet interest1pkt(transport->sentPackets.back()); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 110 | BOOST_CHECK(interest1pkt.has<lp::FragmentField>()); |
| 111 | BOOST_CHECK(!interest1pkt.has<lp::SequenceField>()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | BOOST_AUTO_TEST_CASE(SendData) |
| 115 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 116 | // Initialize with Options that disables all services |
| 117 | GenericLinkService::Options options; |
| 118 | options.allowLocalFields = false; |
| 119 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 120 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 121 | auto data1 = makeData("/localhost/test"); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 122 | face->sendData(*data1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 123 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 124 | BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 125 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 126 | lp::Packet data1pkt(transport->sentPackets.back()); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 127 | BOOST_CHECK(data1pkt.has<lp::FragmentField>()); |
| 128 | BOOST_CHECK(!data1pkt.has<lp::SequenceField>()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 131 | BOOST_AUTO_TEST_CASE(SendDataOverrideMtu) |
| 132 | { |
| 133 | // Initialize with Options that disables all services and does not override MTU |
| 134 | GenericLinkService::Options options; |
| 135 | options.allowLocalFields = false; |
| 136 | initialize(options); |
| 137 | |
| 138 | BOOST_CHECK_EQUAL(transport->getMtu(), MTU_UNLIMITED); |
| 139 | BOOST_CHECK_EQUAL(service->getEffectiveMtu(), MTU_UNLIMITED); |
| 140 | BOOST_CHECK_EQUAL(face->getMtu(), MTU_UNLIMITED); |
| 141 | BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_UNLIMITED), false); |
| 142 | BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_INVALID), false); |
| 143 | // Attempts to override MTU will fail when transport MTU is unlimited |
| 144 | BOOST_CHECK_EQUAL(service->canOverrideMtuTo(4000), false); |
| 145 | |
| 146 | // Initialize with Options that disables all services and overrides MTU (Transport MTU 8800) |
| 147 | options.overrideMtu = MIN_MTU; |
| 148 | initialize(options, ndn::MAX_NDN_PACKET_SIZE); |
| 149 | |
| 150 | // Ensure effective MTU is override value |
| 151 | BOOST_CHECK_EQUAL(transport->getMtu(), ndn::MAX_NDN_PACKET_SIZE); |
| 152 | BOOST_CHECK_EQUAL(service->getEffectiveMtu(), MIN_MTU); |
| 153 | BOOST_CHECK_EQUAL(face->getMtu(), MIN_MTU); |
| 154 | |
| 155 | // Check MTU overrides with Transport MTU finite |
| 156 | BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_UNLIMITED), false); |
| 157 | BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_INVALID), false); |
| 158 | BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MIN_MTU - 1), false); |
| 159 | BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MIN_MTU), true); |
| 160 | BOOST_CHECK_EQUAL(service->canOverrideMtuTo(4000), true); |
| 161 | BOOST_CHECK_EQUAL(service->canOverrideMtuTo(20000), true); |
| 162 | |
| 163 | // Send Data with less than MIN_MTU octets |
| 164 | auto data1 = makeData("/localhost"); |
| 165 | BOOST_CHECK_LE(data1->wireEncode().size(), MIN_MTU); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 166 | face->sendData(*data1); |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 167 | |
| 168 | BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1); |
| 169 | BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 0); |
| 170 | |
| 171 | // Send Data with more than MIN_MTU octets |
| 172 | auto data2 = makeData("/localhost/test/1234567890/1234567890/1234567890/1234567890"); |
| 173 | BOOST_CHECK_GT(data2->wireEncode().size(), MIN_MTU); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 174 | face->sendData(*data2); |
Eric Newberry | cb6551e | 2020-03-02 14:12:16 -0800 | [diff] [blame] | 175 | |
| 176 | BOOST_CHECK_EQUAL(service->getCounters().nOutData, 2); |
| 177 | BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1); |
| 178 | |
| 179 | // Override MTU greater than the Transport's MTU will not be utilized |
| 180 | options.overrideMtu = 5000; |
| 181 | initialize(options, 4000); |
| 182 | BOOST_CHECK_EQUAL(service->getEffectiveMtu(), 4000); |
| 183 | BOOST_CHECK_EQUAL(face->getMtu(), 4000); |
| 184 | } |
| 185 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 186 | BOOST_AUTO_TEST_CASE(SendNack) |
| 187 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 188 | // Initialize with Options that disables all services |
| 189 | GenericLinkService::Options options; |
| 190 | options.allowLocalFields = false; |
| 191 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 192 | |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 193 | auto nack1 = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 323), |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 194 | lp::NackReason::NO_ROUTE); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 195 | face->sendNack(nack1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 196 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 197 | BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 198 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 199 | lp::Packet nack1pkt(transport->sentPackets.back()); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 200 | BOOST_CHECK(nack1pkt.has<lp::NackField>()); |
| 201 | BOOST_CHECK(nack1pkt.has<lp::FragmentField>()); |
| 202 | BOOST_CHECK(!nack1pkt.has<lp::SequenceField>()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | BOOST_AUTO_TEST_CASE(ReceiveBareInterest) |
| 206 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 207 | // Initialize with Options that disables all services |
| 208 | GenericLinkService::Options options; |
| 209 | options.allowLocalFields = false; |
| 210 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 211 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 212 | auto interest1 = makeInterest("/23Rd9hEiR"); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 213 | transport->receivePacket(interest1->wireEncode()); |
| 214 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 215 | BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 216 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 217 | BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest1->wireEncode()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | BOOST_AUTO_TEST_CASE(ReceiveInterest) |
| 221 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 222 | // Initialize with Options that disables all services |
| 223 | GenericLinkService::Options options; |
| 224 | options.allowLocalFields = false; |
| 225 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 226 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 227 | auto interest1 = makeInterest("/23Rd9hEiR"); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 228 | lp::Packet lpPacket; |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 229 | lpPacket.set<lp::FragmentField>({interest1->wireEncode().begin(), interest1->wireEncode().end()}); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 230 | lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding |
| 231 | |
| 232 | transport->receivePacket(lpPacket.wireEncode()); |
| 233 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 234 | BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 235 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 236 | BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest1->wireEncode()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | BOOST_AUTO_TEST_CASE(ReceiveBareData) |
| 240 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 241 | // Initialize with Options that disables all services |
| 242 | GenericLinkService::Options options; |
| 243 | options.allowLocalFields = false; |
| 244 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 245 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 246 | auto data1 = makeData("/12345678"); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 247 | transport->receivePacket(data1->wireEncode()); |
| 248 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 249 | BOOST_CHECK_EQUAL(service->getCounters().nInData, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 250 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 251 | BOOST_CHECK_EQUAL(receivedData.back().wireEncode(), data1->wireEncode()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | BOOST_AUTO_TEST_CASE(ReceiveData) |
| 255 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 256 | // Initialize with Options that disables all services |
| 257 | GenericLinkService::Options options; |
| 258 | options.allowLocalFields = false; |
| 259 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 260 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 261 | auto data1 = makeData("/12345689"); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 262 | lp::Packet lpPacket; |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 263 | lpPacket.set<lp::FragmentField>({data1->wireEncode().begin(), data1->wireEncode().end()}); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 264 | lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding |
| 265 | |
| 266 | transport->receivePacket(lpPacket.wireEncode()); |
| 267 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 268 | BOOST_CHECK_EQUAL(service->getCounters().nInData, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 269 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 270 | BOOST_CHECK_EQUAL(receivedData.back().wireEncode(), data1->wireEncode()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | BOOST_AUTO_TEST_CASE(ReceiveNack) |
| 274 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 275 | // Initialize with Options that disables all services |
| 276 | GenericLinkService::Options options; |
| 277 | options.allowLocalFields = false; |
| 278 | initialize(options); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 279 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 280 | auto nack1 = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 323), |
| 281 | lp::NackReason::NO_ROUTE); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 282 | lp::Packet lpPacket; |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 283 | lpPacket.set<lp::FragmentField>({nack1.getInterest().wireEncode().begin(), |
| 284 | nack1.getInterest().wireEncode().end()}); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 285 | lpPacket.set<lp::NackField>(nack1.getHeader()); |
| 286 | |
| 287 | transport->receivePacket(lpPacket.wireEncode()); |
| 288 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 289 | BOOST_CHECK_EQUAL(service->getCounters().nInNacks, 1); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 290 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 291 | BOOST_CHECK_EQUAL(receivedNacks.back().getReason(), nack1.getReason()); |
| 292 | BOOST_CHECK_EQUAL(receivedNacks.back().getInterest().wireEncode(), nack1.getInterest().wireEncode()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 295 | BOOST_AUTO_TEST_CASE(ReceiveIdlePacket) |
| 296 | { |
| 297 | // Initialize with Options that disables all services |
| 298 | GenericLinkService::Options options; |
| 299 | options.allowLocalFields = false; |
| 300 | initialize(options); |
| 301 | |
| 302 | lp::Packet lpPacket; |
| 303 | lpPacket.set<lp::SequenceField>(0); |
| 304 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 305 | transport->receivePacket(lpPacket.wireEncode()); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 306 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 307 | // IDLE packet should be ignored, but is not an error |
| 308 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 309 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 310 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 311 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 312 | } |
| 313 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 314 | BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive |
| 315 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 316 | BOOST_AUTO_TEST_SUITE(Fragmentation) |
| 317 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 318 | BOOST_AUTO_TEST_CASE(FragmentationDisabledExceedMtuDrop) |
| 319 | { |
| 320 | // Initialize with Options that disable fragmentation |
| 321 | GenericLinkService::Options options; |
| 322 | options.allowFragmentation = false; |
| 323 | initialize(options); |
| 324 | |
| 325 | transport->setMtu(55); |
| 326 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 327 | auto data = makeData("/test/data/123456789/987654321/123456789"); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 328 | face->sendData(*data); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 329 | |
| 330 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0); |
| 331 | BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1); |
| 332 | } |
| 333 | |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 334 | // It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero |
| 335 | // This test case ensures that packets are dropped if the MTU is zero |
| 336 | BOOST_AUTO_TEST_CASE(FragmentationDisabledZeroMtuDrop) |
| 337 | { |
| 338 | // Initialize with Options that disable fragmentation |
| 339 | GenericLinkService::Options options; |
| 340 | options.allowFragmentation = false; |
| 341 | initialize(options); |
| 342 | |
| 343 | transport->setMtu(0); |
| 344 | |
| 345 | auto data = makeData("/test/data/123456789/987654321/123456789"); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 346 | face->sendData(*data); |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 347 | |
| 348 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0); |
| 349 | BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1); |
| 350 | } |
| 351 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 352 | BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu) |
| 353 | { |
| 354 | // Initialize with Options that enable fragmentation |
| 355 | GenericLinkService::Options options; |
| 356 | options.allowFragmentation = true; |
| 357 | initialize(options); |
| 358 | |
| 359 | transport->setMtu(MTU_UNLIMITED); |
| 360 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 361 | auto data = makeData("/test/data/123456789/987654321/123456789"); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 362 | face->sendData(*data); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 363 | |
| 364 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
| 365 | } |
| 366 | |
| 367 | BOOST_AUTO_TEST_CASE(FragmentationUnderMtu) |
| 368 | { |
| 369 | // Initialize with Options that enable fragmentation |
| 370 | GenericLinkService::Options options; |
| 371 | options.allowFragmentation = true; |
| 372 | initialize(options); |
| 373 | |
| 374 | transport->setMtu(105); |
| 375 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 376 | auto data = makeData("/test/data/123456789/987654321/123456789"); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 377 | face->sendData(*data); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 378 | |
| 379 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
| 380 | } |
| 381 | |
| 382 | BOOST_AUTO_TEST_CASE(FragmentationOverMtu) |
| 383 | { |
| 384 | // Initialize with Options that enable fragmentation |
| 385 | GenericLinkService::Options options; |
| 386 | options.allowFragmentation = true; |
| 387 | initialize(options); |
| 388 | |
| 389 | transport->setMtu(60); |
| 390 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 391 | auto data = makeData("/test/data/123456789/987654321/123456789"); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 392 | face->sendData(*data); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 393 | |
| 394 | BOOST_CHECK_GT(transport->sentPackets.size(), 1); |
| 395 | } |
| 396 | |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 397 | // It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero |
| 398 | // This test case ensures that packets are dropped if the MTU is zero |
| 399 | BOOST_AUTO_TEST_CASE(FragmentationZeroMtuDrop) |
| 400 | { |
| 401 | // Initialize with Options that enable fragmentation |
| 402 | GenericLinkService::Options options; |
| 403 | options.allowFragmentation = true; |
| 404 | initialize(options); |
| 405 | |
| 406 | transport->setMtu(0); |
| 407 | |
| 408 | auto data = makeData("/test/data/123456789/987654321/123456789"); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 409 | face->sendData(*data); |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 410 | |
| 411 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0); |
| 412 | BOOST_CHECK_EQUAL(service->getCounters().nFragmentationErrors, 1); |
| 413 | } |
| 414 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 415 | BOOST_AUTO_TEST_CASE(ReassembleFragments) |
| 416 | { |
| 417 | // Initialize with Options that enables reassembly |
| 418 | GenericLinkService::Options options; |
| 419 | options.allowReassembly = true; |
| 420 | initialize(options); |
| 421 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 422 | auto interest = makeInterest( |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 423 | "/mt7P130BHXmtLm5dwaY5dpUM6SWYNN2B05g7y3UhsQuLvDdnTWdNnTeEiLuW3FAbJRSG3tzQ0UfaSEgG9rvYHmsKtgPMag1Hj4Tr"); |
| 424 | lp::Packet packet(interest->wireEncode()); |
| 425 | |
| 426 | // fragment the packet |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 427 | LpFragmenter fragmenter({}); |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 428 | auto [isOk, frags] = fragmenter.fragmentPacket(packet, 100); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 429 | BOOST_REQUIRE(isOk); |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 430 | BOOST_TEST(frags.size() > 1); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 431 | |
| 432 | // receive the fragments |
| 433 | for (ssize_t fragIndex = frags.size() - 1; fragIndex >= 0; --fragIndex) { |
| 434 | size_t sequence = 1000 + fragIndex; |
| 435 | frags[fragIndex].add<lp::SequenceField>(sequence); |
| 436 | |
| 437 | transport->receivePacket(frags[fragIndex].wireEncode()); |
| 438 | |
| 439 | if (fragIndex > 0) { |
| 440 | BOOST_CHECK(receivedInterests.empty()); |
| 441 | BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 1); |
| 442 | } |
| 443 | else { |
| 444 | BOOST_CHECK_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 445 | BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest->wireEncode()); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 446 | BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 0); |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 451 | BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex) |
| 452 | { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 453 | // Initialize with Options that disables reassembly |
| 454 | GenericLinkService::Options options; |
| 455 | options.allowReassembly = false; |
| 456 | initialize(options); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 457 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 458 | auto interest = makeInterest("/IgFe6NvH"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 459 | lp::Packet packet(interest->wireEncode()); |
| 460 | packet.set<lp::FragIndexField>(140); |
| 461 | |
| 462 | transport->receivePacket(packet.wireEncode()); |
| 463 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 464 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 465 | BOOST_CHECK(receivedInterests.empty()); |
| 466 | } |
| 467 | |
| 468 | BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount) |
| 469 | { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 470 | // Initialize with Options that disables reassembly |
| 471 | GenericLinkService::Options options; |
| 472 | options.allowReassembly = false; |
| 473 | initialize(options); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 474 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 475 | auto interest = makeInterest("/SeGmEjvIVX"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 476 | lp::Packet packet(interest->wireEncode()); |
| 477 | packet.set<lp::FragCountField>(276); |
| 478 | |
| 479 | transport->receivePacket(packet.wireEncode()); |
| 480 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 481 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 482 | BOOST_CHECK(receivedInterests.empty()); |
| 483 | } |
| 484 | |
| 485 | BOOST_AUTO_TEST_SUITE_END() // Fragmentation |
| 486 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 487 | BOOST_AUTO_TEST_SUITE(Reliability) |
| 488 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 489 | BOOST_AUTO_TEST_CASE(SendInterest) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 490 | { |
| 491 | // Initialize with Options that enables reliability |
| 492 | GenericLinkService::Options options; |
| 493 | options.allowLocalFields = false; |
| 494 | options.reliabilityOptions.isEnabled = true; |
| 495 | initialize(options); |
| 496 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 497 | auto interest1 = makeInterest("/localhost/test"); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 498 | face->sendInterest(*interest1); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 499 | |
| 500 | BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1); |
| 501 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 502 | lp::Packet interest1pkt(transport->sentPackets.back()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 503 | BOOST_CHECK(interest1pkt.has<lp::FragmentField>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 504 | BOOST_CHECK(interest1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 507 | BOOST_AUTO_TEST_CASE(SendData) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 508 | { |
| 509 | // Initialize with Options that enables reliability |
| 510 | GenericLinkService::Options options; |
| 511 | options.allowLocalFields = false; |
| 512 | options.reliabilityOptions.isEnabled = true; |
| 513 | initialize(options); |
| 514 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 515 | auto data1 = makeData("/localhost/test"); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 516 | face->sendData(*data1); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 517 | |
| 518 | BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1); |
| 519 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 520 | lp::Packet data1pkt(transport->sentPackets.back()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 521 | BOOST_CHECK(data1pkt.has<lp::FragmentField>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 522 | BOOST_CHECK(data1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 525 | BOOST_AUTO_TEST_CASE(SendNack) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 526 | { |
| 527 | // Initialize with Options that enables reliability |
| 528 | GenericLinkService::Options options; |
| 529 | options.allowLocalFields = false; |
| 530 | options.reliabilityOptions.isEnabled = true; |
| 531 | initialize(options); |
| 532 | |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 533 | auto nack1 = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 323), |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 534 | lp::NackReason::NO_ROUTE); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 535 | face->sendNack(nack1); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 536 | |
| 537 | BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1); |
| 538 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 539 | lp::Packet nack1pkt(transport->sentPackets.back()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 540 | BOOST_CHECK(nack1pkt.has<lp::NackField>()); |
| 541 | BOOST_CHECK(nack1pkt.has<lp::FragmentField>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 542 | BOOST_CHECK(nack1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Eric Newberry | 32f7eac | 2020-02-07 14:40:17 -0800 | [diff] [blame] | 545 | BOOST_AUTO_TEST_CASE(DropDuplicatePacket) |
| 546 | { |
| 547 | // Initialize with Options that enables reliability |
| 548 | GenericLinkService::Options options; |
| 549 | options.allowLocalFields = false; |
| 550 | options.reliabilityOptions.isEnabled = true; |
| 551 | initialize(options); |
| 552 | |
| 553 | Interest interest("/test/prefix"); |
Eric Newberry | 32f7eac | 2020-02-07 14:40:17 -0800 | [diff] [blame] | 554 | lp::Packet pkt1; |
| 555 | pkt1.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()}); |
| 556 | pkt1.add<lp::SequenceField>(7); |
| 557 | pkt1.add<lp::TxSequenceField>(12); |
| 558 | transport->receivePacket(pkt1.wireEncode()); |
| 559 | BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1); |
| 560 | BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 0); |
| 561 | |
| 562 | lp::Packet pkt2; |
| 563 | pkt2.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()}); |
| 564 | pkt2.add<lp::SequenceField>(7); |
| 565 | pkt2.add<lp::TxSequenceField>(13); |
| 566 | transport->receivePacket(pkt2.wireEncode()); |
| 567 | BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1); |
| 568 | BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 1); |
| 569 | } |
| 570 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 571 | BOOST_AUTO_TEST_SUITE_END() // Reliability |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 572 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 573 | // congestion detection and marking |
| 574 | BOOST_AUTO_TEST_SUITE(CongestionMark) |
| 575 | |
| 576 | BOOST_AUTO_TEST_CASE(NoCongestion) |
| 577 | { |
| 578 | GenericLinkService::Options options; |
| 579 | options.allowCongestionMarking = true; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 580 | options.baseCongestionMarkingInterval = 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 581 | initialize(options, MTU_UNLIMITED, 65536); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 582 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 583 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 584 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 585 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 586 | auto interest = makeInterest("/12345678"); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 587 | |
| 588 | // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes |
| 589 | |
| 590 | // no congestion |
| 591 | transport->setSendQueueLength(0); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 592 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 593 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 594 | lp::Packet pkt1(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 595 | BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 596 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 597 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 598 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 599 | |
| 600 | // no congestion |
| 601 | transport->setSendQueueLength(32768); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 602 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 603 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 604 | lp::Packet pkt2(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 605 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 606 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 607 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 608 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 609 | } |
| 610 | |
| 611 | BOOST_AUTO_TEST_CASE(CongestionCoDel) |
| 612 | { |
| 613 | GenericLinkService::Options options; |
| 614 | options.allowCongestionMarking = true; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 615 | options.baseCongestionMarkingInterval = 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 616 | initialize(options, MTU_UNLIMITED, 65536); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 617 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 618 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 619 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 620 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 621 | auto interest = makeInterest("/12345678"); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 622 | |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 623 | // first congested packet, will not be marked |
| 624 | transport->setSendQueueLength(65537); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 625 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 626 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 627 | lp::Packet pkt0(transport->sentPackets.back()); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 628 | BOOST_REQUIRE_EQUAL(pkt0.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 629 | auto nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 630 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 631 | |
| 632 | time::nanoseconds markingInterval( |
| 633 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 634 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 635 | |
| 636 | advanceClocks(markingInterval + 1_ms); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 637 | face->sendInterest(*interest); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 638 | lp::Packet pkt1(transport->sentPackets.back()); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 639 | |
| 640 | // First congestion mark appears after one interval (100 ms) |
| 641 | BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1); |
| 642 | BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 643 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 644 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 645 | |
| 646 | // advance clock to half of marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 647 | advanceClocks(markingInterval / 2); // 50ms |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 648 | |
| 649 | // second congested packet, but within marking interval, will not be marked |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 650 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 651 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 652 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 653 | lp::Packet pkt2(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 654 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 655 | |
| 656 | markingInterval = time::nanoseconds( |
| 657 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 658 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 659 | nextMarkTime += markingInterval; |
| 660 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 661 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 662 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 663 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 664 | |
| 665 | // advance clocks past end of initial interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 666 | this->advanceClocks((markingInterval / 2) + 1_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 667 | |
| 668 | // first congested packet after waiting marking interval, will be marked |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 669 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 670 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 671 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 672 | lp::Packet pkt3(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 673 | BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1); |
| 674 | BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 675 | markingInterval = time::nanoseconds( |
| 676 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 677 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 678 | nextMarkTime += markingInterval; |
| 679 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 680 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 681 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2); |
| 682 | |
| 683 | // advance clock partway through current marking interval |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 684 | this->advanceClocks(markingInterval - 20_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 685 | |
| 686 | // still congested, but within marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 687 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 688 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 689 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 690 | lp::Packet pkt4(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 691 | BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0); |
| 692 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 693 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 694 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2); |
| 695 | |
| 696 | // advance clocks past end of current marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 697 | this->advanceClocks(21_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 698 | |
| 699 | // still congested, after marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 700 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 701 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 702 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 703 | lp::Packet pkt5(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 704 | BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1); |
| 705 | BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1); |
| 706 | markingInterval = time::nanoseconds( |
| 707 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 708 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 709 | nextMarkTime += markingInterval; |
| 710 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 711 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3); |
| 712 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3); |
| 713 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 714 | this->advanceClocks(1_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 715 | |
| 716 | // still congested, but within marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 717 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 718 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 719 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 720 | lp::Packet pkt6(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 721 | BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0); |
| 722 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 723 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3); |
| 724 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3); |
| 725 | |
| 726 | this->advanceClocks(markingInterval); |
| 727 | |
| 728 | // still congested, after marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 729 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 730 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 731 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 732 | lp::Packet pkt7(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 733 | BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1); |
| 734 | BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1); |
| 735 | markingInterval = time::nanoseconds( |
| 736 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 737 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 738 | nextMarkTime += markingInterval; |
| 739 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 740 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4); |
| 741 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 742 | |
| 743 | // no more congestion |
| 744 | transport->setSendQueueLength(30000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 745 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 746 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 747 | lp::Packet pkt8(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 748 | BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 749 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 750 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 751 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 752 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 753 | this->advanceClocks(50_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 754 | |
| 755 | // send queue congested again, but can't mark packet because within one full interval of last mark |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 756 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 757 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 758 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 759 | lp::Packet pkt9(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 760 | BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 761 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 762 | markingInterval = time::nanoseconds( |
| 763 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 764 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 765 | nextMarkTime = time::steady_clock::now() + markingInterval; |
| 766 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 767 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 768 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 769 | |
| 770 | // advance clock past full 100ms interval since last mark |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 771 | this->advanceClocks(markingInterval + 2_ms); |
| 772 | BOOST_CHECK_GT(time::steady_clock::now(), nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 773 | |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 774 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 775 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 776 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 777 | lp::Packet pkt10(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 778 | BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1); |
| 779 | BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 780 | markingInterval = time::nanoseconds( |
| 781 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 782 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 783 | nextMarkTime += markingInterval; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 784 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 785 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 786 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5); |
| 787 | |
| 788 | // advance clock partway through 100ms marking interval |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 789 | this->advanceClocks(50_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 790 | |
| 791 | // not marked since within 100ms window before can mark again |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 792 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 793 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 794 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 795 | lp::Packet pkt11(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 796 | BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0); |
| 797 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 798 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 799 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5); |
| 800 | |
| 801 | // advance clocks past m_nextMarkTime |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 802 | this->advanceClocks(51_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 803 | |
| 804 | // markable packet, queue length still above threshold |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 805 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 806 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 807 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 808 | lp::Packet pkt12(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 809 | BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1); |
| 810 | BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1); |
| 811 | markingInterval = time::nanoseconds( |
| 812 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 813 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 814 | nextMarkTime += markingInterval; |
| 815 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 816 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 817 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
| 818 | |
| 819 | // no more congestion |
| 820 | transport->setSendQueueLength(10000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 821 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 822 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 823 | lp::Packet pkt13(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 824 | BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 825 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 826 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 827 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
| 828 | |
| 829 | // advance clocks past one full interval since last mark |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 830 | this->advanceClocks(102_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 831 | |
| 832 | // start congestion again |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 833 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 834 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 835 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 836 | lp::Packet pkt14(transport->sentPackets.back()); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 837 | BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 838 | nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 839 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 840 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 841 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 842 | |
| 843 | // no more congestion, cancel marking interval |
| 844 | transport->setSendQueueLength(5000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 845 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 846 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 847 | lp::Packet pkt15(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 848 | BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 849 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 850 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 851 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | BOOST_AUTO_TEST_CASE(DefaultThreshold) |
| 855 | { |
| 856 | GenericLinkService::Options options; |
| 857 | options.allowCongestionMarking = true; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 858 | options.baseCongestionMarkingInterval = 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 859 | initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 860 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 861 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 862 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 863 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 864 | auto interest = makeInterest("/12345678"); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 865 | |
| 866 | // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure |
| 867 | // the queue capacity |
| 868 | |
| 869 | // no congestion |
| 870 | transport->setSendQueueLength(0); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 871 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 872 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 873 | lp::Packet pkt1(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 874 | BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 875 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 876 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 877 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 878 | |
| 879 | // no congestion |
| 880 | transport->setSendQueueLength(65536); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 881 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 882 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 883 | lp::Packet pkt2(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 884 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 885 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 886 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 887 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 888 | |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 889 | // first congested (not marked yet) packet |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 890 | transport->setSendQueueLength(65537); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 891 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 892 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 893 | lp::Packet pkt3(transport->sentPackets.back()); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 894 | BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | ae43030 | 2023-05-11 01:42:46 -0400 | [diff] [blame] | 895 | auto nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 896 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 897 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 898 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | BOOST_AUTO_TEST_SUITE_END() // CongestionMark |
| 902 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 903 | BOOST_AUTO_TEST_SUITE(LpFields) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 904 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 905 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId) |
| 906 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 907 | // Initialize with Options that enables local fields |
| 908 | GenericLinkService::Options options; |
| 909 | options.allowLocalFields = true; |
| 910 | initialize(options); |
| 911 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 912 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 913 | lp::Packet packet(interest->wireEncode()); |
| 914 | packet.set<lp::NextHopFaceIdField>(1000); |
| 915 | |
| 916 | transport->receivePacket(packet.wireEncode()); |
| 917 | |
| 918 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 919 | auto tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>(); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 920 | BOOST_REQUIRE(tag != nullptr); |
| 921 | BOOST_CHECK_EQUAL(*tag, 1000); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled) |
| 925 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 926 | // Initialize with Options that disables local fields |
| 927 | GenericLinkService::Options options; |
| 928 | options.allowLocalFields = false; |
| 929 | initialize(options); |
| 930 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 931 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 932 | lp::Packet packet(interest->wireEncode()); |
| 933 | packet.set<lp::NextHopFaceIdField>(1000); |
| 934 | |
| 935 | transport->receivePacket(packet.wireEncode()); |
| 936 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 937 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 938 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData) |
| 942 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 943 | // Initialize with Options that enables local fields |
| 944 | GenericLinkService::Options options; |
| 945 | options.allowLocalFields = true; |
| 946 | initialize(options); |
| 947 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 948 | auto data = makeData("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 949 | lp::Packet packet(data->wireEncode()); |
| 950 | packet.set<lp::NextHopFaceIdField>(1000); |
| 951 | |
| 952 | transport->receivePacket(packet.wireEncode()); |
| 953 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 954 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 955 | BOOST_CHECK(receivedData.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack) |
| 959 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 960 | // Initialize with Options that enables local fields |
| 961 | GenericLinkService::Options options; |
| 962 | options.allowLocalFields = true; |
| 963 | initialize(options); |
| 964 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 965 | auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123), |
| 966 | lp::NackReason::NO_ROUTE); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 967 | lp::Packet packet; |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 968 | packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(), |
| 969 | nack.getInterest().wireEncode().end()}); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 970 | packet.set<lp::NackField>(nack.getHeader()); |
| 971 | packet.set<lp::NextHopFaceIdField>(1000); |
| 972 | |
| 973 | transport->receivePacket(packet.wireEncode()); |
| 974 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 975 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 976 | BOOST_CHECK(receivedNacks.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 979 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicy) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 980 | { |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 981 | // Initialize with Options that disables local fields |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 982 | GenericLinkService::Options options; |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 983 | options.allowLocalFields = false; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 984 | initialize(options); |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 985 | // CachePolicy is unprivileged and does not require allowLocalFields option. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 986 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 987 | auto data = makeData("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 988 | lp::Packet packet(data->wireEncode()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 989 | packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 990 | |
| 991 | transport->receivePacket(packet.wireEncode()); |
| 992 | |
| 993 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 994 | auto tag = receivedData.back().getTag<lp::CachePolicyTag>(); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 995 | BOOST_REQUIRE(tag != nullptr); |
| 996 | BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 997 | } |
| 998 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 999 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1000 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1001 | // Initialize with Options that enables local fields |
| 1002 | GenericLinkService::Options options; |
| 1003 | options.allowLocalFields = true; |
| 1004 | initialize(options); |
| 1005 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1006 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1007 | lp::Packet packet(interest->wireEncode()); |
| 1008 | lp::CachePolicy policy; |
| 1009 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 1010 | packet.set<lp::CachePolicyField>(policy); |
| 1011 | |
| 1012 | transport->receivePacket(packet.wireEncode()); |
| 1013 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1014 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1015 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 1018 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1019 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1020 | // Initialize with Options that enables local fields |
| 1021 | GenericLinkService::Options options; |
| 1022 | options.allowLocalFields = true; |
| 1023 | initialize(options); |
| 1024 | |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 1025 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123), |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1026 | lp::NackReason::NO_ROUTE); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1027 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 1028 | packet.set<lp::NackField>(nack.getHeader()); |
| 1029 | lp::CachePolicy policy; |
| 1030 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 1031 | packet.set<lp::CachePolicyField>(policy); |
| 1032 | |
| 1033 | transport->receivePacket(packet.wireEncode()); |
| 1034 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1035 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1036 | BOOST_CHECK(receivedNacks.empty()); |
| 1037 | } |
| 1038 | |
| 1039 | BOOST_AUTO_TEST_CASE(SendIncomingFaceId) |
| 1040 | { |
| 1041 | // Initialize with Options that enables local fields |
| 1042 | GenericLinkService::Options options; |
| 1043 | options.allowLocalFields = true; |
| 1044 | initialize(options); |
| 1045 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1046 | auto interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1047 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1048 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1049 | face->sendInterest(*interest); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1050 | |
| 1051 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1052 | lp::Packet sent(transport->sentPackets.back()); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1053 | BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>()); |
| 1054 | BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000); |
| 1055 | } |
| 1056 | |
| 1057 | BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled) |
| 1058 | { |
| 1059 | // Initialize with Options that disables local fields |
| 1060 | GenericLinkService::Options options; |
| 1061 | options.allowLocalFields = false; |
| 1062 | initialize(options); |
| 1063 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1064 | auto interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1065 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1066 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1067 | face->sendInterest(*interest); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1068 | |
| 1069 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1070 | lp::Packet sent(transport->sentPackets.back()); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1071 | BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>()); |
| 1072 | } |
| 1073 | |
| 1074 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest) |
| 1075 | { |
| 1076 | // Initialize with Options that enables local fields |
| 1077 | GenericLinkService::Options options; |
| 1078 | options.allowLocalFields = true; |
| 1079 | initialize(options); |
| 1080 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1081 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1082 | lp::Packet packet(interest->wireEncode()); |
| 1083 | packet.set<lp::IncomingFaceIdField>(1000); |
| 1084 | |
| 1085 | transport->receivePacket(packet.wireEncode()); |
| 1086 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1087 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1088 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1089 | BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData) |
| 1093 | { |
| 1094 | // Initialize with Options that enables local fields |
| 1095 | GenericLinkService::Options options; |
| 1096 | options.allowLocalFields = true; |
| 1097 | initialize(options); |
| 1098 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1099 | auto data = makeData("/z1megUh9Bj"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1100 | lp::Packet packet(data->wireEncode()); |
| 1101 | packet.set<lp::IncomingFaceIdField>(1000); |
| 1102 | |
| 1103 | transport->receivePacket(packet.wireEncode()); |
| 1104 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1105 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1106 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1107 | BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack) |
| 1111 | { |
| 1112 | // Initialize with Options that enables local fields |
| 1113 | GenericLinkService::Options options; |
| 1114 | options.allowLocalFields = true; |
| 1115 | initialize(options); |
| 1116 | |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 1117 | lp::Nack nack = makeNack(*makeInterest("/TPAhdiHz", false, std::nullopt, 278), |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1118 | lp::NackReason::CONGESTION); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1119 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 1120 | packet.set<lp::NackField>(nack.getHeader()); |
| 1121 | packet.set<lp::IncomingFaceIdField>(1000); |
| 1122 | |
| 1123 | transport->receivePacket(packet.wireEncode()); |
| 1124 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1125 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1126 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1127 | BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1130 | BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest) |
| 1131 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1132 | auto interest = makeInterest("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1133 | interest->setTag(make_shared<lp::CongestionMarkTag>(1)); |
| 1134 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1135 | face->sendInterest(*interest); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1136 | |
| 1137 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1138 | lp::Packet sent(transport->sentPackets.back()); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1139 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1140 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1); |
| 1141 | } |
| 1142 | |
| 1143 | BOOST_AUTO_TEST_CASE(SendCongestionMarkData) |
| 1144 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1145 | auto data = makeData("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1146 | data->setTag(make_shared<lp::CongestionMarkTag>(0)); |
| 1147 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1148 | face->sendData(*data); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1149 | |
| 1150 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1151 | lp::Packet sent(transport->sentPackets.back()); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1152 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1153 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0); |
| 1154 | } |
| 1155 | |
| 1156 | BOOST_AUTO_TEST_CASE(SendCongestionMarkNack) |
| 1157 | { |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 1158 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123), |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1159 | lp::NackReason::NO_ROUTE); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1160 | nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max())); |
| 1161 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1162 | face->sendNack(nack); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1163 | |
| 1164 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1165 | lp::Packet sent(transport->sentPackets.back()); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1166 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1167 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max()); |
| 1168 | } |
| 1169 | |
| 1170 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest) |
| 1171 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1172 | auto interest = makeInterest("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1173 | lp::Packet packet(interest->wireEncode()); |
| 1174 | packet.set<lp::CongestionMarkField>(1); |
| 1175 | |
| 1176 | transport->receivePacket(packet.wireEncode()); |
| 1177 | |
| 1178 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1179 | auto tag = receivedInterests.back().getTag<lp::CongestionMarkTag>(); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1180 | BOOST_REQUIRE(tag != nullptr); |
| 1181 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1182 | } |
| 1183 | |
| 1184 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData) |
| 1185 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1186 | auto data = makeData("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1187 | lp::Packet packet(data->wireEncode()); |
| 1188 | packet.set<lp::CongestionMarkField>(1); |
| 1189 | |
| 1190 | transport->receivePacket(packet.wireEncode()); |
| 1191 | |
| 1192 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1193 | auto tag = receivedData.back().getTag<lp::CongestionMarkTag>(); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1194 | BOOST_REQUIRE(tag != nullptr); |
| 1195 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1196 | } |
| 1197 | |
| 1198 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack) |
| 1199 | { |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 1200 | auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123), |
| 1201 | lp::NackReason::NO_ROUTE); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1202 | lp::Packet packet; |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 1203 | packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(), |
| 1204 | nack.getInterest().wireEncode().end()}); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1205 | packet.set<lp::NackField>(nack.getHeader()); |
| 1206 | packet.set<lp::CongestionMarkField>(1); |
| 1207 | |
| 1208 | transport->receivePacket(packet.wireEncode()); |
| 1209 | |
| 1210 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1211 | auto tag = receivedNacks.back().getTag<lp::CongestionMarkTag>(); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1212 | BOOST_REQUIRE(tag != nullptr); |
| 1213 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1214 | } |
| 1215 | |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1216 | BOOST_AUTO_TEST_CASE(SendNonDiscovery) |
| 1217 | { |
| 1218 | GenericLinkService::Options options; |
| 1219 | options.allowSelfLearning = true; |
| 1220 | initialize(options); |
| 1221 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1222 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1223 | interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{})); |
| 1224 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1225 | face->sendInterest(*interest); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1226 | |
| 1227 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1228 | lp::Packet sent(transport->sentPackets.back()); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1229 | BOOST_CHECK(sent.has<lp::NonDiscoveryField>()); |
| 1230 | } |
| 1231 | |
| 1232 | BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled) |
| 1233 | { |
| 1234 | GenericLinkService::Options options; |
| 1235 | options.allowSelfLearning = false; |
| 1236 | initialize(options); |
| 1237 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1238 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1239 | interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{})); |
| 1240 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1241 | face->sendInterest(*interest); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1242 | |
| 1243 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1244 | lp::Packet sent(transport->sentPackets.back()); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1245 | BOOST_CHECK(!sent.has<lp::NonDiscoveryField>()); |
| 1246 | } |
| 1247 | |
| 1248 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery) |
| 1249 | { |
| 1250 | GenericLinkService::Options options; |
| 1251 | options.allowSelfLearning = true; |
| 1252 | initialize(options); |
| 1253 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1254 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1255 | lp::Packet packet(interest->wireEncode()); |
| 1256 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1257 | |
| 1258 | transport->receivePacket(packet.wireEncode()); |
| 1259 | |
| 1260 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1261 | auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1262 | BOOST_CHECK(tag != nullptr); |
| 1263 | } |
| 1264 | |
| 1265 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled) |
| 1266 | { |
| 1267 | GenericLinkService::Options options; |
| 1268 | options.allowSelfLearning = false; |
| 1269 | initialize(options); |
| 1270 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1271 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1272 | lp::Packet packet(interest->wireEncode()); |
| 1273 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1274 | |
| 1275 | transport->receivePacket(packet.wireEncode()); |
| 1276 | |
| 1277 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
| 1278 | BOOST_CHECK_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1279 | auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1280 | BOOST_CHECK(tag == nullptr); |
| 1281 | } |
| 1282 | |
| 1283 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData) |
| 1284 | { |
| 1285 | GenericLinkService::Options options; |
| 1286 | options.allowSelfLearning = true; |
| 1287 | initialize(options); |
| 1288 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1289 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1290 | lp::Packet packet(data->wireEncode()); |
| 1291 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1292 | |
| 1293 | transport->receivePacket(packet.wireEncode()); |
| 1294 | |
| 1295 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1296 | BOOST_CHECK(receivedData.empty()); |
| 1297 | } |
| 1298 | |
| 1299 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack) |
| 1300 | { |
| 1301 | GenericLinkService::Options options; |
| 1302 | options.allowSelfLearning = true; |
| 1303 | initialize(options); |
| 1304 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 1305 | auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123), |
| 1306 | lp::NackReason::NO_ROUTE); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1307 | lp::Packet packet; |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 1308 | packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(), |
| 1309 | nack.getInterest().wireEncode().end()}); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1310 | packet.set<lp::NackField>(nack.getHeader()); |
| 1311 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1312 | |
| 1313 | transport->receivePacket(packet.wireEncode()); |
| 1314 | |
| 1315 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1316 | BOOST_CHECK(receivedNacks.empty()); |
| 1317 | } |
| 1318 | |
| 1319 | BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement) |
| 1320 | { |
| 1321 | GenericLinkService::Options options; |
| 1322 | options.allowSelfLearning = true; |
| 1323 | initialize(options); |
| 1324 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1325 | auto data = makeData("/12345678"); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1326 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1327 | data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah)); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1328 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1329 | face->sendData(*data); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1330 | |
| 1331 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1332 | lp::Packet sent(transport->sentPackets.back()); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1333 | BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>()); |
| 1334 | } |
| 1335 | |
| 1336 | BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled) |
| 1337 | { |
| 1338 | GenericLinkService::Options options; |
| 1339 | options.allowSelfLearning = false; |
| 1340 | initialize(options); |
| 1341 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1342 | auto data = makeData("/12345678"); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1343 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1344 | data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah)); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1345 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1346 | face->sendData(*data); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1347 | |
| 1348 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1349 | lp::Packet sent(transport->sentPackets.back()); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1350 | BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>()); |
| 1351 | } |
| 1352 | |
| 1353 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement) |
| 1354 | { |
| 1355 | GenericLinkService::Options options; |
| 1356 | options.allowSelfLearning = true; |
| 1357 | initialize(options); |
| 1358 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1359 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1360 | lp::Packet packet(data->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1361 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1362 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1363 | |
| 1364 | transport->receivePacket(packet.wireEncode()); |
| 1365 | |
| 1366 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1367 | auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>(); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1368 | BOOST_CHECK_EQUAL(tag->get().getPrefixAnn()->getAnnouncedName(), "/local/ndn/prefix"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled) |
| 1372 | { |
| 1373 | GenericLinkService::Options options; |
| 1374 | options.allowSelfLearning = false; |
| 1375 | initialize(options); |
| 1376 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1377 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1378 | lp::Packet packet(data->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1379 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1380 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1381 | |
| 1382 | transport->receivePacket(packet.wireEncode()); |
| 1383 | |
| 1384 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
| 1385 | BOOST_CHECK_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1386 | auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1387 | BOOST_CHECK(tag == nullptr); |
| 1388 | } |
| 1389 | |
| 1390 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest) |
| 1391 | { |
| 1392 | GenericLinkService::Options options; |
| 1393 | options.allowSelfLearning = true; |
| 1394 | initialize(options); |
| 1395 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1396 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1397 | lp::Packet packet(interest->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1398 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1399 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1400 | |
| 1401 | transport->receivePacket(packet.wireEncode()); |
| 1402 | |
| 1403 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1404 | BOOST_CHECK(receivedInterests.empty()); |
| 1405 | } |
| 1406 | |
| 1407 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack) |
| 1408 | { |
| 1409 | GenericLinkService::Options options; |
| 1410 | options.allowSelfLearning = true; |
| 1411 | initialize(options); |
| 1412 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 1413 | auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123), |
| 1414 | lp::NackReason::NO_ROUTE); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1415 | lp::Packet packet; |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 1416 | packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(), |
| 1417 | nack.getInterest().wireEncode().end()}); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1418 | packet.set<lp::NackField>(nack.getHeader()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1419 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1420 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1421 | |
| 1422 | transport->receivePacket(packet.wireEncode()); |
| 1423 | |
| 1424 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1425 | BOOST_CHECK(receivedNacks.empty()); |
| 1426 | } |
| 1427 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1428 | BOOST_AUTO_TEST_SUITE_END() // LpFields |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1429 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1430 | BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets |
| 1431 | |
| 1432 | BOOST_AUTO_TEST_CASE(WrongTlvType) |
| 1433 | { |
| 1434 | // Initialize with Options that disables all services |
| 1435 | GenericLinkService::Options options; |
| 1436 | options.allowLocalFields = false; |
| 1437 | initialize(options); |
| 1438 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1439 | auto packet = ndn::encoding::makeEmptyBlock(tlv::Name); |
| 1440 | transport->receivePacket(packet); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1441 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1442 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1443 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 1444 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 1445 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 1446 | } |
| 1447 | |
| 1448 | BOOST_AUTO_TEST_CASE(Unparsable) |
| 1449 | { |
| 1450 | // Initialize with Options that disables all services |
| 1451 | GenericLinkService::Options options; |
| 1452 | options.allowLocalFields = false; |
| 1453 | initialize(options); |
| 1454 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1455 | auto packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x"); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1456 | BOOST_CHECK_THROW(packet.parse(), tlv::Error); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1457 | transport->receivePacket(packet); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1458 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1459 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1460 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 1461 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 1462 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 1463 | } |
| 1464 | |
| 1465 | BOOST_AUTO_TEST_SUITE_END() // Malformed |
| 1466 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1467 | BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService |
| 1468 | BOOST_AUTO_TEST_SUITE_END() // Face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1469 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 1470 | } // namespace nfd::tests |