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