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); |
| 166 | BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1); |
| 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); |
| 186 | BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1); |
| 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); |
| 201 | BOOST_CHECK_EQUAL(receivedData.back(), *data1); |
| 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); |
| 221 | BOOST_CHECK_EQUAL(receivedData.back(), *data1); |
| 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); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 242 | BOOST_CHECK(receivedNacks.back().getReason() == nack1.getReason()); |
| 243 | BOOST_CHECK(receivedNacks.back().getInterest() == nack1.getInterest()); |
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); |
| 363 | BOOST_CHECK_EQUAL(receivedInterests.back(), *interest); |
| 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()); |
| 510 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, time::steady_clock::TimePoint::min()); |
| 511 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 512 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0); |
| 513 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 514 | auto interest = makeInterest("/12345678"); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 515 | |
| 516 | // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes |
| 517 | |
| 518 | // first congested packet, will be marked |
| 519 | transport->setSendQueueLength(32769); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 520 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 521 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 522 | lp::Packet pkt1(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 523 | BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1); |
| 524 | BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 525 | time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 526 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 527 | time::steady_clock::TimePoint lastMarkTime = time::steady_clock::now(); |
| 528 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 529 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 530 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 531 | |
| 532 | // advance clock to half of marking interval cycle |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 533 | advanceClocks(50_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 534 | |
| 535 | // second congested packet, but within marking interval, will not be marked |
| 536 | transport->setSendQueueLength(33000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 537 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 538 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 539 | lp::Packet pkt2(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 540 | BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0); |
| 541 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 542 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 543 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 544 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 545 | |
| 546 | // advance clocks past end of initial interval cycle |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 547 | this->advanceClocks(51_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 548 | |
| 549 | // first congested packet after waiting marking interval, will be marked |
| 550 | transport->setSendQueueLength(40000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 551 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 552 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 553 | lp::Packet pkt3(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 554 | BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1); |
| 555 | BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1); |
| 556 | time::nanoseconds markingInterval( |
| 557 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 558 | std::sqrt(service->m_nMarkedSinceInMarkingState))); |
| 559 | nextMarkTime += markingInterval; |
| 560 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 561 | lastMarkTime = time::steady_clock::now(); |
| 562 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 563 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 564 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2); |
| 565 | |
| 566 | // advance clock partway through current marking interval |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 567 | this->advanceClocks(markingInterval - 10_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 568 | |
| 569 | // still congested, but within marking interval cycle |
| 570 | transport->setSendQueueLength(38000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 571 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 572 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 573 | lp::Packet pkt4(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 574 | BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0); |
| 575 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 576 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 577 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 578 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2); |
| 579 | |
| 580 | // advance clocks past end of current marking interval cycle |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 581 | this->advanceClocks(11_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 582 | |
| 583 | // still congested, after marking interval cycle |
| 584 | transport->setSendQueueLength(39000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 585 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 586 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 587 | lp::Packet pkt5(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 588 | BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1); |
| 589 | BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1); |
| 590 | markingInterval = time::nanoseconds( |
| 591 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 592 | std::sqrt(service->m_nMarkedSinceInMarkingState))); |
| 593 | nextMarkTime += markingInterval; |
| 594 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 595 | lastMarkTime = time::steady_clock::now(); |
| 596 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 597 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3); |
| 598 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3); |
| 599 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 600 | this->advanceClocks(1_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 601 | |
| 602 | // still congested, but within marking interval cycle |
| 603 | transport->setSendQueueLength(38000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 604 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 605 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 606 | lp::Packet pkt6(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 607 | BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0); |
| 608 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 609 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 610 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3); |
| 611 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3); |
| 612 | |
| 613 | this->advanceClocks(markingInterval); |
| 614 | |
| 615 | // still congested, after marking interval cycle |
| 616 | transport->setSendQueueLength(34000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 617 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 618 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 619 | lp::Packet pkt7(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 620 | BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1); |
| 621 | BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1); |
| 622 | markingInterval = time::nanoseconds( |
| 623 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 624 | std::sqrt(service->m_nMarkedSinceInMarkingState))); |
| 625 | nextMarkTime += markingInterval; |
| 626 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 627 | lastMarkTime = time::steady_clock::now(); |
| 628 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 629 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4); |
| 630 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 631 | |
| 632 | // no more congestion |
| 633 | transport->setSendQueueLength(30000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 634 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 635 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 636 | lp::Packet pkt8(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 637 | BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0); |
| 638 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 639 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 640 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 641 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 642 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 643 | this->advanceClocks(50_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 644 | |
| 645 | // send queue congested again, but can't mark packet because within one full interval of last mark |
| 646 | transport->setSendQueueLength(50000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 647 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 648 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 649 | lp::Packet pkt9(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 650 | BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0); |
| 651 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 652 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 653 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 654 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4); |
| 655 | |
| 656 | // advance clock past full 100ms interval since last mark |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 657 | this->advanceClocks(51_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 658 | |
| 659 | transport->setSendQueueLength(40000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 660 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 661 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 662 | lp::Packet pkt10(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 663 | BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1); |
| 664 | BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 665 | nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 666 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 667 | lastMarkTime = time::steady_clock::now(); |
| 668 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 669 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 670 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5); |
| 671 | |
| 672 | // advance clock partway through 100ms marking interval |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 673 | this->advanceClocks(50_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 674 | |
| 675 | // not marked since within 100ms window before can mark again |
| 676 | transport->setSendQueueLength(50000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 677 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 678 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 679 | lp::Packet pkt11(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 680 | BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0); |
| 681 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 682 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 683 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 684 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5); |
| 685 | |
| 686 | // advance clocks past m_nextMarkTime |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 687 | this->advanceClocks(51_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 688 | |
| 689 | // markable packet, queue length still above threshold |
| 690 | transport->setSendQueueLength(33000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 691 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 692 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 693 | lp::Packet pkt12(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 694 | BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1); |
| 695 | BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1); |
| 696 | markingInterval = time::nanoseconds( |
| 697 | static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() / |
| 698 | std::sqrt(service->m_nMarkedSinceInMarkingState))); |
| 699 | nextMarkTime += markingInterval; |
| 700 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 701 | lastMarkTime = time::steady_clock::now(); |
| 702 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 703 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2); |
| 704 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
| 705 | |
| 706 | // no more congestion |
| 707 | transport->setSendQueueLength(10000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 708 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 709 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 710 | lp::Packet pkt13(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 711 | BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0); |
| 712 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 713 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 714 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 715 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6); |
| 716 | |
| 717 | // advance clocks past one full interval since last mark |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 718 | this->advanceClocks(101_ms); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 719 | |
| 720 | // start congestion again |
| 721 | transport->setSendQueueLength(50000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 722 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 723 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 724 | lp::Packet pkt14(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 725 | BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 1); |
| 726 | BOOST_CHECK_EQUAL(pkt14.get<lp::CongestionMarkField>(), 1); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 727 | nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 728 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 729 | lastMarkTime = time::steady_clock::now(); |
| 730 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 731 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 732 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 7); |
| 733 | |
| 734 | // no more congestion, cancel marking interval |
| 735 | transport->setSendQueueLength(5000); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 736 | face->sendInterest(*interest, 0); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 737 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 738 | lp::Packet pkt15(transport->sentPackets.back().packet); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 739 | BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0); |
| 740 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max()); |
| 741 | BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime); |
| 742 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0); |
| 743 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 7); |
| 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 | |
| 781 | // first congested (and marked) packet |
| 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); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 786 | BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1); |
| 787 | BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 788 | time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 789 | BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime); |
| 790 | BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1); |
| 791 | BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1); |
| 792 | } |
| 793 | |
| 794 | BOOST_AUTO_TEST_SUITE_END() // CongestionMark |
| 795 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 796 | BOOST_AUTO_TEST_SUITE(LpFields) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 797 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 798 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId) |
| 799 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 800 | // Initialize with Options that enables local fields |
| 801 | GenericLinkService::Options options; |
| 802 | options.allowLocalFields = true; |
| 803 | initialize(options); |
| 804 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 805 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 806 | lp::Packet packet(interest->wireEncode()); |
| 807 | packet.set<lp::NextHopFaceIdField>(1000); |
| 808 | |
| 809 | transport->receivePacket(packet.wireEncode()); |
| 810 | |
| 811 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 812 | shared_ptr<lp::NextHopFaceIdTag> tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>(); |
| 813 | BOOST_REQUIRE(tag != nullptr); |
| 814 | BOOST_CHECK_EQUAL(*tag, 1000); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled) |
| 818 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 819 | // Initialize with Options that disables local fields |
| 820 | GenericLinkService::Options options; |
| 821 | options.allowLocalFields = false; |
| 822 | initialize(options); |
| 823 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 824 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 825 | lp::Packet packet(interest->wireEncode()); |
| 826 | packet.set<lp::NextHopFaceIdField>(1000); |
| 827 | |
| 828 | transport->receivePacket(packet.wireEncode()); |
| 829 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 830 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 831 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData) |
| 835 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 836 | // Initialize with Options that enables local fields |
| 837 | GenericLinkService::Options options; |
| 838 | options.allowLocalFields = true; |
| 839 | initialize(options); |
| 840 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 841 | auto data = makeData("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 842 | lp::Packet packet(data->wireEncode()); |
| 843 | packet.set<lp::NextHopFaceIdField>(1000); |
| 844 | |
| 845 | transport->receivePacket(packet.wireEncode()); |
| 846 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 847 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 848 | BOOST_CHECK(receivedData.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack) |
| 852 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 853 | // Initialize with Options that enables local fields |
| 854 | GenericLinkService::Options options; |
| 855 | options.allowLocalFields = true; |
| 856 | initialize(options); |
| 857 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 858 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 859 | lp::NackReason::NO_ROUTE); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 860 | lp::Packet packet; |
| 861 | packet.set<lp::FragmentField>(std::make_pair( |
| 862 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 863 | packet.set<lp::NackField>(nack.getHeader()); |
| 864 | packet.set<lp::NextHopFaceIdField>(1000); |
| 865 | |
| 866 | transport->receivePacket(packet.wireEncode()); |
| 867 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 868 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 869 | BOOST_CHECK(receivedNacks.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 872 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicy) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 873 | { |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 874 | // Initialize with Options that disables local fields |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 875 | GenericLinkService::Options options; |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 876 | options.allowLocalFields = false; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 877 | initialize(options); |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 878 | // CachePolicy is unprivileged and does not require allowLocalFields option. |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 879 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 880 | auto data = makeData("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 881 | lp::Packet packet(data->wireEncode()); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 882 | packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 883 | |
| 884 | transport->receivePacket(packet.wireEncode()); |
| 885 | |
| 886 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 887 | shared_ptr<lp::CachePolicyTag> tag = receivedData.back().getTag<lp::CachePolicyTag>(); |
| 888 | BOOST_REQUIRE(tag != nullptr); |
| 889 | BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 892 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 893 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 894 | // Initialize with Options that enables local fields |
| 895 | GenericLinkService::Options options; |
| 896 | options.allowLocalFields = true; |
| 897 | initialize(options); |
| 898 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 899 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 900 | lp::Packet packet(interest->wireEncode()); |
| 901 | lp::CachePolicy policy; |
| 902 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 903 | packet.set<lp::CachePolicyField>(policy); |
| 904 | |
| 905 | transport->receivePacket(packet.wireEncode()); |
| 906 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 907 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 908 | BOOST_CHECK(receivedInterests.empty()); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Junxiao Shi | 6eb0271 | 2017-05-27 22:48:02 +0000 | [diff] [blame] | 911 | BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 912 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 913 | // Initialize with Options that enables local fields |
| 914 | GenericLinkService::Options options; |
| 915 | options.allowLocalFields = true; |
| 916 | initialize(options); |
| 917 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 918 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 919 | lp::NackReason::NO_ROUTE); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 920 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 921 | packet.set<lp::NackField>(nack.getHeader()); |
| 922 | lp::CachePolicy policy; |
| 923 | policy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 924 | packet.set<lp::CachePolicyField>(policy); |
| 925 | |
| 926 | transport->receivePacket(packet.wireEncode()); |
| 927 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 928 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 929 | BOOST_CHECK(receivedNacks.empty()); |
| 930 | } |
| 931 | |
| 932 | BOOST_AUTO_TEST_CASE(SendIncomingFaceId) |
| 933 | { |
| 934 | // Initialize with Options that enables local fields |
| 935 | GenericLinkService::Options options; |
| 936 | options.allowLocalFields = true; |
| 937 | initialize(options); |
| 938 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 939 | auto interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 940 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 941 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 942 | face->sendInterest(*interest, 0); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 943 | |
| 944 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 945 | lp::Packet sent(transport->sentPackets.back().packet); |
| 946 | BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>()); |
| 947 | BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000); |
| 948 | } |
| 949 | |
| 950 | BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled) |
| 951 | { |
| 952 | // Initialize with Options that disables local fields |
| 953 | GenericLinkService::Options options; |
| 954 | options.allowLocalFields = false; |
| 955 | initialize(options); |
| 956 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 957 | auto interest = makeInterest("/12345678"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 958 | interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000)); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 959 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 960 | face->sendInterest(*interest, 0); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 961 | |
| 962 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 963 | lp::Packet sent(transport->sentPackets.back().packet); |
| 964 | BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>()); |
| 965 | } |
| 966 | |
| 967 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest) |
| 968 | { |
| 969 | // Initialize with Options that enables local fields |
| 970 | GenericLinkService::Options options; |
| 971 | options.allowLocalFields = true; |
| 972 | initialize(options); |
| 973 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 974 | auto interest = makeInterest("/12345678"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 975 | lp::Packet packet(interest->wireEncode()); |
| 976 | packet.set<lp::IncomingFaceIdField>(1000); |
| 977 | |
| 978 | transport->receivePacket(packet.wireEncode()); |
| 979 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 980 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 981 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 982 | BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData) |
| 986 | { |
| 987 | // Initialize with Options that enables local fields |
| 988 | GenericLinkService::Options options; |
| 989 | options.allowLocalFields = true; |
| 990 | initialize(options); |
| 991 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 992 | auto data = makeData("/z1megUh9Bj"); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 993 | lp::Packet packet(data->wireEncode()); |
| 994 | packet.set<lp::IncomingFaceIdField>(1000); |
| 995 | |
| 996 | transport->receivePacket(packet.wireEncode()); |
| 997 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 998 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 999 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1000 | BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack) |
| 1004 | { |
| 1005 | // Initialize with Options that enables local fields |
| 1006 | GenericLinkService::Options options; |
| 1007 | options.allowLocalFields = true; |
| 1008 | initialize(options); |
| 1009 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1010 | lp::Nack nack = makeNack(*makeInterest("/TPAhdiHz", false, nullopt, 278), |
| 1011 | lp::NackReason::CONGESTION); |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1012 | lp::Packet packet(nack.getInterest().wireEncode()); |
| 1013 | packet.set<lp::NackField>(nack.getHeader()); |
| 1014 | packet.set<lp::IncomingFaceIdField>(1000); |
| 1015 | |
| 1016 | transport->receivePacket(packet.wireEncode()); |
| 1017 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1018 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1019 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 1020 | BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1023 | BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest) |
| 1024 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1025 | auto interest = makeInterest("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1026 | interest->setTag(make_shared<lp::CongestionMarkTag>(1)); |
| 1027 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1028 | face->sendInterest(*interest, 0); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1029 | |
| 1030 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1031 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1032 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1033 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1); |
| 1034 | } |
| 1035 | |
| 1036 | BOOST_AUTO_TEST_CASE(SendCongestionMarkData) |
| 1037 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1038 | auto data = makeData("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1039 | data->setTag(make_shared<lp::CongestionMarkTag>(0)); |
| 1040 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1041 | face->sendData(*data, 0); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1042 | |
| 1043 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1044 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1045 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1046 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0); |
| 1047 | } |
| 1048 | |
| 1049 | BOOST_AUTO_TEST_CASE(SendCongestionMarkNack) |
| 1050 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1051 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1052 | lp::NackReason::NO_ROUTE); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1053 | nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max())); |
| 1054 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1055 | face->sendNack(nack, 0); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1056 | |
| 1057 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1058 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1059 | BOOST_REQUIRE(sent.has<lp::CongestionMarkField>()); |
| 1060 | BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max()); |
| 1061 | } |
| 1062 | |
| 1063 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest) |
| 1064 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1065 | auto interest = makeInterest("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1066 | lp::Packet packet(interest->wireEncode()); |
| 1067 | packet.set<lp::CongestionMarkField>(1); |
| 1068 | |
| 1069 | transport->receivePacket(packet.wireEncode()); |
| 1070 | |
| 1071 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 1072 | shared_ptr<lp::CongestionMarkTag> tag = receivedInterests.back().getTag<lp::CongestionMarkTag>(); |
| 1073 | BOOST_REQUIRE(tag != nullptr); |
| 1074 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1075 | } |
| 1076 | |
| 1077 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData) |
| 1078 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1079 | auto data = makeData("/12345678"); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1080 | lp::Packet packet(data->wireEncode()); |
| 1081 | packet.set<lp::CongestionMarkField>(1); |
| 1082 | |
| 1083 | transport->receivePacket(packet.wireEncode()); |
| 1084 | |
| 1085 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 1086 | shared_ptr<lp::CongestionMarkTag> tag = receivedData.back().getTag<lp::CongestionMarkTag>(); |
| 1087 | BOOST_REQUIRE(tag != nullptr); |
| 1088 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1089 | } |
| 1090 | |
| 1091 | BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack) |
| 1092 | { |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1093 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1094 | lp::NackReason::NO_ROUTE); |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1095 | lp::Packet packet; |
| 1096 | packet.set<lp::FragmentField>(std::make_pair( |
| 1097 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 1098 | packet.set<lp::NackField>(nack.getHeader()); |
| 1099 | packet.set<lp::CongestionMarkField>(1); |
| 1100 | |
| 1101 | transport->receivePacket(packet.wireEncode()); |
| 1102 | |
| 1103 | BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1); |
| 1104 | shared_ptr<lp::CongestionMarkTag> tag = receivedNacks.back().getTag<lp::CongestionMarkTag>(); |
| 1105 | BOOST_REQUIRE(tag != nullptr); |
| 1106 | BOOST_CHECK_EQUAL(*tag, 1); |
| 1107 | } |
| 1108 | |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1109 | BOOST_AUTO_TEST_CASE(SendNonDiscovery) |
| 1110 | { |
| 1111 | GenericLinkService::Options options; |
| 1112 | options.allowSelfLearning = true; |
| 1113 | initialize(options); |
| 1114 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1115 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1116 | interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{})); |
| 1117 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1118 | face->sendInterest(*interest, 0); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1119 | |
| 1120 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1121 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1122 | BOOST_CHECK(sent.has<lp::NonDiscoveryField>()); |
| 1123 | } |
| 1124 | |
| 1125 | BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled) |
| 1126 | { |
| 1127 | GenericLinkService::Options options; |
| 1128 | options.allowSelfLearning = false; |
| 1129 | initialize(options); |
| 1130 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1131 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1132 | interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{})); |
| 1133 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1134 | face->sendInterest(*interest, 0); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1135 | |
| 1136 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1137 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1138 | BOOST_CHECK(!sent.has<lp::NonDiscoveryField>()); |
| 1139 | } |
| 1140 | |
| 1141 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery) |
| 1142 | { |
| 1143 | GenericLinkService::Options options; |
| 1144 | options.allowSelfLearning = true; |
| 1145 | initialize(options); |
| 1146 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1147 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1148 | lp::Packet packet(interest->wireEncode()); |
| 1149 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1150 | |
| 1151 | transport->receivePacket(packet.wireEncode()); |
| 1152 | |
| 1153 | BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1); |
| 1154 | shared_ptr<lp::NonDiscoveryTag> tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>(); |
| 1155 | BOOST_CHECK(tag != nullptr); |
| 1156 | } |
| 1157 | |
| 1158 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled) |
| 1159 | { |
| 1160 | GenericLinkService::Options options; |
| 1161 | options.allowSelfLearning = false; |
| 1162 | initialize(options); |
| 1163 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1164 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1165 | lp::Packet packet(interest->wireEncode()); |
| 1166 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1167 | |
| 1168 | transport->receivePacket(packet.wireEncode()); |
| 1169 | |
| 1170 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
| 1171 | BOOST_CHECK_EQUAL(receivedInterests.size(), 1); |
| 1172 | |
| 1173 | shared_ptr<lp::NonDiscoveryTag> tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>(); |
| 1174 | BOOST_CHECK(tag == nullptr); |
| 1175 | } |
| 1176 | |
| 1177 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData) |
| 1178 | { |
| 1179 | GenericLinkService::Options options; |
| 1180 | options.allowSelfLearning = true; |
| 1181 | initialize(options); |
| 1182 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1183 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1184 | lp::Packet packet(data->wireEncode()); |
| 1185 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1186 | |
| 1187 | transport->receivePacket(packet.wireEncode()); |
| 1188 | |
| 1189 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1190 | BOOST_CHECK(receivedData.empty()); |
| 1191 | } |
| 1192 | |
| 1193 | BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack) |
| 1194 | { |
| 1195 | GenericLinkService::Options options; |
| 1196 | options.allowSelfLearning = true; |
| 1197 | initialize(options); |
| 1198 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1199 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1200 | lp::NackReason::NO_ROUTE); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1201 | lp::Packet packet; |
| 1202 | packet.set<lp::FragmentField>(std::make_pair( |
| 1203 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 1204 | packet.set<lp::NackField>(nack.getHeader()); |
| 1205 | packet.set<lp::NonDiscoveryField>(lp::EmptyValue{}); |
| 1206 | |
| 1207 | transport->receivePacket(packet.wireEncode()); |
| 1208 | |
| 1209 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1210 | BOOST_CHECK(receivedNacks.empty()); |
| 1211 | } |
| 1212 | |
| 1213 | BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement) |
| 1214 | { |
| 1215 | GenericLinkService::Options options; |
| 1216 | options.allowSelfLearning = true; |
| 1217 | initialize(options); |
| 1218 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1219 | auto data = makeData("/12345678"); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1220 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1221 | data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah)); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1222 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1223 | face->sendData(*data, 0); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1224 | |
| 1225 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1226 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1227 | BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>()); |
| 1228 | } |
| 1229 | |
| 1230 | BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled) |
| 1231 | { |
| 1232 | GenericLinkService::Options options; |
| 1233 | options.allowSelfLearning = false; |
| 1234 | initialize(options); |
| 1235 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1236 | auto data = makeData("/12345678"); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1237 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1238 | data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah)); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1239 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 1240 | face->sendData(*data, 0); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1241 | |
| 1242 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 1243 | lp::Packet sent(transport->sentPackets.back().packet); |
| 1244 | BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>()); |
| 1245 | } |
| 1246 | |
| 1247 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement) |
| 1248 | { |
| 1249 | GenericLinkService::Options options; |
| 1250 | options.allowSelfLearning = true; |
| 1251 | initialize(options); |
| 1252 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1253 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1254 | lp::Packet packet(data->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1255 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1256 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1257 | |
| 1258 | transport->receivePacket(packet.wireEncode()); |
| 1259 | |
| 1260 | BOOST_REQUIRE_EQUAL(receivedData.size(), 1); |
| 1261 | shared_ptr<lp::PrefixAnnouncementTag> tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>(); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1262 | BOOST_CHECK_EQUAL(tag->get().getPrefixAnn()->getAnnouncedName(), "/local/ndn/prefix"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled) |
| 1266 | { |
| 1267 | GenericLinkService::Options options; |
| 1268 | options.allowSelfLearning = false; |
| 1269 | initialize(options); |
| 1270 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1271 | auto data = makeData("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1272 | lp::Packet packet(data->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1273 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1274 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1275 | |
| 1276 | transport->receivePacket(packet.wireEncode()); |
| 1277 | |
| 1278 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error |
| 1279 | BOOST_CHECK_EQUAL(receivedData.size(), 1); |
| 1280 | |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1281 | shared_ptr<lp::PrefixAnnouncementTag> tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>(); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1282 | BOOST_CHECK(tag == nullptr); |
| 1283 | } |
| 1284 | |
| 1285 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest) |
| 1286 | { |
| 1287 | GenericLinkService::Options options; |
| 1288 | options.allowSelfLearning = true; |
| 1289 | initialize(options); |
| 1290 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1291 | auto interest = makeInterest("/12345678"); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1292 | lp::Packet packet(interest->wireEncode()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1293 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1294 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1295 | |
| 1296 | transport->receivePacket(packet.wireEncode()); |
| 1297 | |
| 1298 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1299 | BOOST_CHECK(receivedInterests.empty()); |
| 1300 | } |
| 1301 | |
| 1302 | BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack) |
| 1303 | { |
| 1304 | GenericLinkService::Options options; |
| 1305 | options.allowSelfLearning = true; |
| 1306 | initialize(options); |
| 1307 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 1308 | lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123), |
| 1309 | lp::NackReason::NO_ROUTE); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1310 | lp::Packet packet; |
| 1311 | packet.set<lp::FragmentField>(std::make_pair( |
| 1312 | nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end())); |
| 1313 | packet.set<lp::NackField>(nack.getHeader()); |
Teng Liang | bce3cb5 | 2018-09-05 20:08:27 -0700 | [diff] [blame] | 1314 | auto pah = makePrefixAnnHeader("/local/ndn/prefix"); |
| 1315 | packet.set<lp::PrefixAnnouncementField>(pah); |
Teng Liang | fdcbb4d | 2018-01-27 16:01:35 -0700 | [diff] [blame] | 1316 | |
| 1317 | transport->receivePacket(packet.wireEncode()); |
| 1318 | |
| 1319 | BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1); |
| 1320 | BOOST_CHECK(receivedNacks.empty()); |
| 1321 | } |
| 1322 | |
Eric Newberry | ee400b5 | 2016-11-24 14:12:48 +0000 | [diff] [blame] | 1323 | BOOST_AUTO_TEST_SUITE_END() // LpFields |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1324 | |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1325 | BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets |
| 1326 | |
| 1327 | BOOST_AUTO_TEST_CASE(WrongTlvType) |
| 1328 | { |
| 1329 | // Initialize with Options that disables all services |
| 1330 | GenericLinkService::Options options; |
| 1331 | options.allowLocalFields = false; |
| 1332 | initialize(options); |
| 1333 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1334 | auto packet = ndn::encoding::makeEmptyBlock(tlv::Name); |
| 1335 | transport->receivePacket(packet); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1336 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1337 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1338 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 1339 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 1340 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 1341 | } |
| 1342 | |
| 1343 | BOOST_AUTO_TEST_CASE(Unparsable) |
| 1344 | { |
| 1345 | // Initialize with Options that disables all services |
| 1346 | GenericLinkService::Options options; |
| 1347 | options.allowLocalFields = false; |
| 1348 | initialize(options); |
| 1349 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1350 | auto packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x"); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1351 | BOOST_CHECK_THROW(packet.parse(), tlv::Error); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 1352 | transport->receivePacket(packet); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1353 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1354 | BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1); |
Eric Newberry | a1939ba | 2015-10-09 12:35:03 -0700 | [diff] [blame] | 1355 | BOOST_CHECK_EQUAL(receivedInterests.size(), 0); |
| 1356 | BOOST_CHECK_EQUAL(receivedData.size(), 0); |
| 1357 | BOOST_CHECK_EQUAL(receivedNacks.size(), 0); |
| 1358 | } |
| 1359 | |
| 1360 | BOOST_AUTO_TEST_SUITE_END() // Malformed |
| 1361 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 1362 | BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService |
| 1363 | BOOST_AUTO_TEST_SUITE_END() // Face |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1364 | |
| 1365 | } // namespace tests |
| 1366 | } // namespace face |
| 1367 | } // namespace nfd |