blob: 8346a314e1855f8bdbacbc9273388adcf5d681a6 [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
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>
Eric Newberrya98bf932015-09-21 00:58:47 -070037
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040038namespace nfd::tests {
Eric Newberrya98bf932015-09-21 00:58:47 -070039
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040040using namespace nfd::face;
Eric Newberrya98bf932015-09-21 00:58:47 -070041
42BOOST_AUTO_TEST_SUITE(Face)
43
Junxiao Shicde37ad2015-12-24 01:02:05 -070044using nfd::Face;
45
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040046class GenericLinkServiceFixture : public GlobalIoTimeFixture, public KeyChainFixture
Eric Newberrya98bf932015-09-21 00:58:47 -070047{
48protected:
49 GenericLinkServiceFixture()
Eric Newberrya98bf932015-09-21 00:58:47 -070050 {
Eric Newberrya98bf932015-09-21 00:58:47 -070051 // By default, GenericLinkService is created with default options.
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040052 // Test cases may invoke initialize() with alternate options.
53 initialize({});
Eric Newberrya98bf932015-09-21 00:58:47 -070054 }
55
56 void
Eric Newberryb49313d2017-12-24 20:22:27 -070057 initialize(const GenericLinkService::Options& options,
58 ssize_t mtu = MTU_UNLIMITED,
59 ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED)
Eric Newberrya98bf932015-09-21 00:58:47 -070060 {
Davide Pesaventoe4b22382018-06-10 14:37:24 -040061 face = make_unique<Face>(make_unique<GenericLinkService>(options),
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040062 make_unique<DummyTransport>("dummy://", "dummy://",
Davide Pesaventoe4b22382018-06-10 14:37:24 -040063 ndn::nfd::FACE_SCOPE_NON_LOCAL,
64 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
65 ndn::nfd::LINK_TYPE_POINT_TO_POINT,
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040066 mtu, sendQueueCapacity));
Eric Newberrya98bf932015-09-21 00:58:47 -070067 service = static_cast<GenericLinkService*>(face->getLinkService());
68 transport = static_cast<DummyTransport*>(face->getTransport());
69
70 face->afterReceiveInterest.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000071 [this] (const Interest& interest, const EndpointId&) { receivedInterests.push_back(interest); });
Eric Newberrya98bf932015-09-21 00:58:47 -070072 face->afterReceiveData.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000073 [this] (const Data& data, const EndpointId&) { receivedData.push_back(data); });
Eric Newberrya98bf932015-09-21 00:58:47 -070074 face->afterReceiveNack.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000075 [this] (const lp::Nack& nack, const EndpointId&) { receivedNacks.push_back(nack); });
Eric Newberrya98bf932015-09-21 00:58:47 -070076 }
77
Teng Liangbce3cb52018-09-05 20:08:27 -070078 lp::PrefixAnnouncementHeader
79 makePrefixAnnHeader(const Name& announcedName)
80 {
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040081 return lp::PrefixAnnouncementHeader{signPrefixAnn(makePrefixAnn(announcedName, 1_h),
82 m_keyChain, ndn::signingWithSha256())};
Teng Liangbce3cb52018-09-05 20:08:27 -070083 }
84
Eric Newberrya98bf932015-09-21 00:58:47 -070085protected:
Junxiao Shicde37ad2015-12-24 01:02:05 -070086 unique_ptr<Face> face;
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040087 GenericLinkService* service = nullptr;
88 DummyTransport* transport = nullptr;
Eric Newberrya98bf932015-09-21 00:58:47 -070089 std::vector<Interest> receivedInterests;
90 std::vector<Data> receivedData;
91 std::vector<lp::Nack> receivedNacks;
92};
93
94BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture)
95
Eric Newberrya98bf932015-09-21 00:58:47 -070096BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields
97
98BOOST_AUTO_TEST_CASE(SendInterest)
99{
Eric Newberry86d31872015-09-23 16:24:59 -0700100 // Initialize with Options that disables all services
101 GenericLinkService::Options options;
102 options.allowLocalFields = false;
103 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700104
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400105 auto interest1 = makeInterest("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700106 face->sendInterest(*interest1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700107
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700108 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700109 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700110 lp::Packet interest1pkt(transport->sentPackets.back());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700111 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
112 BOOST_CHECK(!interest1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700113}
114
115BOOST_AUTO_TEST_CASE(SendData)
116{
Eric Newberry86d31872015-09-23 16:24:59 -0700117 // Initialize with Options that disables all services
118 GenericLinkService::Options options;
119 options.allowLocalFields = false;
120 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700121
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400122 auto data1 = makeData("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700123 face->sendData(*data1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700124
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700125 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700126 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700127 lp::Packet data1pkt(transport->sentPackets.back());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700128 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
129 BOOST_CHECK(!data1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700130}
131
Eric Newberrycb6551e2020-03-02 14:12:16 -0800132BOOST_AUTO_TEST_CASE(SendDataOverrideMtu)
133{
134 // Initialize with Options that disables all services and does not override MTU
135 GenericLinkService::Options options;
136 options.allowLocalFields = false;
137 initialize(options);
138
139 BOOST_CHECK_EQUAL(transport->getMtu(), MTU_UNLIMITED);
140 BOOST_CHECK_EQUAL(service->getEffectiveMtu(), MTU_UNLIMITED);
141 BOOST_CHECK_EQUAL(face->getMtu(), MTU_UNLIMITED);
142 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_UNLIMITED), false);
143 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_INVALID), false);
144 // Attempts to override MTU will fail when transport MTU is unlimited
145 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(4000), false);
146
147 // Initialize with Options that disables all services and overrides MTU (Transport MTU 8800)
148 options.overrideMtu = MIN_MTU;
149 initialize(options, ndn::MAX_NDN_PACKET_SIZE);
150
151 // Ensure effective MTU is override value
152 BOOST_CHECK_EQUAL(transport->getMtu(), ndn::MAX_NDN_PACKET_SIZE);
153 BOOST_CHECK_EQUAL(service->getEffectiveMtu(), MIN_MTU);
154 BOOST_CHECK_EQUAL(face->getMtu(), MIN_MTU);
155
156 // Check MTU overrides with Transport MTU finite
157 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_UNLIMITED), false);
158 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_INVALID), false);
159 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MIN_MTU - 1), false);
160 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MIN_MTU), true);
161 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(4000), true);
162 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(20000), true);
163
164 // Send Data with less than MIN_MTU octets
165 auto data1 = makeData("/localhost");
166 BOOST_CHECK_LE(data1->wireEncode().size(), MIN_MTU);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700167 face->sendData(*data1);
Eric Newberrycb6551e2020-03-02 14:12:16 -0800168
169 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
170 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 0);
171
172 // Send Data with more than MIN_MTU octets
173 auto data2 = makeData("/localhost/test/1234567890/1234567890/1234567890/1234567890");
174 BOOST_CHECK_GT(data2->wireEncode().size(), MIN_MTU);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700175 face->sendData(*data2);
Eric Newberrycb6551e2020-03-02 14:12:16 -0800176
177 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 2);
178 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
179
180 // Override MTU greater than the Transport's MTU will not be utilized
181 options.overrideMtu = 5000;
182 initialize(options, 4000);
183 BOOST_CHECK_EQUAL(service->getEffectiveMtu(), 4000);
184 BOOST_CHECK_EQUAL(face->getMtu(), 4000);
185}
186
Eric Newberrya98bf932015-09-21 00:58:47 -0700187BOOST_AUTO_TEST_CASE(SendNack)
188{
Eric Newberry86d31872015-09-23 16:24:59 -0700189 // Initialize with Options that disables all services
190 GenericLinkService::Options options;
191 options.allowLocalFields = false;
192 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700193
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400194 auto nack1 = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 323),
Junxiao Shi9d727852019-05-14 13:44:22 -0600195 lp::NackReason::NO_ROUTE);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700196 face->sendNack(nack1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700197
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700198 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700199 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700200 lp::Packet nack1pkt(transport->sentPackets.back());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700201 BOOST_CHECK(nack1pkt.has<lp::NackField>());
202 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
203 BOOST_CHECK(!nack1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700204}
205
206BOOST_AUTO_TEST_CASE(ReceiveBareInterest)
207{
Eric Newberry86d31872015-09-23 16:24:59 -0700208 // Initialize with Options that disables all services
209 GenericLinkService::Options options;
210 options.allowLocalFields = false;
211 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700212
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400213 auto interest1 = makeInterest("/23Rd9hEiR");
Eric Newberrya98bf932015-09-21 00:58:47 -0700214 transport->receivePacket(interest1->wireEncode());
215
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700216 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700217 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400218 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700219}
220
221BOOST_AUTO_TEST_CASE(ReceiveInterest)
222{
Eric Newberry86d31872015-09-23 16:24:59 -0700223 // Initialize with Options that disables all services
224 GenericLinkService::Options options;
225 options.allowLocalFields = false;
226 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700227
Junxiao Shi9d727852019-05-14 13:44:22 -0600228 auto interest1 = makeInterest("/23Rd9hEiR");
Eric Newberrya98bf932015-09-21 00:58:47 -0700229 lp::Packet lpPacket;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400230 lpPacket.set<lp::FragmentField>({interest1->wireEncode().begin(), interest1->wireEncode().end()});
Eric Newberrya98bf932015-09-21 00:58:47 -0700231 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
232
233 transport->receivePacket(lpPacket.wireEncode());
234
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700235 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700236 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400237 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700238}
239
240BOOST_AUTO_TEST_CASE(ReceiveBareData)
241{
Eric Newberry86d31872015-09-23 16:24:59 -0700242 // Initialize with Options that disables all services
243 GenericLinkService::Options options;
244 options.allowLocalFields = false;
245 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700246
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400247 auto data1 = makeData("/12345678");
Eric Newberrya98bf932015-09-21 00:58:47 -0700248 transport->receivePacket(data1->wireEncode());
249
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700250 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700251 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400252 BOOST_CHECK_EQUAL(receivedData.back().wireEncode(), data1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700253}
254
255BOOST_AUTO_TEST_CASE(ReceiveData)
256{
Eric Newberry86d31872015-09-23 16:24:59 -0700257 // Initialize with Options that disables all services
258 GenericLinkService::Options options;
259 options.allowLocalFields = false;
260 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700261
Junxiao Shi9d727852019-05-14 13:44:22 -0600262 auto data1 = makeData("/12345689");
Eric Newberrya98bf932015-09-21 00:58:47 -0700263 lp::Packet lpPacket;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400264 lpPacket.set<lp::FragmentField>({data1->wireEncode().begin(), data1->wireEncode().end()});
Eric Newberrya98bf932015-09-21 00:58:47 -0700265 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
266
267 transport->receivePacket(lpPacket.wireEncode());
268
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700269 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700270 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400271 BOOST_CHECK_EQUAL(receivedData.back().wireEncode(), data1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700272}
273
274BOOST_AUTO_TEST_CASE(ReceiveNack)
275{
Eric Newberry86d31872015-09-23 16:24:59 -0700276 // Initialize with Options that disables all services
277 GenericLinkService::Options options;
278 options.allowLocalFields = false;
279 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700280
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400281 auto nack1 = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 323),
282 lp::NackReason::NO_ROUTE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700283 lp::Packet lpPacket;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400284 lpPacket.set<lp::FragmentField>({nack1.getInterest().wireEncode().begin(),
285 nack1.getInterest().wireEncode().end()});
Eric Newberrya98bf932015-09-21 00:58:47 -0700286 lpPacket.set<lp::NackField>(nack1.getHeader());
287
288 transport->receivePacket(lpPacket.wireEncode());
289
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700290 BOOST_CHECK_EQUAL(service->getCounters().nInNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700291 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400292 BOOST_CHECK_EQUAL(receivedNacks.back().getReason(), nack1.getReason());
293 BOOST_CHECK_EQUAL(receivedNacks.back().getInterest().wireEncode(), nack1.getInterest().wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700294}
295
Eric Newberrya1939ba2015-10-09 12:35:03 -0700296BOOST_AUTO_TEST_CASE(ReceiveIdlePacket)
297{
298 // Initialize with Options that disables all services
299 GenericLinkService::Options options;
300 options.allowLocalFields = false;
301 initialize(options);
302
303 lp::Packet lpPacket;
304 lpPacket.set<lp::SequenceField>(0);
305
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400306 transport->receivePacket(lpPacket.wireEncode());
Eric Newberrya1939ba2015-10-09 12:35:03 -0700307
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700308 // IDLE packet should be ignored, but is not an error
309 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0);
Eric Newberrya1939ba2015-10-09 12:35:03 -0700310 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
311 BOOST_CHECK_EQUAL(receivedData.size(), 0);
312 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
313}
314
Eric Newberrya98bf932015-09-21 00:58:47 -0700315BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive
316
Eric Newberry86d31872015-09-23 16:24:59 -0700317BOOST_AUTO_TEST_SUITE(Fragmentation)
318
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700319BOOST_AUTO_TEST_CASE(FragmentationDisabledExceedMtuDrop)
320{
321 // Initialize with Options that disable fragmentation
322 GenericLinkService::Options options;
323 options.allowFragmentation = false;
324 initialize(options);
325
326 transport->setMtu(55);
327
Junxiao Shi9d727852019-05-14 13:44:22 -0600328 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700329 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700330
331 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
332 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
333}
334
Eric Newberryf3ee8082020-01-28 13:44:18 -0800335// It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero
336// This test case ensures that packets are dropped if the MTU is zero
337BOOST_AUTO_TEST_CASE(FragmentationDisabledZeroMtuDrop)
338{
339 // Initialize with Options that disable fragmentation
340 GenericLinkService::Options options;
341 options.allowFragmentation = false;
342 initialize(options);
343
344 transport->setMtu(0);
345
346 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700347 face->sendData(*data);
Eric Newberryf3ee8082020-01-28 13:44:18 -0800348
349 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
350 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
351}
352
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700353BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu)
354{
355 // Initialize with Options that enable fragmentation
356 GenericLinkService::Options options;
357 options.allowFragmentation = true;
358 initialize(options);
359
360 transport->setMtu(MTU_UNLIMITED);
361
Junxiao Shi9d727852019-05-14 13:44:22 -0600362 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700363 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700364
365 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
366}
367
368BOOST_AUTO_TEST_CASE(FragmentationUnderMtu)
369{
370 // Initialize with Options that enable fragmentation
371 GenericLinkService::Options options;
372 options.allowFragmentation = true;
373 initialize(options);
374
375 transport->setMtu(105);
376
Junxiao Shi9d727852019-05-14 13:44:22 -0600377 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700378 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700379
380 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
381}
382
383BOOST_AUTO_TEST_CASE(FragmentationOverMtu)
384{
385 // Initialize with Options that enable fragmentation
386 GenericLinkService::Options options;
387 options.allowFragmentation = true;
388 initialize(options);
389
390 transport->setMtu(60);
391
Junxiao Shi9d727852019-05-14 13:44:22 -0600392 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700393 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700394
395 BOOST_CHECK_GT(transport->sentPackets.size(), 1);
396}
397
Eric Newberryf3ee8082020-01-28 13:44:18 -0800398// It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero
399// This test case ensures that packets are dropped if the MTU is zero
400BOOST_AUTO_TEST_CASE(FragmentationZeroMtuDrop)
401{
402 // Initialize with Options that enable fragmentation
403 GenericLinkService::Options options;
404 options.allowFragmentation = true;
405 initialize(options);
406
407 transport->setMtu(0);
408
409 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700410 face->sendData(*data);
Eric Newberryf3ee8082020-01-28 13:44:18 -0800411
412 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
413 BOOST_CHECK_EQUAL(service->getCounters().nFragmentationErrors, 1);
414}
415
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700416BOOST_AUTO_TEST_CASE(ReassembleFragments)
417{
418 // Initialize with Options that enables reassembly
419 GenericLinkService::Options options;
420 options.allowReassembly = true;
421 initialize(options);
422
Junxiao Shi9d727852019-05-14 13:44:22 -0600423 auto interest = makeInterest(
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700424 "/mt7P130BHXmtLm5dwaY5dpUM6SWYNN2B05g7y3UhsQuLvDdnTWdNnTeEiLuW3FAbJRSG3tzQ0UfaSEgG9rvYHmsKtgPMag1Hj4Tr");
425 lp::Packet packet(interest->wireEncode());
426
427 // fragment the packet
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400428 LpFragmenter fragmenter({});
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400429 auto [isOk, frags] = fragmenter.fragmentPacket(packet, 100);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700430 BOOST_REQUIRE(isOk);
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400431 BOOST_TEST(frags.size() > 1);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700432
433 // receive the fragments
434 for (ssize_t fragIndex = frags.size() - 1; fragIndex >= 0; --fragIndex) {
435 size_t sequence = 1000 + fragIndex;
436 frags[fragIndex].add<lp::SequenceField>(sequence);
437
438 transport->receivePacket(frags[fragIndex].wireEncode());
439
440 if (fragIndex > 0) {
441 BOOST_CHECK(receivedInterests.empty());
442 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 1);
443 }
444 else {
445 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400446 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest->wireEncode());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700447 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 0);
448 }
449 }
450}
451
Eric Newberry86d31872015-09-23 16:24:59 -0700452BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex)
453{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700454 // Initialize with Options that disables reassembly
455 GenericLinkService::Options options;
456 options.allowReassembly = false;
457 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700458
Junxiao Shi9d727852019-05-14 13:44:22 -0600459 auto interest = makeInterest("/IgFe6NvH");
Eric Newberry86d31872015-09-23 16:24:59 -0700460 lp::Packet packet(interest->wireEncode());
461 packet.set<lp::FragIndexField>(140);
462
463 transport->receivePacket(packet.wireEncode());
464
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700465 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700466 BOOST_CHECK(receivedInterests.empty());
467}
468
469BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount)
470{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700471 // Initialize with Options that disables reassembly
472 GenericLinkService::Options options;
473 options.allowReassembly = false;
474 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700475
Junxiao Shi9d727852019-05-14 13:44:22 -0600476 auto interest = makeInterest("/SeGmEjvIVX");
Eric Newberry86d31872015-09-23 16:24:59 -0700477 lp::Packet packet(interest->wireEncode());
478 packet.set<lp::FragCountField>(276);
479
480 transport->receivePacket(packet.wireEncode());
481
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700482 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700483 BOOST_CHECK(receivedInterests.empty());
484}
485
486BOOST_AUTO_TEST_SUITE_END() // Fragmentation
487
Eric Newberry185ab292017-03-28 06:45:39 +0000488BOOST_AUTO_TEST_SUITE(Reliability)
489
Eric Newberry7b0071e2017-07-03 17:33:31 +0000490BOOST_AUTO_TEST_CASE(SendInterest)
Eric Newberry185ab292017-03-28 06:45:39 +0000491{
492 // Initialize with Options that enables reliability
493 GenericLinkService::Options options;
494 options.allowLocalFields = false;
495 options.reliabilityOptions.isEnabled = true;
496 initialize(options);
497
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400498 auto interest1 = makeInterest("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700499 face->sendInterest(*interest1);
Eric Newberry185ab292017-03-28 06:45:39 +0000500
501 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
502 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700503 lp::Packet interest1pkt(transport->sentPackets.back());
Eric Newberry185ab292017-03-28 06:45:39 +0000504 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000505 BOOST_CHECK(interest1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000506}
507
Eric Newberry7b0071e2017-07-03 17:33:31 +0000508BOOST_AUTO_TEST_CASE(SendData)
Eric Newberry185ab292017-03-28 06:45:39 +0000509{
510 // Initialize with Options that enables reliability
511 GenericLinkService::Options options;
512 options.allowLocalFields = false;
513 options.reliabilityOptions.isEnabled = true;
514 initialize(options);
515
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400516 auto data1 = makeData("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700517 face->sendData(*data1);
Eric Newberry185ab292017-03-28 06:45:39 +0000518
519 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
520 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700521 lp::Packet data1pkt(transport->sentPackets.back());
Eric Newberry185ab292017-03-28 06:45:39 +0000522 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000523 BOOST_CHECK(data1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000524}
525
Eric Newberry7b0071e2017-07-03 17:33:31 +0000526BOOST_AUTO_TEST_CASE(SendNack)
Eric Newberry185ab292017-03-28 06:45:39 +0000527{
528 // Initialize with Options that enables reliability
529 GenericLinkService::Options options;
530 options.allowLocalFields = false;
531 options.reliabilityOptions.isEnabled = true;
532 initialize(options);
533
Davide Pesaventob7bfcb92022-05-22 23:55:23 -0400534 auto nack1 = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 323),
Junxiao Shi9d727852019-05-14 13:44:22 -0600535 lp::NackReason::NO_ROUTE);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700536 face->sendNack(nack1);
Eric Newberry185ab292017-03-28 06:45:39 +0000537
538 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
539 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700540 lp::Packet nack1pkt(transport->sentPackets.back());
Eric Newberry185ab292017-03-28 06:45:39 +0000541 BOOST_CHECK(nack1pkt.has<lp::NackField>());
542 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000543 BOOST_CHECK(nack1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000544}
545
Eric Newberry32f7eac2020-02-07 14:40:17 -0800546BOOST_AUTO_TEST_CASE(DropDuplicatePacket)
547{
548 // Initialize with Options that enables reliability
549 GenericLinkService::Options options;
550 options.allowLocalFields = false;
551 options.reliabilityOptions.isEnabled = true;
552 initialize(options);
553
554 Interest interest("/test/prefix");
Eric Newberry32f7eac2020-02-07 14:40:17 -0800555 lp::Packet pkt1;
556 pkt1.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()});
557 pkt1.add<lp::SequenceField>(7);
558 pkt1.add<lp::TxSequenceField>(12);
559 transport->receivePacket(pkt1.wireEncode());
560 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
561 BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 0);
562
563 lp::Packet pkt2;
564 pkt2.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()});
565 pkt2.add<lp::SequenceField>(7);
566 pkt2.add<lp::TxSequenceField>(13);
567 transport->receivePacket(pkt2.wireEncode());
568 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
569 BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 1);
570}
571
Eric Newberry185ab292017-03-28 06:45:39 +0000572BOOST_AUTO_TEST_SUITE_END() // Reliability
Eric Newberry86d31872015-09-23 16:24:59 -0700573
Eric Newberryb49313d2017-12-24 20:22:27 -0700574// congestion detection and marking
575BOOST_AUTO_TEST_SUITE(CongestionMark)
576
577BOOST_AUTO_TEST_CASE(NoCongestion)
578{
579 GenericLinkService::Options options;
580 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400581 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700582 initialize(options, MTU_UNLIMITED, 65536);
Davide Pesaventoae430302023-05-11 01:42:46 -0400583 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700584 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
585 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
586
Junxiao Shi9d727852019-05-14 13:44:22 -0600587 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700588
589 // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes
590
591 // no congestion
592 transport->setSendQueueLength(0);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700593 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700594 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700595 lp::Packet pkt1(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700596 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400597 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700598 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
599 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
600
601 // no congestion
602 transport->setSendQueueLength(32768);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700603 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700604 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Teng Liang13d582a2020-07-21 20:23:11 -0700605 lp::Packet pkt2(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700606 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400607 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700608 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
609 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
610}
611
612BOOST_AUTO_TEST_CASE(CongestionCoDel)
613{
614 GenericLinkService::Options options;
615 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400616 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700617 initialize(options, MTU_UNLIMITED, 65536);
Davide Pesaventoae430302023-05-11 01:42:46 -0400618 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700619 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
620 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
621
Junxiao Shi9d727852019-05-14 13:44:22 -0600622 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700623
Klaus Schneider380668b2019-10-02 01:21:13 -0700624 // first congested packet, will not be marked
625 transport->setSendQueueLength(65537);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700626 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700627 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700628 lp::Packet pkt0(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700629 BOOST_REQUIRE_EQUAL(pkt0.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400630 auto nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700631 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700632
633 time::nanoseconds markingInterval(
634 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
635 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
636
637 advanceClocks(markingInterval + 1_ms);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700638 face->sendInterest(*interest);
Teng Liang13d582a2020-07-21 20:23:11 -0700639 lp::Packet pkt1(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700640
641 // First congestion mark appears after one interval (100 ms)
642 BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1);
643 BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1);
Eric Newberryb49313d2017-12-24 20:22:27 -0700644 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
645 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
646
647 // advance clock to half of marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700648 advanceClocks(markingInterval / 2); // 50ms
Eric Newberryb49313d2017-12-24 20:22:27 -0700649
650 // second congested packet, but within marking interval, will not be marked
Klaus Schneider380668b2019-10-02 01:21:13 -0700651 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700652 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700653 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Teng Liang13d582a2020-07-21 20:23:11 -0700654 lp::Packet pkt2(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700655 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700656
657 markingInterval = time::nanoseconds(
658 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
659 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
660 nextMarkTime += markingInterval;
661
Eric Newberryb49313d2017-12-24 20:22:27 -0700662 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700663 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
664 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
665
666 // advance clocks past end of initial interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700667 this->advanceClocks((markingInterval / 2) + 1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700668
669 // first congested packet after waiting marking interval, will be marked
Klaus Schneider380668b2019-10-02 01:21:13 -0700670 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700671 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700672 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4);
Teng Liang13d582a2020-07-21 20:23:11 -0700673 lp::Packet pkt3(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700674 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1);
675 BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700676 markingInterval = time::nanoseconds(
677 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
678 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700679 nextMarkTime += markingInterval;
680 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700681 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
682 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
683
684 // advance clock partway through current marking interval
Klaus Schneider380668b2019-10-02 01:21:13 -0700685 this->advanceClocks(markingInterval - 20_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700686
687 // still congested, but within marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700688 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700689 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700690 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Teng Liang13d582a2020-07-21 20:23:11 -0700691 lp::Packet pkt4(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700692 BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0);
693 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700694 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
695 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
696
697 // advance clocks past end of current marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700698 this->advanceClocks(21_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700699
700 // still congested, after marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700701 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700702 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700703 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6);
Teng Liang13d582a2020-07-21 20:23:11 -0700704 lp::Packet pkt5(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700705 BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1);
706 BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1);
707 markingInterval = time::nanoseconds(
708 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700709 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700710 nextMarkTime += markingInterval;
711 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700712 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
713 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
714
Davide Pesavento14e71f02019-03-28 17:35:25 -0400715 this->advanceClocks(1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700716
717 // still congested, but within marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700718 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700719 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700720 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7);
Teng Liang13d582a2020-07-21 20:23:11 -0700721 lp::Packet pkt6(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700722 BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0);
723 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700724 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
725 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
726
727 this->advanceClocks(markingInterval);
728
729 // still congested, after marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700730 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700731 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700732 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8);
Teng Liang13d582a2020-07-21 20:23:11 -0700733 lp::Packet pkt7(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700734 BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1);
735 BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1);
736 markingInterval = time::nanoseconds(
737 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700738 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700739 nextMarkTime += markingInterval;
740 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700741 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4);
742 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
743
744 // no more congestion
745 transport->setSendQueueLength(30000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700746 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700747 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9);
Teng Liang13d582a2020-07-21 20:23:11 -0700748 lp::Packet pkt8(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700749 BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400750 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700751 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
752 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
753
Davide Pesavento14e71f02019-03-28 17:35:25 -0400754 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700755
756 // send queue congested again, but can't mark packet because within one full interval of last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700757 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700758 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700759 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10);
Teng Liang13d582a2020-07-21 20:23:11 -0700760 lp::Packet pkt9(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700761 BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700762 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
763 markingInterval = time::nanoseconds(
764 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
765 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
766 nextMarkTime = time::steady_clock::now() + markingInterval;
767 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700768 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
769 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
770
771 // advance clock past full 100ms interval since last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700772 this->advanceClocks(markingInterval + 2_ms);
773 BOOST_CHECK_GT(time::steady_clock::now(), nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700774
Klaus Schneider380668b2019-10-02 01:21:13 -0700775 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700776 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700777 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11);
Teng Liang13d582a2020-07-21 20:23:11 -0700778 lp::Packet pkt10(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700779 BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1);
780 BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700781 markingInterval = time::nanoseconds(
782 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
783 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
784 nextMarkTime += markingInterval;
Eric Newberryb49313d2017-12-24 20:22:27 -0700785 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700786 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
787 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
788
789 // advance clock partway through 100ms marking interval
Davide Pesavento14e71f02019-03-28 17:35:25 -0400790 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700791
792 // not marked since within 100ms window before can mark again
Klaus Schneider380668b2019-10-02 01:21:13 -0700793 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700794 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700795 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12);
Teng Liang13d582a2020-07-21 20:23:11 -0700796 lp::Packet pkt11(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700797 BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0);
798 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700799 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
800 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
801
802 // advance clocks past m_nextMarkTime
Davide Pesavento14e71f02019-03-28 17:35:25 -0400803 this->advanceClocks(51_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700804
805 // markable packet, queue length still above threshold
Klaus Schneider380668b2019-10-02 01:21:13 -0700806 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700807 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700808 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13);
Teng Liang13d582a2020-07-21 20:23:11 -0700809 lp::Packet pkt12(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700810 BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1);
811 BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1);
812 markingInterval = time::nanoseconds(
813 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700814 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700815 nextMarkTime += markingInterval;
816 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700817 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
818 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
819
820 // no more congestion
821 transport->setSendQueueLength(10000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700822 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700823 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14);
Teng Liang13d582a2020-07-21 20:23:11 -0700824 lp::Packet pkt13(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700825 BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400826 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700827 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
828 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
829
830 // advance clocks past one full interval since last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700831 this->advanceClocks(102_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700832
833 // start congestion again
Klaus Schneider380668b2019-10-02 01:21:13 -0700834 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700835 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700836 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15);
Teng Liang13d582a2020-07-21 20:23:11 -0700837 lp::Packet pkt14(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700838 BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400839 nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700840 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700841 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
842 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
Eric Newberryb49313d2017-12-24 20:22:27 -0700843
844 // no more congestion, cancel marking interval
845 transport->setSendQueueLength(5000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700846 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700847 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16);
Teng Liang13d582a2020-07-21 20:23:11 -0700848 lp::Packet pkt15(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700849 BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400850 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700851 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700852 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
Eric Newberryb49313d2017-12-24 20:22:27 -0700853}
854
855BOOST_AUTO_TEST_CASE(DefaultThreshold)
856{
857 GenericLinkService::Options options;
858 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400859 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700860 initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED);
Davide Pesaventoae430302023-05-11 01:42:46 -0400861 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700862 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
863 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
864
Junxiao Shi9d727852019-05-14 13:44:22 -0600865 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700866
867 // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure
868 // the queue capacity
869
870 // no congestion
871 transport->setSendQueueLength(0);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700872 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700873 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700874 lp::Packet pkt1(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700875 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400876 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700877 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
878 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
879
880 // no congestion
881 transport->setSendQueueLength(65536);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700882 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700883 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Teng Liang13d582a2020-07-21 20:23:11 -0700884 lp::Packet pkt2(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700885 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400886 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::time_point::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700887 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
888 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
889
Klaus Schneider380668b2019-10-02 01:21:13 -0700890 // first congested (not marked yet) packet
Eric Newberryb49313d2017-12-24 20:22:27 -0700891 transport->setSendQueueLength(65537);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700892 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700893 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Teng Liang13d582a2020-07-21 20:23:11 -0700894 lp::Packet pkt3(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700895 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 0);
Davide Pesaventoae430302023-05-11 01:42:46 -0400896 auto nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700897 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700898 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
899 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700900}
901
902BOOST_AUTO_TEST_SUITE_END() // CongestionMark
903
Eric Newberryee400b52016-11-24 14:12:48 +0000904BOOST_AUTO_TEST_SUITE(LpFields)
Eric Newberrya98bf932015-09-21 00:58:47 -0700905
Eric Newberrya98bf932015-09-21 00:58:47 -0700906BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId)
907{
Eric Newberry86d31872015-09-23 16:24:59 -0700908 // Initialize with Options that enables local fields
909 GenericLinkService::Options options;
910 options.allowLocalFields = true;
911 initialize(options);
912
Junxiao Shi9d727852019-05-14 13:44:22 -0600913 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700914 lp::Packet packet(interest->wireEncode());
915 packet.set<lp::NextHopFaceIdField>(1000);
916
917 transport->receivePacket(packet.wireEncode());
918
919 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400920 auto tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>();
Junxiao Shi0de23a22015-12-03 20:07:02 +0000921 BOOST_REQUIRE(tag != nullptr);
922 BOOST_CHECK_EQUAL(*tag, 1000);
Eric Newberrya98bf932015-09-21 00:58:47 -0700923}
924
925BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled)
926{
Eric Newberry86d31872015-09-23 16:24:59 -0700927 // Initialize with Options that disables local fields
928 GenericLinkService::Options options;
929 options.allowLocalFields = false;
930 initialize(options);
931
Junxiao Shi9d727852019-05-14 13:44:22 -0600932 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700933 lp::Packet packet(interest->wireEncode());
934 packet.set<lp::NextHopFaceIdField>(1000);
935
936 transport->receivePacket(packet.wireEncode());
937
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700938 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700939 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700940}
941
942BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData)
943{
Eric Newberry86d31872015-09-23 16:24:59 -0700944 // Initialize with Options that enables local fields
945 GenericLinkService::Options options;
946 options.allowLocalFields = true;
947 initialize(options);
948
Junxiao Shi9d727852019-05-14 13:44:22 -0600949 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700950 lp::Packet packet(data->wireEncode());
951 packet.set<lp::NextHopFaceIdField>(1000);
952
953 transport->receivePacket(packet.wireEncode());
954
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700955 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700956 BOOST_CHECK(receivedData.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700957}
958
959BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack)
960{
Eric Newberry86d31872015-09-23 16:24:59 -0700961 // Initialize with Options that enables local fields
962 GenericLinkService::Options options;
963 options.allowLocalFields = true;
964 initialize(options);
965
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400966 auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
967 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -0700968 lp::Packet packet;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400969 packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(),
970 nack.getInterest().wireEncode().end()});
Eric Newberry86d31872015-09-23 16:24:59 -0700971 packet.set<lp::NackField>(nack.getHeader());
972 packet.set<lp::NextHopFaceIdField>(1000);
973
974 transport->receivePacket(packet.wireEncode());
975
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700976 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700977 BOOST_CHECK(receivedNacks.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700978}
979
Junxiao Shi6eb02712017-05-27 22:48:02 +0000980BOOST_AUTO_TEST_CASE(ReceiveCachePolicy)
Eric Newberrya98bf932015-09-21 00:58:47 -0700981{
Junxiao Shi6eb02712017-05-27 22:48:02 +0000982 // Initialize with Options that disables local fields
Eric Newberry86d31872015-09-23 16:24:59 -0700983 GenericLinkService::Options options;
Junxiao Shi6eb02712017-05-27 22:48:02 +0000984 options.allowLocalFields = false;
Eric Newberry86d31872015-09-23 16:24:59 -0700985 initialize(options);
Junxiao Shi6eb02712017-05-27 22:48:02 +0000986 // CachePolicy is unprivileged and does not require allowLocalFields option.
Eric Newberry86d31872015-09-23 16:24:59 -0700987
Junxiao Shi9d727852019-05-14 13:44:22 -0600988 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700989 lp::Packet packet(data->wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000990 packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE));
Eric Newberry86d31872015-09-23 16:24:59 -0700991
992 transport->receivePacket(packet.wireEncode());
993
994 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400995 auto tag = receivedData.back().getTag<lp::CachePolicyTag>();
Junxiao Shi0de23a22015-12-03 20:07:02 +0000996 BOOST_REQUIRE(tag != nullptr);
997 BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700998}
999
Junxiao Shi6eb02712017-05-27 22:48:02 +00001000BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest)
Eric Newberrya98bf932015-09-21 00:58:47 -07001001{
Eric Newberry86d31872015-09-23 16:24:59 -07001002 // Initialize with Options that enables local fields
1003 GenericLinkService::Options options;
1004 options.allowLocalFields = true;
1005 initialize(options);
1006
Junxiao Shi9d727852019-05-14 13:44:22 -06001007 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -07001008 lp::Packet packet(interest->wireEncode());
1009 lp::CachePolicy policy;
1010 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
1011 packet.set<lp::CachePolicyField>(policy);
1012
1013 transport->receivePacket(packet.wireEncode());
1014
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001015 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -07001016 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -07001017}
1018
Junxiao Shi6eb02712017-05-27 22:48:02 +00001019BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack)
Eric Newberrya98bf932015-09-21 00:58:47 -07001020{
Eric Newberry86d31872015-09-23 16:24:59 -07001021 // Initialize with Options that enables local fields
1022 GenericLinkService::Options options;
1023 options.allowLocalFields = true;
1024 initialize(options);
1025
Davide Pesaventob7bfcb92022-05-22 23:55:23 -04001026 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
Junxiao Shi9d727852019-05-14 13:44:22 -06001027 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -07001028 lp::Packet packet(nack.getInterest().wireEncode());
1029 packet.set<lp::NackField>(nack.getHeader());
1030 lp::CachePolicy policy;
1031 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
1032 packet.set<lp::CachePolicyField>(policy);
1033
1034 transport->receivePacket(packet.wireEncode());
1035
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001036 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -07001037 BOOST_CHECK(receivedNacks.empty());
1038}
1039
1040BOOST_AUTO_TEST_CASE(SendIncomingFaceId)
1041{
1042 // Initialize with Options that enables local fields
1043 GenericLinkService::Options options;
1044 options.allowLocalFields = true;
1045 initialize(options);
1046
Junxiao Shi9d727852019-05-14 13:44:22 -06001047 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +00001048 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -07001049
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001050 face->sendInterest(*interest);
Eric Newberry86d31872015-09-23 16:24:59 -07001051
1052 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001053 lp::Packet sent(transport->sentPackets.back());
Eric Newberry86d31872015-09-23 16:24:59 -07001054 BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>());
1055 BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000);
1056}
1057
1058BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled)
1059{
1060 // Initialize with Options that disables local fields
1061 GenericLinkService::Options options;
1062 options.allowLocalFields = false;
1063 initialize(options);
1064
Junxiao Shi9d727852019-05-14 13:44:22 -06001065 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +00001066 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -07001067
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001068 face->sendInterest(*interest);
Eric Newberry86d31872015-09-23 16:24:59 -07001069
1070 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001071 lp::Packet sent(transport->sentPackets.back());
Eric Newberry86d31872015-09-23 16:24:59 -07001072 BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>());
1073}
1074
1075BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest)
1076{
1077 // Initialize with Options that enables local fields
1078 GenericLinkService::Options options;
1079 options.allowLocalFields = true;
1080 initialize(options);
1081
Junxiao Shi9d727852019-05-14 13:44:22 -06001082 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -07001083 lp::Packet packet(interest->wireEncode());
1084 packet.set<lp::IncomingFaceIdField>(1000);
1085
1086 transport->receivePacket(packet.wireEncode());
1087
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001088 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001089 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001090 BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001091}
1092
1093BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData)
1094{
1095 // Initialize with Options that enables local fields
1096 GenericLinkService::Options options;
1097 options.allowLocalFields = true;
1098 initialize(options);
1099
Junxiao Shi9d727852019-05-14 13:44:22 -06001100 auto data = makeData("/z1megUh9Bj");
Eric Newberry86d31872015-09-23 16:24:59 -07001101 lp::Packet packet(data->wireEncode());
1102 packet.set<lp::IncomingFaceIdField>(1000);
1103
1104 transport->receivePacket(packet.wireEncode());
1105
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001106 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001107 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001108 BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001109}
1110
1111BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack)
1112{
1113 // Initialize with Options that enables local fields
1114 GenericLinkService::Options options;
1115 options.allowLocalFields = true;
1116 initialize(options);
1117
Davide Pesaventob7bfcb92022-05-22 23:55:23 -04001118 lp::Nack nack = makeNack(*makeInterest("/TPAhdiHz", false, std::nullopt, 278),
Junxiao Shi9d727852019-05-14 13:44:22 -06001119 lp::NackReason::CONGESTION);
Eric Newberry86d31872015-09-23 16:24:59 -07001120 lp::Packet packet(nack.getInterest().wireEncode());
1121 packet.set<lp::NackField>(nack.getHeader());
1122 packet.set<lp::IncomingFaceIdField>(1000);
1123
1124 transport->receivePacket(packet.wireEncode());
1125
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001126 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001127 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001128 BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberrya98bf932015-09-21 00:58:47 -07001129}
1130
Eric Newberryee400b52016-11-24 14:12:48 +00001131BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest)
1132{
Junxiao Shi9d727852019-05-14 13:44:22 -06001133 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001134 interest->setTag(make_shared<lp::CongestionMarkTag>(1));
1135
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001136 face->sendInterest(*interest);
Eric Newberryee400b52016-11-24 14:12:48 +00001137
1138 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001139 lp::Packet sent(transport->sentPackets.back());
Eric Newberryee400b52016-11-24 14:12:48 +00001140 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1141 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1);
1142}
1143
1144BOOST_AUTO_TEST_CASE(SendCongestionMarkData)
1145{
Junxiao Shi9d727852019-05-14 13:44:22 -06001146 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001147 data->setTag(make_shared<lp::CongestionMarkTag>(0));
1148
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001149 face->sendData(*data);
Eric Newberryee400b52016-11-24 14:12:48 +00001150
1151 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001152 lp::Packet sent(transport->sentPackets.back());
Eric Newberryee400b52016-11-24 14:12:48 +00001153 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1154 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0);
1155}
1156
1157BOOST_AUTO_TEST_CASE(SendCongestionMarkNack)
1158{
Davide Pesaventob7bfcb92022-05-22 23:55:23 -04001159 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
Junxiao Shi9d727852019-05-14 13:44:22 -06001160 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001161 nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max()));
1162
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001163 face->sendNack(nack);
Eric Newberryee400b52016-11-24 14:12:48 +00001164
1165 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001166 lp::Packet sent(transport->sentPackets.back());
Eric Newberryee400b52016-11-24 14:12:48 +00001167 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1168 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max());
1169}
1170
1171BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest)
1172{
Junxiao Shi9d727852019-05-14 13:44:22 -06001173 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001174 lp::Packet packet(interest->wireEncode());
1175 packet.set<lp::CongestionMarkField>(1);
1176
1177 transport->receivePacket(packet.wireEncode());
1178
1179 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001180 auto tag = receivedInterests.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001181 BOOST_REQUIRE(tag != nullptr);
1182 BOOST_CHECK_EQUAL(*tag, 1);
1183}
1184
1185BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData)
1186{
Junxiao Shi9d727852019-05-14 13:44:22 -06001187 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001188 lp::Packet packet(data->wireEncode());
1189 packet.set<lp::CongestionMarkField>(1);
1190
1191 transport->receivePacket(packet.wireEncode());
1192
1193 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001194 auto tag = receivedData.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001195 BOOST_REQUIRE(tag != nullptr);
1196 BOOST_CHECK_EQUAL(*tag, 1);
1197}
1198
1199BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack)
1200{
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001201 auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
1202 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001203 lp::Packet packet;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001204 packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(),
1205 nack.getInterest().wireEncode().end()});
Eric Newberryee400b52016-11-24 14:12:48 +00001206 packet.set<lp::NackField>(nack.getHeader());
1207 packet.set<lp::CongestionMarkField>(1);
1208
1209 transport->receivePacket(packet.wireEncode());
1210
1211 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001212 auto tag = receivedNacks.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001213 BOOST_REQUIRE(tag != nullptr);
1214 BOOST_CHECK_EQUAL(*tag, 1);
1215}
1216
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001217BOOST_AUTO_TEST_CASE(SendNonDiscovery)
1218{
1219 GenericLinkService::Options options;
1220 options.allowSelfLearning = true;
1221 initialize(options);
1222
Junxiao Shi9d727852019-05-14 13:44:22 -06001223 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001224 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1225
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001226 face->sendInterest(*interest);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001227
1228 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001229 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001230 BOOST_CHECK(sent.has<lp::NonDiscoveryField>());
1231}
1232
1233BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled)
1234{
1235 GenericLinkService::Options options;
1236 options.allowSelfLearning = false;
1237 initialize(options);
1238
Junxiao Shi9d727852019-05-14 13:44:22 -06001239 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001240 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1241
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001242 face->sendInterest(*interest);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001243
1244 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001245 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001246 BOOST_CHECK(!sent.has<lp::NonDiscoveryField>());
1247}
1248
1249BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery)
1250{
1251 GenericLinkService::Options options;
1252 options.allowSelfLearning = true;
1253 initialize(options);
1254
Junxiao Shi9d727852019-05-14 13:44:22 -06001255 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001256 lp::Packet packet(interest->wireEncode());
1257 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1258
1259 transport->receivePacket(packet.wireEncode());
1260
1261 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001262 auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001263 BOOST_CHECK(tag != nullptr);
1264}
1265
1266BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled)
1267{
1268 GenericLinkService::Options options;
1269 options.allowSelfLearning = false;
1270 initialize(options);
1271
Junxiao Shi9d727852019-05-14 13:44:22 -06001272 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001273 lp::Packet packet(interest->wireEncode());
1274 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1275
1276 transport->receivePacket(packet.wireEncode());
1277
1278 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1279 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001280 auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001281 BOOST_CHECK(tag == nullptr);
1282}
1283
1284BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData)
1285{
1286 GenericLinkService::Options options;
1287 options.allowSelfLearning = true;
1288 initialize(options);
1289
Junxiao Shi9d727852019-05-14 13:44:22 -06001290 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001291 lp::Packet packet(data->wireEncode());
1292 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1293
1294 transport->receivePacket(packet.wireEncode());
1295
1296 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1297 BOOST_CHECK(receivedData.empty());
1298}
1299
1300BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack)
1301{
1302 GenericLinkService::Options options;
1303 options.allowSelfLearning = true;
1304 initialize(options);
1305
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001306 auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
1307 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001308 lp::Packet packet;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001309 packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(),
1310 nack.getInterest().wireEncode().end()});
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001311 packet.set<lp::NackField>(nack.getHeader());
1312 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1313
1314 transport->receivePacket(packet.wireEncode());
1315
1316 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1317 BOOST_CHECK(receivedNacks.empty());
1318}
1319
1320BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement)
1321{
1322 GenericLinkService::Options options;
1323 options.allowSelfLearning = true;
1324 initialize(options);
1325
Junxiao Shi9d727852019-05-14 13:44:22 -06001326 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001327 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1328 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001329
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001330 face->sendData(*data);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001331
1332 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001333 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001334 BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>());
1335}
1336
1337BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled)
1338{
1339 GenericLinkService::Options options;
1340 options.allowSelfLearning = false;
1341 initialize(options);
1342
Junxiao Shi9d727852019-05-14 13:44:22 -06001343 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001344 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1345 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001346
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001347 face->sendData(*data);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001348
1349 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001350 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001351 BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>());
1352}
1353
1354BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement)
1355{
1356 GenericLinkService::Options options;
1357 options.allowSelfLearning = true;
1358 initialize(options);
1359
Junxiao Shi9d727852019-05-14 13:44:22 -06001360 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001361 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001362 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1363 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001364
1365 transport->receivePacket(packet.wireEncode());
1366
1367 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001368 auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangbce3cb52018-09-05 20:08:27 -07001369 BOOST_CHECK_EQUAL(tag->get().getPrefixAnn()->getAnnouncedName(), "/local/ndn/prefix");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001370}
1371
1372BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled)
1373{
1374 GenericLinkService::Options options;
1375 options.allowSelfLearning = false;
1376 initialize(options);
1377
Junxiao Shi9d727852019-05-14 13:44:22 -06001378 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001379 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001380 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1381 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001382
1383 transport->receivePacket(packet.wireEncode());
1384
1385 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1386 BOOST_CHECK_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001387 auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001388 BOOST_CHECK(tag == nullptr);
1389}
1390
1391BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest)
1392{
1393 GenericLinkService::Options options;
1394 options.allowSelfLearning = true;
1395 initialize(options);
1396
Junxiao Shi9d727852019-05-14 13:44:22 -06001397 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001398 lp::Packet packet(interest->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001399 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1400 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001401
1402 transport->receivePacket(packet.wireEncode());
1403
1404 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1405 BOOST_CHECK(receivedInterests.empty());
1406}
1407
1408BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack)
1409{
1410 GenericLinkService::Options options;
1411 options.allowSelfLearning = true;
1412 initialize(options);
1413
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001414 auto nack = makeNack(*makeInterest("/localhost/test", false, std::nullopt, 123),
1415 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001416 lp::Packet packet;
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04001417 packet.set<lp::FragmentField>({nack.getInterest().wireEncode().begin(),
1418 nack.getInterest().wireEncode().end()});
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001419 packet.set<lp::NackField>(nack.getHeader());
Teng Liangbce3cb52018-09-05 20:08:27 -07001420 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1421 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001422
1423 transport->receivePacket(packet.wireEncode());
1424
1425 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1426 BOOST_CHECK(receivedNacks.empty());
1427}
1428
Eric Newberryee400b52016-11-24 14:12:48 +00001429BOOST_AUTO_TEST_SUITE_END() // LpFields
Eric Newberrya98bf932015-09-21 00:58:47 -07001430
Eric Newberrya1939ba2015-10-09 12:35:03 -07001431BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets
1432
1433BOOST_AUTO_TEST_CASE(WrongTlvType)
1434{
1435 // Initialize with Options that disables all services
1436 GenericLinkService::Options options;
1437 options.allowLocalFields = false;
1438 initialize(options);
1439
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001440 auto packet = ndn::encoding::makeEmptyBlock(tlv::Name);
1441 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001442
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001443 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001444 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1445 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1446 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1447}
1448
1449BOOST_AUTO_TEST_CASE(Unparsable)
1450{
1451 // Initialize with Options that disables all services
1452 GenericLinkService::Options options;
1453 options.allowLocalFields = false;
1454 initialize(options);
1455
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001456 auto packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x");
Eric Newberrya1939ba2015-10-09 12:35:03 -07001457 BOOST_CHECK_THROW(packet.parse(), tlv::Error);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001458 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001459
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001460 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001461 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1462 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1463 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1464}
1465
1466BOOST_AUTO_TEST_SUITE_END() // Malformed
1467
Eric Newberry86d31872015-09-23 16:24:59 -07001468BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService
1469BOOST_AUTO_TEST_SUITE_END() // Face
Eric Newberrya98bf932015-09-21 00:58:47 -07001470
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04001471} // namespace nfd::tests