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