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