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