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