Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 1d12d2f | 2019-03-22 12:44:14 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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 | |
| 285 | BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu) |
| 286 | { |
| 287 | // Initialize with Options that enable fragmentation |
| 288 | GenericLinkService::Options options; |
| 289 | options.allowFragmentation = true; |
| 290 | initialize(options); |
| 291 | |
| 292 | transport->setMtu(MTU_UNLIMITED); |
| 293 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 294 | auto data = makeData("/test/data/123456789/987654321/123456789"); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 295 | face->sendData(*data, 0); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 296 | |
| 297 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
| 298 | } |
| 299 | |
| 300 | BOOST_AUTO_TEST_CASE(FragmentationUnderMtu) |
| 301 | { |
| 302 | // Initialize with Options that enable fragmentation |
| 303 | GenericLinkService::Options options; |
| 304 | options.allowFragmentation = true; |
| 305 | initialize(options); |
| 306 | |
| 307 | transport->setMtu(105); |
| 308 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 309 | auto data = makeData("/test/data/123456789/987654321/123456789"); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 310 | face->sendData(*data, 0); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 311 | |
| 312 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
| 313 | } |
| 314 | |
| 315 | BOOST_AUTO_TEST_CASE(FragmentationOverMtu) |
| 316 | { |
| 317 | // Initialize with Options that enable fragmentation |
| 318 | GenericLinkService::Options options; |
| 319 | options.allowFragmentation = true; |
| 320 | initialize(options); |
| 321 | |
| 322 | transport->setMtu(60); |
| 323 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 324 | auto data = makeData("/test/data/123456789/987654321/123456789"); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 325 | face->sendData(*data, 0); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 326 | |
| 327 | BOOST_CHECK_GT(transport->sentPackets.size(), 1); |
| 328 | } |
| 329 | |
| 330 | BOOST_AUTO_TEST_CASE(ReassembleFragments) |
| 331 | { |
| 332 | // Initialize with Options that enables reassembly |
| 333 | GenericLinkService::Options options; |
| 334 | options.allowReassembly = true; |
| 335 | initialize(options); |
| 336 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 337 | auto interest = makeInterest( |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 338 | "/mt7P130BHXmtLm5dwaY5dpUM6SWYNN2B05g7y3UhsQuLvDdnTWdNnTeEiLuW3FAbJRSG3tzQ0UfaSEgG9rvYHmsKtgPMag1Hj4Tr"); |
| 339 | lp::Packet packet(interest->wireEncode()); |
| 340 | |
| 341 | // fragment the packet |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 342 | LpFragmenter fragmenter({}); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 343 | size_t mtu = 100; |
| 344 | bool isOk = false; |
| 345 | std::vector<lp::Packet> frags; |
| 346 | std::tie(isOk, frags) = fragmenter.fragmentPacket(packet, mtu); |
| 347 | BOOST_REQUIRE(isOk); |
| 348 | BOOST_CHECK_GT(frags.size(), 1); |
| 349 | |
| 350 | // receive the fragments |
| 351 | for (ssize_t fragIndex = frags.size() - 1; fragIndex >= 0; --fragIndex) { |
| 352 | size_t sequence = 1000 + fragIndex; |
| 353 | frags[fragIndex].add<lp::SequenceField>(sequence); |
| 354 | |
| 355 | transport->receivePacket(frags[fragIndex].wireEncode()); |
| 356 | |
| 357 | if (fragIndex > 0) { |
| 358 | BOOST_CHECK(receivedInterests.empty()); |
| 359 | BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 1); |
| 360 | } |
| 361 | else { |
| 362 | BOOST_CHECK_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 363 | BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest->wireEncode()); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 364 | BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 0); |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 369 | BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex) |
| 370 | { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 371 | // Initialize with Options that disables reassembly |
| 372 | GenericLinkService::Options options; |
| 373 | options.allowReassembly = false; |
| 374 | initialize(options); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 375 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 376 | auto interest = makeInterest("/IgFe6NvH"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 377 | lp::Packet packet(interest->wireEncode()); |
| 378 | packet.set<lp::FragIndexField>(140); |
| 379 | |
| 380 | transport->receivePacket(packet.wireEncode()); |
| 381 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 382 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 383 | BOOST_CHECK(receivedInterests.empty()); |
| 384 | } |
| 385 | |
| 386 | BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount) |
| 387 | { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 388 | // Initialize with Options that disables reassembly |
| 389 | GenericLinkService::Options options; |
| 390 | options.allowReassembly = false; |
| 391 | initialize(options); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 392 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 393 | auto interest = makeInterest("/SeGmEjvIVX"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 394 | lp::Packet packet(interest->wireEncode()); |
| 395 | packet.set<lp::FragCountField>(276); |
| 396 | |
| 397 | transport->receivePacket(packet.wireEncode()); |
| 398 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 399 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 400 | BOOST_CHECK(receivedInterests.empty()); |
| 401 | } |
| 402 | |
| 403 | BOOST_AUTO_TEST_SUITE_END() // Fragmentation |
| 404 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 405 | BOOST_AUTO_TEST_SUITE(Reliability) |
| 406 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 407 | BOOST_AUTO_TEST_CASE(SendInterest) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 408 | { |
| 409 | // Initialize with Options that enables reliability |
| 410 | GenericLinkService::Options options; |
| 411 | options.allowLocalFields = false; |
| 412 | options.reliabilityOptions.isEnabled = true; |
| 413 | initialize(options); |
| 414 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 415 | auto interest1 = makeInterest("/localhost/test"); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 416 | face->sendInterest(*interest1, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 417 | |
| 418 | BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1); |
| 419 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 420 | lp::Packet interest1pkt(transport->sentPackets.back().packet); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 421 | BOOST_CHECK(interest1pkt.has<lp::FragmentField>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 422 | BOOST_CHECK(interest1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 425 | BOOST_AUTO_TEST_CASE(SendData) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 426 | { |
| 427 | // Initialize with Options that enables reliability |
| 428 | GenericLinkService::Options options; |
| 429 | options.allowLocalFields = false; |
| 430 | options.reliabilityOptions.isEnabled = true; |
| 431 | initialize(options); |
| 432 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 433 | auto data1 = makeData("/localhost/test"); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 434 | face->sendData(*data1, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 435 | |
| 436 | BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1); |
| 437 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 438 | lp::Packet data1pkt(transport->sentPackets.back().packet); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 439 | BOOST_CHECK(data1pkt.has<lp::FragmentField>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 440 | BOOST_CHECK(data1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 443 | BOOST_AUTO_TEST_CASE(SendNack) |
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 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 451 | auto nack1 = makeNack(*makeInterest("/localhost/test", false, nullopt, 323), |
| 452 | lp::NackReason::NO_ROUTE); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 453 | face->sendNack(nack1, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 454 | |
| 455 | BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1); |
| 456 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 457 | lp::Packet nack1pkt(transport->sentPackets.back().packet); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 458 | BOOST_CHECK(nack1pkt.has<lp::NackField>()); |
| 459 | BOOST_CHECK(nack1pkt.has<lp::FragmentField>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 460 | BOOST_CHECK(nack1pkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | BOOST_AUTO_TEST_SUITE_END() // Reliability |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 464 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 465 | // congestion detection and marking |
| 466 | BOOST_AUTO_TEST_SUITE(CongestionMark) |
| 467 | |
| 468 | BOOST_AUTO_TEST_CASE(NoCongestion) |
| 469 | { |
| 470 | GenericLinkService::Options options; |
| 471 | options.allowCongestionMarking = true; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 472 | options.baseCongestionMarkingInterval = 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 473 | initialize(options, MTU_UNLIMITED, 65536); |
| 474 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 475 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 476 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 477 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 478 | auto interest = makeInterest("/12345678"); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 479 | |
| 480 | // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes |
| 481 | |
| 482 | // no congestion |
| 483 | transport->setSendQueueLength(0); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 484 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 485 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 486 | lp::Packet pkt1(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 487 | BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0); |
| 488 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 489 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 490 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 491 | |
| 492 | // no congestion |
| 493 | transport->setSendQueueLength(32768); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 494 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 495 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 496 | lp::Packet pkt2(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 497 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
| 498 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 499 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 500 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 501 | } |
| 502 | |
| 503 | BOOST_AUTO_TEST_CASE(CongestionCoDel) |
| 504 | { |
| 505 | GenericLinkService::Options options; |
| 506 | options.allowCongestionMarking = true; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 507 | options.baseCongestionMarkingInterval = 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 508 | initialize(options, MTU_UNLIMITED, 65536); |
| 509 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 510 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 511 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 512 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 513 | auto interest = makeInterest("/12345678"); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 514 | |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 515 | // first congested packet, will not be marked |
| 516 | transport->setSendQueueLength(65537); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 517 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 518 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 519 | lp::Packet pkt0(transport->sentPackets.back().packet); |
| 520 | BOOST_REQUIRE_EQUAL(pkt0.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 521 | time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 522 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 523 | |
| 524 | time::nanoseconds markingInterval( |
| 525 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 526 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 527 | |
| 528 | advanceClocks(markingInterval + 1_ms); |
| 529 | face->sendInterest(*interest, 0); |
| 530 | lp::Packet pkt1(transport->sentPackets.back().packet); |
| 531 | |
| 532 | // First congestion mark appears after one interval (100 ms) |
| 533 | BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1); |
| 534 | BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 535 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 536 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 537 | |
| 538 | // advance clock to half of marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 539 | advanceClocks(markingInterval / 2); // 50ms |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 540 | |
| 541 | // second congested packet, but within marking interval, will not be marked |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 542 | transport->setSendQueueLength(66000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 543 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 544 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 545 | lp::Packet pkt2(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 546 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 547 | |
| 548 | markingInterval = time::nanoseconds( |
| 549 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 550 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 551 | nextMarkTime += markingInterval; |
| 552 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 553 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 554 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 555 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 556 | |
| 557 | // advance clocks past end of initial interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 558 | this->advanceClocks((markingInterval / 2) + 1_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 559 | |
| 560 | // first congested packet after waiting marking interval, will be marked |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 561 | transport->setSendQueueLength(66000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 562 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 563 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 564 | lp::Packet pkt3(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 565 | BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1); |
| 566 | BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 567 | markingInterval = time::nanoseconds( |
| 568 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 569 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 570 | nextMarkTime += markingInterval; |
| 571 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 572 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 573 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2); |
| 574 | |
| 575 | // advance clock partway through current marking interval |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 576 | this->advanceClocks(markingInterval - 20_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 577 | |
| 578 | // still congested, but within marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 579 | transport->setSendQueueLength(66000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 580 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 581 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 582 | lp::Packet pkt4(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 583 | BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0); |
| 584 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 585 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 586 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2); |
| 587 | |
| 588 | // advance clocks past end of current marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 589 | this->advanceClocks(21_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 590 | |
| 591 | // still congested, after marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 592 | transport->setSendQueueLength(66000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 593 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 594 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 595 | lp::Packet pkt5(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 596 | BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1); |
| 597 | BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1); |
| 598 | markingInterval = time::nanoseconds( |
| 599 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 600 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 601 | nextMarkTime += markingInterval; |
| 602 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 603 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3); |
| 604 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3); |
| 605 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 606 | this->advanceClocks(1_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 607 | |
| 608 | // still congested, but within marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 609 | transport->setSendQueueLength(66000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 610 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 611 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 612 | lp::Packet pkt6(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 613 | BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0); |
| 614 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 615 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3); |
| 616 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3); |
| 617 | |
| 618 | this->advanceClocks(markingInterval); |
| 619 | |
| 620 | // still congested, after marking interval cycle |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 621 | transport->setSendQueueLength(66000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 622 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 623 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 624 | lp::Packet pkt7(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 625 | BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1); |
| 626 | BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1); |
| 627 | markingInterval = time::nanoseconds( |
| 628 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 629 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 630 | nextMarkTime += markingInterval; |
| 631 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 632 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4); |
| 633 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 634 | |
| 635 | // no more congestion |
| 636 | transport->setSendQueueLength(30000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 637 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 638 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 639 | lp::Packet pkt8(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 640 | BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0); |
| 641 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 642 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 643 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 644 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 645 | this->advanceClocks(50_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 646 | |
| 647 | // 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^] | 648 | transport->setSendQueueLength(66000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 649 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 650 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 651 | lp::Packet pkt9(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 652 | BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 653 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 654 | markingInterval = time::nanoseconds( |
| 655 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 656 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 657 | nextMarkTime = time::steady_clock::now() + markingInterval; |
| 658 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 659 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 660 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 661 | |
| 662 | // advance clock past full 100ms interval since last mark |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 663 | this->advanceClocks(markingInterval + 2_ms); |
| 664 | BOOST_CHECK_GT(time::steady_clock::now(), nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 665 | |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 666 | transport->setSendQueueLength(66000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 667 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 668 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 669 | lp::Packet pkt10(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 670 | BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1); |
| 671 | BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 672 | markingInterval = time::nanoseconds( |
| 673 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 674 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
| 675 | nextMarkTime += markingInterval; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 676 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 677 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 678 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5); |
| 679 | |
| 680 | // advance clock partway through 100ms marking interval |
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 | // not marked since within 100ms window before can mark again |
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(), 12); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 687 | lp::Packet pkt11(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 688 | BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0); |
| 689 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 690 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 691 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5); |
| 692 | |
| 693 | // advance clocks past m_nextMarkTime |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 694 | this->advanceClocks(51_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 695 | |
| 696 | // markable packet, queue length still above threshold |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 697 | transport->setSendQueueLength(66000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 698 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 699 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 700 | lp::Packet pkt12(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 701 | BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1); |
| 702 | BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1); |
| 703 | markingInterval = time::nanoseconds( |
| 704 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 705 | std::sqrt(service->m_nMarkedSinceInMarkingState + 1))); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 706 | nextMarkTime += markingInterval; |
| 707 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 708 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 709 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
| 710 | |
| 711 | // no more congestion |
| 712 | transport->setSendQueueLength(10000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 713 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 714 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 715 | lp::Packet pkt13(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 716 | BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0); |
| 717 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 718 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 719 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
| 720 | |
| 721 | // advance clocks past one full interval since last mark |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 722 | this->advanceClocks(102_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 723 | |
| 724 | // start congestion again |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 725 | transport->setSendQueueLength(66000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 726 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 727 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 728 | lp::Packet pkt14(transport->sentPackets.back().packet); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 729 | BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 730 | nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 731 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 732 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 733 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 734 | |
| 735 | // no more congestion, cancel marking interval |
| 736 | transport->setSendQueueLength(5000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 737 | face->sendInterest(*interest, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 738 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 739 | lp::Packet pkt15(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 740 | BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0); |
| 741 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 742 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 743 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | BOOST_AUTO_TEST_CASE(DefaultThreshold) |
| 747 | { |
| 748 | GenericLinkService::Options options; |
| 749 | options.allowCongestionMarking = true; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 750 | options.baseCongestionMarkingInterval = 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 751 | initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED); |
| 752 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 753 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 754 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 755 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 756 | auto interest = makeInterest("/12345678"); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 757 | |
| 758 | // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure |
| 759 | // the queue capacity |
| 760 | |
| 761 | // no congestion |
| 762 | transport->setSendQueueLength(0); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 763 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 764 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 765 | lp::Packet pkt1(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 766 | BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0); |
| 767 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 768 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 769 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 770 | |
| 771 | // no congestion |
| 772 | transport->setSendQueueLength(65536); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 773 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 774 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 775 | lp::Packet pkt2(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 776 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
| 777 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 778 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 779 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 780 | |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 781 | // first congested (not marked yet) packet |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 782 | transport->setSendQueueLength(65537); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 783 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 784 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 785 | lp::Packet pkt3(transport->sentPackets.back().packet); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 786 | BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 0); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 787 | time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 788 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
Klaus Schneider | 380668b | 2019-10-02 01:21:13 -0700 | [diff] [blame^] | 789 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 790 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | BOOST_AUTO_TEST_SUITE_END() // CongestionMark |
| 794 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 795 | BOOST_AUTO_TEST_SUITE(LpFields) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 796 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 797 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId) |
| 798 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 799 | // Initialize with Options that enables local fields |
| 800 | GenericLinkService::Options options; |
| 801 | options.allowLocalFields = true; |
| 802 | initialize(options); |
| 803 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 804 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 805 | lp::Packet packet(interest->wireEncode()); |
| 806 | packet.set<lp::NextHopFaceIdField>(1000); |
| 807 | |
| 808 | transport->receivePacket(packet.wireEncode()); |
| 809 | |
| 810 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 811 | auto tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>(); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 812 | BOOST_REQUIRE(tag != nullptr); |
| 813 | BOOST_CHECK_EQUAL(*tag, 1000); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled) |
| 817 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 818 | // Initialize with Options that disables local fields |
| 819 | GenericLinkService::Options options; |
| 820 | options.allowLocalFields = false; |
| 821 | initialize(options); |
| 822 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 823 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 824 | lp::Packet packet(interest->wireEncode()); |
| 825 | packet.set<lp::NextHopFaceIdField>(1000); |
| 826 | |
| 827 | transport->receivePacket(packet.wireEncode()); |
| 828 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 829 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 830 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData) |
| 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 data = makeData("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 841 | lp::Packet packet(data->wireEncode()); |
| 842 | packet.set<lp::NextHopFaceIdField>(1000); |
| 843 | |
| 844 | transport->receivePacket(packet.wireEncode()); |
| 845 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 846 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 847 | BOOST_CHECK(receivedData.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack) |
| 851 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 852 | // Initialize with Options that enables local fields |
| 853 | GenericLinkService::Options options; |
| 854 | options.allowLocalFields = true; |
| 855 | initialize(options); |
| 856 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 857 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 858 | lp::NackReason::NO_ROUTE); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 859 | lp::Packet packet; |
| 860 | packet.set<lp::FragmentField>(std::make_pair( |
| 861 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 862 | packet.set<lp::NackField>(nack.getHeader()); |
| 863 | packet.set<lp::NextHopFaceIdField>(1000); |
| 864 | |
| 865 | transport->receivePacket(packet.wireEncode()); |
| 866 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 867 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 868 | BOOST_CHECK(receivedNacks.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 871 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicy) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 872 | { |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 873 | // Initialize with Options that disables local fields |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 874 | GenericLinkService::Options options; |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 875 | options.allowLocalFields = false; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 876 | initialize(options); |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 877 | // CachePolicy is unprivileged and does not require allowLocalFields option. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 878 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 879 | auto data = makeData("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 880 | lp::Packet packet(data->wireEncode()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 881 | packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 882 | |
| 883 | transport->receivePacket(packet.wireEncode()); |
| 884 | |
| 885 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 886 | auto tag = receivedData.back().getTag<lp::CachePolicyTag>(); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 887 | BOOST_REQUIRE(tag != nullptr); |
| 888 | BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 889 | } |
| 890 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 891 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 892 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 893 | // Initialize with Options that enables local fields |
| 894 | GenericLinkService::Options options; |
| 895 | options.allowLocalFields = true; |
| 896 | initialize(options); |
| 897 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 898 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 899 | lp::Packet packet(interest->wireEncode()); |
| 900 | lp::CachePolicy policy; |
| 901 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 902 | packet.set<lp::CachePolicyField>(policy); |
| 903 | |
| 904 | transport->receivePacket(packet.wireEncode()); |
| 905 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 906 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 907 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 910 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 911 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 912 | // Initialize with Options that enables local fields |
| 913 | GenericLinkService::Options options; |
| 914 | options.allowLocalFields = true; |
| 915 | initialize(options); |
| 916 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 917 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 918 | lp::NackReason::NO_ROUTE); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 919 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 920 | packet.set<lp::NackField>(nack.getHeader()); |
| 921 | lp::CachePolicy policy; |
| 922 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 923 | packet.set<lp::CachePolicyField>(policy); |
| 924 | |
| 925 | transport->receivePacket(packet.wireEncode()); |
| 926 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 927 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 928 | BOOST_CHECK(receivedNacks.empty()); |
| 929 | } |
| 930 | |
| 931 | BOOST_AUTO_TEST_CASE(SendIncomingFaceId) |
| 932 | { |
| 933 | // Initialize with Options that enables local fields |
| 934 | GenericLinkService::Options options; |
| 935 | options.allowLocalFields = true; |
| 936 | initialize(options); |
| 937 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 938 | auto interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 939 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 940 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 941 | face->sendInterest(*interest, 0); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 942 | |
| 943 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 944 | lp::Packet sent(transport->sentPackets.back().packet); |
| 945 | BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>()); |
| 946 | BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000); |
| 947 | } |
| 948 | |
| 949 | BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled) |
| 950 | { |
| 951 | // Initialize with Options that disables local fields |
| 952 | GenericLinkService::Options options; |
| 953 | options.allowLocalFields = false; |
| 954 | initialize(options); |
| 955 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 956 | auto interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 957 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 958 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 959 | face->sendInterest(*interest, 0); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 960 | |
| 961 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 962 | lp::Packet sent(transport->sentPackets.back().packet); |
| 963 | BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>()); |
| 964 | } |
| 965 | |
| 966 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest) |
| 967 | { |
| 968 | // Initialize with Options that enables local fields |
| 969 | GenericLinkService::Options options; |
| 970 | options.allowLocalFields = true; |
| 971 | initialize(options); |
| 972 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 973 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 974 | lp::Packet packet(interest->wireEncode()); |
| 975 | packet.set<lp::IncomingFaceIdField>(1000); |
| 976 | |
| 977 | transport->receivePacket(packet.wireEncode()); |
| 978 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 979 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 980 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 981 | BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData) |
| 985 | { |
| 986 | // Initialize with Options that enables local fields |
| 987 | GenericLinkService::Options options; |
| 988 | options.allowLocalFields = true; |
| 989 | initialize(options); |
| 990 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 991 | auto data = makeData("/z1megUh9Bj"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 992 | lp::Packet packet(data->wireEncode()); |
| 993 | packet.set<lp::IncomingFaceIdField>(1000); |
| 994 | |
| 995 | transport->receivePacket(packet.wireEncode()); |
| 996 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 997 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 998 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 999 | BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack) |
| 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 | lp::Nack nack = makeNack(*makeInterest("/TPAhdiHz", false, nullopt, 278), |
| 1010 | lp::NackReason::CONGESTION); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1011 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 1012 | packet.set<lp::NackField>(nack.getHeader()); |
| 1013 | packet.set<lp::IncomingFaceIdField>(1000); |
| 1014 | |
| 1015 | transport->receivePacket(packet.wireEncode()); |
| 1016 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1017 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1018 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1019 | BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1022 | BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest) |
| 1023 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1024 | auto interest = makeInterest("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1025 | interest->setTag(make_shared<lp::CongestionMarkTag>(1)); |
| 1026 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1027 | face->sendInterest(*interest, 0); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1028 | |
| 1029 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1030 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1031 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1032 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1); |
| 1033 | } |
| 1034 | |
| 1035 | BOOST_AUTO_TEST_CASE(SendCongestionMarkData) |
| 1036 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1037 | auto data = makeData("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1038 | data->setTag(make_shared<lp::CongestionMarkTag>(0)); |
| 1039 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1040 | face->sendData(*data, 0); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1041 | |
| 1042 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1043 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1044 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1045 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0); |
| 1046 | } |
| 1047 | |
| 1048 | BOOST_AUTO_TEST_CASE(SendCongestionMarkNack) |
| 1049 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1050 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1051 | lp::NackReason::NO_ROUTE); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1052 | nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max())); |
| 1053 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1054 | face->sendNack(nack, 0); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1055 | |
| 1056 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1057 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1058 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1059 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max()); |
| 1060 | } |
| 1061 | |
| 1062 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest) |
| 1063 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1064 | auto interest = makeInterest("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1065 | lp::Packet packet(interest->wireEncode()); |
| 1066 | packet.set<lp::CongestionMarkField>(1); |
| 1067 | |
| 1068 | transport->receivePacket(packet.wireEncode()); |
| 1069 | |
| 1070 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1071 | auto tag = receivedInterests.back().getTag<lp::CongestionMarkTag>(); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1072 | BOOST_REQUIRE(tag != nullptr); |
| 1073 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1074 | } |
| 1075 | |
| 1076 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData) |
| 1077 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1078 | auto data = makeData("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1079 | lp::Packet packet(data->wireEncode()); |
| 1080 | packet.set<lp::CongestionMarkField>(1); |
| 1081 | |
| 1082 | transport->receivePacket(packet.wireEncode()); |
| 1083 | |
| 1084 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1085 | auto tag = receivedData.back().getTag<lp::CongestionMarkTag>(); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1086 | BOOST_REQUIRE(tag != nullptr); |
| 1087 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1088 | } |
| 1089 | |
| 1090 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack) |
| 1091 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1092 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1093 | lp::NackReason::NO_ROUTE); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1094 | lp::Packet packet; |
| 1095 | packet.set<lp::FragmentField>(std::make_pair( |
| 1096 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 1097 | packet.set<lp::NackField>(nack.getHeader()); |
| 1098 | packet.set<lp::CongestionMarkField>(1); |
| 1099 | |
| 1100 | transport->receivePacket(packet.wireEncode()); |
| 1101 | |
| 1102 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1103 | auto tag = receivedNacks.back().getTag<lp::CongestionMarkTag>(); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1104 | BOOST_REQUIRE(tag != nullptr); |
| 1105 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1106 | } |
| 1107 | |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1108 | BOOST_AUTO_TEST_CASE(SendNonDiscovery) |
| 1109 | { |
| 1110 | GenericLinkService::Options options; |
| 1111 | options.allowSelfLearning = true; |
| 1112 | initialize(options); |
| 1113 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1114 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1115 | interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{})); |
| 1116 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1117 | face->sendInterest(*interest, 0); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1118 | |
| 1119 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1120 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1121 | BOOST_CHECK(sent.has<lp::NonDiscoveryField>()); |
| 1122 | } |
| 1123 | |
| 1124 | BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled) |
| 1125 | { |
| 1126 | GenericLinkService::Options options; |
| 1127 | options.allowSelfLearning = false; |
| 1128 | initialize(options); |
| 1129 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1130 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1131 | interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{})); |
| 1132 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1133 | face->sendInterest(*interest, 0); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1134 | |
| 1135 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1136 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1137 | BOOST_CHECK(!sent.has<lp::NonDiscoveryField>()); |
| 1138 | } |
| 1139 | |
| 1140 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery) |
| 1141 | { |
| 1142 | GenericLinkService::Options options; |
| 1143 | options.allowSelfLearning = true; |
| 1144 | initialize(options); |
| 1145 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1146 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1147 | lp::Packet packet(interest->wireEncode()); |
| 1148 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1149 | |
| 1150 | transport->receivePacket(packet.wireEncode()); |
| 1151 | |
| 1152 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1153 | auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1154 | BOOST_CHECK(tag != nullptr); |
| 1155 | } |
| 1156 | |
| 1157 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled) |
| 1158 | { |
| 1159 | GenericLinkService::Options options; |
| 1160 | options.allowSelfLearning = false; |
| 1161 | initialize(options); |
| 1162 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1163 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1164 | lp::Packet packet(interest->wireEncode()); |
| 1165 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1166 | |
| 1167 | transport->receivePacket(packet.wireEncode()); |
| 1168 | |
| 1169 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
| 1170 | BOOST_CHECK_EQUAL(receivedInterests.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1171 | auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1172 | BOOST_CHECK(tag == nullptr); |
| 1173 | } |
| 1174 | |
| 1175 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData) |
| 1176 | { |
| 1177 | GenericLinkService::Options options; |
| 1178 | options.allowSelfLearning = true; |
| 1179 | initialize(options); |
| 1180 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1181 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1182 | lp::Packet packet(data->wireEncode()); |
| 1183 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1184 | |
| 1185 | transport->receivePacket(packet.wireEncode()); |
| 1186 | |
| 1187 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1188 | BOOST_CHECK(receivedData.empty()); |
| 1189 | } |
| 1190 | |
| 1191 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack) |
| 1192 | { |
| 1193 | GenericLinkService::Options options; |
| 1194 | options.allowSelfLearning = true; |
| 1195 | initialize(options); |
| 1196 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1197 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1198 | lp::NackReason::NO_ROUTE); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1199 | lp::Packet packet; |
| 1200 | packet.set<lp::FragmentField>(std::make_pair( |
| 1201 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 1202 | packet.set<lp::NackField>(nack.getHeader()); |
| 1203 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1204 | |
| 1205 | transport->receivePacket(packet.wireEncode()); |
| 1206 | |
| 1207 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1208 | BOOST_CHECK(receivedNacks.empty()); |
| 1209 | } |
| 1210 | |
| 1211 | BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement) |
| 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 | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1218 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1219 | data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah)); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1220 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1221 | face->sendData(*data, 0); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1222 | |
| 1223 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1224 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1225 | BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>()); |
| 1226 | } |
| 1227 | |
| 1228 | BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled) |
| 1229 | { |
| 1230 | GenericLinkService::Options options; |
| 1231 | options.allowSelfLearning = false; |
| 1232 | initialize(options); |
| 1233 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1234 | auto data = makeData("/12345678"); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1235 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1236 | data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah)); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1237 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1238 | face->sendData(*data, 0); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1239 | |
| 1240 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1241 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1242 | BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>()); |
| 1243 | } |
| 1244 | |
| 1245 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement) |
| 1246 | { |
| 1247 | GenericLinkService::Options options; |
| 1248 | options.allowSelfLearning = true; |
| 1249 | initialize(options); |
| 1250 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1251 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1252 | lp::Packet packet(data->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1253 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1254 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1255 | |
| 1256 | transport->receivePacket(packet.wireEncode()); |
| 1257 | |
| 1258 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1259 | auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>(); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1260 | BOOST_CHECK_EQUAL(tag->get().getPrefixAnn()->getAnnouncedName(), "/local/ndn/prefix"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled) |
| 1264 | { |
| 1265 | GenericLinkService::Options options; |
| 1266 | options.allowSelfLearning = false; |
| 1267 | initialize(options); |
| 1268 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1269 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1270 | lp::Packet packet(data->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1271 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1272 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1273 | |
| 1274 | transport->receivePacket(packet.wireEncode()); |
| 1275 | |
| 1276 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
| 1277 | BOOST_CHECK_EQUAL(receivedData.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 1278 | auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1279 | BOOST_CHECK(tag == nullptr); |
| 1280 | } |
| 1281 | |
| 1282 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest) |
| 1283 | { |
| 1284 | GenericLinkService::Options options; |
| 1285 | options.allowSelfLearning = true; |
| 1286 | initialize(options); |
| 1287 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1288 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1289 | lp::Packet packet(interest->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1290 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1291 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1292 | |
| 1293 | transport->receivePacket(packet.wireEncode()); |
| 1294 | |
| 1295 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1296 | BOOST_CHECK(receivedInterests.empty()); |
| 1297 | } |
| 1298 | |
| 1299 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack) |
| 1300 | { |
| 1301 | GenericLinkService::Options options; |
| 1302 | options.allowSelfLearning = true; |
| 1303 | initialize(options); |
| 1304 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1305 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1306 | lp::NackReason::NO_ROUTE); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1307 | lp::Packet packet; |
| 1308 | packet.set<lp::FragmentField>(std::make_pair( |
| 1309 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 1310 | packet.set<lp::NackField>(nack.getHeader()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1311 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1312 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1313 | |
| 1314 | transport->receivePacket(packet.wireEncode()); |
| 1315 | |
| 1316 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1317 | BOOST_CHECK(receivedNacks.empty()); |
| 1318 | } |
| 1319 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1320 | BOOST_AUTO_TEST_SUITE_END() // LpFields |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1321 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1322 | BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets |
| 1323 | |
| 1324 | BOOST_AUTO_TEST_CASE(WrongTlvType) |
| 1325 | { |
| 1326 | // Initialize with Options that disables all services |
| 1327 | GenericLinkService::Options options; |
| 1328 | options.allowLocalFields = false; |
| 1329 | initialize(options); |
| 1330 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1331 | auto packet = ndn::encoding::makeEmptyBlock(tlv::Name); |
| 1332 | transport->receivePacket(packet); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1333 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1334 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1335 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 1336 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 1337 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 1338 | } |
| 1339 | |
| 1340 | BOOST_AUTO_TEST_CASE(Unparsable) |
| 1341 | { |
| 1342 | // Initialize with Options that disables all services |
| 1343 | GenericLinkService::Options options; |
| 1344 | options.allowLocalFields = false; |
| 1345 | initialize(options); |
| 1346 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1347 | auto packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x"); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1348 | BOOST_CHECK_THROW(packet.parse(), tlv::Error); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1349 | transport->receivePacket(packet); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1350 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1351 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1352 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 1353 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 1354 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 1355 | } |
| 1356 | |
| 1357 | BOOST_AUTO_TEST_SUITE_END() // Malformed |
| 1358 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1359 | BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService |
| 1360 | BOOST_AUTO_TEST_SUITE_END() // Face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1361 | |
| 1362 | } // namespace tests |
| 1363 | } // namespace face |
| 1364 | } // namespace nfd |