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