blob: a11d524fdc8a2b28aecc824a4324bbba7a50222f [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry7b0071e2017-07-03 17:33:31 +00002/*
Eric Newberryf3ee8082020-01-28 13:44:18 -08003 * Copyright (c) 2014-2020, Regents of the University of California,
Eric Newberrya98bf932015-09-21 00:58:47 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "face/generic-link-service.hpp"
Junxiao Shicde37ad2015-12-24 01:02:05 -070027#include "face/face.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070028
Davide Pesavento0064c1d2018-03-03 18:43:53 -050029#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040030#include "tests/key-chain-fixture.hpp"
31#include "tests/daemon/global-io-fixture.hpp"
32#include "dummy-transport.hpp"
Eric Newberryb49313d2017-12-24 20:22:27 -070033
Teng Liangfdcbb4d2018-01-27 16:01:35 -070034#include <ndn-cxx/lp/empty-value.hpp>
Teng Liangbce3cb52018-09-05 20:08:27 -070035#include <ndn-cxx/lp/prefix-announcement-header.hpp>
Eric Newberryb49313d2017-12-24 20:22:27 -070036#include <ndn-cxx/lp/tags.hpp>
Eric Newberrya98bf932015-09-21 00:58:47 -070037
38namespace nfd {
39namespace face {
40namespace tests {
41
42using namespace nfd::tests;
43
44BOOST_AUTO_TEST_SUITE(Face)
45
Junxiao Shicde37ad2015-12-24 01:02:05 -070046using nfd::Face;
47
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040048class GenericLinkServiceFixture : public GlobalIoTimeFixture, public KeyChainFixture
Eric Newberrya98bf932015-09-21 00:58:47 -070049{
50protected:
51 GenericLinkServiceFixture()
Eric Newberrya98bf932015-09-21 00:58:47 -070052 {
Eric Newberrya98bf932015-09-21 00:58:47 -070053 // By default, GenericLinkService is created with default options.
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040054 // Test cases may invoke initialize() with alternate options.
55 initialize({});
Eric Newberrya98bf932015-09-21 00:58:47 -070056 }
57
58 void
Eric Newberryb49313d2017-12-24 20:22:27 -070059 initialize(const GenericLinkService::Options& options,
60 ssize_t mtu = MTU_UNLIMITED,
61 ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED)
Eric Newberrya98bf932015-09-21 00:58:47 -070062 {
Davide Pesaventoe4b22382018-06-10 14:37:24 -040063 face = make_unique<Face>(make_unique<GenericLinkService>(options),
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040064 make_unique<DummyTransport>("dummy://", "dummy://",
Davide Pesaventoe4b22382018-06-10 14:37:24 -040065 ndn::nfd::FACE_SCOPE_NON_LOCAL,
66 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
67 ndn::nfd::LINK_TYPE_POINT_TO_POINT,
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040068 mtu, sendQueueCapacity));
Eric Newberrya98bf932015-09-21 00:58:47 -070069 service = static_cast<GenericLinkService*>(face->getLinkService());
70 transport = static_cast<DummyTransport*>(face->getTransport());
71
72 face->afterReceiveInterest.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000073 [this] (const Interest& interest, const EndpointId&) { receivedInterests.push_back(interest); });
Eric Newberrya98bf932015-09-21 00:58:47 -070074 face->afterReceiveData.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000075 [this] (const Data& data, const EndpointId&) { receivedData.push_back(data); });
Eric Newberrya98bf932015-09-21 00:58:47 -070076 face->afterReceiveNack.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000077 [this] (const lp::Nack& nack, const EndpointId&) { receivedNacks.push_back(nack); });
Eric Newberrya98bf932015-09-21 00:58:47 -070078 }
79
Teng Liangbce3cb52018-09-05 20:08:27 -070080 lp::PrefixAnnouncementHeader
81 makePrefixAnnHeader(const Name& announcedName)
82 {
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040083 return lp::PrefixAnnouncementHeader{signPrefixAnn(makePrefixAnn(announcedName, 1_h),
84 m_keyChain, ndn::signingWithSha256())};
Teng Liangbce3cb52018-09-05 20:08:27 -070085 }
86
Eric Newberrya98bf932015-09-21 00:58:47 -070087protected:
Junxiao Shicde37ad2015-12-24 01:02:05 -070088 unique_ptr<Face> face;
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040089 GenericLinkService* service = nullptr;
90 DummyTransport* transport = nullptr;
Eric Newberrya98bf932015-09-21 00:58:47 -070091 std::vector<Interest> receivedInterests;
92 std::vector<Data> receivedData;
93 std::vector<lp::Nack> receivedNacks;
94};
95
96BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture)
97
Eric Newberrya98bf932015-09-21 00:58:47 -070098BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields
99
100BOOST_AUTO_TEST_CASE(SendInterest)
101{
Eric Newberry86d31872015-09-23 16:24:59 -0700102 // Initialize with Options that disables all services
103 GenericLinkService::Options options;
104 options.allowLocalFields = false;
105 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700106
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400107 auto interest1 = makeInterest("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700108 face->sendInterest(*interest1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700109
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700110 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700111 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700112 lp::Packet interest1pkt(transport->sentPackets.back());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700113 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
114 BOOST_CHECK(!interest1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700115}
116
117BOOST_AUTO_TEST_CASE(SendData)
118{
Eric Newberry86d31872015-09-23 16:24:59 -0700119 // Initialize with Options that disables all services
120 GenericLinkService::Options options;
121 options.allowLocalFields = false;
122 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700123
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400124 auto data1 = makeData("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700125 face->sendData(*data1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700126
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700127 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700128 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700129 lp::Packet data1pkt(transport->sentPackets.back());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700130 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
131 BOOST_CHECK(!data1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700132}
133
Eric Newberrycb6551e2020-03-02 14:12:16 -0800134BOOST_AUTO_TEST_CASE(SendDataOverrideMtu)
135{
136 // Initialize with Options that disables all services and does not override MTU
137 GenericLinkService::Options options;
138 options.allowLocalFields = false;
139 initialize(options);
140
141 BOOST_CHECK_EQUAL(transport->getMtu(), MTU_UNLIMITED);
142 BOOST_CHECK_EQUAL(service->getEffectiveMtu(), MTU_UNLIMITED);
143 BOOST_CHECK_EQUAL(face->getMtu(), MTU_UNLIMITED);
144 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_UNLIMITED), false);
145 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_INVALID), false);
146 // Attempts to override MTU will fail when transport MTU is unlimited
147 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(4000), false);
148
149 // Initialize with Options that disables all services and overrides MTU (Transport MTU 8800)
150 options.overrideMtu = MIN_MTU;
151 initialize(options, ndn::MAX_NDN_PACKET_SIZE);
152
153 // Ensure effective MTU is override value
154 BOOST_CHECK_EQUAL(transport->getMtu(), ndn::MAX_NDN_PACKET_SIZE);
155 BOOST_CHECK_EQUAL(service->getEffectiveMtu(), MIN_MTU);
156 BOOST_CHECK_EQUAL(face->getMtu(), MIN_MTU);
157
158 // Check MTU overrides with Transport MTU finite
159 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_UNLIMITED), false);
160 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MTU_INVALID), false);
161 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MIN_MTU - 1), false);
162 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(MIN_MTU), true);
163 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(4000), true);
164 BOOST_CHECK_EQUAL(service->canOverrideMtuTo(20000), true);
165
166 // Send Data with less than MIN_MTU octets
167 auto data1 = makeData("/localhost");
168 BOOST_CHECK_LE(data1->wireEncode().size(), MIN_MTU);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700169 face->sendData(*data1);
Eric Newberrycb6551e2020-03-02 14:12:16 -0800170
171 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
172 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 0);
173
174 // Send Data with more than MIN_MTU octets
175 auto data2 = makeData("/localhost/test/1234567890/1234567890/1234567890/1234567890");
176 BOOST_CHECK_GT(data2->wireEncode().size(), MIN_MTU);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700177 face->sendData(*data2);
Eric Newberrycb6551e2020-03-02 14:12:16 -0800178
179 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 2);
180 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
181
182 // Override MTU greater than the Transport's MTU will not be utilized
183 options.overrideMtu = 5000;
184 initialize(options, 4000);
185 BOOST_CHECK_EQUAL(service->getEffectiveMtu(), 4000);
186 BOOST_CHECK_EQUAL(face->getMtu(), 4000);
187}
188
Eric Newberrya98bf932015-09-21 00:58:47 -0700189BOOST_AUTO_TEST_CASE(SendNack)
190{
Eric Newberry86d31872015-09-23 16:24:59 -0700191 // Initialize with Options that disables all services
192 GenericLinkService::Options options;
193 options.allowLocalFields = false;
194 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700195
Junxiao Shi9d727852019-05-14 13:44:22 -0600196 auto nack1 = makeNack(*makeInterest("/localhost/test", false, nullopt, 323),
197 lp::NackReason::NO_ROUTE);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700198 face->sendNack(nack1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700199
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700200 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700201 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700202 lp::Packet nack1pkt(transport->sentPackets.back());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700203 BOOST_CHECK(nack1pkt.has<lp::NackField>());
204 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
205 BOOST_CHECK(!nack1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700206}
207
208BOOST_AUTO_TEST_CASE(ReceiveBareInterest)
209{
Eric Newberry86d31872015-09-23 16:24:59 -0700210 // Initialize with Options that disables all services
211 GenericLinkService::Options options;
212 options.allowLocalFields = false;
213 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700214
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400215 auto interest1 = makeInterest("/23Rd9hEiR");
Eric Newberrya98bf932015-09-21 00:58:47 -0700216 transport->receivePacket(interest1->wireEncode());
217
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700218 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700219 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400220 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700221}
222
223BOOST_AUTO_TEST_CASE(ReceiveInterest)
224{
Eric Newberry86d31872015-09-23 16:24:59 -0700225 // Initialize with Options that disables all services
226 GenericLinkService::Options options;
227 options.allowLocalFields = false;
228 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700229
Junxiao Shi9d727852019-05-14 13:44:22 -0600230 auto interest1 = makeInterest("/23Rd9hEiR");
Eric Newberrya98bf932015-09-21 00:58:47 -0700231 lp::Packet lpPacket;
232 lpPacket.set<lp::FragmentField>(std::make_pair(
233 interest1->wireEncode().begin(), interest1->wireEncode().end()));
234 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
235
236 transport->receivePacket(lpPacket.wireEncode());
237
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700238 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700239 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400240 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700241}
242
243BOOST_AUTO_TEST_CASE(ReceiveBareData)
244{
Eric Newberry86d31872015-09-23 16:24:59 -0700245 // Initialize with Options that disables all services
246 GenericLinkService::Options options;
247 options.allowLocalFields = false;
248 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700249
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400250 auto data1 = makeData("/12345678");
Eric Newberrya98bf932015-09-21 00:58:47 -0700251 transport->receivePacket(data1->wireEncode());
252
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700253 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700254 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400255 BOOST_CHECK_EQUAL(receivedData.back().wireEncode(), data1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700256}
257
258BOOST_AUTO_TEST_CASE(ReceiveData)
259{
Eric Newberry86d31872015-09-23 16:24:59 -0700260 // Initialize with Options that disables all services
261 GenericLinkService::Options options;
262 options.allowLocalFields = false;
263 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700264
Junxiao Shi9d727852019-05-14 13:44:22 -0600265 auto data1 = makeData("/12345689");
Eric Newberrya98bf932015-09-21 00:58:47 -0700266 lp::Packet lpPacket;
267 lpPacket.set<lp::FragmentField>(std::make_pair(
268 data1->wireEncode().begin(), data1->wireEncode().end()));
269 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
270
271 transport->receivePacket(lpPacket.wireEncode());
272
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700273 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700274 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400275 BOOST_CHECK_EQUAL(receivedData.back().wireEncode(), data1->wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700276}
277
278BOOST_AUTO_TEST_CASE(ReceiveNack)
279{
Eric Newberry86d31872015-09-23 16:24:59 -0700280 // Initialize with Options that disables all services
281 GenericLinkService::Options options;
282 options.allowLocalFields = false;
283 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700284
Junxiao Shi9d727852019-05-14 13:44:22 -0600285 lp::Nack nack1 = makeNack(*makeInterest("/localhost/test", false, nullopt, 323),
286 lp::NackReason::NO_ROUTE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700287 lp::Packet lpPacket;
288 lpPacket.set<lp::FragmentField>(std::make_pair(
289 nack1.getInterest().wireEncode().begin(), nack1.getInterest().wireEncode().end()));
290 lpPacket.set<lp::NackField>(nack1.getHeader());
291
292 transport->receivePacket(lpPacket.wireEncode());
293
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700294 BOOST_CHECK_EQUAL(service->getCounters().nInNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700295 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400296 BOOST_CHECK_EQUAL(receivedNacks.back().getReason(), nack1.getReason());
297 BOOST_CHECK_EQUAL(receivedNacks.back().getInterest().wireEncode(), nack1.getInterest().wireEncode());
Eric Newberrya98bf932015-09-21 00:58:47 -0700298}
299
Eric Newberrya1939ba2015-10-09 12:35:03 -0700300BOOST_AUTO_TEST_CASE(ReceiveIdlePacket)
301{
302 // Initialize with Options that disables all services
303 GenericLinkService::Options options;
304 options.allowLocalFields = false;
305 initialize(options);
306
307 lp::Packet lpPacket;
308 lpPacket.set<lp::SequenceField>(0);
309
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400310 transport->receivePacket(lpPacket.wireEncode());
Eric Newberrya1939ba2015-10-09 12:35:03 -0700311
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700312 // IDLE packet should be ignored, but is not an error
313 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0);
Eric Newberrya1939ba2015-10-09 12:35:03 -0700314 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
315 BOOST_CHECK_EQUAL(receivedData.size(), 0);
316 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
317}
318
Eric Newberrya98bf932015-09-21 00:58:47 -0700319BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive
320
Eric Newberry86d31872015-09-23 16:24:59 -0700321BOOST_AUTO_TEST_SUITE(Fragmentation)
322
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700323BOOST_AUTO_TEST_CASE(FragmentationDisabledExceedMtuDrop)
324{
325 // Initialize with Options that disable fragmentation
326 GenericLinkService::Options options;
327 options.allowFragmentation = false;
328 initialize(options);
329
330 transport->setMtu(55);
331
Junxiao Shi9d727852019-05-14 13:44:22 -0600332 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700333 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700334
335 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
336 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
337}
338
Eric Newberryf3ee8082020-01-28 13:44:18 -0800339// It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero
340// This test case ensures that packets are dropped if the MTU is zero
341BOOST_AUTO_TEST_CASE(FragmentationDisabledZeroMtuDrop)
342{
343 // Initialize with Options that disable fragmentation
344 GenericLinkService::Options options;
345 options.allowFragmentation = false;
346 initialize(options);
347
348 transport->setMtu(0);
349
350 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700351 face->sendData(*data);
Eric Newberryf3ee8082020-01-28 13:44:18 -0800352
353 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
354 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
355}
356
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700357BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu)
358{
359 // Initialize with Options that enable fragmentation
360 GenericLinkService::Options options;
361 options.allowFragmentation = true;
362 initialize(options);
363
364 transport->setMtu(MTU_UNLIMITED);
365
Junxiao Shi9d727852019-05-14 13:44:22 -0600366 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700367 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700368
369 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
370}
371
372BOOST_AUTO_TEST_CASE(FragmentationUnderMtu)
373{
374 // Initialize with Options that enable fragmentation
375 GenericLinkService::Options options;
376 options.allowFragmentation = true;
377 initialize(options);
378
379 transport->setMtu(105);
380
Junxiao Shi9d727852019-05-14 13:44:22 -0600381 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700382 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700383
384 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
385}
386
387BOOST_AUTO_TEST_CASE(FragmentationOverMtu)
388{
389 // Initialize with Options that enable fragmentation
390 GenericLinkService::Options options;
391 options.allowFragmentation = true;
392 initialize(options);
393
394 transport->setMtu(60);
395
Junxiao Shi9d727852019-05-14 13:44:22 -0600396 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700397 face->sendData(*data);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700398
399 BOOST_CHECK_GT(transport->sentPackets.size(), 1);
400}
401
Eric Newberryf3ee8082020-01-28 13:44:18 -0800402// It is possible for some interfaces (e.g., virtual Ethernet) to have their MTU set to zero
403// This test case ensures that packets are dropped if the MTU is zero
404BOOST_AUTO_TEST_CASE(FragmentationZeroMtuDrop)
405{
406 // Initialize with Options that enable fragmentation
407 GenericLinkService::Options options;
408 options.allowFragmentation = true;
409 initialize(options);
410
411 transport->setMtu(0);
412
413 auto data = makeData("/test/data/123456789/987654321/123456789");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700414 face->sendData(*data);
Eric Newberryf3ee8082020-01-28 13:44:18 -0800415
416 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
417 BOOST_CHECK_EQUAL(service->getCounters().nFragmentationErrors, 1);
418}
419
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700420BOOST_AUTO_TEST_CASE(ReassembleFragments)
421{
422 // Initialize with Options that enables reassembly
423 GenericLinkService::Options options;
424 options.allowReassembly = true;
425 initialize(options);
426
Junxiao Shi9d727852019-05-14 13:44:22 -0600427 auto interest = makeInterest(
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700428 "/mt7P130BHXmtLm5dwaY5dpUM6SWYNN2B05g7y3UhsQuLvDdnTWdNnTeEiLuW3FAbJRSG3tzQ0UfaSEgG9rvYHmsKtgPMag1Hj4Tr");
429 lp::Packet packet(interest->wireEncode());
430
431 // fragment the packet
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400432 LpFragmenter fragmenter({});
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700433 size_t mtu = 100;
434 bool isOk = false;
435 std::vector<lp::Packet> frags;
436 std::tie(isOk, frags) = fragmenter.fragmentPacket(packet, mtu);
437 BOOST_REQUIRE(isOk);
438 BOOST_CHECK_GT(frags.size(), 1);
439
440 // receive the fragments
441 for (ssize_t fragIndex = frags.size() - 1; fragIndex >= 0; --fragIndex) {
442 size_t sequence = 1000 + fragIndex;
443 frags[fragIndex].add<lp::SequenceField>(sequence);
444
445 transport->receivePacket(frags[fragIndex].wireEncode());
446
447 if (fragIndex > 0) {
448 BOOST_CHECK(receivedInterests.empty());
449 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 1);
450 }
451 else {
452 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400453 BOOST_CHECK_EQUAL(receivedInterests.back().wireEncode(), interest->wireEncode());
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700454 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 0);
455 }
456 }
457}
458
Eric Newberry86d31872015-09-23 16:24:59 -0700459BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex)
460{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700461 // Initialize with Options that disables reassembly
462 GenericLinkService::Options options;
463 options.allowReassembly = false;
464 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700465
Junxiao Shi9d727852019-05-14 13:44:22 -0600466 auto interest = makeInterest("/IgFe6NvH");
Eric Newberry86d31872015-09-23 16:24:59 -0700467 lp::Packet packet(interest->wireEncode());
468 packet.set<lp::FragIndexField>(140);
469
470 transport->receivePacket(packet.wireEncode());
471
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700472 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700473 BOOST_CHECK(receivedInterests.empty());
474}
475
476BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount)
477{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700478 // Initialize with Options that disables reassembly
479 GenericLinkService::Options options;
480 options.allowReassembly = false;
481 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700482
Junxiao Shi9d727852019-05-14 13:44:22 -0600483 auto interest = makeInterest("/SeGmEjvIVX");
Eric Newberry86d31872015-09-23 16:24:59 -0700484 lp::Packet packet(interest->wireEncode());
485 packet.set<lp::FragCountField>(276);
486
487 transport->receivePacket(packet.wireEncode());
488
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700489 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700490 BOOST_CHECK(receivedInterests.empty());
491}
492
493BOOST_AUTO_TEST_SUITE_END() // Fragmentation
494
Eric Newberry185ab292017-03-28 06:45:39 +0000495BOOST_AUTO_TEST_SUITE(Reliability)
496
Eric Newberry7b0071e2017-07-03 17:33:31 +0000497BOOST_AUTO_TEST_CASE(SendInterest)
Eric Newberry185ab292017-03-28 06:45:39 +0000498{
499 // Initialize with Options that enables reliability
500 GenericLinkService::Options options;
501 options.allowLocalFields = false;
502 options.reliabilityOptions.isEnabled = true;
503 initialize(options);
504
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400505 auto interest1 = makeInterest("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700506 face->sendInterest(*interest1);
Eric Newberry185ab292017-03-28 06:45:39 +0000507
508 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
509 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700510 lp::Packet interest1pkt(transport->sentPackets.back());
Eric Newberry185ab292017-03-28 06:45:39 +0000511 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000512 BOOST_CHECK(interest1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000513}
514
Eric Newberry7b0071e2017-07-03 17:33:31 +0000515BOOST_AUTO_TEST_CASE(SendData)
Eric Newberry185ab292017-03-28 06:45:39 +0000516{
517 // Initialize with Options that enables reliability
518 GenericLinkService::Options options;
519 options.allowLocalFields = false;
520 options.reliabilityOptions.isEnabled = true;
521 initialize(options);
522
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400523 auto data1 = makeData("/localhost/test");
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700524 face->sendData(*data1);
Eric Newberry185ab292017-03-28 06:45:39 +0000525
526 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
527 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700528 lp::Packet data1pkt(transport->sentPackets.back());
Eric Newberry185ab292017-03-28 06:45:39 +0000529 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000530 BOOST_CHECK(data1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000531}
532
Eric Newberry7b0071e2017-07-03 17:33:31 +0000533BOOST_AUTO_TEST_CASE(SendNack)
Eric Newberry185ab292017-03-28 06:45:39 +0000534{
535 // Initialize with Options that enables reliability
536 GenericLinkService::Options options;
537 options.allowLocalFields = false;
538 options.reliabilityOptions.isEnabled = true;
539 initialize(options);
540
Junxiao Shi9d727852019-05-14 13:44:22 -0600541 auto nack1 = makeNack(*makeInterest("/localhost/test", false, nullopt, 323),
542 lp::NackReason::NO_ROUTE);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700543 face->sendNack(nack1);
Eric Newberry185ab292017-03-28 06:45:39 +0000544
545 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
546 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700547 lp::Packet nack1pkt(transport->sentPackets.back());
Eric Newberry185ab292017-03-28 06:45:39 +0000548 BOOST_CHECK(nack1pkt.has<lp::NackField>());
549 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000550 BOOST_CHECK(nack1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000551}
552
Eric Newberry32f7eac2020-02-07 14:40:17 -0800553BOOST_AUTO_TEST_CASE(DropDuplicatePacket)
554{
555 // Initialize with Options that enables reliability
556 GenericLinkService::Options options;
557 options.allowLocalFields = false;
558 options.reliabilityOptions.isEnabled = true;
559 initialize(options);
560
561 Interest interest("/test/prefix");
562 interest.setCanBePrefix(false);
563 lp::Packet pkt1;
564 pkt1.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()});
565 pkt1.add<lp::SequenceField>(7);
566 pkt1.add<lp::TxSequenceField>(12);
567 transport->receivePacket(pkt1.wireEncode());
568 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
569 BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 0);
570
571 lp::Packet pkt2;
572 pkt2.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()});
573 pkt2.add<lp::SequenceField>(7);
574 pkt2.add<lp::TxSequenceField>(13);
575 transport->receivePacket(pkt2.wireEncode());
576 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
577 BOOST_CHECK_EQUAL(service->getCounters().nDuplicateSequence, 1);
578}
579
Eric Newberry185ab292017-03-28 06:45:39 +0000580BOOST_AUTO_TEST_SUITE_END() // Reliability
Eric Newberry86d31872015-09-23 16:24:59 -0700581
Eric Newberryb49313d2017-12-24 20:22:27 -0700582// congestion detection and marking
583BOOST_AUTO_TEST_SUITE(CongestionMark)
584
585BOOST_AUTO_TEST_CASE(NoCongestion)
586{
587 GenericLinkService::Options options;
588 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400589 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700590 initialize(options, MTU_UNLIMITED, 65536);
591 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
592 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
593 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
594
Junxiao Shi9d727852019-05-14 13:44:22 -0600595 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700596
597 // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes
598
599 // no congestion
600 transport->setSendQueueLength(0);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700601 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700602 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700603 lp::Packet pkt1(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700604 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
605 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
606 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
607 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
608
609 // no congestion
610 transport->setSendQueueLength(32768);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700611 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700612 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Teng Liang13d582a2020-07-21 20:23:11 -0700613 lp::Packet pkt2(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700614 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
615 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
616 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
617 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
618}
619
620BOOST_AUTO_TEST_CASE(CongestionCoDel)
621{
622 GenericLinkService::Options options;
623 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400624 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700625 initialize(options, MTU_UNLIMITED, 65536);
626 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700627 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
628 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
629
Junxiao Shi9d727852019-05-14 13:44:22 -0600630 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700631
Klaus Schneider380668b2019-10-02 01:21:13 -0700632 // first congested packet, will not be marked
633 transport->setSendQueueLength(65537);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700634 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700635 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700636 lp::Packet pkt0(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700637 BOOST_REQUIRE_EQUAL(pkt0.count<lp::CongestionMarkField>(), 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400638 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700639 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700640
641 time::nanoseconds markingInterval(
642 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
643 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
644
645 advanceClocks(markingInterval + 1_ms);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700646 face->sendInterest(*interest);
Teng Liang13d582a2020-07-21 20:23:11 -0700647 lp::Packet pkt1(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700648
649 // First congestion mark appears after one interval (100 ms)
650 BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1);
651 BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1);
Eric Newberryb49313d2017-12-24 20:22:27 -0700652 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
653 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
654
655 // advance clock to half of marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700656 advanceClocks(markingInterval / 2); // 50ms
Eric Newberryb49313d2017-12-24 20:22:27 -0700657
658 // second congested packet, but within marking interval, will not be marked
Klaus Schneider380668b2019-10-02 01:21:13 -0700659 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700660 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700661 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Teng Liang13d582a2020-07-21 20:23:11 -0700662 lp::Packet pkt2(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700663 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700664
665 markingInterval = time::nanoseconds(
666 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
667 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
668 nextMarkTime += markingInterval;
669
Eric Newberryb49313d2017-12-24 20:22:27 -0700670 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700671 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
672 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
673
674 // advance clocks past end of initial interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700675 this->advanceClocks((markingInterval / 2) + 1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700676
677 // first congested packet after waiting marking interval, will be marked
Klaus Schneider380668b2019-10-02 01:21:13 -0700678 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700679 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700680 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4);
Teng Liang13d582a2020-07-21 20:23:11 -0700681 lp::Packet pkt3(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700682 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1);
683 BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700684 markingInterval = time::nanoseconds(
685 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
686 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700687 nextMarkTime += markingInterval;
688 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700689 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
690 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
691
692 // advance clock partway through current marking interval
Klaus Schneider380668b2019-10-02 01:21:13 -0700693 this->advanceClocks(markingInterval - 20_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700694
695 // still congested, but within marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700696 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700697 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700698 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Teng Liang13d582a2020-07-21 20:23:11 -0700699 lp::Packet pkt4(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700700 BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0);
701 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700702 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
703 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
704
705 // advance clocks past end of current marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700706 this->advanceClocks(21_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700707
708 // still congested, after marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700709 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700710 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700711 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6);
Teng Liang13d582a2020-07-21 20:23:11 -0700712 lp::Packet pkt5(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700713 BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1);
714 BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1);
715 markingInterval = time::nanoseconds(
716 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700717 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700718 nextMarkTime += markingInterval;
719 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700720 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
721 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
722
Davide Pesavento14e71f02019-03-28 17:35:25 -0400723 this->advanceClocks(1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700724
725 // still congested, but within marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700726 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700727 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700728 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7);
Teng Liang13d582a2020-07-21 20:23:11 -0700729 lp::Packet pkt6(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700730 BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0);
731 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700732 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
733 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
734
735 this->advanceClocks(markingInterval);
736
737 // still congested, after marking interval cycle
Klaus Schneider380668b2019-10-02 01:21:13 -0700738 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700739 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700740 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8);
Teng Liang13d582a2020-07-21 20:23:11 -0700741 lp::Packet pkt7(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700742 BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1);
743 BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1);
744 markingInterval = time::nanoseconds(
745 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700746 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700747 nextMarkTime += markingInterval;
748 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700749 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4);
750 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
751
752 // no more congestion
753 transport->setSendQueueLength(30000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700754 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700755 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9);
Teng Liang13d582a2020-07-21 20:23:11 -0700756 lp::Packet pkt8(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700757 BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0);
758 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700759 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
760 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
761
Davide Pesavento14e71f02019-03-28 17:35:25 -0400762 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700763
764 // send queue congested again, but can't mark packet because within one full interval of last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700765 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700766 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700767 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10);
Teng Liang13d582a2020-07-21 20:23:11 -0700768 lp::Packet pkt9(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700769 BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700770 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
771 markingInterval = time::nanoseconds(
772 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
773 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
774 nextMarkTime = time::steady_clock::now() + markingInterval;
775 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700776 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
777 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
778
779 // advance clock past full 100ms interval since last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700780 this->advanceClocks(markingInterval + 2_ms);
781 BOOST_CHECK_GT(time::steady_clock::now(), nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700782
Klaus Schneider380668b2019-10-02 01:21:13 -0700783 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700784 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700785 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11);
Teng Liang13d582a2020-07-21 20:23:11 -0700786 lp::Packet pkt10(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700787 BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1);
788 BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1);
Klaus Schneider380668b2019-10-02 01:21:13 -0700789 markingInterval = time::nanoseconds(
790 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
791 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
792 nextMarkTime += markingInterval;
Eric Newberryb49313d2017-12-24 20:22:27 -0700793 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700794 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
795 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
796
797 // advance clock partway through 100ms marking interval
Davide Pesavento14e71f02019-03-28 17:35:25 -0400798 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700799
800 // not marked since within 100ms window before can mark again
Klaus Schneider380668b2019-10-02 01:21:13 -0700801 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700802 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700803 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12);
Teng Liang13d582a2020-07-21 20:23:11 -0700804 lp::Packet pkt11(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700805 BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0);
806 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700807 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
808 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
809
810 // advance clocks past m_nextMarkTime
Davide Pesavento14e71f02019-03-28 17:35:25 -0400811 this->advanceClocks(51_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700812
813 // markable packet, queue length still above threshold
Klaus Schneider380668b2019-10-02 01:21:13 -0700814 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700815 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700816 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13);
Teng Liang13d582a2020-07-21 20:23:11 -0700817 lp::Packet pkt12(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700818 BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1);
819 BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1);
820 markingInterval = time::nanoseconds(
821 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
Klaus Schneider380668b2019-10-02 01:21:13 -0700822 std::sqrt(service->m_nMarkedSinceInMarkingState + 1)));
Eric Newberryb49313d2017-12-24 20:22:27 -0700823 nextMarkTime += markingInterval;
824 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Eric Newberryb49313d2017-12-24 20:22:27 -0700825 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
826 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
827
828 // no more congestion
829 transport->setSendQueueLength(10000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700830 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700831 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14);
Teng Liang13d582a2020-07-21 20:23:11 -0700832 lp::Packet pkt13(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700833 BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0);
834 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700835 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
836 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
837
838 // advance clocks past one full interval since last mark
Klaus Schneider380668b2019-10-02 01:21:13 -0700839 this->advanceClocks(102_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700840
841 // start congestion again
Klaus Schneider380668b2019-10-02 01:21:13 -0700842 transport->setSendQueueLength(66000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700843 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700844 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15);
Teng Liang13d582a2020-07-21 20:23:11 -0700845 lp::Packet pkt14(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700846 BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400847 nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700848 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700849 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
850 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
Eric Newberryb49313d2017-12-24 20:22:27 -0700851
852 // no more congestion, cancel marking interval
853 transport->setSendQueueLength(5000);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700854 face->sendInterest(*interest);
Klaus Schneider380668b2019-10-02 01:21:13 -0700855 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16);
Teng Liang13d582a2020-07-21 20:23:11 -0700856 lp::Packet pkt15(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700857 BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0);
858 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
Eric Newberryb49313d2017-12-24 20:22:27 -0700859 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
Klaus Schneider380668b2019-10-02 01:21:13 -0700860 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
Eric Newberryb49313d2017-12-24 20:22:27 -0700861}
862
863BOOST_AUTO_TEST_CASE(DefaultThreshold)
864{
865 GenericLinkService::Options options;
866 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400867 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700868 initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED);
869 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
870 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
871 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
872
Junxiao Shi9d727852019-05-14 13:44:22 -0600873 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700874
875 // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure
876 // the queue capacity
877
878 // no congestion
879 transport->setSendQueueLength(0);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700880 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700881 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -0700882 lp::Packet pkt1(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700883 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
884 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
885 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
886 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
887
888 // no congestion
889 transport->setSendQueueLength(65536);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700890 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700891 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Teng Liang13d582a2020-07-21 20:23:11 -0700892 lp::Packet pkt2(transport->sentPackets.back());
Eric Newberryb49313d2017-12-24 20:22:27 -0700893 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
894 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
895 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
896 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
897
Klaus Schneider380668b2019-10-02 01:21:13 -0700898 // first congested (not marked yet) packet
Eric Newberryb49313d2017-12-24 20:22:27 -0700899 transport->setSendQueueLength(65537);
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700900 face->sendInterest(*interest);
Eric Newberryb49313d2017-12-24 20:22:27 -0700901 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Teng Liang13d582a2020-07-21 20:23:11 -0700902 lp::Packet pkt3(transport->sentPackets.back());
Klaus Schneider380668b2019-10-02 01:21:13 -0700903 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 0);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400904 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700905 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
Klaus Schneider380668b2019-10-02 01:21:13 -0700906 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
907 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700908}
909
910BOOST_AUTO_TEST_SUITE_END() // CongestionMark
911
Eric Newberryee400b52016-11-24 14:12:48 +0000912BOOST_AUTO_TEST_SUITE(LpFields)
Eric Newberrya98bf932015-09-21 00:58:47 -0700913
Eric Newberrya98bf932015-09-21 00:58:47 -0700914BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId)
915{
Eric Newberry86d31872015-09-23 16:24:59 -0700916 // Initialize with Options that enables local fields
917 GenericLinkService::Options options;
918 options.allowLocalFields = true;
919 initialize(options);
920
Junxiao Shi9d727852019-05-14 13:44:22 -0600921 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700922 lp::Packet packet(interest->wireEncode());
923 packet.set<lp::NextHopFaceIdField>(1000);
924
925 transport->receivePacket(packet.wireEncode());
926
927 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -0400928 auto tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>();
Junxiao Shi0de23a22015-12-03 20:07:02 +0000929 BOOST_REQUIRE(tag != nullptr);
930 BOOST_CHECK_EQUAL(*tag, 1000);
Eric Newberrya98bf932015-09-21 00:58:47 -0700931}
932
933BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled)
934{
Eric Newberry86d31872015-09-23 16:24:59 -0700935 // Initialize with Options that disables local fields
936 GenericLinkService::Options options;
937 options.allowLocalFields = false;
938 initialize(options);
939
Junxiao Shi9d727852019-05-14 13:44:22 -0600940 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700941 lp::Packet packet(interest->wireEncode());
942 packet.set<lp::NextHopFaceIdField>(1000);
943
944 transport->receivePacket(packet.wireEncode());
945
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700946 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700947 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700948}
949
950BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData)
951{
Eric Newberry86d31872015-09-23 16:24:59 -0700952 // Initialize with Options that enables local fields
953 GenericLinkService::Options options;
954 options.allowLocalFields = true;
955 initialize(options);
956
Junxiao Shi9d727852019-05-14 13:44:22 -0600957 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700958 lp::Packet packet(data->wireEncode());
959 packet.set<lp::NextHopFaceIdField>(1000);
960
961 transport->receivePacket(packet.wireEncode());
962
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700963 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700964 BOOST_CHECK(receivedData.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700965}
966
967BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack)
968{
Eric Newberry86d31872015-09-23 16:24:59 -0700969 // Initialize with Options that enables local fields
970 GenericLinkService::Options options;
971 options.allowLocalFields = true;
972 initialize(options);
973
Junxiao Shi9d727852019-05-14 13:44:22 -0600974 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
975 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -0700976 lp::Packet packet;
977 packet.set<lp::FragmentField>(std::make_pair(
978 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
979 packet.set<lp::NackField>(nack.getHeader());
980 packet.set<lp::NextHopFaceIdField>(1000);
981
982 transport->receivePacket(packet.wireEncode());
983
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700984 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700985 BOOST_CHECK(receivedNacks.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700986}
987
Junxiao Shi6eb02712017-05-27 22:48:02 +0000988BOOST_AUTO_TEST_CASE(ReceiveCachePolicy)
Eric Newberrya98bf932015-09-21 00:58:47 -0700989{
Junxiao Shi6eb02712017-05-27 22:48:02 +0000990 // Initialize with Options that disables local fields
Eric Newberry86d31872015-09-23 16:24:59 -0700991 GenericLinkService::Options options;
Junxiao Shi6eb02712017-05-27 22:48:02 +0000992 options.allowLocalFields = false;
Eric Newberry86d31872015-09-23 16:24:59 -0700993 initialize(options);
Junxiao Shi6eb02712017-05-27 22:48:02 +0000994 // CachePolicy is unprivileged and does not require allowLocalFields option.
Eric Newberry86d31872015-09-23 16:24:59 -0700995
Junxiao Shi9d727852019-05-14 13:44:22 -0600996 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700997 lp::Packet packet(data->wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000998 packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE));
Eric Newberry86d31872015-09-23 16:24:59 -0700999
1000 transport->receivePacket(packet.wireEncode());
1001
1002 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001003 auto tag = receivedData.back().getTag<lp::CachePolicyTag>();
Junxiao Shi0de23a22015-12-03 20:07:02 +00001004 BOOST_REQUIRE(tag != nullptr);
1005 BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE);
Eric Newberrya98bf932015-09-21 00:58:47 -07001006}
1007
Junxiao Shi6eb02712017-05-27 22:48:02 +00001008BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest)
Eric Newberrya98bf932015-09-21 00:58:47 -07001009{
Eric Newberry86d31872015-09-23 16:24:59 -07001010 // Initialize with Options that enables local fields
1011 GenericLinkService::Options options;
1012 options.allowLocalFields = true;
1013 initialize(options);
1014
Junxiao Shi9d727852019-05-14 13:44:22 -06001015 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -07001016 lp::Packet packet(interest->wireEncode());
1017 lp::CachePolicy policy;
1018 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
1019 packet.set<lp::CachePolicyField>(policy);
1020
1021 transport->receivePacket(packet.wireEncode());
1022
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001023 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -07001024 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -07001025}
1026
Junxiao Shi6eb02712017-05-27 22:48:02 +00001027BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack)
Eric Newberrya98bf932015-09-21 00:58:47 -07001028{
Eric Newberry86d31872015-09-23 16:24:59 -07001029 // Initialize with Options that enables local fields
1030 GenericLinkService::Options options;
1031 options.allowLocalFields = true;
1032 initialize(options);
1033
Junxiao Shi9d727852019-05-14 13:44:22 -06001034 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1035 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -07001036 lp::Packet packet(nack.getInterest().wireEncode());
1037 packet.set<lp::NackField>(nack.getHeader());
1038 lp::CachePolicy policy;
1039 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
1040 packet.set<lp::CachePolicyField>(policy);
1041
1042 transport->receivePacket(packet.wireEncode());
1043
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001044 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -07001045 BOOST_CHECK(receivedNacks.empty());
1046}
1047
1048BOOST_AUTO_TEST_CASE(SendIncomingFaceId)
1049{
1050 // Initialize with Options that enables local fields
1051 GenericLinkService::Options options;
1052 options.allowLocalFields = true;
1053 initialize(options);
1054
Junxiao Shi9d727852019-05-14 13:44:22 -06001055 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +00001056 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -07001057
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001058 face->sendInterest(*interest);
Eric Newberry86d31872015-09-23 16:24:59 -07001059
1060 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001061 lp::Packet sent(transport->sentPackets.back());
Eric Newberry86d31872015-09-23 16:24:59 -07001062 BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>());
1063 BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000);
1064}
1065
1066BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled)
1067{
1068 // Initialize with Options that disables local fields
1069 GenericLinkService::Options options;
1070 options.allowLocalFields = false;
1071 initialize(options);
1072
Junxiao Shi9d727852019-05-14 13:44:22 -06001073 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +00001074 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -07001075
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001076 face->sendInterest(*interest);
Eric Newberry86d31872015-09-23 16:24:59 -07001077
1078 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001079 lp::Packet sent(transport->sentPackets.back());
Eric Newberry86d31872015-09-23 16:24:59 -07001080 BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>());
1081}
1082
1083BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest)
1084{
1085 // Initialize with Options that enables local fields
1086 GenericLinkService::Options options;
1087 options.allowLocalFields = true;
1088 initialize(options);
1089
Junxiao Shi9d727852019-05-14 13:44:22 -06001090 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -07001091 lp::Packet packet(interest->wireEncode());
1092 packet.set<lp::IncomingFaceIdField>(1000);
1093
1094 transport->receivePacket(packet.wireEncode());
1095
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001096 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001097 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001098 BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001099}
1100
1101BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData)
1102{
1103 // Initialize with Options that enables local fields
1104 GenericLinkService::Options options;
1105 options.allowLocalFields = true;
1106 initialize(options);
1107
Junxiao Shi9d727852019-05-14 13:44:22 -06001108 auto data = makeData("/z1megUh9Bj");
Eric Newberry86d31872015-09-23 16:24:59 -07001109 lp::Packet packet(data->wireEncode());
1110 packet.set<lp::IncomingFaceIdField>(1000);
1111
1112 transport->receivePacket(packet.wireEncode());
1113
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001114 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001115 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001116 BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001117}
1118
1119BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack)
1120{
1121 // Initialize with Options that enables local fields
1122 GenericLinkService::Options options;
1123 options.allowLocalFields = true;
1124 initialize(options);
1125
Junxiao Shi9d727852019-05-14 13:44:22 -06001126 lp::Nack nack = makeNack(*makeInterest("/TPAhdiHz", false, nullopt, 278),
1127 lp::NackReason::CONGESTION);
Eric Newberry86d31872015-09-23 16:24:59 -07001128 lp::Packet packet(nack.getInterest().wireEncode());
1129 packet.set<lp::NackField>(nack.getHeader());
1130 packet.set<lp::IncomingFaceIdField>(1000);
1131
1132 transport->receivePacket(packet.wireEncode());
1133
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001134 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001135 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001136 BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberrya98bf932015-09-21 00:58:47 -07001137}
1138
Eric Newberryee400b52016-11-24 14:12:48 +00001139BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest)
1140{
Junxiao Shi9d727852019-05-14 13:44:22 -06001141 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001142 interest->setTag(make_shared<lp::CongestionMarkTag>(1));
1143
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001144 face->sendInterest(*interest);
Eric Newberryee400b52016-11-24 14:12:48 +00001145
1146 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001147 lp::Packet sent(transport->sentPackets.back());
Eric Newberryee400b52016-11-24 14:12:48 +00001148 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1149 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1);
1150}
1151
1152BOOST_AUTO_TEST_CASE(SendCongestionMarkData)
1153{
Junxiao Shi9d727852019-05-14 13:44:22 -06001154 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001155 data->setTag(make_shared<lp::CongestionMarkTag>(0));
1156
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001157 face->sendData(*data);
Eric Newberryee400b52016-11-24 14:12:48 +00001158
1159 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001160 lp::Packet sent(transport->sentPackets.back());
Eric Newberryee400b52016-11-24 14:12:48 +00001161 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1162 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0);
1163}
1164
1165BOOST_AUTO_TEST_CASE(SendCongestionMarkNack)
1166{
Junxiao Shi9d727852019-05-14 13:44:22 -06001167 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1168 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001169 nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max()));
1170
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001171 face->sendNack(nack);
Eric Newberryee400b52016-11-24 14:12:48 +00001172
1173 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001174 lp::Packet sent(transport->sentPackets.back());
Eric Newberryee400b52016-11-24 14:12:48 +00001175 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1176 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max());
1177}
1178
1179BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest)
1180{
Junxiao Shi9d727852019-05-14 13:44:22 -06001181 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001182 lp::Packet packet(interest->wireEncode());
1183 packet.set<lp::CongestionMarkField>(1);
1184
1185 transport->receivePacket(packet.wireEncode());
1186
1187 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001188 auto tag = receivedInterests.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001189 BOOST_REQUIRE(tag != nullptr);
1190 BOOST_CHECK_EQUAL(*tag, 1);
1191}
1192
1193BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData)
1194{
Junxiao Shi9d727852019-05-14 13:44:22 -06001195 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001196 lp::Packet packet(data->wireEncode());
1197 packet.set<lp::CongestionMarkField>(1);
1198
1199 transport->receivePacket(packet.wireEncode());
1200
1201 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001202 auto tag = receivedData.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001203 BOOST_REQUIRE(tag != nullptr);
1204 BOOST_CHECK_EQUAL(*tag, 1);
1205}
1206
1207BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack)
1208{
Junxiao Shi9d727852019-05-14 13:44:22 -06001209 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1210 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001211 lp::Packet packet;
1212 packet.set<lp::FragmentField>(std::make_pair(
1213 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1214 packet.set<lp::NackField>(nack.getHeader());
1215 packet.set<lp::CongestionMarkField>(1);
1216
1217 transport->receivePacket(packet.wireEncode());
1218
1219 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001220 auto tag = receivedNacks.back().getTag<lp::CongestionMarkTag>();
Eric Newberryee400b52016-11-24 14:12:48 +00001221 BOOST_REQUIRE(tag != nullptr);
1222 BOOST_CHECK_EQUAL(*tag, 1);
1223}
1224
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001225BOOST_AUTO_TEST_CASE(SendNonDiscovery)
1226{
1227 GenericLinkService::Options options;
1228 options.allowSelfLearning = true;
1229 initialize(options);
1230
Junxiao Shi9d727852019-05-14 13:44:22 -06001231 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001232 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1233
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001234 face->sendInterest(*interest);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001235
1236 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001237 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001238 BOOST_CHECK(sent.has<lp::NonDiscoveryField>());
1239}
1240
1241BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled)
1242{
1243 GenericLinkService::Options options;
1244 options.allowSelfLearning = false;
1245 initialize(options);
1246
Junxiao Shi9d727852019-05-14 13:44:22 -06001247 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001248 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1249
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001250 face->sendInterest(*interest);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001251
1252 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001253 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001254 BOOST_CHECK(!sent.has<lp::NonDiscoveryField>());
1255}
1256
1257BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery)
1258{
1259 GenericLinkService::Options options;
1260 options.allowSelfLearning = true;
1261 initialize(options);
1262
Junxiao Shi9d727852019-05-14 13:44:22 -06001263 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001264 lp::Packet packet(interest->wireEncode());
1265 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1266
1267 transport->receivePacket(packet.wireEncode());
1268
1269 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001270 auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001271 BOOST_CHECK(tag != nullptr);
1272}
1273
1274BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled)
1275{
1276 GenericLinkService::Options options;
1277 options.allowSelfLearning = false;
1278 initialize(options);
1279
Junxiao Shi9d727852019-05-14 13:44:22 -06001280 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001281 lp::Packet packet(interest->wireEncode());
1282 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1283
1284 transport->receivePacket(packet.wireEncode());
1285
1286 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1287 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001288 auto tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001289 BOOST_CHECK(tag == nullptr);
1290}
1291
1292BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData)
1293{
1294 GenericLinkService::Options options;
1295 options.allowSelfLearning = true;
1296 initialize(options);
1297
Junxiao Shi9d727852019-05-14 13:44:22 -06001298 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001299 lp::Packet packet(data->wireEncode());
1300 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1301
1302 transport->receivePacket(packet.wireEncode());
1303
1304 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1305 BOOST_CHECK(receivedData.empty());
1306}
1307
1308BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack)
1309{
1310 GenericLinkService::Options options;
1311 options.allowSelfLearning = true;
1312 initialize(options);
1313
Junxiao Shi9d727852019-05-14 13:44:22 -06001314 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1315 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001316 lp::Packet packet;
1317 packet.set<lp::FragmentField>(std::make_pair(
1318 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1319 packet.set<lp::NackField>(nack.getHeader());
1320 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1321
1322 transport->receivePacket(packet.wireEncode());
1323
1324 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1325 BOOST_CHECK(receivedNacks.empty());
1326}
1327
1328BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement)
1329{
1330 GenericLinkService::Options options;
1331 options.allowSelfLearning = true;
1332 initialize(options);
1333
Junxiao Shi9d727852019-05-14 13:44:22 -06001334 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001335 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1336 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001337
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001338 face->sendData(*data);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001339
1340 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001341 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001342 BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>());
1343}
1344
1345BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled)
1346{
1347 GenericLinkService::Options options;
1348 options.allowSelfLearning = false;
1349 initialize(options);
1350
Junxiao Shi9d727852019-05-14 13:44:22 -06001351 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001352 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1353 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001354
Teng Liangf3bc3ae2020-06-08 10:19:25 -07001355 face->sendData(*data);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001356
1357 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Teng Liang13d582a2020-07-21 20:23:11 -07001358 lp::Packet sent(transport->sentPackets.back());
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001359 BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>());
1360}
1361
1362BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement)
1363{
1364 GenericLinkService::Options options;
1365 options.allowSelfLearning = true;
1366 initialize(options);
1367
Junxiao Shi9d727852019-05-14 13:44:22 -06001368 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001369 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001370 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1371 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001372
1373 transport->receivePacket(packet.wireEncode());
1374
1375 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001376 auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangbce3cb52018-09-05 20:08:27 -07001377 BOOST_CHECK_EQUAL(tag->get().getPrefixAnn()->getAnnouncedName(), "/local/ndn/prefix");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001378}
1379
1380BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled)
1381{
1382 GenericLinkService::Options options;
1383 options.allowSelfLearning = false;
1384 initialize(options);
1385
Junxiao Shi9d727852019-05-14 13:44:22 -06001386 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001387 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001388 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1389 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001390
1391 transport->receivePacket(packet.wireEncode());
1392
1393 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1394 BOOST_CHECK_EQUAL(receivedData.size(), 1);
Davide Pesavento7890a9f2019-08-25 23:11:18 -04001395 auto tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001396 BOOST_CHECK(tag == nullptr);
1397}
1398
1399BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest)
1400{
1401 GenericLinkService::Options options;
1402 options.allowSelfLearning = true;
1403 initialize(options);
1404
Junxiao Shi9d727852019-05-14 13:44:22 -06001405 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001406 lp::Packet packet(interest->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001407 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1408 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001409
1410 transport->receivePacket(packet.wireEncode());
1411
1412 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1413 BOOST_CHECK(receivedInterests.empty());
1414}
1415
1416BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack)
1417{
1418 GenericLinkService::Options options;
1419 options.allowSelfLearning = true;
1420 initialize(options);
1421
Junxiao Shi9d727852019-05-14 13:44:22 -06001422 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1423 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001424 lp::Packet packet;
1425 packet.set<lp::FragmentField>(std::make_pair(
1426 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1427 packet.set<lp::NackField>(nack.getHeader());
Teng Liangbce3cb52018-09-05 20:08:27 -07001428 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1429 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001430
1431 transport->receivePacket(packet.wireEncode());
1432
1433 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1434 BOOST_CHECK(receivedNacks.empty());
1435}
1436
Eric Newberryee400b52016-11-24 14:12:48 +00001437BOOST_AUTO_TEST_SUITE_END() // LpFields
Eric Newberrya98bf932015-09-21 00:58:47 -07001438
Eric Newberrya1939ba2015-10-09 12:35:03 -07001439BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets
1440
1441BOOST_AUTO_TEST_CASE(WrongTlvType)
1442{
1443 // Initialize with Options that disables all services
1444 GenericLinkService::Options options;
1445 options.allowLocalFields = false;
1446 initialize(options);
1447
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001448 auto packet = ndn::encoding::makeEmptyBlock(tlv::Name);
1449 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001450
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001451 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001452 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1453 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1454 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1455}
1456
1457BOOST_AUTO_TEST_CASE(Unparsable)
1458{
1459 // Initialize with Options that disables all services
1460 GenericLinkService::Options options;
1461 options.allowLocalFields = false;
1462 initialize(options);
1463
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001464 auto packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x");
Eric Newberrya1939ba2015-10-09 12:35:03 -07001465 BOOST_CHECK_THROW(packet.parse(), tlv::Error);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001466 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001467
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001468 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001469 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1470 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1471 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1472}
1473
1474BOOST_AUTO_TEST_SUITE_END() // Malformed
1475
Eric Newberry86d31872015-09-23 16:24:59 -07001476BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService
1477BOOST_AUTO_TEST_SUITE_END() // Face
Eric Newberrya98bf932015-09-21 00:58:47 -07001478
1479} // namespace tests
1480} // namespace face
1481} // namespace nfd