blob: 693d393237239e6be210fb761265ec9999027435 [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry7b0071e2017-07-03 17:33:31 +00002/*
Eric Newberryf3ee8082020-01-28 13:44:18 -08003 * Copyright (c) 2014-2020, Regents of the University of California,
Eric Newberrya98bf932015-09-21 00:58:47 -07004 * 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 Shicde37ad2015-12-24 01:02:05 -070027#include "face/face.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070028
Davide Pesavento0064c1d2018-03-03 18:43:53 -050029#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040030#include "tests/key-chain-fixture.hpp"
31#include "tests/daemon/global-io-fixture.hpp"
32#include "dummy-transport.hpp"
Eric Newberryb49313d2017-12-24 20:22:27 -070033
Teng Liangfdcbb4d2018-01-27 16:01:35 -070034#include <ndn-cxx/lp/empty-value.hpp>
Teng Liangbce3cb52018-09-05 20:08:27 -070035#include <ndn-cxx/lp/prefix-announcement-header.hpp>
Eric Newberryb49313d2017-12-24 20:22:27 -070036#include <ndn-cxx/lp/tags.hpp>
Teng Liangbce3cb52018-09-05 20:08:27 -070037#include <ndn-cxx/security/signing-helpers.hpp>
Eric Newberrya98bf932015-09-21 00:58:47 -070038
39namespace nfd {
40namespace face {
41namespace tests {
42
43using namespace nfd::tests;
44
45BOOST_AUTO_TEST_SUITE(Face)
46
Junxiao Shicde37ad2015-12-24 01:02:05 -070047using nfd::Face;
48
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040049class GenericLinkServiceFixture : public GlobalIoTimeFixture, public KeyChainFixture
Eric Newberrya98bf932015-09-21 00:58:47 -070050{
51protected:
52 GenericLinkServiceFixture()
Eric Newberrya98bf932015-09-21 00:58:47 -070053 {
Eric Newberrya98bf932015-09-21 00:58:47 -070054 // By default, GenericLinkService is created with default options.
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040055 // Test cases may invoke initialize() with alternate options.
56 initialize({});
Eric Newberrya98bf932015-09-21 00:58:47 -070057 }
58
59 void
Eric Newberryb49313d2017-12-24 20:22:27 -070060 initialize(const GenericLinkService::Options& options,
61 ssize_t mtu = MTU_UNLIMITED,
62 ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED)
Eric Newberrya98bf932015-09-21 00:58:47 -070063 {
Davide Pesaventoe4b22382018-06-10 14:37:24 -040064 face = make_unique<Face>(make_unique<GenericLinkService>(options),
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040065 make_unique<DummyTransport>("dummy://", "dummy://",
Davide Pesaventoe4b22382018-06-10 14:37:24 -040066 ndn::nfd::FACE_SCOPE_NON_LOCAL,
67 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
68 ndn::nfd::LINK_TYPE_POINT_TO_POINT,
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040069 mtu, sendQueueCapacity));
Eric Newberrya98bf932015-09-21 00:58:47 -070070 service = static_cast<GenericLinkService*>(face->getLinkService());
71 transport = static_cast<DummyTransport*>(face->getTransport());
72
73 face->afterReceiveInterest.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000074 [this] (const Interest& interest, const EndpointId&) { receivedInterests.push_back(interest); });
Eric Newberrya98bf932015-09-21 00:58:47 -070075 face->afterReceiveData.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000076 [this] (const Data& data, const EndpointId&) { receivedData.push_back(data); });
Eric Newberrya98bf932015-09-21 00:58:47 -070077 face->afterReceiveNack.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000078 [this] (const lp::Nack& nack, const EndpointId&) { receivedNacks.push_back(nack); });
Eric Newberrya98bf932015-09-21 00:58:47 -070079 }
80
Teng Liangbce3cb52018-09-05 20:08:27 -070081 lp::PrefixAnnouncementHeader
82 makePrefixAnnHeader(const Name& announcedName)
83 {
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040084 return lp::PrefixAnnouncementHeader{signPrefixAnn(makePrefixAnn(announcedName, 1_h),
85 m_keyChain, ndn::signingWithSha256())};
Teng Liangbce3cb52018-09-05 20:08:27 -070086 }
87
Eric Newberrya98bf932015-09-21 00:58:47 -070088protected:
Junxiao Shicde37ad2015-12-24 01:02:05 -070089 unique_ptr<Face> face;
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040090 GenericLinkService* service = nullptr;
91 DummyTransport* transport = nullptr;
Eric Newberrya98bf932015-09-21 00:58:47 -070092 std::vector<Interest> receivedInterests;
93 std::vector<Data> receivedData;
94 std::vector<lp::Nack> receivedNacks;
95};
96
97BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture)
98
Eric Newberrya98bf932015-09-21 00:58:47 -070099BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields
100
101BOOST_AUTO_TEST_CASE(SendInterest)
102{
Eric Newberry86d31872015-09-23 16:24:59 -0700103 // Initialize with Options that disables all services
104 GenericLinkService::Options options;
105 options.allowLocalFields = false;
106 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700107
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400108 auto interest1 = makeInterest("/localhost/test");
ashiqopu075bb7d2019-03-10 01:38:21 +0000109 face->sendInterest(*interest1, 0);
Eric Newberrya98bf932015-09-21 00:58:47 -0700110
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700111 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700112 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400113 lp::Packet interest1pkt(transport->sentPackets.back().packet);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700114 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
115 BOOST_CHECK(!interest1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700116}
117
118BOOST_AUTO_TEST_CASE(SendData)
119{
Eric Newberry86d31872015-09-23 16:24:59 -0700120 // Initialize with Options that disables all services
121 GenericLinkService::Options options;
122 options.allowLocalFields = false;
123 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700124
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400125 auto data1 = makeData("/localhost/test");
ashiqopu075bb7d2019-03-10 01:38:21 +0000126 face->sendData(*data1, 0);
Eric Newberrya98bf932015-09-21 00:58:47 -0700127
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700128 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700129 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400130 lp::Packet data1pkt(transport->sentPackets.back().packet);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700131 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
132 BOOST_CHECK(!data1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700133}
134
135BOOST_AUTO_TEST_CASE(SendNack)
136{
Eric Newberry86d31872015-09-23 16:24:59 -0700137 // Initialize with Options that disables all services
138 GenericLinkService::Options options;
139 options.allowLocalFields = false;
140 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700141
Junxiao Shi9d727852019-05-14 13:44:22 -0600142 auto nack1 = makeNack(*makeInterest("/localhost/test", false, nullopt, 323),
143 lp::NackReason::NO_ROUTE);
ashiqopu075bb7d2019-03-10 01:38:21 +0000144 face->sendNack(nack1, 0);
Eric Newberrya98bf932015-09-21 00:58:47 -0700145
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700146 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700147 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400148 lp::Packet nack1pkt(transport->sentPackets.back().packet);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700149 BOOST_CHECK(nack1pkt.has<lp::NackField>());
150 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
151 BOOST_CHECK(!nack1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700152}
153
154BOOST_AUTO_TEST_CASE(ReceiveBareInterest)
155{
Eric Newberry86d31872015-09-23 16:24:59 -0700156 // Initialize with Options that disables all services
157 GenericLinkService::Options options;
158 options.allowLocalFields = false;
159 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700160
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400161 auto interest1 = makeInterest("/23Rd9hEiR");
Eric Newberrya98bf932015-09-21 00:58:47 -0700162 transport->receivePacket(interest1->wireEncode());
163
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700164 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700165 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400166 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700167}
168
169BOOST_AUTO_TEST_CASE(ReceiveInterest)
170{
Eric Newberry86d31872015-09-23 16:24:59 -0700171 // Initialize with Options that disables all services
172 GenericLinkService::Options options;
173 options.allowLocalFields = false;
174 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700175
Junxiao Shi9d727852019-05-14 13:44:22 -0600176 auto interest1 = makeInterest("/23Rd9hEiR");
Eric Newberrya98bf932015-09-21 00:58:47 -0700177 lp::Packet lpPacket;
178 lpPacket.set<lp::FragmentField>(std::make_pair(
179 interest1->wireEncode().begin(), interest1->wireEncode().end()));
180 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
181
182 transport->receivePacket(lpPacket.wireEncode());
183
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700184 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700185 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400186 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700187}
188
189BOOST_AUTO_TEST_CASE(ReceiveBareData)
190{
Eric Newberry86d31872015-09-23 16:24:59 -0700191 // Initialize with Options that disables all services
192 GenericLinkService::Options options;
193 options.allowLocalFields = false;
194 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700195
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400196 auto data1 = makeData("/12345678");
Eric Newberrya98bf932015-09-21 00:58:47 -0700197 transport->receivePacket(data1->wireEncode());
198
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700199 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700200 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400201 BOOST_CHECK_EQUAL(receivedData.back().wireEncode(), data1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700202}
203
204BOOST_AUTO_TEST_CASE(ReceiveData)
205{
Eric Newberry86d31872015-09-23 16:24:59 -0700206 // Initialize with Options that disables all services
207 GenericLinkService::Options options;
208 options.allowLocalFields = false;
209 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700210
Junxiao Shi9d727852019-05-14 13:44:22 -0600211 auto data1 = makeData("/12345689");
Eric Newberrya98bf932015-09-21 00:58:47 -0700212 lp::Packet lpPacket;
213 lpPacket.set<lp::FragmentField>(std::make_pair(
214 data1->wireEncode().begin(), data1->wireEncode().end()));
215 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
216
217 transport->receivePacket(lpPacket.wireEncode());
218
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700219 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700220 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400221 BOOST_CHECK_EQUAL(receivedData.back().wireEncode(), data1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700222}
223
224BOOST_AUTO_TEST_CASE(ReceiveNack)
225{
Eric Newberry86d31872015-09-23 16:24:59 -0700226 // Initialize with Options that disables all services
227 GenericLinkService::Options options;
228 options.allowLocalFields = false;
229 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700230
Junxiao Shi9d727852019-05-14 13:44:22 -0600231 lp::Nack nack1 = makeNack(*makeInterest("/localhost/test", false, nullopt, 323),
232 lp::NackReason::NO_ROUTE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700233 lp::Packet lpPacket;
234 lpPacket.set<lp::FragmentField>(std::make_pair(
235 nack1.getInterest().wireEncode().begin(), nack1.getInterest().wireEncode().end()));
236 lpPacket.set<lp::NackField>(nack1.getHeader());
237
238 transport->receivePacket(lpPacket.wireEncode());
239
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700240 BOOST_CHECK_EQUAL(service->getCounters().nInNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700241 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400242 BOOST_CHECK_EQUAL(receivedNacks.back().getReason(), nack1.getReason());
243 BOOST_CHECK_EQUAL(receivedNacks.back().getInterest().wireEncode(), nack1.getInterest().wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700244}
245
Eric Newberrya1939ba2015-10-09 12:35:03 -0700246BOOST_AUTO_TEST_CASE(ReceiveIdlePacket)
247{
248 // Initialize with Options that disables all services
249 GenericLinkService::Options options;
250 options.allowLocalFields = false;
251 initialize(options);
252
253 lp::Packet lpPacket;
254 lpPacket.set<lp::SequenceField>(0);
255
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400256 transport->receivePacket(lpPacket.wireEncode());
Eric Newberrya1939ba2015-10-09 12:35:03 -0700257
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700258 // IDLE packet should be ignored, but is not an error
259 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0);
Eric Newberrya1939ba2015-10-09 12:35:03 -0700260 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
261 BOOST_CHECK_EQUAL(receivedData.size(), 0);
262 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
263}
264
Eric Newberrya98bf932015-09-21 00:58:47 -0700265BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive
266
Eric Newberry86d31872015-09-23 16:24:59 -0700267BOOST_AUTO_TEST_SUITE(Fragmentation)
268
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700269BOOST_AUTO_TEST_CASE(FragmentationDisabledExceedMtuDrop)
270{
271 // Initialize with Options that disable fragmentation
272 GenericLinkService::Options options;
273 options.allowFragmentation = false;
274 initialize(options);
275
276 transport->setMtu(55);
277
Junxiao Shi9d727852019-05-14 13:44:22 -0600278 auto data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000279 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700280
281 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
282 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
283}
284
Eric Newberryf3ee8082020-01-28 13:44:18 -0800285// It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero
286// This test case ensures that packets are dropped if the MTU is zero
287BOOST_AUTO_TEST_CASE(FragmentationDisabledZeroMtuDrop)
288{
289 // Initialize with Options that disable fragmentation
290 GenericLinkService::Options options;
291 options.allowFragmentation = false;
292 initialize(options);
293
294 transport->setMtu(0);
295
296 auto data = makeData("/test/data/123456789/987654321/123456789");
297 face->sendData(*data, 0);
298
299 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
300 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
301}
302
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700303BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu)
304{
305 // Initialize with Options that enable fragmentation
306 GenericLinkService::Options options;
307 options.allowFragmentation = true;
308 initialize(options);
309
310 transport->setMtu(MTU_UNLIMITED);
311
Junxiao Shi9d727852019-05-14 13:44:22 -0600312 auto data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000313 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700314
315 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
316}
317
318BOOST_AUTO_TEST_CASE(FragmentationUnderMtu)
319{
320 // Initialize with Options that enable fragmentation
321 GenericLinkService::Options options;
322 options.allowFragmentation = true;
323 initialize(options);
324
325 transport->setMtu(105);
326
Junxiao Shi9d727852019-05-14 13:44:22 -0600327 auto data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000328 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700329
330 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
331}
332
333BOOST_AUTO_TEST_CASE(FragmentationOverMtu)
334{
335 // Initialize with Options that enable fragmentation
336 GenericLinkService::Options options;
337 options.allowFragmentation = true;
338 initialize(options);
339
340 transport->setMtu(60);
341
Junxiao Shi9d727852019-05-14 13:44:22 -0600342 auto data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000343 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700344
345 BOOST_CHECK_GT(transport->sentPackets.size(), 1);
346}
347
Eric Newberryf3ee8082020-01-28 13:44:18 -0800348// It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero
349// This test case ensures that packets are dropped if the MTU is zero
350BOOST_AUTO_TEST_CASE(FragmentationZeroMtuDrop)
351{
352 // Initialize with Options that enable fragmentation
353 GenericLinkService::Options options;
354 options.allowFragmentation = true;
355 initialize(options);
356
357 transport->setMtu(0);
358
359 auto data = makeData("/test/data/123456789/987654321/123456789");
360 face->sendData(*data, 0);
361
362 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
363 BOOST_CHECK_EQUAL(service->getCounters().nFragmentationErrors, 1);
364}
365
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700366BOOST_AUTO_TEST_CASE(ReassembleFragments)
367{
368 // Initialize with Options that enables reassembly
369 GenericLinkService::Options options;
370 options.allowReassembly = true;
371 initialize(options);
372
Junxiao Shi9d727852019-05-14 13:44:22 -0600373 auto interest = makeInterest(
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700374 "/mt7P130BHXmtLm5dwaY5dpUM6SWYNN2B05g7y3UhsQuLvDdnTWdNnTeEiLuW3FAbJRSG3tzQ0UfaSEgG9rvYHmsKtgPMag1Hj4Tr");
375 lp::Packet packet(interest->wireEncode());
376
377 // fragment the packet
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400378 LpFragmenter fragmenter({});
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700379 size_t mtu = 100;
380 bool isOk = false;
381 std::vector<lp::Packet> frags;
382 std::tie(isOk, frags) = fragmenter.fragmentPacket(packet, mtu);
383 BOOST_REQUIRE(isOk);
384 BOOST_CHECK_GT(frags.size(), 1);
385
386 // receive the fragments
387 for (ssize_t fragIndex = frags.size() - 1; fragIndex >= 0; --fragIndex) {
388 size_t sequence = 1000 + fragIndex;
389 frags[fragIndex].add<lp::SequenceField>(sequence);
390
391 transport->receivePacket(frags[fragIndex].wireEncode());
392
393 if (fragIndex > 0) {
394 BOOST_CHECK(receivedInterests.empty());
395 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 1);
396 }
397 else {
398 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400399 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest->wireEncode());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700400 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 0);
401 }
402 }
403}
404
Eric Newberry86d31872015-09-23 16:24:59 -0700405BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex)
406{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700407 // Initialize with Options that disables reassembly
408 GenericLinkService::Options options;
409 options.allowReassembly = false;
410 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700411
Junxiao Shi9d727852019-05-14 13:44:22 -0600412 auto interest = makeInterest("/IgFe6NvH");
Eric Newberry86d31872015-09-23 16:24:59 -0700413 lp::Packet packet(interest->wireEncode());
414 packet.set<lp::FragIndexField>(140);
415
416 transport->receivePacket(packet.wireEncode());
417
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700418 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700419 BOOST_CHECK(receivedInterests.empty());
420}
421
422BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount)
423{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700424 // Initialize with Options that disables reassembly
425 GenericLinkService::Options options;
426 options.allowReassembly = false;
427 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700428
Junxiao Shi9d727852019-05-14 13:44:22 -0600429 auto interest = makeInterest("/SeGmEjvIVX");
Eric Newberry86d31872015-09-23 16:24:59 -0700430 lp::Packet packet(interest->wireEncode());
431 packet.set<lp::FragCountField>(276);
432
433 transport->receivePacket(packet.wireEncode());
434
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700435 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700436 BOOST_CHECK(receivedInterests.empty());
437}
438
439BOOST_AUTO_TEST_SUITE_END() // Fragmentation
440
Eric Newberry185ab292017-03-28 06:45:39 +0000441BOOST_AUTO_TEST_SUITE(Reliability)
442
Eric Newberry7b0071e2017-07-03 17:33:31 +0000443BOOST_AUTO_TEST_CASE(SendInterest)
Eric Newberry185ab292017-03-28 06:45:39 +0000444{
445 // Initialize with Options that enables reliability
446 GenericLinkService::Options options;
447 options.allowLocalFields = false;
448 options.reliabilityOptions.isEnabled = true;
449 initialize(options);
450
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400451 auto interest1 = makeInterest("/localhost/test");
ashiqopu075bb7d2019-03-10 01:38:21 +0000452 face->sendInterest(*interest1, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000453
454 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
455 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400456 lp::Packet interest1pkt(transport->sentPackets.back().packet);
Eric Newberry185ab292017-03-28 06:45:39 +0000457 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000458 BOOST_CHECK(interest1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000459}
460
Eric Newberry7b0071e2017-07-03 17:33:31 +0000461BOOST_AUTO_TEST_CASE(SendData)
Eric Newberry185ab292017-03-28 06:45:39 +0000462{
463 // Initialize with Options that enables reliability
464 GenericLinkService::Options options;
465 options.allowLocalFields = false;
466 options.reliabilityOptions.isEnabled = true;
467 initialize(options);
468
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400469 auto data1 = makeData("/localhost/test");
ashiqopu075bb7d2019-03-10 01:38:21 +0000470 face->sendData(*data1, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000471
472 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
473 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400474 lp::Packet data1pkt(transport->sentPackets.back().packet);
Eric Newberry185ab292017-03-28 06:45:39 +0000475 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000476 BOOST_CHECK(data1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000477}
478
Eric Newberry7b0071e2017-07-03 17:33:31 +0000479BOOST_AUTO_TEST_CASE(SendNack)
Eric Newberry185ab292017-03-28 06:45:39 +0000480{
481 // Initialize with Options that enables reliability
482 GenericLinkService::Options options;
483 options.allowLocalFields = false;
484 options.reliabilityOptions.isEnabled = true;
485 initialize(options);
486
Junxiao Shi9d727852019-05-14 13:44:22 -0600487 auto nack1 = makeNack(*makeInterest("/localhost/test", false, nullopt, 323),
488 lp::NackReason::NO_ROUTE);
ashiqopu075bb7d2019-03-10 01:38:21 +0000489 face->sendNack(nack1, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000490
491 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
492 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400493 lp::Packet nack1pkt(transport->sentPackets.back().packet);
Eric Newberry185ab292017-03-28 06:45:39 +0000494 BOOST_CHECK(nack1pkt.has<lp::NackField>());
495 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000496 BOOST_CHECK(nack1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000497}
498
499BOOST_AUTO_TEST_SUITE_END() // Reliability
Eric Newberry86d31872015-09-23 16:24:59 -0700500
Eric Newberryb49313d2017-12-24 20:22:27 -0700501// congestion detection and marking
502BOOST_AUTO_TEST_SUITE(CongestionMark)
503
504BOOST_AUTO_TEST_CASE(NoCongestion)
505{
506 GenericLinkService::Options options;
507 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400508 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700509 initialize(options, MTU_UNLIMITED, 65536);
510 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
511 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
512 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
513
Junxiao Shi9d727852019-05-14 13:44:22 -0600514 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700515
516 // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes
517
518 // no congestion
519 transport->setSendQueueLength(0);
ashiqopu075bb7d2019-03-10 01:38:21 +0000520 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700521 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400522 lp::Packet pkt1(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700523 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
524 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
525 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
526 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
527
528 // no congestion
529 transport->setSendQueueLength(32768);
ashiqopu075bb7d2019-03-10 01:38:21 +0000530 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700531 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400532 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700533 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
534 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
535 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
536 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
537}
538
539BOOST_AUTO_TEST_CASE(CongestionCoDel)
540{
541 GenericLinkService::Options options;
542 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400543 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700544 initialize(options, MTU_UNLIMITED, 65536);
545 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700546 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
547 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
548
Junxiao Shi9d727852019-05-14 13:44:22 -0600549 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700550
Klaus Schneider380668b2019-10-02 01:21:13 -0700551 // first congested packet, will not be marked
552 transport->setSendQueueLength(65537);
ashiqopu075bb7d2019-03-10 01:38:21 +0000553 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700554 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700555 lp::Packet pkt0(transport->sentPackets.back().packet);
556 BOOST_REQUIRE_EQUAL(pkt0.count<lp::CongestionMarkField>(), 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400557 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700558 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700559
560 time::nanoseconds markingInterval(
561 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
562 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
563
564 advanceClocks(markingInterval + 1_ms);
565 face->sendInterest(*interest, 0);
566 lp::Packet pkt1(transport->sentPackets.back().packet);
567
568 // First congestion mark appears after one interval (100 ms)
569 BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1);
570 BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1);
Eric Newberryb49313d2017-12-24 20:22:27 -0700571 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
572 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
573
574 // advance clock to half of marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700575 advanceClocks(markingInterval / 2); // 50ms
Eric Newberryb49313d2017-12-24 20:22:27 -0700576
577 // second congested packet, but within marking interval, will not be marked
Klaus Schneider380668b2019-10-02 01:21:13 -0700578 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000579 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700580 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400581 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700582 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700583
584 markingInterval = time::nanoseconds(
585 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
586 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
587 nextMarkTime += markingInterval;
588
Eric Newberryb49313d2017-12-24 20:22:27 -0700589 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700590 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
591 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
592
593 // advance clocks past end of initial interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700594 this->advanceClocks((markingInterval / 2) + 1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700595
596 // first congested packet after waiting marking interval, will be marked
Klaus Schneider380668b2019-10-02 01:21:13 -0700597 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000598 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700599 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400600 lp::Packet pkt3(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700601 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1);
602 BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700603 markingInterval = time::nanoseconds(
604 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
605 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700606 nextMarkTime += markingInterval;
607 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700608 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
609 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
610
611 // advance clock partway through current marking interval
Klaus Schneider380668b2019-10-02 01:21:13 -0700612 this->advanceClocks(markingInterval - 20_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700613
614 // still congested, but within marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700615 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000616 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700617 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400618 lp::Packet pkt4(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700619 BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0);
620 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700621 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
622 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
623
624 // advance clocks past end of current marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700625 this->advanceClocks(21_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700626
627 // still congested, after marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700628 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000629 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700630 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400631 lp::Packet pkt5(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700632 BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1);
633 BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1);
634 markingInterval = time::nanoseconds(
635 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700636 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700637 nextMarkTime += markingInterval;
638 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700639 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
640 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
641
Davide Pesavento14e71f02019-03-28 17:35:25 -0400642 this->advanceClocks(1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700643
644 // still congested, but within marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700645 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000646 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700647 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400648 lp::Packet pkt6(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700649 BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0);
650 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700651 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
652 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
653
654 this->advanceClocks(markingInterval);
655
656 // still congested, after marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700657 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000658 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700659 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400660 lp::Packet pkt7(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700661 BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1);
662 BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1);
663 markingInterval = time::nanoseconds(
664 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700665 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700666 nextMarkTime += markingInterval;
667 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700668 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4);
669 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
670
671 // no more congestion
672 transport->setSendQueueLength(30000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000673 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700674 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400675 lp::Packet pkt8(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700676 BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0);
677 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700678 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
679 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
680
Davide Pesavento14e71f02019-03-28 17:35:25 -0400681 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700682
683 // send queue congested again, but can't mark packet because within one full interval of last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700684 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000685 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700686 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400687 lp::Packet pkt9(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700688 BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700689 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
690 markingInterval = time::nanoseconds(
691 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
692 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
693 nextMarkTime = time::steady_clock::now() + markingInterval;
694 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700695 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
696 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
697
698 // advance clock past full 100ms interval since last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700699 this->advanceClocks(markingInterval + 2_ms);
700 BOOST_CHECK_GT(time::steady_clock::now(), nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700701
Klaus Schneider380668b2019-10-02 01:21:13 -0700702 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000703 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700704 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400705 lp::Packet pkt10(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700706 BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1);
707 BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700708 markingInterval = time::nanoseconds(
709 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
710 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
711 nextMarkTime += markingInterval;
Eric Newberryb49313d2017-12-24 20:22:27 -0700712 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700713 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
714 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
715
716 // advance clock partway through 100ms marking interval
Davide Pesavento14e71f02019-03-28 17:35:25 -0400717 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700718
719 // not marked since within 100ms window before can mark again
Klaus Schneider380668b2019-10-02 01:21:13 -0700720 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000721 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700722 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400723 lp::Packet pkt11(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700724 BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0);
725 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700726 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
727 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
728
729 // advance clocks past m_nextMarkTime
Davide Pesavento14e71f02019-03-28 17:35:25 -0400730 this->advanceClocks(51_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700731
732 // markable packet, queue length still above threshold
Klaus Schneider380668b2019-10-02 01:21:13 -0700733 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000734 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700735 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400736 lp::Packet pkt12(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700737 BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1);
738 BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1);
739 markingInterval = time::nanoseconds(
740 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700741 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700742 nextMarkTime += markingInterval;
743 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700744 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
745 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
746
747 // no more congestion
748 transport->setSendQueueLength(10000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000749 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700750 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400751 lp::Packet pkt13(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700752 BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0);
753 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700754 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
755 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
756
757 // advance clocks past one full interval since last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700758 this->advanceClocks(102_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700759
760 // start congestion again
Klaus Schneider380668b2019-10-02 01:21:13 -0700761 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000762 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700763 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400764 lp::Packet pkt14(transport->sentPackets.back().packet);
Klaus Schneider380668b2019-10-02 01:21:13 -0700765 BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400766 nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700767 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700768 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
769 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
Eric Newberryb49313d2017-12-24 20:22:27 -0700770
771 // no more congestion, cancel marking interval
772 transport->setSendQueueLength(5000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000773 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700774 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400775 lp::Packet pkt15(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700776 BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0);
777 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700778 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700779 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
Eric Newberryb49313d2017-12-24 20:22:27 -0700780}
781
782BOOST_AUTO_TEST_CASE(DefaultThreshold)
783{
784 GenericLinkService::Options options;
785 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400786 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700787 initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED);
788 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
789 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
790 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
791
Junxiao Shi9d727852019-05-14 13:44:22 -0600792 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700793
794 // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure
795 // the queue capacity
796
797 // no congestion
798 transport->setSendQueueLength(0);
ashiqopu075bb7d2019-03-10 01:38:21 +0000799 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700800 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400801 lp::Packet pkt1(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700802 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
803 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
804 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
805 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
806
807 // no congestion
808 transport->setSendQueueLength(65536);
ashiqopu075bb7d2019-03-10 01:38:21 +0000809 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700810 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400811 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700812 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
813 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
814 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
815 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
816
Klaus Schneider380668b2019-10-02 01:21:13 -0700817 // first congested (not marked yet) packet
Eric Newberryb49313d2017-12-24 20:22:27 -0700818 transport->setSendQueueLength(65537);
ashiqopu075bb7d2019-03-10 01:38:21 +0000819 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700820 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400821 lp::Packet pkt3(transport->sentPackets.back().packet);
Klaus Schneider380668b2019-10-02 01:21:13 -0700822 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400823 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700824 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700825 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
826 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700827}
828
829BOOST_AUTO_TEST_SUITE_END() // CongestionMark
830
Eric Newberryee400b52016-11-24 14:12:48 +0000831BOOST_AUTO_TEST_SUITE(LpFields)
Eric Newberrya98bf932015-09-21 00:58:47 -0700832
Eric Newberrya98bf932015-09-21 00:58:47 -0700833BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId)
834{
Eric Newberry86d31872015-09-23 16:24:59 -0700835 // Initialize with Options that enables local fields
836 GenericLinkService::Options options;
837 options.allowLocalFields = true;
838 initialize(options);
839
Junxiao Shi9d727852019-05-14 13:44:22 -0600840 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700841 lp::Packet packet(interest->wireEncode());
842 packet.set<lp::NextHopFaceIdField>(1000);
843
844 transport->receivePacket(packet.wireEncode());
845
846 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400847 auto tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>();
Junxiao Shi0de23a22015-12-03 20:07:02 +0000848 BOOST_REQUIRE(tag != nullptr);
849 BOOST_CHECK_EQUAL(*tag, 1000);
Eric Newberrya98bf932015-09-21 00:58:47 -0700850}
851
852BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled)
853{
Eric Newberry86d31872015-09-23 16:24:59 -0700854 // Initialize with Options that disables local fields
855 GenericLinkService::Options options;
856 options.allowLocalFields = false;
857 initialize(options);
858
Junxiao Shi9d727852019-05-14 13:44:22 -0600859 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700860 lp::Packet packet(interest->wireEncode());
861 packet.set<lp::NextHopFaceIdField>(1000);
862
863 transport->receivePacket(packet.wireEncode());
864
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700865 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700866 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700867}
868
869BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData)
870{
Eric Newberry86d31872015-09-23 16:24:59 -0700871 // Initialize with Options that enables local fields
872 GenericLinkService::Options options;
873 options.allowLocalFields = true;
874 initialize(options);
875
Junxiao Shi9d727852019-05-14 13:44:22 -0600876 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700877 lp::Packet packet(data->wireEncode());
878 packet.set<lp::NextHopFaceIdField>(1000);
879
880 transport->receivePacket(packet.wireEncode());
881
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700882 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700883 BOOST_CHECK(receivedData.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700884}
885
886BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack)
887{
Eric Newberry86d31872015-09-23 16:24:59 -0700888 // Initialize with Options that enables local fields
889 GenericLinkService::Options options;
890 options.allowLocalFields = true;
891 initialize(options);
892
Junxiao Shi9d727852019-05-14 13:44:22 -0600893 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
894 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -0700895 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 Newberry4c3e6b82015-11-10 16:48:42 -0700903 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700904 BOOST_CHECK(receivedNacks.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700905}
906
Junxiao Shi6eb02712017-05-27 22:48:02 +0000907BOOST_AUTO_TEST_CASE(ReceiveCachePolicy)
Eric Newberrya98bf932015-09-21 00:58:47 -0700908{
Junxiao Shi6eb02712017-05-27 22:48:02 +0000909 // Initialize with Options that disables local fields
Eric Newberry86d31872015-09-23 16:24:59 -0700910 GenericLinkService::Options options;
Junxiao Shi6eb02712017-05-27 22:48:02 +0000911 options.allowLocalFields = false;
Eric Newberry86d31872015-09-23 16:24:59 -0700912 initialize(options);
Junxiao Shi6eb02712017-05-27 22:48:02 +0000913 // CachePolicy is unprivileged and does not require allowLocalFields option.
Eric Newberry86d31872015-09-23 16:24:59 -0700914
Junxiao Shi9d727852019-05-14 13:44:22 -0600915 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700916 lp::Packet packet(data->wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000917 packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE));
Eric Newberry86d31872015-09-23 16:24:59 -0700918
919 transport->receivePacket(packet.wireEncode());
920
921 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400922 auto tag = receivedData.back().getTag<lp::CachePolicyTag>();
Junxiao Shi0de23a22015-12-03 20:07:02 +0000923 BOOST_REQUIRE(tag != nullptr);
924 BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700925}
926
Junxiao Shi6eb02712017-05-27 22:48:02 +0000927BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest)
Eric Newberrya98bf932015-09-21 00:58:47 -0700928{
Eric Newberry86d31872015-09-23 16:24:59 -0700929 // Initialize with Options that enables local fields
930 GenericLinkService::Options options;
931 options.allowLocalFields = true;
932 initialize(options);
933
Junxiao Shi9d727852019-05-14 13:44:22 -0600934 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700935 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 Newberry4c3e6b82015-11-10 16:48:42 -0700942 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700943 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700944}
945
Junxiao Shi6eb02712017-05-27 22:48:02 +0000946BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack)
Eric Newberrya98bf932015-09-21 00:58:47 -0700947{
Eric Newberry86d31872015-09-23 16:24:59 -0700948 // Initialize with Options that enables local fields
949 GenericLinkService::Options options;
950 options.allowLocalFields = true;
951 initialize(options);
952
Junxiao Shi9d727852019-05-14 13:44:22 -0600953 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
954 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -0700955 lp::Packet packet(nack.getInterest().wireEncode());
956 packet.set<lp::NackField>(nack.getHeader());
957 lp::CachePolicy policy;
958 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
959 packet.set<lp::CachePolicyField>(policy);
960
961 transport->receivePacket(packet.wireEncode());
962
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700963 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700964 BOOST_CHECK(receivedNacks.empty());
965}
966
967BOOST_AUTO_TEST_CASE(SendIncomingFaceId)
968{
969 // Initialize with Options that enables local fields
970 GenericLinkService::Options options;
971 options.allowLocalFields = true;
972 initialize(options);
973
Junxiao Shi9d727852019-05-14 13:44:22 -0600974 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +0000975 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -0700976
ashiqopu075bb7d2019-03-10 01:38:21 +0000977 face->sendInterest(*interest, 0);
Eric Newberry86d31872015-09-23 16:24:59 -0700978
979 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
980 lp::Packet sent(transport->sentPackets.back().packet);
981 BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>());
982 BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000);
983}
984
985BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled)
986{
987 // Initialize with Options that disables local fields
988 GenericLinkService::Options options;
989 options.allowLocalFields = false;
990 initialize(options);
991
Junxiao Shi9d727852019-05-14 13:44:22 -0600992 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +0000993 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -0700994
ashiqopu075bb7d2019-03-10 01:38:21 +0000995 face->sendInterest(*interest, 0);
Eric Newberry86d31872015-09-23 16:24:59 -0700996
997 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
998 lp::Packet sent(transport->sentPackets.back().packet);
999 BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>());
1000}
1001
1002BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest)
1003{
1004 // Initialize with Options that enables local fields
1005 GenericLinkService::Options options;
1006 options.allowLocalFields = true;
1007 initialize(options);
1008
Junxiao Shi9d727852019-05-14 13:44:22 -06001009 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -07001010 lp::Packet packet(interest->wireEncode());
1011 packet.set<lp::IncomingFaceIdField>(1000);
1012
1013 transport->receivePacket(packet.wireEncode());
1014
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001015 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001016 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001017 BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001018}
1019
1020BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData)
1021{
1022 // Initialize with Options that enables local fields
1023 GenericLinkService::Options options;
1024 options.allowLocalFields = true;
1025 initialize(options);
1026
Junxiao Shi9d727852019-05-14 13:44:22 -06001027 auto data = makeData("/z1megUh9Bj");
Eric Newberry86d31872015-09-23 16:24:59 -07001028 lp::Packet packet(data->wireEncode());
1029 packet.set<lp::IncomingFaceIdField>(1000);
1030
1031 transport->receivePacket(packet.wireEncode());
1032
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001033 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001034 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001035 BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001036}
1037
1038BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack)
1039{
1040 // Initialize with Options that enables local fields
1041 GenericLinkService::Options options;
1042 options.allowLocalFields = true;
1043 initialize(options);
1044
Junxiao Shi9d727852019-05-14 13:44:22 -06001045 lp::Nack nack = makeNack(*makeInterest("/TPAhdiHz", false, nullopt, 278),
1046 lp::NackReason::CONGESTION);
Eric Newberry86d31872015-09-23 16:24:59 -07001047 lp::Packet packet(nack.getInterest().wireEncode());
1048 packet.set<lp::NackField>(nack.getHeader());
1049 packet.set<lp::IncomingFaceIdField>(1000);
1050
1051 transport->receivePacket(packet.wireEncode());
1052
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001053 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001054 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001055 BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberrya98bf932015-09-21 00:58:47 -07001056}
1057
Eric Newberryee400b52016-11-24 14:12:48 +00001058BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest)
1059{
Junxiao Shi9d727852019-05-14 13:44:22 -06001060 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001061 interest->setTag(make_shared<lp::CongestionMarkTag>(1));
1062
ashiqopu075bb7d2019-03-10 01:38:21 +00001063 face->sendInterest(*interest, 0);
Eric Newberryee400b52016-11-24 14:12:48 +00001064
1065 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1066 lp::Packet sent(transport->sentPackets.back().packet);
1067 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1068 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1);
1069}
1070
1071BOOST_AUTO_TEST_CASE(SendCongestionMarkData)
1072{
Junxiao Shi9d727852019-05-14 13:44:22 -06001073 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001074 data->setTag(make_shared<lp::CongestionMarkTag>(0));
1075
ashiqopu075bb7d2019-03-10 01:38:21 +00001076 face->sendData(*data, 0);
Eric Newberryee400b52016-11-24 14:12:48 +00001077
1078 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1079 lp::Packet sent(transport->sentPackets.back().packet);
1080 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1081 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0);
1082}
1083
1084BOOST_AUTO_TEST_CASE(SendCongestionMarkNack)
1085{
Junxiao Shi9d727852019-05-14 13:44:22 -06001086 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1087 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001088 nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max()));
1089
ashiqopu075bb7d2019-03-10 01:38:21 +00001090 face->sendNack(nack, 0);
Eric Newberryee400b52016-11-24 14:12:48 +00001091
1092 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1093 lp::Packet sent(transport->sentPackets.back().packet);
1094 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1095 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max());
1096}
1097
1098BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest)
1099{
Junxiao Shi9d727852019-05-14 13:44:22 -06001100 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001101 lp::Packet packet(interest->wireEncode());
1102 packet.set<lp::CongestionMarkField>(1);
1103
1104 transport->receivePacket(packet.wireEncode());
1105
1106 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001107 auto tag = receivedInterests.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001108 BOOST_REQUIRE(tag != nullptr);
1109 BOOST_CHECK_EQUAL(*tag, 1);
1110}
1111
1112BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData)
1113{
Junxiao Shi9d727852019-05-14 13:44:22 -06001114 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001115 lp::Packet packet(data->wireEncode());
1116 packet.set<lp::CongestionMarkField>(1);
1117
1118 transport->receivePacket(packet.wireEncode());
1119
1120 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001121 auto tag = receivedData.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001122 BOOST_REQUIRE(tag != nullptr);
1123 BOOST_CHECK_EQUAL(*tag, 1);
1124}
1125
1126BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack)
1127{
Junxiao Shi9d727852019-05-14 13:44:22 -06001128 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1129 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001130 lp::Packet packet;
1131 packet.set<lp::FragmentField>(std::make_pair(
1132 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1133 packet.set<lp::NackField>(nack.getHeader());
1134 packet.set<lp::CongestionMarkField>(1);
1135
1136 transport->receivePacket(packet.wireEncode());
1137
1138 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001139 auto tag = receivedNacks.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001140 BOOST_REQUIRE(tag != nullptr);
1141 BOOST_CHECK_EQUAL(*tag, 1);
1142}
1143
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001144BOOST_AUTO_TEST_CASE(SendNonDiscovery)
1145{
1146 GenericLinkService::Options options;
1147 options.allowSelfLearning = true;
1148 initialize(options);
1149
Junxiao Shi9d727852019-05-14 13:44:22 -06001150 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001151 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1152
ashiqopu075bb7d2019-03-10 01:38:21 +00001153 face->sendInterest(*interest, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001154
1155 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1156 lp::Packet sent(transport->sentPackets.back().packet);
1157 BOOST_CHECK(sent.has<lp::NonDiscoveryField>());
1158}
1159
1160BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled)
1161{
1162 GenericLinkService::Options options;
1163 options.allowSelfLearning = false;
1164 initialize(options);
1165
Junxiao Shi9d727852019-05-14 13:44:22 -06001166 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001167 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1168
ashiqopu075bb7d2019-03-10 01:38:21 +00001169 face->sendInterest(*interest, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001170
1171 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1172 lp::Packet sent(transport->sentPackets.back().packet);
1173 BOOST_CHECK(!sent.has<lp::NonDiscoveryField>());
1174}
1175
1176BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery)
1177{
1178 GenericLinkService::Options options;
1179 options.allowSelfLearning = true;
1180 initialize(options);
1181
Junxiao Shi9d727852019-05-14 13:44:22 -06001182 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001183 lp::Packet packet(interest->wireEncode());
1184 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1185
1186 transport->receivePacket(packet.wireEncode());
1187
1188 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001189 auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001190 BOOST_CHECK(tag != nullptr);
1191}
1192
1193BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled)
1194{
1195 GenericLinkService::Options options;
1196 options.allowSelfLearning = false;
1197 initialize(options);
1198
Junxiao Shi9d727852019-05-14 13:44:22 -06001199 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001200 lp::Packet packet(interest->wireEncode());
1201 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1202
1203 transport->receivePacket(packet.wireEncode());
1204
1205 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1206 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001207 auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001208 BOOST_CHECK(tag == nullptr);
1209}
1210
1211BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData)
1212{
1213 GenericLinkService::Options options;
1214 options.allowSelfLearning = true;
1215 initialize(options);
1216
Junxiao Shi9d727852019-05-14 13:44:22 -06001217 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001218 lp::Packet packet(data->wireEncode());
1219 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1220
1221 transport->receivePacket(packet.wireEncode());
1222
1223 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1224 BOOST_CHECK(receivedData.empty());
1225}
1226
1227BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack)
1228{
1229 GenericLinkService::Options options;
1230 options.allowSelfLearning = true;
1231 initialize(options);
1232
Junxiao Shi9d727852019-05-14 13:44:22 -06001233 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1234 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001235 lp::Packet packet;
1236 packet.set<lp::FragmentField>(std::make_pair(
1237 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1238 packet.set<lp::NackField>(nack.getHeader());
1239 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1240
1241 transport->receivePacket(packet.wireEncode());
1242
1243 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1244 BOOST_CHECK(receivedNacks.empty());
1245}
1246
1247BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement)
1248{
1249 GenericLinkService::Options options;
1250 options.allowSelfLearning = true;
1251 initialize(options);
1252
Junxiao Shi9d727852019-05-14 13:44:22 -06001253 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001254 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1255 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001256
ashiqopu075bb7d2019-03-10 01:38:21 +00001257 face->sendData(*data, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001258
1259 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1260 lp::Packet sent(transport->sentPackets.back().packet);
1261 BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>());
1262}
1263
1264BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled)
1265{
1266 GenericLinkService::Options options;
1267 options.allowSelfLearning = false;
1268 initialize(options);
1269
Junxiao Shi9d727852019-05-14 13:44:22 -06001270 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001271 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1272 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001273
ashiqopu075bb7d2019-03-10 01:38:21 +00001274 face->sendData(*data, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001275
1276 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1277 lp::Packet sent(transport->sentPackets.back().packet);
1278 BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>());
1279}
1280
1281BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement)
1282{
1283 GenericLinkService::Options options;
1284 options.allowSelfLearning = true;
1285 initialize(options);
1286
Junxiao Shi9d727852019-05-14 13:44:22 -06001287 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001288 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001289 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1290 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001291
1292 transport->receivePacket(packet.wireEncode());
1293
1294 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001295 auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangbce3cb52018-09-05 20:08:27 -07001296 BOOST_CHECK_EQUAL(tag->get().getPrefixAnn()->getAnnouncedName(), "/local/ndn/prefix");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001297}
1298
1299BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled)
1300{
1301 GenericLinkService::Options options;
1302 options.allowSelfLearning = false;
1303 initialize(options);
1304
Junxiao Shi9d727852019-05-14 13:44:22 -06001305 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001306 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001307 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1308 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001309
1310 transport->receivePacket(packet.wireEncode());
1311
1312 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1313 BOOST_CHECK_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001314 auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001315 BOOST_CHECK(tag == nullptr);
1316}
1317
1318BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest)
1319{
1320 GenericLinkService::Options options;
1321 options.allowSelfLearning = true;
1322 initialize(options);
1323
Junxiao Shi9d727852019-05-14 13:44:22 -06001324 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001325 lp::Packet packet(interest->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001326 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1327 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001328
1329 transport->receivePacket(packet.wireEncode());
1330
1331 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1332 BOOST_CHECK(receivedInterests.empty());
1333}
1334
1335BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack)
1336{
1337 GenericLinkService::Options options;
1338 options.allowSelfLearning = true;
1339 initialize(options);
1340
Junxiao Shi9d727852019-05-14 13:44:22 -06001341 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1342 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001343 lp::Packet packet;
1344 packet.set<lp::FragmentField>(std::make_pair(
1345 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1346 packet.set<lp::NackField>(nack.getHeader());
Teng Liangbce3cb52018-09-05 20:08:27 -07001347 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1348 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001349
1350 transport->receivePacket(packet.wireEncode());
1351
1352 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1353 BOOST_CHECK(receivedNacks.empty());
1354}
1355
Eric Newberryee400b52016-11-24 14:12:48 +00001356BOOST_AUTO_TEST_SUITE_END() // LpFields
Eric Newberrya98bf932015-09-21 00:58:47 -07001357
Eric Newberrya1939ba2015-10-09 12:35:03 -07001358BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets
1359
1360BOOST_AUTO_TEST_CASE(WrongTlvType)
1361{
1362 // Initialize with Options that disables all services
1363 GenericLinkService::Options options;
1364 options.allowLocalFields = false;
1365 initialize(options);
1366
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001367 auto packet = ndn::encoding::makeEmptyBlock(tlv::Name);
1368 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001369
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001370 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001371 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1372 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1373 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1374}
1375
1376BOOST_AUTO_TEST_CASE(Unparsable)
1377{
1378 // Initialize with Options that disables all services
1379 GenericLinkService::Options options;
1380 options.allowLocalFields = false;
1381 initialize(options);
1382
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001383 auto packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x");
Eric Newberrya1939ba2015-10-09 12:35:03 -07001384 BOOST_CHECK_THROW(packet.parse(), tlv::Error);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001385 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001386
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001387 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001388 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1389 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1390 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1391}
1392
1393BOOST_AUTO_TEST_SUITE_END() // Malformed
1394
Eric Newberry86d31872015-09-23 16:24:59 -07001395BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService
1396BOOST_AUTO_TEST_SUITE_END() // Face
Eric Newberrya98bf932015-09-21 00:58:47 -07001397
1398} // namespace tests
1399} // namespace face
1400} // namespace nfd