blob: e6b85d1fcf132c78fd4e50da9af5042b930ba0d7 [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
Eric Newberry32f7eac2020-02-07 14:40:17 -0800499BOOST_AUTO_TEST_CASE(DropDuplicatePacket)
500{
501 // Initialize with Options that enables reliability
502 GenericLinkService::Options options;
503 options.allowLocalFields = false;
504 options.reliabilityOptions.isEnabled = true;
505 initialize(options);
506
507 Interest interest("/test/prefix");
508 interest.setCanBePrefix(false);
509 lp::Packet pkt1;
510 pkt1.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()});
511 pkt1.add<lp::SequenceField>(7);
512 pkt1.add<lp::TxSequenceField>(12);
513 transport->receivePacket(pkt1.wireEncode());
514 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
515 BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 0);
516
517 lp::Packet pkt2;
518 pkt2.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()});
519 pkt2.add<lp::SequenceField>(7);
520 pkt2.add<lp::TxSequenceField>(13);
521 transport->receivePacket(pkt2.wireEncode());
522 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
523 BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 1);
524}
525
Eric Newberry185ab292017-03-28 06:45:39 +0000526BOOST_AUTO_TEST_SUITE_END() // Reliability
Eric Newberry86d31872015-09-23 16:24:59 -0700527
Eric Newberryb49313d2017-12-24 20:22:27 -0700528// congestion detection and marking
529BOOST_AUTO_TEST_SUITE(CongestionMark)
530
531BOOST_AUTO_TEST_CASE(NoCongestion)
532{
533 GenericLinkService::Options options;
534 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400535 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700536 initialize(options, MTU_UNLIMITED, 65536);
537 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
538 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
539 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
540
Junxiao Shi9d727852019-05-14 13:44:22 -0600541 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700542
543 // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes
544
545 // no congestion
546 transport->setSendQueueLength(0);
ashiqopu075bb7d2019-03-10 01:38:21 +0000547 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700548 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400549 lp::Packet pkt1(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700550 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
551 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
552 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
553 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
554
555 // no congestion
556 transport->setSendQueueLength(32768);
ashiqopu075bb7d2019-03-10 01:38:21 +0000557 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700558 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400559 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700560 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
561 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
562 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
563 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
564}
565
566BOOST_AUTO_TEST_CASE(CongestionCoDel)
567{
568 GenericLinkService::Options options;
569 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400570 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700571 initialize(options, MTU_UNLIMITED, 65536);
572 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700573 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
574 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
575
Junxiao Shi9d727852019-05-14 13:44:22 -0600576 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700577
Klaus Schneider380668b2019-10-02 01:21:13 -0700578 // first congested packet, will not be marked
579 transport->setSendQueueLength(65537);
ashiqopu075bb7d2019-03-10 01:38:21 +0000580 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700581 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700582 lp::Packet pkt0(transport->sentPackets.back().packet);
583 BOOST_REQUIRE_EQUAL(pkt0.count<lp::CongestionMarkField>(), 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400584 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700585 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700586
587 time::nanoseconds markingInterval(
588 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
589 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
590
591 advanceClocks(markingInterval + 1_ms);
592 face->sendInterest(*interest, 0);
593 lp::Packet pkt1(transport->sentPackets.back().packet);
594
595 // First congestion mark appears after one interval (100 ms)
596 BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1);
597 BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1);
Eric Newberryb49313d2017-12-24 20:22:27 -0700598 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
599 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
600
601 // advance clock to half of marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700602 advanceClocks(markingInterval / 2); // 50ms
Eric Newberryb49313d2017-12-24 20:22:27 -0700603
604 // second congested packet, but within marking interval, will not be marked
Klaus Schneider380668b2019-10-02 01:21:13 -0700605 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000606 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700607 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400608 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700609 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700610
611 markingInterval = time::nanoseconds(
612 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
613 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
614 nextMarkTime += markingInterval;
615
Eric Newberryb49313d2017-12-24 20:22:27 -0700616 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700617 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
618 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
619
620 // advance clocks past end of initial interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700621 this->advanceClocks((markingInterval / 2) + 1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700622
623 // first congested packet after waiting marking interval, will be marked
Klaus Schneider380668b2019-10-02 01:21:13 -0700624 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000625 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700626 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400627 lp::Packet pkt3(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700628 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1);
629 BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700630 markingInterval = time::nanoseconds(
631 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
632 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700633 nextMarkTime += markingInterval;
634 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700635 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
636 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
637
638 // advance clock partway through current marking interval
Klaus Schneider380668b2019-10-02 01:21:13 -0700639 this->advanceClocks(markingInterval - 20_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700640
641 // still congested, but within marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700642 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000643 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700644 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400645 lp::Packet pkt4(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700646 BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0);
647 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700648 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
649 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
650
651 // advance clocks past end of current marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700652 this->advanceClocks(21_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700653
654 // still congested, after marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700655 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000656 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700657 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400658 lp::Packet pkt5(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700659 BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1);
660 BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1);
661 markingInterval = time::nanoseconds(
662 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700663 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700664 nextMarkTime += markingInterval;
665 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700666 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
667 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
668
Davide Pesavento14e71f02019-03-28 17:35:25 -0400669 this->advanceClocks(1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700670
671 // still congested, but within marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700672 transport->setSendQueueLength(66000);
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(), 7);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400675 lp::Packet pkt6(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700676 BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0);
677 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700678 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
679 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
680
681 this->advanceClocks(markingInterval);
682
683 // still congested, after marking interval cycle
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(), 8);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400687 lp::Packet pkt7(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700688 BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1);
689 BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1);
690 markingInterval = time::nanoseconds(
691 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700692 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700693 nextMarkTime += markingInterval;
694 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700695 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4);
696 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
697
698 // no more congestion
699 transport->setSendQueueLength(30000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000700 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700701 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400702 lp::Packet pkt8(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700703 BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0);
704 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700705 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
706 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
707
Davide Pesavento14e71f02019-03-28 17:35:25 -0400708 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700709
710 // send queue congested again, but can't mark packet because within one full interval of last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700711 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000712 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700713 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400714 lp::Packet pkt9(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700715 BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700716 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
717 markingInterval = time::nanoseconds(
718 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
719 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
720 nextMarkTime = time::steady_clock::now() + markingInterval;
721 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700722 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
723 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
724
725 // advance clock past full 100ms interval since last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700726 this->advanceClocks(markingInterval + 2_ms);
727 BOOST_CHECK_GT(time::steady_clock::now(), nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700728
Klaus Schneider380668b2019-10-02 01:21:13 -0700729 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000730 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700731 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400732 lp::Packet pkt10(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700733 BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1);
734 BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700735 markingInterval = time::nanoseconds(
736 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
737 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
738 nextMarkTime += markingInterval;
Eric Newberryb49313d2017-12-24 20:22:27 -0700739 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700740 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
741 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
742
743 // advance clock partway through 100ms marking interval
Davide Pesavento14e71f02019-03-28 17:35:25 -0400744 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700745
746 // not marked since within 100ms window before can mark again
Klaus Schneider380668b2019-10-02 01:21:13 -0700747 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000748 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700749 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400750 lp::Packet pkt11(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700751 BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0);
752 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700753 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
754 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
755
756 // advance clocks past m_nextMarkTime
Davide Pesavento14e71f02019-03-28 17:35:25 -0400757 this->advanceClocks(51_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700758
759 // markable packet, queue length still above threshold
Klaus Schneider380668b2019-10-02 01:21:13 -0700760 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000761 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700762 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400763 lp::Packet pkt12(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700764 BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1);
765 BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1);
766 markingInterval = time::nanoseconds(
767 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700768 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700769 nextMarkTime += markingInterval;
770 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700771 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
772 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
773
774 // no more congestion
775 transport->setSendQueueLength(10000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000776 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700777 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400778 lp::Packet pkt13(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700779 BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0);
780 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700781 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
782 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
783
784 // advance clocks past one full interval since last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700785 this->advanceClocks(102_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700786
787 // start congestion again
Klaus Schneider380668b2019-10-02 01:21:13 -0700788 transport->setSendQueueLength(66000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000789 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700790 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400791 lp::Packet pkt14(transport->sentPackets.back().packet);
Klaus Schneider380668b2019-10-02 01:21:13 -0700792 BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400793 nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700794 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700795 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
796 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
Eric Newberryb49313d2017-12-24 20:22:27 -0700797
798 // no more congestion, cancel marking interval
799 transport->setSendQueueLength(5000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000800 face->sendInterest(*interest, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700801 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400802 lp::Packet pkt15(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700803 BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0);
804 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700805 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700806 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
Eric Newberryb49313d2017-12-24 20:22:27 -0700807}
808
809BOOST_AUTO_TEST_CASE(DefaultThreshold)
810{
811 GenericLinkService::Options options;
812 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400813 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700814 initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED);
815 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
816 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
817 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
818
Junxiao Shi9d727852019-05-14 13:44:22 -0600819 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700820
821 // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure
822 // the queue capacity
823
824 // no congestion
825 transport->setSendQueueLength(0);
ashiqopu075bb7d2019-03-10 01:38:21 +0000826 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700827 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400828 lp::Packet pkt1(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700829 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
830 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
831 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
832 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
833
834 // no congestion
835 transport->setSendQueueLength(65536);
ashiqopu075bb7d2019-03-10 01:38:21 +0000836 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700837 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400838 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700839 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
840 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
841 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
842 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
843
Klaus Schneider380668b2019-10-02 01:21:13 -0700844 // first congested (not marked yet) packet
Eric Newberryb49313d2017-12-24 20:22:27 -0700845 transport->setSendQueueLength(65537);
ashiqopu075bb7d2019-03-10 01:38:21 +0000846 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700847 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400848 lp::Packet pkt3(transport->sentPackets.back().packet);
Klaus Schneider380668b2019-10-02 01:21:13 -0700849 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400850 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700851 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700852 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
853 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700854}
855
856BOOST_AUTO_TEST_SUITE_END() // CongestionMark
857
Eric Newberryee400b52016-11-24 14:12:48 +0000858BOOST_AUTO_TEST_SUITE(LpFields)
Eric Newberrya98bf932015-09-21 00:58:47 -0700859
Eric Newberrya98bf932015-09-21 00:58:47 -0700860BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId)
861{
Eric Newberry86d31872015-09-23 16:24:59 -0700862 // Initialize with Options that enables local fields
863 GenericLinkService::Options options;
864 options.allowLocalFields = true;
865 initialize(options);
866
Junxiao Shi9d727852019-05-14 13:44:22 -0600867 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700868 lp::Packet packet(interest->wireEncode());
869 packet.set<lp::NextHopFaceIdField>(1000);
870
871 transport->receivePacket(packet.wireEncode());
872
873 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400874 auto tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>();
Junxiao Shi0de23a22015-12-03 20:07:02 +0000875 BOOST_REQUIRE(tag != nullptr);
876 BOOST_CHECK_EQUAL(*tag, 1000);
Eric Newberrya98bf932015-09-21 00:58:47 -0700877}
878
879BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled)
880{
Eric Newberry86d31872015-09-23 16:24:59 -0700881 // Initialize with Options that disables local fields
882 GenericLinkService::Options options;
883 options.allowLocalFields = false;
884 initialize(options);
885
Junxiao Shi9d727852019-05-14 13:44:22 -0600886 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700887 lp::Packet packet(interest->wireEncode());
888 packet.set<lp::NextHopFaceIdField>(1000);
889
890 transport->receivePacket(packet.wireEncode());
891
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700892 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700893 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700894}
895
896BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData)
897{
Eric Newberry86d31872015-09-23 16:24:59 -0700898 // Initialize with Options that enables local fields
899 GenericLinkService::Options options;
900 options.allowLocalFields = true;
901 initialize(options);
902
Junxiao Shi9d727852019-05-14 13:44:22 -0600903 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700904 lp::Packet packet(data->wireEncode());
905 packet.set<lp::NextHopFaceIdField>(1000);
906
907 transport->receivePacket(packet.wireEncode());
908
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700909 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700910 BOOST_CHECK(receivedData.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700911}
912
913BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack)
914{
Eric Newberry86d31872015-09-23 16:24:59 -0700915 // Initialize with Options that enables local fields
916 GenericLinkService::Options options;
917 options.allowLocalFields = true;
918 initialize(options);
919
Junxiao Shi9d727852019-05-14 13:44:22 -0600920 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
921 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -0700922 lp::Packet packet;
923 packet.set<lp::FragmentField>(std::make_pair(
924 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
925 packet.set<lp::NackField>(nack.getHeader());
926 packet.set<lp::NextHopFaceIdField>(1000);
927
928 transport->receivePacket(packet.wireEncode());
929
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700930 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700931 BOOST_CHECK(receivedNacks.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700932}
933
Junxiao Shi6eb02712017-05-27 22:48:02 +0000934BOOST_AUTO_TEST_CASE(ReceiveCachePolicy)
Eric Newberrya98bf932015-09-21 00:58:47 -0700935{
Junxiao Shi6eb02712017-05-27 22:48:02 +0000936 // Initialize with Options that disables local fields
Eric Newberry86d31872015-09-23 16:24:59 -0700937 GenericLinkService::Options options;
Junxiao Shi6eb02712017-05-27 22:48:02 +0000938 options.allowLocalFields = false;
Eric Newberry86d31872015-09-23 16:24:59 -0700939 initialize(options);
Junxiao Shi6eb02712017-05-27 22:48:02 +0000940 // CachePolicy is unprivileged and does not require allowLocalFields option.
Eric Newberry86d31872015-09-23 16:24:59 -0700941
Junxiao Shi9d727852019-05-14 13:44:22 -0600942 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700943 lp::Packet packet(data->wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000944 packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE));
Eric Newberry86d31872015-09-23 16:24:59 -0700945
946 transport->receivePacket(packet.wireEncode());
947
948 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400949 auto tag = receivedData.back().getTag<lp::CachePolicyTag>();
Junxiao Shi0de23a22015-12-03 20:07:02 +0000950 BOOST_REQUIRE(tag != nullptr);
951 BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700952}
953
Junxiao Shi6eb02712017-05-27 22:48:02 +0000954BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest)
Eric Newberrya98bf932015-09-21 00:58:47 -0700955{
Eric Newberry86d31872015-09-23 16:24:59 -0700956 // Initialize with Options that enables local fields
957 GenericLinkService::Options options;
958 options.allowLocalFields = true;
959 initialize(options);
960
Junxiao Shi9d727852019-05-14 13:44:22 -0600961 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700962 lp::Packet packet(interest->wireEncode());
963 lp::CachePolicy policy;
964 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
965 packet.set<lp::CachePolicyField>(policy);
966
967 transport->receivePacket(packet.wireEncode());
968
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700969 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700970 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700971}
972
Junxiao Shi6eb02712017-05-27 22:48:02 +0000973BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack)
Eric Newberrya98bf932015-09-21 00:58:47 -0700974{
Eric Newberry86d31872015-09-23 16:24:59 -0700975 // Initialize with Options that enables local fields
976 GenericLinkService::Options options;
977 options.allowLocalFields = true;
978 initialize(options);
979
Junxiao Shi9d727852019-05-14 13:44:22 -0600980 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
981 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -0700982 lp::Packet packet(nack.getInterest().wireEncode());
983 packet.set<lp::NackField>(nack.getHeader());
984 lp::CachePolicy policy;
985 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
986 packet.set<lp::CachePolicyField>(policy);
987
988 transport->receivePacket(packet.wireEncode());
989
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700990 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700991 BOOST_CHECK(receivedNacks.empty());
992}
993
994BOOST_AUTO_TEST_CASE(SendIncomingFaceId)
995{
996 // Initialize with Options that enables local fields
997 GenericLinkService::Options options;
998 options.allowLocalFields = true;
999 initialize(options);
1000
Junxiao Shi9d727852019-05-14 13:44:22 -06001001 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +00001002 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -07001003
ashiqopu075bb7d2019-03-10 01:38:21 +00001004 face->sendInterest(*interest, 0);
Eric Newberry86d31872015-09-23 16:24:59 -07001005
1006 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1007 lp::Packet sent(transport->sentPackets.back().packet);
1008 BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>());
1009 BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000);
1010}
1011
1012BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled)
1013{
1014 // Initialize with Options that disables local fields
1015 GenericLinkService::Options options;
1016 options.allowLocalFields = false;
1017 initialize(options);
1018
Junxiao Shi9d727852019-05-14 13:44:22 -06001019 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +00001020 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -07001021
ashiqopu075bb7d2019-03-10 01:38:21 +00001022 face->sendInterest(*interest, 0);
Eric Newberry86d31872015-09-23 16:24:59 -07001023
1024 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1025 lp::Packet sent(transport->sentPackets.back().packet);
1026 BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>());
1027}
1028
1029BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest)
1030{
1031 // Initialize with Options that enables local fields
1032 GenericLinkService::Options options;
1033 options.allowLocalFields = true;
1034 initialize(options);
1035
Junxiao Shi9d727852019-05-14 13:44:22 -06001036 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -07001037 lp::Packet packet(interest->wireEncode());
1038 packet.set<lp::IncomingFaceIdField>(1000);
1039
1040 transport->receivePacket(packet.wireEncode());
1041
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001042 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001043 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001044 BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001045}
1046
1047BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData)
1048{
1049 // Initialize with Options that enables local fields
1050 GenericLinkService::Options options;
1051 options.allowLocalFields = true;
1052 initialize(options);
1053
Junxiao Shi9d727852019-05-14 13:44:22 -06001054 auto data = makeData("/z1megUh9Bj");
Eric Newberry86d31872015-09-23 16:24:59 -07001055 lp::Packet packet(data->wireEncode());
1056 packet.set<lp::IncomingFaceIdField>(1000);
1057
1058 transport->receivePacket(packet.wireEncode());
1059
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001060 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001061 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001062 BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001063}
1064
1065BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack)
1066{
1067 // Initialize with Options that enables local fields
1068 GenericLinkService::Options options;
1069 options.allowLocalFields = true;
1070 initialize(options);
1071
Junxiao Shi9d727852019-05-14 13:44:22 -06001072 lp::Nack nack = makeNack(*makeInterest("/TPAhdiHz", false, nullopt, 278),
1073 lp::NackReason::CONGESTION);
Eric Newberry86d31872015-09-23 16:24:59 -07001074 lp::Packet packet(nack.getInterest().wireEncode());
1075 packet.set<lp::NackField>(nack.getHeader());
1076 packet.set<lp::IncomingFaceIdField>(1000);
1077
1078 transport->receivePacket(packet.wireEncode());
1079
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001080 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001081 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001082 BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberrya98bf932015-09-21 00:58:47 -07001083}
1084
Eric Newberryee400b52016-11-24 14:12:48 +00001085BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest)
1086{
Junxiao Shi9d727852019-05-14 13:44:22 -06001087 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001088 interest->setTag(make_shared<lp::CongestionMarkTag>(1));
1089
ashiqopu075bb7d2019-03-10 01:38:21 +00001090 face->sendInterest(*interest, 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>(), 1);
1096}
1097
1098BOOST_AUTO_TEST_CASE(SendCongestionMarkData)
1099{
Junxiao Shi9d727852019-05-14 13:44:22 -06001100 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001101 data->setTag(make_shared<lp::CongestionMarkTag>(0));
1102
ashiqopu075bb7d2019-03-10 01:38:21 +00001103 face->sendData(*data, 0);
Eric Newberryee400b52016-11-24 14:12:48 +00001104
1105 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1106 lp::Packet sent(transport->sentPackets.back().packet);
1107 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1108 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0);
1109}
1110
1111BOOST_AUTO_TEST_CASE(SendCongestionMarkNack)
1112{
Junxiao Shi9d727852019-05-14 13:44:22 -06001113 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1114 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001115 nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max()));
1116
ashiqopu075bb7d2019-03-10 01:38:21 +00001117 face->sendNack(nack, 0);
Eric Newberryee400b52016-11-24 14:12:48 +00001118
1119 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1120 lp::Packet sent(transport->sentPackets.back().packet);
1121 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1122 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max());
1123}
1124
1125BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest)
1126{
Junxiao Shi9d727852019-05-14 13:44:22 -06001127 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001128 lp::Packet packet(interest->wireEncode());
1129 packet.set<lp::CongestionMarkField>(1);
1130
1131 transport->receivePacket(packet.wireEncode());
1132
1133 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001134 auto tag = receivedInterests.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001135 BOOST_REQUIRE(tag != nullptr);
1136 BOOST_CHECK_EQUAL(*tag, 1);
1137}
1138
1139BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData)
1140{
Junxiao Shi9d727852019-05-14 13:44:22 -06001141 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001142 lp::Packet packet(data->wireEncode());
1143 packet.set<lp::CongestionMarkField>(1);
1144
1145 transport->receivePacket(packet.wireEncode());
1146
1147 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001148 auto tag = receivedData.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001149 BOOST_REQUIRE(tag != nullptr);
1150 BOOST_CHECK_EQUAL(*tag, 1);
1151}
1152
1153BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack)
1154{
Junxiao Shi9d727852019-05-14 13:44:22 -06001155 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1156 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001157 lp::Packet packet;
1158 packet.set<lp::FragmentField>(std::make_pair(
1159 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1160 packet.set<lp::NackField>(nack.getHeader());
1161 packet.set<lp::CongestionMarkField>(1);
1162
1163 transport->receivePacket(packet.wireEncode());
1164
1165 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001166 auto tag = receivedNacks.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001167 BOOST_REQUIRE(tag != nullptr);
1168 BOOST_CHECK_EQUAL(*tag, 1);
1169}
1170
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001171BOOST_AUTO_TEST_CASE(SendNonDiscovery)
1172{
1173 GenericLinkService::Options options;
1174 options.allowSelfLearning = true;
1175 initialize(options);
1176
Junxiao Shi9d727852019-05-14 13:44:22 -06001177 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001178 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1179
ashiqopu075bb7d2019-03-10 01:38:21 +00001180 face->sendInterest(*interest, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001181
1182 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1183 lp::Packet sent(transport->sentPackets.back().packet);
1184 BOOST_CHECK(sent.has<lp::NonDiscoveryField>());
1185}
1186
1187BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled)
1188{
1189 GenericLinkService::Options options;
1190 options.allowSelfLearning = false;
1191 initialize(options);
1192
Junxiao Shi9d727852019-05-14 13:44:22 -06001193 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001194 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1195
ashiqopu075bb7d2019-03-10 01:38:21 +00001196 face->sendInterest(*interest, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001197
1198 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1199 lp::Packet sent(transport->sentPackets.back().packet);
1200 BOOST_CHECK(!sent.has<lp::NonDiscoveryField>());
1201}
1202
1203BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery)
1204{
1205 GenericLinkService::Options options;
1206 options.allowSelfLearning = true;
1207 initialize(options);
1208
Junxiao Shi9d727852019-05-14 13:44:22 -06001209 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001210 lp::Packet packet(interest->wireEncode());
1211 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1212
1213 transport->receivePacket(packet.wireEncode());
1214
1215 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001216 auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001217 BOOST_CHECK(tag != nullptr);
1218}
1219
1220BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled)
1221{
1222 GenericLinkService::Options options;
1223 options.allowSelfLearning = false;
1224 initialize(options);
1225
Junxiao Shi9d727852019-05-14 13:44:22 -06001226 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001227 lp::Packet packet(interest->wireEncode());
1228 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1229
1230 transport->receivePacket(packet.wireEncode());
1231
1232 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1233 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001234 auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001235 BOOST_CHECK(tag == nullptr);
1236}
1237
1238BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData)
1239{
1240 GenericLinkService::Options options;
1241 options.allowSelfLearning = true;
1242 initialize(options);
1243
Junxiao Shi9d727852019-05-14 13:44:22 -06001244 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001245 lp::Packet packet(data->wireEncode());
1246 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1247
1248 transport->receivePacket(packet.wireEncode());
1249
1250 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1251 BOOST_CHECK(receivedData.empty());
1252}
1253
1254BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack)
1255{
1256 GenericLinkService::Options options;
1257 options.allowSelfLearning = true;
1258 initialize(options);
1259
Junxiao Shi9d727852019-05-14 13:44:22 -06001260 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1261 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001262 lp::Packet packet;
1263 packet.set<lp::FragmentField>(std::make_pair(
1264 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1265 packet.set<lp::NackField>(nack.getHeader());
1266 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1267
1268 transport->receivePacket(packet.wireEncode());
1269
1270 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1271 BOOST_CHECK(receivedNacks.empty());
1272}
1273
1274BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement)
1275{
1276 GenericLinkService::Options options;
1277 options.allowSelfLearning = true;
1278 initialize(options);
1279
Junxiao Shi9d727852019-05-14 13:44:22 -06001280 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001281 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1282 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001283
ashiqopu075bb7d2019-03-10 01:38:21 +00001284 face->sendData(*data, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001285
1286 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1287 lp::Packet sent(transport->sentPackets.back().packet);
1288 BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>());
1289}
1290
1291BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled)
1292{
1293 GenericLinkService::Options options;
1294 options.allowSelfLearning = false;
1295 initialize(options);
1296
Junxiao Shi9d727852019-05-14 13:44:22 -06001297 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001298 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1299 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001300
ashiqopu075bb7d2019-03-10 01:38:21 +00001301 face->sendData(*data, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001302
1303 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1304 lp::Packet sent(transport->sentPackets.back().packet);
1305 BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>());
1306}
1307
1308BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement)
1309{
1310 GenericLinkService::Options options;
1311 options.allowSelfLearning = true;
1312 initialize(options);
1313
Junxiao Shi9d727852019-05-14 13:44:22 -06001314 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001315 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001316 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1317 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001318
1319 transport->receivePacket(packet.wireEncode());
1320
1321 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001322 auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangbce3cb52018-09-05 20:08:27 -07001323 BOOST_CHECK_EQUAL(tag->get().getPrefixAnn()->getAnnouncedName(), "/local/ndn/prefix");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001324}
1325
1326BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled)
1327{
1328 GenericLinkService::Options options;
1329 options.allowSelfLearning = false;
1330 initialize(options);
1331
Junxiao Shi9d727852019-05-14 13:44:22 -06001332 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001333 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001334 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1335 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001336
1337 transport->receivePacket(packet.wireEncode());
1338
1339 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1340 BOOST_CHECK_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001341 auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001342 BOOST_CHECK(tag == nullptr);
1343}
1344
1345BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest)
1346{
1347 GenericLinkService::Options options;
1348 options.allowSelfLearning = true;
1349 initialize(options);
1350
Junxiao Shi9d727852019-05-14 13:44:22 -06001351 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001352 lp::Packet packet(interest->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001353 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1354 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001355
1356 transport->receivePacket(packet.wireEncode());
1357
1358 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1359 BOOST_CHECK(receivedInterests.empty());
1360}
1361
1362BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack)
1363{
1364 GenericLinkService::Options options;
1365 options.allowSelfLearning = true;
1366 initialize(options);
1367
Junxiao Shi9d727852019-05-14 13:44:22 -06001368 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1369 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001370 lp::Packet packet;
1371 packet.set<lp::FragmentField>(std::make_pair(
1372 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1373 packet.set<lp::NackField>(nack.getHeader());
Teng Liangbce3cb52018-09-05 20:08:27 -07001374 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1375 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001376
1377 transport->receivePacket(packet.wireEncode());
1378
1379 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1380 BOOST_CHECK(receivedNacks.empty());
1381}
1382
Eric Newberryee400b52016-11-24 14:12:48 +00001383BOOST_AUTO_TEST_SUITE_END() // LpFields
Eric Newberrya98bf932015-09-21 00:58:47 -07001384
Eric Newberrya1939ba2015-10-09 12:35:03 -07001385BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets
1386
1387BOOST_AUTO_TEST_CASE(WrongTlvType)
1388{
1389 // Initialize with Options that disables all services
1390 GenericLinkService::Options options;
1391 options.allowLocalFields = false;
1392 initialize(options);
1393
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001394 auto packet = ndn::encoding::makeEmptyBlock(tlv::Name);
1395 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001396
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001397 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001398 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1399 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1400 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1401}
1402
1403BOOST_AUTO_TEST_CASE(Unparsable)
1404{
1405 // Initialize with Options that disables all services
1406 GenericLinkService::Options options;
1407 options.allowLocalFields = false;
1408 initialize(options);
1409
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001410 auto packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x");
Eric Newberrya1939ba2015-10-09 12:35:03 -07001411 BOOST_CHECK_THROW(packet.parse(), tlv::Error);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001412 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001413
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001414 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001415 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1416 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1417 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1418}
1419
1420BOOST_AUTO_TEST_SUITE_END() // Malformed
1421
Eric Newberry86d31872015-09-23 16:24:59 -07001422BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService
1423BOOST_AUTO_TEST_SUITE_END() // Face
Eric Newberrya98bf932015-09-21 00:58:47 -07001424
1425} // namespace tests
1426} // namespace face
1427} // namespace nfd