Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 2 | /* |
Eric Newberry | f3ee808 | 2020-01-28 13:44:18 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, Regents of the University of California, |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "face/generic-link-service.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 27 | #include "face/face.hpp" |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 28 | |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 30 | #include "tests/key-chain-fixture.hpp" |
| 31 | #include "tests/daemon/global-io-fixture.hpp" |
| 32 | #include "dummy-transport.hpp" |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 33 | |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 34 | #include <ndn-cxx/lp/empty-value.hpp> |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 35 | #include <ndn-cxx/lp/prefix-announcement-header.hpp> |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 36 | #include <ndn-cxx/lp/tags.hpp> |
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"); |
| 562 | interest.setCanBePrefix(false); |
| 563 | lp::Packet pkt1; |
| 564 | pkt1.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()}); |
| 565 | pkt1.add<lp::SequenceField>(7); |
| 566 | pkt1.add<lp::TxSequenceField>(12); |
| 567 | transport->receivePacket(pkt1.wireEncode()); |
| 568 | BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1); |
| 569 | BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 0); |
| 570 | |
| 571 | lp::Packet pkt2; |
| 572 | pkt2.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()}); |
| 573 | pkt2.add<lp::SequenceField>(7); |
| 574 | pkt2.add<lp::TxSequenceField>(13); |
| 575 | transport->receivePacket(pkt2.wireEncode()); |
| 576 | BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1); |
| 577 | BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 1); |
| 578 | } |
| 579 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 580 | BOOST_AUTO_TEST_SUITE_END() // Reliability |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 581 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 582 | // congestion detection and marking |
| 583 | BOOST_AUTO_TEST_SUITE(CongestionMark) |
| 584 | |
| 585 | BOOST_AUTO_TEST_CASE(NoCongestion) |
| 586 | { |
| 587 | GenericLinkService::Options options; |
| 588 | options.allowCongestionMarking = true; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 589 | options.baseCongestionMarkingInterval = 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 590 | initialize(options, MTU_UNLIMITED, 65536); |
| 591 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 592 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 593 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 594 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 595 | auto interest = makeInterest("/12345678"); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 596 | |
| 597 | // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes |
| 598 | |
| 599 | // no congestion |
| 600 | transport->setSendQueueLength(0); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 601 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 602 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 603 | lp::Packet pkt1(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 604 | BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0); |
| 605 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 606 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 607 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 608 | |
| 609 | // no congestion |
| 610 | transport->setSendQueueLength(32768); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 611 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 612 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 613 | lp::Packet pkt2(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 614 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
| 615 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 616 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 617 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 618 | } |
| 619 | |
| 620 | BOOST_AUTO_TEST_CASE(CongestionCoDel) |
| 621 | { |
| 622 | GenericLinkService::Options options; |
| 623 | options.allowCongestionMarking = true; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 624 | options.baseCongestionMarkingInterval = 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 625 | initialize(options, MTU_UNLIMITED, 65536); |
| 626 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 627 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 628 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 629 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 630 | auto interest = makeInterest("/12345678"); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 631 | |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 632 | // first congested packet, will not be marked |
| 633 | transport->setSendQueueLength(65537); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 634 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 635 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 636 | lp::Packet pkt0(transport->sentPackets.back()); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 637 | BOOST_REQUIRE_EQUAL(pkt0.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 638 | time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 639 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 640 | |
| 641 | time::nanoseconds markingInterval( |
| 642 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 643 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 644 | |
| 645 | advanceClocks(markingInterval + 1_ms); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 646 | face->sendInterest(*interest); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 647 | lp::Packet pkt1(transport->sentPackets.back()); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 648 | |
| 649 | // First congestion mark appears after one interval (100 ms) |
| 650 | BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1); |
| 651 | BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 652 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 653 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 654 | |
| 655 | // advance clock to half of marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 656 | advanceClocks(markingInterval / 2); // 50ms |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 657 | |
| 658 | // second congested packet, but within marking interval, will not be marked |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 659 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 660 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 661 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 662 | lp::Packet pkt2(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 663 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 664 | |
| 665 | markingInterval = time::nanoseconds( |
| 666 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 667 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 668 | nextMarkTime += markingInterval; |
| 669 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 670 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 671 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 672 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 673 | |
| 674 | // advance clocks past end of initial interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 675 | this->advanceClocks((markingInterval / 2) + 1_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 676 | |
| 677 | // first congested packet after waiting marking interval, will be marked |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 678 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 679 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 680 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 681 | lp::Packet pkt3(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 682 | BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1); |
| 683 | BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 684 | markingInterval = time::nanoseconds( |
| 685 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 686 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 687 | nextMarkTime += markingInterval; |
| 688 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 689 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 690 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2); |
| 691 | |
| 692 | // advance clock partway through current marking interval |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 693 | this->advanceClocks(markingInterval - 20_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 694 | |
| 695 | // still congested, but within marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 696 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 697 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 698 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 699 | lp::Packet pkt4(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 700 | BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0); |
| 701 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 702 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 703 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2); |
| 704 | |
| 705 | // advance clocks past end of current marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 706 | this->advanceClocks(21_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 707 | |
| 708 | // still congested, after marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 709 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 710 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 711 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 712 | lp::Packet pkt5(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 713 | BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1); |
| 714 | BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1); |
| 715 | markingInterval = time::nanoseconds( |
| 716 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 717 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 718 | nextMarkTime += markingInterval; |
| 719 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 720 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3); |
| 721 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3); |
| 722 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 723 | this->advanceClocks(1_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 724 | |
| 725 | // still congested, but within marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 726 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 727 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 728 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 729 | lp::Packet pkt6(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 730 | BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0); |
| 731 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 732 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3); |
| 733 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3); |
| 734 | |
| 735 | this->advanceClocks(markingInterval); |
| 736 | |
| 737 | // still congested, after marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 738 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 739 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 740 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 741 | lp::Packet pkt7(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 742 | BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1); |
| 743 | BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1); |
| 744 | markingInterval = time::nanoseconds( |
| 745 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 746 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 747 | nextMarkTime += markingInterval; |
| 748 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 749 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4); |
| 750 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 751 | |
| 752 | // no more congestion |
| 753 | transport->setSendQueueLength(30000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 754 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 755 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 756 | lp::Packet pkt8(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 757 | BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0); |
| 758 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 759 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 760 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 761 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 762 | this->advanceClocks(50_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 763 | |
| 764 | // 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] | 765 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 766 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 767 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 768 | lp::Packet pkt9(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 769 | BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 770 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 771 | markingInterval = time::nanoseconds( |
| 772 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 773 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 774 | nextMarkTime = time::steady_clock::now() + markingInterval; |
| 775 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 776 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 777 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 778 | |
| 779 | // advance clock past full 100ms interval since last mark |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 780 | this->advanceClocks(markingInterval + 2_ms); |
| 781 | BOOST_CHECK_GT(time::steady_clock::now(), nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 782 | |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 783 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 784 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 785 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 786 | lp::Packet pkt10(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 787 | BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1); |
| 788 | BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 789 | markingInterval = time::nanoseconds( |
| 790 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 791 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 792 | nextMarkTime += markingInterval; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 793 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 794 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 795 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5); |
| 796 | |
| 797 | // advance clock partway through 100ms marking interval |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 798 | this->advanceClocks(50_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 799 | |
| 800 | // not marked since within 100ms window before can mark again |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 801 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 802 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 803 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 804 | lp::Packet pkt11(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 805 | BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0); |
| 806 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 807 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 808 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5); |
| 809 | |
| 810 | // advance clocks past m_nextMarkTime |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 811 | this->advanceClocks(51_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 812 | |
| 813 | // markable packet, queue length still above threshold |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 814 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 815 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 816 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 817 | lp::Packet pkt12(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 818 | BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1); |
| 819 | BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1); |
| 820 | markingInterval = time::nanoseconds( |
| 821 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 822 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 823 | nextMarkTime += markingInterval; |
| 824 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 825 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 826 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
| 827 | |
| 828 | // no more congestion |
| 829 | transport->setSendQueueLength(10000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 830 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 831 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 832 | lp::Packet pkt13(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 833 | BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0); |
| 834 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 835 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 836 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
| 837 | |
| 838 | // advance clocks past one full interval since last mark |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 839 | this->advanceClocks(102_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 840 | |
| 841 | // start congestion again |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 842 | transport->setSendQueueLength(66000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 843 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 844 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 845 | lp::Packet pkt14(transport->sentPackets.back()); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 846 | BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 847 | nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 848 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 849 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 850 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 851 | |
| 852 | // no more congestion, cancel marking interval |
| 853 | transport->setSendQueueLength(5000); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 854 | face->sendInterest(*interest); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 855 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 856 | lp::Packet pkt15(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 857 | BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0); |
| 858 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 859 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 860 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | BOOST_AUTO_TEST_CASE(DefaultThreshold) |
| 864 | { |
| 865 | GenericLinkService::Options options; |
| 866 | options.allowCongestionMarking = true; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 867 | options.baseCongestionMarkingInterval = 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 868 | initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED); |
| 869 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 870 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 871 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 872 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 873 | auto interest = makeInterest("/12345678"); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 874 | |
| 875 | // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure |
| 876 | // the queue capacity |
| 877 | |
| 878 | // no congestion |
| 879 | transport->setSendQueueLength(0); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 880 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 881 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 882 | lp::Packet pkt1(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 883 | BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0); |
| 884 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 885 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 886 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 887 | |
| 888 | // no congestion |
| 889 | transport->setSendQueueLength(65536); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 890 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 891 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 892 | lp::Packet pkt2(transport->sentPackets.back()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 893 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
| 894 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 895 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 896 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 897 | |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 898 | // first congested (not marked yet) packet |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 899 | transport->setSendQueueLength(65537); |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 900 | face->sendInterest(*interest); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 901 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 902 | lp::Packet pkt3(transport->sentPackets.back()); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 903 | BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 904 | time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 905 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame] | 906 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 907 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | BOOST_AUTO_TEST_SUITE_END() // CongestionMark |
| 911 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 912 | BOOST_AUTO_TEST_SUITE(LpFields) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 913 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 914 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId) |
| 915 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 916 | // Initialize with Options that enables local fields |
| 917 | GenericLinkService::Options options; |
| 918 | options.allowLocalFields = true; |
| 919 | initialize(options); |
| 920 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 921 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 922 | lp::Packet packet(interest->wireEncode()); |
| 923 | packet.set<lp::NextHopFaceIdField>(1000); |
| 924 | |
| 925 | transport->receivePacket(packet.wireEncode()); |
| 926 | |
| 927 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 928 | auto tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>(); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 929 | BOOST_REQUIRE(tag != nullptr); |
| 930 | BOOST_CHECK_EQUAL(*tag, 1000); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled) |
| 934 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 935 | // Initialize with Options that disables local fields |
| 936 | GenericLinkService::Options options; |
| 937 | options.allowLocalFields = false; |
| 938 | initialize(options); |
| 939 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 940 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 941 | lp::Packet packet(interest->wireEncode()); |
| 942 | packet.set<lp::NextHopFaceIdField>(1000); |
| 943 | |
| 944 | transport->receivePacket(packet.wireEncode()); |
| 945 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 946 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 947 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData) |
| 951 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 952 | // Initialize with Options that enables local fields |
| 953 | GenericLinkService::Options options; |
| 954 | options.allowLocalFields = true; |
| 955 | initialize(options); |
| 956 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 957 | auto data = makeData("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 958 | lp::Packet packet(data->wireEncode()); |
| 959 | packet.set<lp::NextHopFaceIdField>(1000); |
| 960 | |
| 961 | transport->receivePacket(packet.wireEncode()); |
| 962 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 963 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 964 | BOOST_CHECK(receivedData.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack) |
| 968 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 969 | // Initialize with Options that enables local fields |
| 970 | GenericLinkService::Options options; |
| 971 | options.allowLocalFields = true; |
| 972 | initialize(options); |
| 973 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 974 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 975 | lp::NackReason::NO_ROUTE); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 976 | lp::Packet packet; |
| 977 | packet.set<lp::FragmentField>(std::make_pair( |
| 978 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 979 | packet.set<lp::NackField>(nack.getHeader()); |
| 980 | packet.set<lp::NextHopFaceIdField>(1000); |
| 981 | |
| 982 | transport->receivePacket(packet.wireEncode()); |
| 983 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 984 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 985 | BOOST_CHECK(receivedNacks.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 986 | } |
| 987 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 988 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicy) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 989 | { |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 990 | // Initialize with Options that disables local fields |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 991 | GenericLinkService::Options options; |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 992 | options.allowLocalFields = false; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 993 | initialize(options); |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 994 | // CachePolicy is unprivileged and does not require allowLocalFields option. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 995 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 996 | auto data = makeData("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 997 | lp::Packet packet(data->wireEncode()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 998 | packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 999 | |
| 1000 | transport->receivePacket(packet.wireEncode()); |
| 1001 | |
| 1002 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1003 | auto tag = receivedData.back().getTag<lp::CachePolicyTag>(); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1004 | BOOST_REQUIRE(tag != nullptr); |
| 1005 | BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 1008 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1009 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1010 | // Initialize with Options that enables local fields |
| 1011 | GenericLinkService::Options options; |
| 1012 | options.allowLocalFields = true; |
| 1013 | initialize(options); |
| 1014 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1015 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1016 | lp::Packet packet(interest->wireEncode()); |
| 1017 | lp::CachePolicy policy; |
| 1018 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 1019 | packet.set<lp::CachePolicyField>(policy); |
| 1020 | |
| 1021 | transport->receivePacket(packet.wireEncode()); |
| 1022 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1023 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1024 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 1027 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1028 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1029 | // Initialize with Options that enables local fields |
| 1030 | GenericLinkService::Options options; |
| 1031 | options.allowLocalFields = true; |
| 1032 | initialize(options); |
| 1033 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1034 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1035 | lp::NackReason::NO_ROUTE); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1036 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 1037 | packet.set<lp::NackField>(nack.getHeader()); |
| 1038 | lp::CachePolicy policy; |
| 1039 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 1040 | packet.set<lp::CachePolicyField>(policy); |
| 1041 | |
| 1042 | transport->receivePacket(packet.wireEncode()); |
| 1043 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1044 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1045 | BOOST_CHECK(receivedNacks.empty()); |
| 1046 | } |
| 1047 | |
| 1048 | BOOST_AUTO_TEST_CASE(SendIncomingFaceId) |
| 1049 | { |
| 1050 | // Initialize with Options that enables local fields |
| 1051 | GenericLinkService::Options options; |
| 1052 | options.allowLocalFields = true; |
| 1053 | initialize(options); |
| 1054 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1055 | auto interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1056 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1057 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1058 | face->sendInterest(*interest); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1059 | |
| 1060 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1061 | lp::Packet sent(transport->sentPackets.back()); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1062 | BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>()); |
| 1063 | BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000); |
| 1064 | } |
| 1065 | |
| 1066 | BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled) |
| 1067 | { |
| 1068 | // Initialize with Options that disables local fields |
| 1069 | GenericLinkService::Options options; |
| 1070 | options.allowLocalFields = false; |
| 1071 | initialize(options); |
| 1072 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1073 | auto interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1074 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1075 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1076 | face->sendInterest(*interest); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1077 | |
| 1078 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1079 | lp::Packet sent(transport->sentPackets.back()); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1080 | BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>()); |
| 1081 | } |
| 1082 | |
| 1083 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest) |
| 1084 | { |
| 1085 | // Initialize with Options that enables local fields |
| 1086 | GenericLinkService::Options options; |
| 1087 | options.allowLocalFields = true; |
| 1088 | initialize(options); |
| 1089 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1090 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1091 | lp::Packet packet(interest->wireEncode()); |
| 1092 | packet.set<lp::IncomingFaceIdField>(1000); |
| 1093 | |
| 1094 | transport->receivePacket(packet.wireEncode()); |
| 1095 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1096 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1097 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1098 | BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData) |
| 1102 | { |
| 1103 | // Initialize with Options that enables local fields |
| 1104 | GenericLinkService::Options options; |
| 1105 | options.allowLocalFields = true; |
| 1106 | initialize(options); |
| 1107 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1108 | auto data = makeData("/z1megUh9Bj"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1109 | lp::Packet packet(data->wireEncode()); |
| 1110 | packet.set<lp::IncomingFaceIdField>(1000); |
| 1111 | |
| 1112 | transport->receivePacket(packet.wireEncode()); |
| 1113 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1114 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1115 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1116 | BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack) |
| 1120 | { |
| 1121 | // Initialize with Options that enables local fields |
| 1122 | GenericLinkService::Options options; |
| 1123 | options.allowLocalFields = true; |
| 1124 | initialize(options); |
| 1125 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1126 | lp::Nack nack = makeNack(*makeInterest("/TPAhdiHz", false, nullopt, 278), |
| 1127 | lp::NackReason::CONGESTION); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1128 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 1129 | packet.set<lp::NackField>(nack.getHeader()); |
| 1130 | packet.set<lp::IncomingFaceIdField>(1000); |
| 1131 | |
| 1132 | transport->receivePacket(packet.wireEncode()); |
| 1133 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1134 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1135 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1136 | BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1139 | BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest) |
| 1140 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1141 | auto interest = makeInterest("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1142 | interest->setTag(make_shared<lp::CongestionMarkTag>(1)); |
| 1143 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1144 | face->sendInterest(*interest); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1145 | |
| 1146 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1147 | lp::Packet sent(transport->sentPackets.back()); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1148 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1149 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1); |
| 1150 | } |
| 1151 | |
| 1152 | BOOST_AUTO_TEST_CASE(SendCongestionMarkData) |
| 1153 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1154 | auto data = makeData("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1155 | data->setTag(make_shared<lp::CongestionMarkTag>(0)); |
| 1156 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1157 | face->sendData(*data); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1158 | |
| 1159 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1160 | lp::Packet sent(transport->sentPackets.back()); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1161 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1162 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0); |
| 1163 | } |
| 1164 | |
| 1165 | BOOST_AUTO_TEST_CASE(SendCongestionMarkNack) |
| 1166 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1167 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1168 | lp::NackReason::NO_ROUTE); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1169 | nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max())); |
| 1170 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1171 | face->sendNack(nack); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1172 | |
| 1173 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1174 | lp::Packet sent(transport->sentPackets.back()); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1175 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1176 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max()); |
| 1177 | } |
| 1178 | |
| 1179 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest) |
| 1180 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1181 | auto interest = makeInterest("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1182 | lp::Packet packet(interest->wireEncode()); |
| 1183 | packet.set<lp::CongestionMarkField>(1); |
| 1184 | |
| 1185 | transport->receivePacket(packet.wireEncode()); |
| 1186 | |
| 1187 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1188 | auto tag = receivedInterests.back().getTag<lp::CongestionMarkTag>(); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1189 | BOOST_REQUIRE(tag != nullptr); |
| 1190 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1191 | } |
| 1192 | |
| 1193 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData) |
| 1194 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1195 | auto data = makeData("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1196 | lp::Packet packet(data->wireEncode()); |
| 1197 | packet.set<lp::CongestionMarkField>(1); |
| 1198 | |
| 1199 | transport->receivePacket(packet.wireEncode()); |
| 1200 | |
| 1201 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1202 | auto tag = receivedData.back().getTag<lp::CongestionMarkTag>(); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1203 | BOOST_REQUIRE(tag != nullptr); |
| 1204 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1205 | } |
| 1206 | |
| 1207 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack) |
| 1208 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1209 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1210 | lp::NackReason::NO_ROUTE); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1211 | lp::Packet packet; |
| 1212 | packet.set<lp::FragmentField>(std::make_pair( |
| 1213 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 1214 | packet.set<lp::NackField>(nack.getHeader()); |
| 1215 | packet.set<lp::CongestionMarkField>(1); |
| 1216 | |
| 1217 | transport->receivePacket(packet.wireEncode()); |
| 1218 | |
| 1219 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1220 | auto tag = receivedNacks.back().getTag<lp::CongestionMarkTag>(); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1221 | BOOST_REQUIRE(tag != nullptr); |
| 1222 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1223 | } |
| 1224 | |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1225 | BOOST_AUTO_TEST_CASE(SendNonDiscovery) |
| 1226 | { |
| 1227 | GenericLinkService::Options options; |
| 1228 | options.allowSelfLearning = true; |
| 1229 | initialize(options); |
| 1230 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1231 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1232 | interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{})); |
| 1233 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1234 | face->sendInterest(*interest); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1235 | |
| 1236 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1237 | lp::Packet sent(transport->sentPackets.back()); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1238 | BOOST_CHECK(sent.has<lp::NonDiscoveryField>()); |
| 1239 | } |
| 1240 | |
| 1241 | BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled) |
| 1242 | { |
| 1243 | GenericLinkService::Options options; |
| 1244 | options.allowSelfLearning = false; |
| 1245 | initialize(options); |
| 1246 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1247 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1248 | interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{})); |
| 1249 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1250 | face->sendInterest(*interest); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1251 | |
| 1252 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1253 | lp::Packet sent(transport->sentPackets.back()); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1254 | BOOST_CHECK(!sent.has<lp::NonDiscoveryField>()); |
| 1255 | } |
| 1256 | |
| 1257 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery) |
| 1258 | { |
| 1259 | GenericLinkService::Options options; |
| 1260 | options.allowSelfLearning = true; |
| 1261 | initialize(options); |
| 1262 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1263 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1264 | lp::Packet packet(interest->wireEncode()); |
| 1265 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1266 | |
| 1267 | transport->receivePacket(packet.wireEncode()); |
| 1268 | |
| 1269 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1270 | auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1271 | BOOST_CHECK(tag != nullptr); |
| 1272 | } |
| 1273 | |
| 1274 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled) |
| 1275 | { |
| 1276 | GenericLinkService::Options options; |
| 1277 | options.allowSelfLearning = false; |
| 1278 | initialize(options); |
| 1279 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1280 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1281 | lp::Packet packet(interest->wireEncode()); |
| 1282 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1283 | |
| 1284 | transport->receivePacket(packet.wireEncode()); |
| 1285 | |
| 1286 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
| 1287 | BOOST_CHECK_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1288 | auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1289 | BOOST_CHECK(tag == nullptr); |
| 1290 | } |
| 1291 | |
| 1292 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData) |
| 1293 | { |
| 1294 | GenericLinkService::Options options; |
| 1295 | options.allowSelfLearning = true; |
| 1296 | initialize(options); |
| 1297 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1298 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1299 | lp::Packet packet(data->wireEncode()); |
| 1300 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1301 | |
| 1302 | transport->receivePacket(packet.wireEncode()); |
| 1303 | |
| 1304 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1305 | BOOST_CHECK(receivedData.empty()); |
| 1306 | } |
| 1307 | |
| 1308 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack) |
| 1309 | { |
| 1310 | GenericLinkService::Options options; |
| 1311 | options.allowSelfLearning = true; |
| 1312 | initialize(options); |
| 1313 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1314 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1315 | lp::NackReason::NO_ROUTE); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1316 | lp::Packet packet; |
| 1317 | packet.set<lp::FragmentField>(std::make_pair( |
| 1318 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 1319 | packet.set<lp::NackField>(nack.getHeader()); |
| 1320 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1321 | |
| 1322 | transport->receivePacket(packet.wireEncode()); |
| 1323 | |
| 1324 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1325 | BOOST_CHECK(receivedNacks.empty()); |
| 1326 | } |
| 1327 | |
| 1328 | BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement) |
| 1329 | { |
| 1330 | GenericLinkService::Options options; |
| 1331 | options.allowSelfLearning = true; |
| 1332 | initialize(options); |
| 1333 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1334 | auto data = makeData("/12345678"); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1335 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1336 | data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah)); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1337 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1338 | face->sendData(*data); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1339 | |
| 1340 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1341 | lp::Packet sent(transport->sentPackets.back()); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1342 | BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>()); |
| 1343 | } |
| 1344 | |
| 1345 | BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled) |
| 1346 | { |
| 1347 | GenericLinkService::Options options; |
| 1348 | options.allowSelfLearning = false; |
| 1349 | initialize(options); |
| 1350 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1351 | auto data = makeData("/12345678"); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1352 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1353 | data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah)); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1354 | |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 1355 | face->sendData(*data); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1356 | |
| 1357 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Teng Liang | 13d582a | 2020-07-21 20:23:11 -0700 | [diff] [blame] | 1358 | lp::Packet sent(transport->sentPackets.back()); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1359 | BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>()); |
| 1360 | } |
| 1361 | |
| 1362 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement) |
| 1363 | { |
| 1364 | GenericLinkService::Options options; |
| 1365 | options.allowSelfLearning = true; |
| 1366 | initialize(options); |
| 1367 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1368 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1369 | lp::Packet packet(data->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1370 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1371 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1372 | |
| 1373 | transport->receivePacket(packet.wireEncode()); |
| 1374 | |
| 1375 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1376 | auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>(); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1377 | BOOST_CHECK_EQUAL(tag->get().getPrefixAnn()->getAnnouncedName(), "/local/ndn/prefix"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled) |
| 1381 | { |
| 1382 | GenericLinkService::Options options; |
| 1383 | options.allowSelfLearning = false; |
| 1384 | initialize(options); |
| 1385 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1386 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1387 | lp::Packet packet(data->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1388 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1389 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1390 | |
| 1391 | transport->receivePacket(packet.wireEncode()); |
| 1392 | |
| 1393 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
| 1394 | BOOST_CHECK_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1395 | auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1396 | BOOST_CHECK(tag == nullptr); |
| 1397 | } |
| 1398 | |
| 1399 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest) |
| 1400 | { |
| 1401 | GenericLinkService::Options options; |
| 1402 | options.allowSelfLearning = true; |
| 1403 | initialize(options); |
| 1404 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1405 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1406 | lp::Packet packet(interest->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1407 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1408 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1409 | |
| 1410 | transport->receivePacket(packet.wireEncode()); |
| 1411 | |
| 1412 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1413 | BOOST_CHECK(receivedInterests.empty()); |
| 1414 | } |
| 1415 | |
| 1416 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack) |
| 1417 | { |
| 1418 | GenericLinkService::Options options; |
| 1419 | options.allowSelfLearning = true; |
| 1420 | initialize(options); |
| 1421 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1422 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1423 | lp::NackReason::NO_ROUTE); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1424 | lp::Packet packet; |
| 1425 | packet.set<lp::FragmentField>(std::make_pair( |
| 1426 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 1427 | packet.set<lp::NackField>(nack.getHeader()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1428 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1429 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1430 | |
| 1431 | transport->receivePacket(packet.wireEncode()); |
| 1432 | |
| 1433 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1434 | BOOST_CHECK(receivedNacks.empty()); |
| 1435 | } |
| 1436 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1437 | BOOST_AUTO_TEST_SUITE_END() // LpFields |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1438 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1439 | BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets |
| 1440 | |
| 1441 | BOOST_AUTO_TEST_CASE(WrongTlvType) |
| 1442 | { |
| 1443 | // Initialize with Options that disables all services |
| 1444 | GenericLinkService::Options options; |
| 1445 | options.allowLocalFields = false; |
| 1446 | initialize(options); |
| 1447 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1448 | auto packet = ndn::encoding::makeEmptyBlock(tlv::Name); |
| 1449 | transport->receivePacket(packet); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1450 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1451 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1452 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 1453 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 1454 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 1455 | } |
| 1456 | |
| 1457 | BOOST_AUTO_TEST_CASE(Unparsable) |
| 1458 | { |
| 1459 | // Initialize with Options that disables all services |
| 1460 | GenericLinkService::Options options; |
| 1461 | options.allowLocalFields = false; |
| 1462 | initialize(options); |
| 1463 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1464 | auto packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x"); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1465 | BOOST_CHECK_THROW(packet.parse(), tlv::Error); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1466 | transport->receivePacket(packet); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1467 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1468 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1469 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 1470 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 1471 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 1472 | } |
| 1473 | |
| 1474 | BOOST_AUTO_TEST_SUITE_END() // Malformed |
| 1475 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1476 | BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService |
| 1477 | BOOST_AUTO_TEST_SUITE_END() // Face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1478 | |
| 1479 | } // namespace tests |
| 1480 | } // namespace face |
| 1481 | } // namespace nfd |