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