blob: b9657938ec69e29135c8375def3359e5801f297c [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/*
Davide Pesaventoae430302023-05-11 01:42:46 -04003 * Copyright (c) 2014-2023, 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
Davide Pesavento9a63bf22023-11-11 17:12:51 -050034#include <ndn-cxx/lp/fields.hpp>
Eric Newberryb49313d2017-12-24 20:22:27 -070035#include <ndn-cxx/lp/tags.hpp>
Eric Newberrya98bf932015-09-21 00:58:47 -070036
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040037namespace nfd::tests {
Eric Newberrya98bf932015-09-21 00:58:47 -070038
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040039using namespace nfd::face;
Eric Newberrya98bf932015-09-21 00:58:47 -070040
41BOOST_AUTO_TEST_SUITE(Face)
42
Junxiao Shicde37ad2015-12-24 01:02:05 -070043using nfd::Face;
44
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040045class GenericLinkServiceFixture : public GlobalIoTimeFixture, public KeyChainFixture
Eric Newberrya98bf932015-09-21 00:58:47 -070046{
47protected:
48 GenericLinkServiceFixture()
Eric Newberrya98bf932015-09-21 00:58:47 -070049 {
Eric Newberrya98bf932015-09-21 00:58:47 -070050 // By default, GenericLinkService is created with default options.
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040051 // Test cases may invoke initialize() with alternate options.
52 initialize({});
Eric Newberrya98bf932015-09-21 00:58:47 -070053 }
54
55 void
Eric Newberryb49313d2017-12-24 20:22:27 -070056 initialize(const GenericLinkService::Options& options,
57 ssize_t mtu = MTU_UNLIMITED,
58 ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED)
Eric Newberrya98bf932015-09-21 00:58:47 -070059 {
Davide Pesaventoe4b22382018-06-10 14:37:24 -040060 face = make_unique<Face>(make_unique<GenericLinkService>(options),
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040061 make_unique<DummyTransport>("dummy://", "dummy://",
Davide Pesaventoe4b22382018-06-10 14:37:24 -040062 ndn::nfd::FACE_SCOPE_NON_LOCAL,
63 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
64 ndn::nfd::LINK_TYPE_POINT_TO_POINT,
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040065 mtu, sendQueueCapacity));
Eric Newberrya98bf932015-09-21 00:58:47 -070066 service = static_cast<GenericLinkService*>(face->getLinkService());
67 transport = static_cast<DummyTransport*>(face->getTransport());
68
69 face->afterReceiveInterest.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000070 [this] (const Interest& interest, const EndpointId&) { receivedInterests.push_back(interest); });
Eric Newberrya98bf932015-09-21 00:58:47 -070071 face->afterReceiveData.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000072 [this] (const Data& data, const EndpointId&) { receivedData.push_back(data); });
Eric Newberrya98bf932015-09-21 00:58:47 -070073 face->afterReceiveNack.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000074 [this] (const lp::Nack& nack, const EndpointId&) { receivedNacks.push_back(nack); });
Eric Newberrya98bf932015-09-21 00:58:47 -070075 }
76
Teng Liangbce3cb52018-09-05 20:08:27 -070077 lp::PrefixAnnouncementHeader
78 makePrefixAnnHeader(const Name& announcedName)
79 {
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040080 return lp::PrefixAnnouncementHeader{signPrefixAnn(makePrefixAnn(announcedName, 1_h),
81 m_keyChain, ndn::signingWithSha256())};
Teng Liangbce3cb52018-09-05 20:08:27 -070082 }
83
Eric Newberrya98bf932015-09-21 00:58:47 -070084protected:
Junxiao Shicde37ad2015-12-24 01:02:05 -070085 unique_ptr<Face> face;
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040086 GenericLinkService* service = nullptr;
87 DummyTransport* transport = nullptr;
Eric Newberrya98bf932015-09-21 00:58:47 -070088 std::vector<Interest> receivedInterests;
89 std::vector<Data> receivedData;
90 std::vector<lp::Nack> receivedNacks;
91};
92
93BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture)
94
Eric Newberrya98bf932015-09-21 00:58:47 -070095BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields
96
97BOOST_AUTO_TEST_CASE(SendInterest)
98{
Eric Newberry86d31872015-09-23 16:24:59 -070099 // Initialize with Options that disables all services
100 GenericLinkService::Options options;
101 options.allowLocalFields = false;
102 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700103
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400104 auto interest1 = makeInterest("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700105 face->sendInterest(*interest1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700106
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700107 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700108 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700109 lp::Packet interest1pkt(transport->sentPackets.back());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700110 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
111 BOOST_CHECK(!interest1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700112}
113
114BOOST_AUTO_TEST_CASE(SendData)
115{
Eric Newberry86d31872015-09-23 16:24:59 -0700116 // Initialize with Options that disables all services
117 GenericLinkService::Options options;
118 options.allowLocalFields = false;
119 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700120
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400121 auto data1 = makeData("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700122 face->sendData(*data1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700123
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700124 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700125 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700126 lp::Packet data1pkt(transport->sentPackets.back());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700127 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
128 BOOST_CHECK(!data1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700129}
130
Eric Newberrycb6551e2020-03-02 14:12:16 -0800131BOOST_AUTO_TEST_CASE(SendDataOverrideMtu)
132{
133 // Initialize with Options that disables all services and does not override MTU
134 GenericLinkService::Options options;
135 options.allowLocalFields = false;
136 initialize(options);
137
138 BOOST_CHECK_EQUAL(transport->getMtu(), MTU_UNLIMITED);
139 BOOST_CHECK_EQUAL(service->getEffectiveMtu(), MTU_UNLIMITED);
140 BOOST_CHECK_EQUAL(face->getMtu(), MTU_UNLIMITED);
141 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_UNLIMITED), false);
142 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_INVALID), false);
143 // Attempts to override MTU will fail when transport MTU is unlimited
144 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(4000), false);
145
146 // Initialize with Options that disables all services and overrides MTU (Transport MTU 8800)
147 options.overrideMtu = MIN_MTU;
148 initialize(options, ndn::MAX_NDN_PACKET_SIZE);
149
150 // Ensure effective MTU is override value
151 BOOST_CHECK_EQUAL(transport->getMtu(), ndn::MAX_NDN_PACKET_SIZE);
152 BOOST_CHECK_EQUAL(service->getEffectiveMtu(), MIN_MTU);
153 BOOST_CHECK_EQUAL(face->getMtu(), MIN_MTU);
154
155 // Check MTU overrides with Transport MTU finite
156 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_UNLIMITED), false);
157 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_INVALID), false);
158 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MIN_MTU - 1), false);
159 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MIN_MTU), true);
160 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(4000), true);
161 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(20000), true);
162
163 // Send Data with less than MIN_MTU octets
164 auto data1 = makeData("/localhost");
165 BOOST_CHECK_LE(data1->wireEncode().size(), MIN_MTU);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700166 face->sendData(*data1);
Eric Newberrycb6551e2020-03-02 14:12:16 -0800167
168 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
169 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 0);
170
171 // Send Data with more than MIN_MTU octets
172 auto data2 = makeData("/localhost/test/1234567890/1234567890/1234567890/1234567890");
173 BOOST_CHECK_GT(data2->wireEncode().size(), MIN_MTU);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700174 face->sendData(*data2);
Eric Newberrycb6551e2020-03-02 14:12:16 -0800175
176 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 2);
177 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
178
179 // Override MTU greater than the Transport's MTU will not be utilized
180 options.overrideMtu = 5000;
181 initialize(options, 4000);
182 BOOST_CHECK_EQUAL(service->getEffectiveMtu(), 4000);
183 BOOST_CHECK_EQUAL(face->getMtu(), 4000);
184}
185
Eric Newberrya98bf932015-09-21 00:58:47 -0700186BOOST_AUTO_TEST_CASE(SendNack)
187{
Eric Newberry86d31872015-09-23 16:24:59 -0700188 // Initialize with Options that disables all services
189 GenericLinkService::Options options;
190 options.allowLocalFields = false;
191 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700192
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400193 auto nack1 = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 323),
Junxiao Shi9d727852019-05-14 13:44:22 -0600194 lp::NackReason::NO_ROUTE);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700195 face->sendNack(nack1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700196
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700197 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700198 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700199 lp::Packet nack1pkt(transport->sentPackets.back());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700200 BOOST_CHECK(nack1pkt.has<lp::NackField>());
201 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
202 BOOST_CHECK(!nack1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700203}
204
205BOOST_AUTO_TEST_CASE(ReceiveBareInterest)
206{
Eric Newberry86d31872015-09-23 16:24:59 -0700207 // Initialize with Options that disables all services
208 GenericLinkService::Options options;
209 options.allowLocalFields = false;
210 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700211
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400212 auto interest1 = makeInterest("/23Rd9hEiR");
Eric Newberrya98bf932015-09-21 00:58:47 -0700213 transport->receivePacket(interest1->wireEncode());
214
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700215 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700216 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400217 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700218}
219
220BOOST_AUTO_TEST_CASE(ReceiveInterest)
221{
Eric Newberry86d31872015-09-23 16:24:59 -0700222 // Initialize with Options that disables all services
223 GenericLinkService::Options options;
224 options.allowLocalFields = false;
225 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700226
Junxiao Shi9d727852019-05-14 13:44:22 -0600227 auto interest1 = makeInterest("/23Rd9hEiR");
Eric Newberrya98bf932015-09-21 00:58:47 -0700228 lp::Packet lpPacket;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400229 lpPacket.set<lp::FragmentField>({interest1->wireEncode().begin(), interest1->wireEncode().end()});
Eric Newberrya98bf932015-09-21 00:58:47 -0700230 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
231
232 transport->receivePacket(lpPacket.wireEncode());
233
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700234 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700235 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400236 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700237}
238
239BOOST_AUTO_TEST_CASE(ReceiveBareData)
240{
Eric Newberry86d31872015-09-23 16:24:59 -0700241 // Initialize with Options that disables all services
242 GenericLinkService::Options options;
243 options.allowLocalFields = false;
244 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700245
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400246 auto data1 = makeData("/12345678");
Eric Newberrya98bf932015-09-21 00:58:47 -0700247 transport->receivePacket(data1->wireEncode());
248
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700249 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700250 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400251 BOOST_CHECK_EQUAL(receivedData.back().wireEncode(), data1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700252}
253
254BOOST_AUTO_TEST_CASE(ReceiveData)
255{
Eric Newberry86d31872015-09-23 16:24:59 -0700256 // Initialize with Options that disables all services
257 GenericLinkService::Options options;
258 options.allowLocalFields = false;
259 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700260
Junxiao Shi9d727852019-05-14 13:44:22 -0600261 auto data1 = makeData("/12345689");
Eric Newberrya98bf932015-09-21 00:58:47 -0700262 lp::Packet lpPacket;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400263 lpPacket.set<lp::FragmentField>({data1->wireEncode().begin(), data1->wireEncode().end()});
Eric Newberrya98bf932015-09-21 00:58:47 -0700264 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
265
266 transport->receivePacket(lpPacket.wireEncode());
267
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700268 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700269 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400270 BOOST_CHECK_EQUAL(receivedData.back().wireEncode(), data1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700271}
272
273BOOST_AUTO_TEST_CASE(ReceiveNack)
274{
Eric Newberry86d31872015-09-23 16:24:59 -0700275 // Initialize with Options that disables all services
276 GenericLinkService::Options options;
277 options.allowLocalFields = false;
278 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700279
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400280 auto nack1 = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 323),
281 lp::NackReason::NO_ROUTE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700282 lp::Packet lpPacket;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400283 lpPacket.set<lp::FragmentField>({nack1.getInterest().wireEncode().begin(),
284 nack1.getInterest().wireEncode().end()});
Eric Newberrya98bf932015-09-21 00:58:47 -0700285 lpPacket.set<lp::NackField>(nack1.getHeader());
286
287 transport->receivePacket(lpPacket.wireEncode());
288
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700289 BOOST_CHECK_EQUAL(service->getCounters().nInNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700290 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400291 BOOST_CHECK_EQUAL(receivedNacks.back().getReason(), nack1.getReason());
292 BOOST_CHECK_EQUAL(receivedNacks.back().getInterest().wireEncode(), nack1.getInterest().wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700293}
294
Eric Newberrya1939ba2015-10-09 12:35:03 -0700295BOOST_AUTO_TEST_CASE(ReceiveIdlePacket)
296{
297 // Initialize with Options that disables all services
298 GenericLinkService::Options options;
299 options.allowLocalFields = false;
300 initialize(options);
301
302 lp::Packet lpPacket;
303 lpPacket.set<lp::SequenceField>(0);
304
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400305 transport->receivePacket(lpPacket.wireEncode());
Eric Newberrya1939ba2015-10-09 12:35:03 -0700306
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700307 // IDLE packet should be ignored, but is not an error
308 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0);
Eric Newberrya1939ba2015-10-09 12:35:03 -0700309 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
310 BOOST_CHECK_EQUAL(receivedData.size(), 0);
311 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
312}
313
Eric Newberrya98bf932015-09-21 00:58:47 -0700314BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive
315
Eric Newberry86d31872015-09-23 16:24:59 -0700316BOOST_AUTO_TEST_SUITE(Fragmentation)
317
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700318BOOST_AUTO_TEST_CASE(FragmentationDisabledExceedMtuDrop)
319{
320 // Initialize with Options that disable fragmentation
321 GenericLinkService::Options options;
322 options.allowFragmentation = false;
323 initialize(options);
324
325 transport->setMtu(55);
326
Junxiao Shi9d727852019-05-14 13:44:22 -0600327 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700328 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700329
330 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
331 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
332}
333
Eric Newberryf3ee8082020-01-28 13:44:18 -0800334// It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero
335// This test case ensures that packets are dropped if the MTU is zero
336BOOST_AUTO_TEST_CASE(FragmentationDisabledZeroMtuDrop)
337{
338 // Initialize with Options that disable fragmentation
339 GenericLinkService::Options options;
340 options.allowFragmentation = false;
341 initialize(options);
342
343 transport->setMtu(0);
344
345 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700346 face->sendData(*data);
Eric Newberryf3ee8082020-01-28 13:44:18 -0800347
348 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
349 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
350}
351
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700352BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu)
353{
354 // Initialize with Options that enable fragmentation
355 GenericLinkService::Options options;
356 options.allowFragmentation = true;
357 initialize(options);
358
359 transport->setMtu(MTU_UNLIMITED);
360
Junxiao Shi9d727852019-05-14 13:44:22 -0600361 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700362 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700363
364 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
365}
366
367BOOST_AUTO_TEST_CASE(FragmentationUnderMtu)
368{
369 // Initialize with Options that enable fragmentation
370 GenericLinkService::Options options;
371 options.allowFragmentation = true;
372 initialize(options);
373
374 transport->setMtu(105);
375
Junxiao Shi9d727852019-05-14 13:44:22 -0600376 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700377 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700378
379 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
380}
381
382BOOST_AUTO_TEST_CASE(FragmentationOverMtu)
383{
384 // Initialize with Options that enable fragmentation
385 GenericLinkService::Options options;
386 options.allowFragmentation = true;
387 initialize(options);
388
389 transport->setMtu(60);
390
Junxiao Shi9d727852019-05-14 13:44:22 -0600391 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700392 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700393
394 BOOST_CHECK_GT(transport->sentPackets.size(), 1);
395}
396
Eric Newberryf3ee8082020-01-28 13:44:18 -0800397// It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero
398// This test case ensures that packets are dropped if the MTU is zero
399BOOST_AUTO_TEST_CASE(FragmentationZeroMtuDrop)
400{
401 // Initialize with Options that enable fragmentation
402 GenericLinkService::Options options;
403 options.allowFragmentation = true;
404 initialize(options);
405
406 transport->setMtu(0);
407
408 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700409 face->sendData(*data);
Eric Newberryf3ee8082020-01-28 13:44:18 -0800410
411 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
412 BOOST_CHECK_EQUAL(service->getCounters().nFragmentationErrors, 1);
413}
414
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700415BOOST_AUTO_TEST_CASE(ReassembleFragments)
416{
417 // Initialize with Options that enables reassembly
418 GenericLinkService::Options options;
419 options.allowReassembly = true;
420 initialize(options);
421
Junxiao Shi9d727852019-05-14 13:44:22 -0600422 auto interest = makeInterest(
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700423 "/mt7P130BHXmtLm5dwaY5dpUM6SWYNN2B05g7y3UhsQuLvDdnTWdNnTeEiLuW3FAbJRSG3tzQ0UfaSEgG9rvYHmsKtgPMag1Hj4Tr");
424 lp::Packet packet(interest->wireEncode());
425
426 // fragment the packet
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400427 LpFragmenter fragmenter({});
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400428 auto [isOk, frags] = fragmenter.fragmentPacket(packet, 100);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700429 BOOST_REQUIRE(isOk);
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400430 BOOST_TEST(frags.size() > 1);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700431
432 // receive the fragments
433 for (ssize_t fragIndex = frags.size() - 1; fragIndex >= 0; --fragIndex) {
434 size_t sequence = 1000 + fragIndex;
435 frags[fragIndex].add<lp::SequenceField>(sequence);
436
437 transport->receivePacket(frags[fragIndex].wireEncode());
438
439 if (fragIndex > 0) {
440 BOOST_CHECK(receivedInterests.empty());
441 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 1);
442 }
443 else {
444 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400445 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest->wireEncode());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700446 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 0);
447 }
448 }
449}
450
Eric Newberry86d31872015-09-23 16:24:59 -0700451BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex)
452{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700453 // Initialize with Options that disables reassembly
454 GenericLinkService::Options options;
455 options.allowReassembly = false;
456 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700457
Junxiao Shi9d727852019-05-14 13:44:22 -0600458 auto interest = makeInterest("/IgFe6NvH");
Eric Newberry86d31872015-09-23 16:24:59 -0700459 lp::Packet packet(interest->wireEncode());
460 packet.set<lp::FragIndexField>(140);
461
462 transport->receivePacket(packet.wireEncode());
463
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700464 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700465 BOOST_CHECK(receivedInterests.empty());
466}
467
468BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount)
469{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700470 // Initialize with Options that disables reassembly
471 GenericLinkService::Options options;
472 options.allowReassembly = false;
473 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700474
Junxiao Shi9d727852019-05-14 13:44:22 -0600475 auto interest = makeInterest("/SeGmEjvIVX");
Eric Newberry86d31872015-09-23 16:24:59 -0700476 lp::Packet packet(interest->wireEncode());
477 packet.set<lp::FragCountField>(276);
478
479 transport->receivePacket(packet.wireEncode());
480
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700481 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700482 BOOST_CHECK(receivedInterests.empty());
483}
484
485BOOST_AUTO_TEST_SUITE_END() // Fragmentation
486
Eric Newberry185ab292017-03-28 06:45:39 +0000487BOOST_AUTO_TEST_SUITE(Reliability)
488
Eric Newberry7b0071e2017-07-03 17:33:31 +0000489BOOST_AUTO_TEST_CASE(SendInterest)
Eric Newberry185ab292017-03-28 06:45:39 +0000490{
491 // Initialize with Options that enables reliability
492 GenericLinkService::Options options;
493 options.allowLocalFields = false;
494 options.reliabilityOptions.isEnabled = true;
495 initialize(options);
496
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400497 auto interest1 = makeInterest("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700498 face->sendInterest(*interest1);
Eric Newberry185ab292017-03-28 06:45:39 +0000499
500 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
501 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700502 lp::Packet interest1pkt(transport->sentPackets.back());
Eric Newberry185ab292017-03-28 06:45:39 +0000503 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000504 BOOST_CHECK(interest1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000505}
506
Eric Newberry7b0071e2017-07-03 17:33:31 +0000507BOOST_AUTO_TEST_CASE(SendData)
Eric Newberry185ab292017-03-28 06:45:39 +0000508{
509 // Initialize with Options that enables reliability
510 GenericLinkService::Options options;
511 options.allowLocalFields = false;
512 options.reliabilityOptions.isEnabled = true;
513 initialize(options);
514
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400515 auto data1 = makeData("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700516 face->sendData(*data1);
Eric Newberry185ab292017-03-28 06:45:39 +0000517
518 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
519 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700520 lp::Packet data1pkt(transport->sentPackets.back());
Eric Newberry185ab292017-03-28 06:45:39 +0000521 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000522 BOOST_CHECK(data1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000523}
524
Eric Newberry7b0071e2017-07-03 17:33:31 +0000525BOOST_AUTO_TEST_CASE(SendNack)
Eric Newberry185ab292017-03-28 06:45:39 +0000526{
527 // Initialize with Options that enables reliability
528 GenericLinkService::Options options;
529 options.allowLocalFields = false;
530 options.reliabilityOptions.isEnabled = true;
531 initialize(options);
532
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400533 auto nack1 = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 323),
Junxiao Shi9d727852019-05-14 13:44:22 -0600534 lp::NackReason::NO_ROUTE);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700535 face->sendNack(nack1);
Eric Newberry185ab292017-03-28 06:45:39 +0000536
537 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
538 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700539 lp::Packet nack1pkt(transport->sentPackets.back());
Eric Newberry185ab292017-03-28 06:45:39 +0000540 BOOST_CHECK(nack1pkt.has<lp::NackField>());
541 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000542 BOOST_CHECK(nack1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000543}
544
Eric Newberry32f7eac2020-02-07 14:40:17 -0800545BOOST_AUTO_TEST_CASE(DropDuplicatePacket)
546{
547 // Initialize with Options that enables reliability
548 GenericLinkService::Options options;
549 options.allowLocalFields = false;
550 options.reliabilityOptions.isEnabled = true;
551 initialize(options);
552
553 Interest interest("/test/prefix");
Eric Newberry32f7eac2020-02-07 14:40:17 -0800554 lp::Packet pkt1;
555 pkt1.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()});
556 pkt1.add<lp::SequenceField>(7);
557 pkt1.add<lp::TxSequenceField>(12);
558 transport->receivePacket(pkt1.wireEncode());
559 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
560 BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 0);
561
562 lp::Packet pkt2;
563 pkt2.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()});
564 pkt2.add<lp::SequenceField>(7);
565 pkt2.add<lp::TxSequenceField>(13);
566 transport->receivePacket(pkt2.wireEncode());
567 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
568 BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 1);
569}
570
Eric Newberry185ab292017-03-28 06:45:39 +0000571BOOST_AUTO_TEST_SUITE_END() // Reliability
Eric Newberry86d31872015-09-23 16:24:59 -0700572
Eric Newberryb49313d2017-12-24 20:22:27 -0700573// congestion detection and marking
574BOOST_AUTO_TEST_SUITE(CongestionMark)
575
576BOOST_AUTO_TEST_CASE(NoCongestion)
577{
578 GenericLinkService::Options options;
579 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400580 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700581 initialize(options, MTU_UNLIMITED, 65536);
Davide Pesaventoae430302023-05-11 01:42:46 -0400582 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700583 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
584 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
585
Junxiao Shi9d727852019-05-14 13:44:22 -0600586 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700587
588 // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes
589
590 // no congestion
591 transport->setSendQueueLength(0);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700592 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700593 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700594 lp::Packet pkt1(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700595 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400596 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700597 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
598 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
599
600 // no congestion
601 transport->setSendQueueLength(32768);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700602 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700603 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Teng Liang13d582a2020-07-21 20:23:11 -0700604 lp::Packet pkt2(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700605 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400606 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700607 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
608 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
609}
610
611BOOST_AUTO_TEST_CASE(CongestionCoDel)
612{
613 GenericLinkService::Options options;
614 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400615 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700616 initialize(options, MTU_UNLIMITED, 65536);
Davide Pesaventoae430302023-05-11 01:42:46 -0400617 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700618 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
619 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
620
Junxiao Shi9d727852019-05-14 13:44:22 -0600621 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700622
Klaus Schneider380668b2019-10-02 01:21:13 -0700623 // first congested packet, will not be marked
624 transport->setSendQueueLength(65537);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700625 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700626 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700627 lp::Packet pkt0(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700628 BOOST_REQUIRE_EQUAL(pkt0.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400629 auto nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700630 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700631
632 time::nanoseconds markingInterval(
633 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
634 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
635
636 advanceClocks(markingInterval + 1_ms);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700637 face->sendInterest(*interest);
Teng Liang13d582a2020-07-21 20:23:11 -0700638 lp::Packet pkt1(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700639
640 // First congestion mark appears after one interval (100 ms)
641 BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1);
642 BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1);
Eric Newberryb49313d2017-12-24 20:22:27 -0700643 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
644 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
645
646 // advance clock to half of marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700647 advanceClocks(markingInterval / 2); // 50ms
Eric Newberryb49313d2017-12-24 20:22:27 -0700648
649 // second congested packet, but within marking interval, will not be marked
Klaus Schneider380668b2019-10-02 01:21:13 -0700650 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700651 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700652 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Teng Liang13d582a2020-07-21 20:23:11 -0700653 lp::Packet pkt2(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700654 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700655
656 markingInterval = time::nanoseconds(
657 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
658 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
659 nextMarkTime += markingInterval;
660
Eric Newberryb49313d2017-12-24 20:22:27 -0700661 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700662 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
663 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
664
665 // advance clocks past end of initial interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700666 this->advanceClocks((markingInterval / 2) + 1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700667
668 // first congested packet after waiting marking interval, will be marked
Klaus Schneider380668b2019-10-02 01:21:13 -0700669 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700670 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700671 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4);
Teng Liang13d582a2020-07-21 20:23:11 -0700672 lp::Packet pkt3(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700673 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1);
674 BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700675 markingInterval = time::nanoseconds(
676 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
677 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700678 nextMarkTime += markingInterval;
679 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700680 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
681 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
682
683 // advance clock partway through current marking interval
Klaus Schneider380668b2019-10-02 01:21:13 -0700684 this->advanceClocks(markingInterval - 20_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700685
686 // still congested, but within marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700687 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700688 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700689 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Teng Liang13d582a2020-07-21 20:23:11 -0700690 lp::Packet pkt4(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700691 BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0);
692 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700693 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
694 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
695
696 // advance clocks past end of current marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700697 this->advanceClocks(21_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700698
699 // still congested, after marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700700 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700701 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700702 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6);
Teng Liang13d582a2020-07-21 20:23:11 -0700703 lp::Packet pkt5(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700704 BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1);
705 BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1);
706 markingInterval = time::nanoseconds(
707 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700708 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700709 nextMarkTime += markingInterval;
710 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700711 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
712 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
713
Davide Pesavento14e71f02019-03-28 17:35:25 -0400714 this->advanceClocks(1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700715
716 // still congested, but within marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700717 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700718 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700719 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7);
Teng Liang13d582a2020-07-21 20:23:11 -0700720 lp::Packet pkt6(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700721 BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0);
722 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700723 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
724 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
725
726 this->advanceClocks(markingInterval);
727
728 // still congested, after marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700729 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700730 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700731 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8);
Teng Liang13d582a2020-07-21 20:23:11 -0700732 lp::Packet pkt7(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700733 BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1);
734 BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1);
735 markingInterval = time::nanoseconds(
736 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700737 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700738 nextMarkTime += markingInterval;
739 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700740 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4);
741 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
742
743 // no more congestion
744 transport->setSendQueueLength(30000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700745 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700746 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9);
Teng Liang13d582a2020-07-21 20:23:11 -0700747 lp::Packet pkt8(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700748 BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400749 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700750 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
751 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
752
Davide Pesavento14e71f02019-03-28 17:35:25 -0400753 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700754
755 // send queue congested again, but can't mark packet because within one full interval of last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700756 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700757 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700758 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10);
Teng Liang13d582a2020-07-21 20:23:11 -0700759 lp::Packet pkt9(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700760 BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700761 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
762 markingInterval = time::nanoseconds(
763 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
764 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
765 nextMarkTime = time::steady_clock::now() + markingInterval;
766 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700767 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
768 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
769
770 // advance clock past full 100ms interval since last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700771 this->advanceClocks(markingInterval + 2_ms);
772 BOOST_CHECK_GT(time::steady_clock::now(), nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700773
Klaus Schneider380668b2019-10-02 01:21:13 -0700774 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700775 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700776 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11);
Teng Liang13d582a2020-07-21 20:23:11 -0700777 lp::Packet pkt10(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700778 BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1);
779 BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700780 markingInterval = time::nanoseconds(
781 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
782 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
783 nextMarkTime += markingInterval;
Eric Newberryb49313d2017-12-24 20:22:27 -0700784 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700785 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
786 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
787
788 // advance clock partway through 100ms marking interval
Davide Pesavento14e71f02019-03-28 17:35:25 -0400789 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700790
791 // not marked since within 100ms window before can mark again
Klaus Schneider380668b2019-10-02 01:21:13 -0700792 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700793 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700794 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12);
Teng Liang13d582a2020-07-21 20:23:11 -0700795 lp::Packet pkt11(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700796 BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0);
797 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700798 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
799 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
800
801 // advance clocks past m_nextMarkTime
Davide Pesavento14e71f02019-03-28 17:35:25 -0400802 this->advanceClocks(51_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700803
804 // markable packet, queue length still above threshold
Klaus Schneider380668b2019-10-02 01:21:13 -0700805 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700806 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700807 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13);
Teng Liang13d582a2020-07-21 20:23:11 -0700808 lp::Packet pkt12(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700809 BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1);
810 BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1);
811 markingInterval = time::nanoseconds(
812 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700813 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700814 nextMarkTime += markingInterval;
815 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700816 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
817 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
818
819 // no more congestion
820 transport->setSendQueueLength(10000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700821 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700822 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14);
Teng Liang13d582a2020-07-21 20:23:11 -0700823 lp::Packet pkt13(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700824 BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400825 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700826 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
827 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
828
829 // advance clocks past one full interval since last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700830 this->advanceClocks(102_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700831
832 // start congestion again
Klaus Schneider380668b2019-10-02 01:21:13 -0700833 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700834 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700835 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15);
Teng Liang13d582a2020-07-21 20:23:11 -0700836 lp::Packet pkt14(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700837 BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400838 nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700839 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700840 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
841 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
Eric Newberryb49313d2017-12-24 20:22:27 -0700842
843 // no more congestion, cancel marking interval
844 transport->setSendQueueLength(5000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700845 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700846 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16);
Teng Liang13d582a2020-07-21 20:23:11 -0700847 lp::Packet pkt15(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700848 BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400849 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700850 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700851 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
Eric Newberryb49313d2017-12-24 20:22:27 -0700852}
853
854BOOST_AUTO_TEST_CASE(DefaultThreshold)
855{
856 GenericLinkService::Options options;
857 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400858 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700859 initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED);
Davide Pesaventoae430302023-05-11 01:42:46 -0400860 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700861 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
862 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
863
Junxiao Shi9d727852019-05-14 13:44:22 -0600864 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700865
866 // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure
867 // the queue capacity
868
869 // no congestion
870 transport->setSendQueueLength(0);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700871 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700872 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700873 lp::Packet pkt1(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700874 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400875 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700876 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
877 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
878
879 // no congestion
880 transport->setSendQueueLength(65536);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700881 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700882 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Teng Liang13d582a2020-07-21 20:23:11 -0700883 lp::Packet pkt2(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700884 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400885 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700886 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
887 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
888
Klaus Schneider380668b2019-10-02 01:21:13 -0700889 // first congested (not marked yet) packet
Eric Newberryb49313d2017-12-24 20:22:27 -0700890 transport->setSendQueueLength(65537);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700891 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700892 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Teng Liang13d582a2020-07-21 20:23:11 -0700893 lp::Packet pkt3(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700894 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400895 auto nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700896 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700897 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
898 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700899}
900
901BOOST_AUTO_TEST_SUITE_END() // CongestionMark
902
Eric Newberryee400b52016-11-24 14:12:48 +0000903BOOST_AUTO_TEST_SUITE(LpFields)
Eric Newberrya98bf932015-09-21 00:58:47 -0700904
Eric Newberrya98bf932015-09-21 00:58:47 -0700905BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId)
906{
Eric Newberry86d31872015-09-23 16:24:59 -0700907 // Initialize with Options that enables local fields
908 GenericLinkService::Options options;
909 options.allowLocalFields = true;
910 initialize(options);
911
Junxiao Shi9d727852019-05-14 13:44:22 -0600912 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700913 lp::Packet packet(interest->wireEncode());
914 packet.set<lp::NextHopFaceIdField>(1000);
915
916 transport->receivePacket(packet.wireEncode());
917
918 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400919 auto tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>();
Junxiao Shi0de23a22015-12-03 20:07:02 +0000920 BOOST_REQUIRE(tag != nullptr);
921 BOOST_CHECK_EQUAL(*tag, 1000);
Eric Newberrya98bf932015-09-21 00:58:47 -0700922}
923
924BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled)
925{
Eric Newberry86d31872015-09-23 16:24:59 -0700926 // Initialize with Options that disables local fields
927 GenericLinkService::Options options;
928 options.allowLocalFields = false;
929 initialize(options);
930
Junxiao Shi9d727852019-05-14 13:44:22 -0600931 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700932 lp::Packet packet(interest->wireEncode());
933 packet.set<lp::NextHopFaceIdField>(1000);
934
935 transport->receivePacket(packet.wireEncode());
936
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700937 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700938 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700939}
940
941BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData)
942{
Eric Newberry86d31872015-09-23 16:24:59 -0700943 // Initialize with Options that enables local fields
944 GenericLinkService::Options options;
945 options.allowLocalFields = true;
946 initialize(options);
947
Junxiao Shi9d727852019-05-14 13:44:22 -0600948 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700949 lp::Packet packet(data->wireEncode());
950 packet.set<lp::NextHopFaceIdField>(1000);
951
952 transport->receivePacket(packet.wireEncode());
953
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700954 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700955 BOOST_CHECK(receivedData.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700956}
957
958BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack)
959{
Eric Newberry86d31872015-09-23 16:24:59 -0700960 // Initialize with Options that enables local fields
961 GenericLinkService::Options options;
962 options.allowLocalFields = true;
963 initialize(options);
964
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400965 auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
966 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -0700967 lp::Packet packet;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400968 packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(),
969 nack.getInterest().wireEncode().end()});
Eric Newberry86d31872015-09-23 16:24:59 -0700970 packet.set<lp::NackField>(nack.getHeader());
971 packet.set<lp::NextHopFaceIdField>(1000);
972
973 transport->receivePacket(packet.wireEncode());
974
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700975 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700976 BOOST_CHECK(receivedNacks.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700977}
978
Junxiao Shi6eb02712017-05-27 22:48:02 +0000979BOOST_AUTO_TEST_CASE(ReceiveCachePolicy)
Eric Newberrya98bf932015-09-21 00:58:47 -0700980{
Junxiao Shi6eb02712017-05-27 22:48:02 +0000981 // Initialize with Options that disables local fields
Eric Newberry86d31872015-09-23 16:24:59 -0700982 GenericLinkService::Options options;
Junxiao Shi6eb02712017-05-27 22:48:02 +0000983 options.allowLocalFields = false;
Eric Newberry86d31872015-09-23 16:24:59 -0700984 initialize(options);
Junxiao Shi6eb02712017-05-27 22:48:02 +0000985 // CachePolicy is unprivileged and does not require allowLocalFields option.
Eric Newberry86d31872015-09-23 16:24:59 -0700986
Junxiao Shi9d727852019-05-14 13:44:22 -0600987 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700988 lp::Packet packet(data->wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000989 packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE));
Eric Newberry86d31872015-09-23 16:24:59 -0700990
991 transport->receivePacket(packet.wireEncode());
992
993 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400994 auto tag = receivedData.back().getTag<lp::CachePolicyTag>();
Junxiao Shi0de23a22015-12-03 20:07:02 +0000995 BOOST_REQUIRE(tag != nullptr);
996 BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700997}
998
Junxiao Shi6eb02712017-05-27 22:48:02 +0000999BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest)
Eric Newberrya98bf932015-09-21 00:58:47 -07001000{
Eric Newberry86d31872015-09-23 16:24:59 -07001001 // Initialize with Options that enables local fields
1002 GenericLinkService::Options options;
1003 options.allowLocalFields = true;
1004 initialize(options);
1005
Junxiao Shi9d727852019-05-14 13:44:22 -06001006 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -07001007 lp::Packet packet(interest->wireEncode());
1008 lp::CachePolicy policy;
1009 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
1010 packet.set<lp::CachePolicyField>(policy);
1011
1012 transport->receivePacket(packet.wireEncode());
1013
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001014 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -07001015 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -07001016}
1017
Junxiao Shi6eb02712017-05-27 22:48:02 +00001018BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack)
Eric Newberrya98bf932015-09-21 00:58:47 -07001019{
Eric Newberry86d31872015-09-23 16:24:59 -07001020 // Initialize with Options that enables local fields
1021 GenericLinkService::Options options;
1022 options.allowLocalFields = true;
1023 initialize(options);
1024
Davide Pesaventob7bfcb92022-05-22 23:55:23 -04001025 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
Junxiao Shi9d727852019-05-14 13:44:22 -06001026 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -07001027 lp::Packet packet(nack.getInterest().wireEncode());
1028 packet.set<lp::NackField>(nack.getHeader());
1029 lp::CachePolicy policy;
1030 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
1031 packet.set<lp::CachePolicyField>(policy);
1032
1033 transport->receivePacket(packet.wireEncode());
1034
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001035 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -07001036 BOOST_CHECK(receivedNacks.empty());
1037}
1038
1039BOOST_AUTO_TEST_CASE(SendIncomingFaceId)
1040{
1041 // Initialize with Options that enables local fields
1042 GenericLinkService::Options options;
1043 options.allowLocalFields = true;
1044 initialize(options);
1045
Junxiao Shi9d727852019-05-14 13:44:22 -06001046 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +00001047 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -07001048
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001049 face->sendInterest(*interest);
Eric Newberry86d31872015-09-23 16:24:59 -07001050
1051 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001052 lp::Packet sent(transport->sentPackets.back());
Eric Newberry86d31872015-09-23 16:24:59 -07001053 BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>());
1054 BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000);
1055}
1056
1057BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled)
1058{
1059 // Initialize with Options that disables local fields
1060 GenericLinkService::Options options;
1061 options.allowLocalFields = false;
1062 initialize(options);
1063
Junxiao Shi9d727852019-05-14 13:44:22 -06001064 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +00001065 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -07001066
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001067 face->sendInterest(*interest);
Eric Newberry86d31872015-09-23 16:24:59 -07001068
1069 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001070 lp::Packet sent(transport->sentPackets.back());
Eric Newberry86d31872015-09-23 16:24:59 -07001071 BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>());
1072}
1073
1074BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest)
1075{
1076 // Initialize with Options that enables local fields
1077 GenericLinkService::Options options;
1078 options.allowLocalFields = true;
1079 initialize(options);
1080
Junxiao Shi9d727852019-05-14 13:44:22 -06001081 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -07001082 lp::Packet packet(interest->wireEncode());
1083 packet.set<lp::IncomingFaceIdField>(1000);
1084
1085 transport->receivePacket(packet.wireEncode());
1086
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001087 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001088 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001089 BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001090}
1091
1092BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData)
1093{
1094 // Initialize with Options that enables local fields
1095 GenericLinkService::Options options;
1096 options.allowLocalFields = true;
1097 initialize(options);
1098
Junxiao Shi9d727852019-05-14 13:44:22 -06001099 auto data = makeData("/z1megUh9Bj");
Eric Newberry86d31872015-09-23 16:24:59 -07001100 lp::Packet packet(data->wireEncode());
1101 packet.set<lp::IncomingFaceIdField>(1000);
1102
1103 transport->receivePacket(packet.wireEncode());
1104
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001105 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001106 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001107 BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001108}
1109
1110BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack)
1111{
1112 // Initialize with Options that enables local fields
1113 GenericLinkService::Options options;
1114 options.allowLocalFields = true;
1115 initialize(options);
1116
Davide Pesaventob7bfcb92022-05-22 23:55:23 -04001117 lp::Nack nack = makeNack(*makeInterest("/TPAhdiHz", false, std::nullopt, 278),
Junxiao Shi9d727852019-05-14 13:44:22 -06001118 lp::NackReason::CONGESTION);
Eric Newberry86d31872015-09-23 16:24:59 -07001119 lp::Packet packet(nack.getInterest().wireEncode());
1120 packet.set<lp::NackField>(nack.getHeader());
1121 packet.set<lp::IncomingFaceIdField>(1000);
1122
1123 transport->receivePacket(packet.wireEncode());
1124
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001125 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001126 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001127 BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberrya98bf932015-09-21 00:58:47 -07001128}
1129
Eric Newberryee400b52016-11-24 14:12:48 +00001130BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest)
1131{
Junxiao Shi9d727852019-05-14 13:44:22 -06001132 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001133 interest->setTag(make_shared<lp::CongestionMarkTag>(1));
1134
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001135 face->sendInterest(*interest);
Eric Newberryee400b52016-11-24 14:12:48 +00001136
1137 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001138 lp::Packet sent(transport->sentPackets.back());
Eric Newberryee400b52016-11-24 14:12:48 +00001139 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1140 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1);
1141}
1142
1143BOOST_AUTO_TEST_CASE(SendCongestionMarkData)
1144{
Junxiao Shi9d727852019-05-14 13:44:22 -06001145 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001146 data->setTag(make_shared<lp::CongestionMarkTag>(0));
1147
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001148 face->sendData(*data);
Eric Newberryee400b52016-11-24 14:12:48 +00001149
1150 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001151 lp::Packet sent(transport->sentPackets.back());
Eric Newberryee400b52016-11-24 14:12:48 +00001152 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1153 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0);
1154}
1155
1156BOOST_AUTO_TEST_CASE(SendCongestionMarkNack)
1157{
Davide Pesaventob7bfcb92022-05-22 23:55:23 -04001158 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
Junxiao Shi9d727852019-05-14 13:44:22 -06001159 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001160 nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max()));
1161
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001162 face->sendNack(nack);
Eric Newberryee400b52016-11-24 14:12:48 +00001163
1164 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001165 lp::Packet sent(transport->sentPackets.back());
Eric Newberryee400b52016-11-24 14:12:48 +00001166 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1167 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max());
1168}
1169
1170BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest)
1171{
Junxiao Shi9d727852019-05-14 13:44:22 -06001172 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001173 lp::Packet packet(interest->wireEncode());
1174 packet.set<lp::CongestionMarkField>(1);
1175
1176 transport->receivePacket(packet.wireEncode());
1177
1178 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001179 auto tag = receivedInterests.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001180 BOOST_REQUIRE(tag != nullptr);
1181 BOOST_CHECK_EQUAL(*tag, 1);
1182}
1183
1184BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData)
1185{
Junxiao Shi9d727852019-05-14 13:44:22 -06001186 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001187 lp::Packet packet(data->wireEncode());
1188 packet.set<lp::CongestionMarkField>(1);
1189
1190 transport->receivePacket(packet.wireEncode());
1191
1192 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001193 auto tag = receivedData.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001194 BOOST_REQUIRE(tag != nullptr);
1195 BOOST_CHECK_EQUAL(*tag, 1);
1196}
1197
1198BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack)
1199{
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001200 auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
1201 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001202 lp::Packet packet;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001203 packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(),
1204 nack.getInterest().wireEncode().end()});
Eric Newberryee400b52016-11-24 14:12:48 +00001205 packet.set<lp::NackField>(nack.getHeader());
1206 packet.set<lp::CongestionMarkField>(1);
1207
1208 transport->receivePacket(packet.wireEncode());
1209
1210 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001211 auto tag = receivedNacks.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001212 BOOST_REQUIRE(tag != nullptr);
1213 BOOST_CHECK_EQUAL(*tag, 1);
1214}
1215
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001216BOOST_AUTO_TEST_CASE(SendNonDiscovery)
1217{
1218 GenericLinkService::Options options;
1219 options.allowSelfLearning = true;
1220 initialize(options);
1221
Junxiao Shi9d727852019-05-14 13:44:22 -06001222 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001223 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1224
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001225 face->sendInterest(*interest);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001226
1227 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001228 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001229 BOOST_CHECK(sent.has<lp::NonDiscoveryField>());
1230}
1231
1232BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled)
1233{
1234 GenericLinkService::Options options;
1235 options.allowSelfLearning = false;
1236 initialize(options);
1237
Junxiao Shi9d727852019-05-14 13:44:22 -06001238 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001239 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1240
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001241 face->sendInterest(*interest);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001242
1243 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001244 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001245 BOOST_CHECK(!sent.has<lp::NonDiscoveryField>());
1246}
1247
1248BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery)
1249{
1250 GenericLinkService::Options options;
1251 options.allowSelfLearning = true;
1252 initialize(options);
1253
Junxiao Shi9d727852019-05-14 13:44:22 -06001254 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001255 lp::Packet packet(interest->wireEncode());
1256 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1257
1258 transport->receivePacket(packet.wireEncode());
1259
1260 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001261 auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001262 BOOST_CHECK(tag != nullptr);
1263}
1264
1265BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled)
1266{
1267 GenericLinkService::Options options;
1268 options.allowSelfLearning = false;
1269 initialize(options);
1270
Junxiao Shi9d727852019-05-14 13:44:22 -06001271 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001272 lp::Packet packet(interest->wireEncode());
1273 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1274
1275 transport->receivePacket(packet.wireEncode());
1276
1277 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1278 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001279 auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001280 BOOST_CHECK(tag == nullptr);
1281}
1282
1283BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData)
1284{
1285 GenericLinkService::Options options;
1286 options.allowSelfLearning = true;
1287 initialize(options);
1288
Junxiao Shi9d727852019-05-14 13:44:22 -06001289 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001290 lp::Packet packet(data->wireEncode());
1291 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1292
1293 transport->receivePacket(packet.wireEncode());
1294
1295 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1296 BOOST_CHECK(receivedData.empty());
1297}
1298
1299BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack)
1300{
1301 GenericLinkService::Options options;
1302 options.allowSelfLearning = true;
1303 initialize(options);
1304
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001305 auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
1306 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001307 lp::Packet packet;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001308 packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(),
1309 nack.getInterest().wireEncode().end()});
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001310 packet.set<lp::NackField>(nack.getHeader());
1311 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1312
1313 transport->receivePacket(packet.wireEncode());
1314
1315 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1316 BOOST_CHECK(receivedNacks.empty());
1317}
1318
1319BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement)
1320{
1321 GenericLinkService::Options options;
1322 options.allowSelfLearning = true;
1323 initialize(options);
1324
Junxiao Shi9d727852019-05-14 13:44:22 -06001325 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001326 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1327 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001328
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001329 face->sendData(*data);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001330
1331 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001332 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001333 BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>());
1334}
1335
1336BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled)
1337{
1338 GenericLinkService::Options options;
1339 options.allowSelfLearning = false;
1340 initialize(options);
1341
Junxiao Shi9d727852019-05-14 13:44:22 -06001342 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001343 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1344 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001345
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001346 face->sendData(*data);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001347
1348 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001349 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001350 BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>());
1351}
1352
1353BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement)
1354{
1355 GenericLinkService::Options options;
1356 options.allowSelfLearning = true;
1357 initialize(options);
1358
Junxiao Shi9d727852019-05-14 13:44:22 -06001359 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001360 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001361 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1362 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001363
1364 transport->receivePacket(packet.wireEncode());
1365
1366 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001367 auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangbce3cb52018-09-05 20:08:27 -07001368 BOOST_CHECK_EQUAL(tag->get().getPrefixAnn()->getAnnouncedName(), "/local/ndn/prefix");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001369}
1370
1371BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled)
1372{
1373 GenericLinkService::Options options;
1374 options.allowSelfLearning = false;
1375 initialize(options);
1376
Junxiao Shi9d727852019-05-14 13:44:22 -06001377 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001378 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001379 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1380 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001381
1382 transport->receivePacket(packet.wireEncode());
1383
1384 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1385 BOOST_CHECK_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001386 auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001387 BOOST_CHECK(tag == nullptr);
1388}
1389
1390BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest)
1391{
1392 GenericLinkService::Options options;
1393 options.allowSelfLearning = true;
1394 initialize(options);
1395
Junxiao Shi9d727852019-05-14 13:44:22 -06001396 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001397 lp::Packet packet(interest->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001398 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1399 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001400
1401 transport->receivePacket(packet.wireEncode());
1402
1403 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1404 BOOST_CHECK(receivedInterests.empty());
1405}
1406
1407BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack)
1408{
1409 GenericLinkService::Options options;
1410 options.allowSelfLearning = true;
1411 initialize(options);
1412
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001413 auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
1414 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001415 lp::Packet packet;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001416 packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(),
1417 nack.getInterest().wireEncode().end()});
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001418 packet.set<lp::NackField>(nack.getHeader());
Teng Liangbce3cb52018-09-05 20:08:27 -07001419 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1420 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001421
1422 transport->receivePacket(packet.wireEncode());
1423
1424 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1425 BOOST_CHECK(receivedNacks.empty());
1426}
1427
Eric Newberryee400b52016-11-24 14:12:48 +00001428BOOST_AUTO_TEST_SUITE_END() // LpFields
Eric Newberrya98bf932015-09-21 00:58:47 -07001429
Eric Newberrya1939ba2015-10-09 12:35:03 -07001430BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets
1431
1432BOOST_AUTO_TEST_CASE(WrongTlvType)
1433{
1434 // Initialize with Options that disables all services
1435 GenericLinkService::Options options;
1436 options.allowLocalFields = false;
1437 initialize(options);
1438
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001439 auto packet = ndn::encoding::makeEmptyBlock(tlv::Name);
1440 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001441
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001442 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001443 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1444 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1445 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1446}
1447
1448BOOST_AUTO_TEST_CASE(Unparsable)
1449{
1450 // Initialize with Options that disables all services
1451 GenericLinkService::Options options;
1452 options.allowLocalFields = false;
1453 initialize(options);
1454
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001455 auto packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x");
Eric Newberrya1939ba2015-10-09 12:35:03 -07001456 BOOST_CHECK_THROW(packet.parse(), tlv::Error);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001457 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001458
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001459 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001460 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1461 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1462 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1463}
1464
1465BOOST_AUTO_TEST_SUITE_END() // Malformed
1466
Eric Newberry86d31872015-09-23 16:24:59 -07001467BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService
1468BOOST_AUTO_TEST_SUITE_END() // Face
Eric Newberrya98bf932015-09-21 00:58:47 -07001469
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04001470} // namespace nfd::tests