blob: 8f0dbaea5eb116b9adef96d2c2ec2530273c6990 [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 Pesavento1d12d2f2019-03-22 12:44:14 -04003 * Copyright (c) 2014-2019, Regents of the University of California,
Eric Newberrya98bf932015-09-21 00:58:47 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "face/generic-link-service.hpp"
Junxiao Shicde37ad2015-12-24 01:02:05 -070027#include "face/face.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070028
Davide Pesavento0064c1d2018-03-03 18:43:53 -050029#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040030#include "tests/key-chain-fixture.hpp"
31#include "tests/daemon/global-io-fixture.hpp"
32#include "dummy-transport.hpp"
Eric Newberryb49313d2017-12-24 20:22:27 -070033
Teng Liangfdcbb4d2018-01-27 16:01:35 -070034#include <ndn-cxx/lp/empty-value.hpp>
Teng Liangbce3cb52018-09-05 20:08:27 -070035#include <ndn-cxx/lp/prefix-announcement-header.hpp>
Eric Newberryb49313d2017-12-24 20:22:27 -070036#include <ndn-cxx/lp/tags.hpp>
Teng Liangbce3cb52018-09-05 20:08:27 -070037#include <ndn-cxx/security/signing-helpers.hpp>
Eric Newberrya98bf932015-09-21 00:58:47 -070038
39namespace nfd {
40namespace face {
41namespace tests {
42
43using namespace nfd::tests;
44
45BOOST_AUTO_TEST_SUITE(Face)
46
Junxiao Shicde37ad2015-12-24 01:02:05 -070047using nfd::Face;
48
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040049class GenericLinkServiceFixture : public GlobalIoTimeFixture, public KeyChainFixture
Eric Newberrya98bf932015-09-21 00:58:47 -070050{
51protected:
52 GenericLinkServiceFixture()
Eric Newberrya98bf932015-09-21 00:58:47 -070053 {
Eric Newberrya98bf932015-09-21 00:58:47 -070054 // By default, GenericLinkService is created with default options.
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040055 // Test cases may invoke initialize() with alternate options.
56 initialize({});
Eric Newberrya98bf932015-09-21 00:58:47 -070057 }
58
59 void
Eric Newberryb49313d2017-12-24 20:22:27 -070060 initialize(const GenericLinkService::Options& options,
61 ssize_t mtu = MTU_UNLIMITED,
62 ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED)
Eric Newberrya98bf932015-09-21 00:58:47 -070063 {
Davide Pesaventoe4b22382018-06-10 14:37:24 -040064 face = make_unique<Face>(make_unique<GenericLinkService>(options),
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040065 make_unique<DummyTransport>("dummy://", "dummy://",
Davide Pesaventoe4b22382018-06-10 14:37:24 -040066 ndn::nfd::FACE_SCOPE_NON_LOCAL,
67 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
68 ndn::nfd::LINK_TYPE_POINT_TO_POINT,
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040069 mtu, sendQueueCapacity));
Eric Newberrya98bf932015-09-21 00:58:47 -070070 service = static_cast<GenericLinkService*>(face->getLinkService());
71 transport = static_cast<DummyTransport*>(face->getTransport());
72
73 face->afterReceiveInterest.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000074 [this] (const Interest& interest, const EndpointId&) { receivedInterests.push_back(interest); });
Eric Newberrya98bf932015-09-21 00:58:47 -070075 face->afterReceiveData.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000076 [this] (const Data& data, const EndpointId&) { receivedData.push_back(data); });
Eric Newberrya98bf932015-09-21 00:58:47 -070077 face->afterReceiveNack.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000078 [this] (const lp::Nack& nack, const EndpointId&) { receivedNacks.push_back(nack); });
Eric Newberrya98bf932015-09-21 00:58:47 -070079 }
80
Teng Liangbce3cb52018-09-05 20:08:27 -070081 lp::PrefixAnnouncementHeader
82 makePrefixAnnHeader(const Name& announcedName)
83 {
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040084 return lp::PrefixAnnouncementHeader{signPrefixAnn(makePrefixAnn(announcedName, 1_h),
85 m_keyChain, ndn::signingWithSha256())};
Teng Liangbce3cb52018-09-05 20:08:27 -070086 }
87
Eric Newberrya98bf932015-09-21 00:58:47 -070088protected:
Junxiao Shicde37ad2015-12-24 01:02:05 -070089 unique_ptr<Face> face;
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040090 GenericLinkService* service = nullptr;
91 DummyTransport* transport = nullptr;
Eric Newberrya98bf932015-09-21 00:58:47 -070092 std::vector<Interest> receivedInterests;
93 std::vector<Data> receivedData;
94 std::vector<lp::Nack> receivedNacks;
95};
96
97BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture)
98
Eric Newberrya98bf932015-09-21 00:58:47 -070099BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields
100
101BOOST_AUTO_TEST_CASE(SendInterest)
102{
Eric Newberry86d31872015-09-23 16:24:59 -0700103 // Initialize with Options that disables all services
104 GenericLinkService::Options options;
105 options.allowLocalFields = false;
106 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700107
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400108 auto interest1 = makeInterest("/localhost/test");
ashiqopu075bb7d2019-03-10 01:38:21 +0000109 face->sendInterest(*interest1, 0);
Eric Newberrya98bf932015-09-21 00:58:47 -0700110
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700111 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700112 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400113 lp::Packet interest1pkt(transport->sentPackets.back().packet);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700114 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
115 BOOST_CHECK(!interest1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700116}
117
118BOOST_AUTO_TEST_CASE(SendData)
119{
Eric Newberry86d31872015-09-23 16:24:59 -0700120 // Initialize with Options that disables all services
121 GenericLinkService::Options options;
122 options.allowLocalFields = false;
123 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700124
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400125 auto data1 = makeData("/localhost/test");
ashiqopu075bb7d2019-03-10 01:38:21 +0000126 face->sendData(*data1, 0);
Eric Newberrya98bf932015-09-21 00:58:47 -0700127
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700128 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700129 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400130 lp::Packet data1pkt(transport->sentPackets.back().packet);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700131 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
132 BOOST_CHECK(!data1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700133}
134
135BOOST_AUTO_TEST_CASE(SendNack)
136{
Eric Newberry86d31872015-09-23 16:24:59 -0700137 // Initialize with Options that disables all services
138 GenericLinkService::Options options;
139 options.allowLocalFields = false;
140 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700141
Junxiao Shi9d727852019-05-14 13:44:22 -0600142 auto nack1 = makeNack(*makeInterest("/localhost/test", false, nullopt, 323),
143 lp::NackReason::NO_ROUTE);
ashiqopu075bb7d2019-03-10 01:38:21 +0000144 face->sendNack(nack1, 0);
Eric Newberrya98bf932015-09-21 00:58:47 -0700145
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700146 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700147 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400148 lp::Packet nack1pkt(transport->sentPackets.back().packet);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700149 BOOST_CHECK(nack1pkt.has<lp::NackField>());
150 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
151 BOOST_CHECK(!nack1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700152}
153
154BOOST_AUTO_TEST_CASE(ReceiveBareInterest)
155{
Eric Newberry86d31872015-09-23 16:24:59 -0700156 // Initialize with Options that disables all services
157 GenericLinkService::Options options;
158 options.allowLocalFields = false;
159 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700160
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400161 auto interest1 = makeInterest("/23Rd9hEiR");
Eric Newberrya98bf932015-09-21 00:58:47 -0700162 transport->receivePacket(interest1->wireEncode());
163
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700164 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700165 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
166 BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
167}
168
169BOOST_AUTO_TEST_CASE(ReceiveInterest)
170{
Eric Newberry86d31872015-09-23 16:24:59 -0700171 // Initialize with Options that disables all services
172 GenericLinkService::Options options;
173 options.allowLocalFields = false;
174 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700175
Junxiao Shi9d727852019-05-14 13:44:22 -0600176 auto interest1 = makeInterest("/23Rd9hEiR");
Eric Newberrya98bf932015-09-21 00:58:47 -0700177 lp::Packet lpPacket;
178 lpPacket.set<lp::FragmentField>(std::make_pair(
179 interest1->wireEncode().begin(), interest1->wireEncode().end()));
180 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
181
182 transport->receivePacket(lpPacket.wireEncode());
183
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700184 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700185 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
186 BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
187}
188
189BOOST_AUTO_TEST_CASE(ReceiveBareData)
190{
Eric Newberry86d31872015-09-23 16:24:59 -0700191 // Initialize with Options that disables all services
192 GenericLinkService::Options options;
193 options.allowLocalFields = false;
194 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700195
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400196 auto data1 = makeData("/12345678");
Eric Newberrya98bf932015-09-21 00:58:47 -0700197 transport->receivePacket(data1->wireEncode());
198
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700199 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700200 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
201 BOOST_CHECK_EQUAL(receivedData.back(), *data1);
202}
203
204BOOST_AUTO_TEST_CASE(ReceiveData)
205{
Eric Newberry86d31872015-09-23 16:24:59 -0700206 // Initialize with Options that disables all services
207 GenericLinkService::Options options;
208 options.allowLocalFields = false;
209 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700210
Junxiao Shi9d727852019-05-14 13:44:22 -0600211 auto data1 = makeData("/12345689");
Eric Newberrya98bf932015-09-21 00:58:47 -0700212 lp::Packet lpPacket;
213 lpPacket.set<lp::FragmentField>(std::make_pair(
214 data1->wireEncode().begin(), data1->wireEncode().end()));
215 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
216
217 transport->receivePacket(lpPacket.wireEncode());
218
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700219 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700220 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
221 BOOST_CHECK_EQUAL(receivedData.back(), *data1);
222}
223
224BOOST_AUTO_TEST_CASE(ReceiveNack)
225{
Eric Newberry86d31872015-09-23 16:24:59 -0700226 // Initialize with Options that disables all services
227 GenericLinkService::Options options;
228 options.allowLocalFields = false;
229 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700230
Junxiao Shi9d727852019-05-14 13:44:22 -0600231 lp::Nack nack1 = makeNack(*makeInterest("/localhost/test", false, nullopt, 323),
232 lp::NackReason::NO_ROUTE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700233 lp::Packet lpPacket;
234 lpPacket.set<lp::FragmentField>(std::make_pair(
235 nack1.getInterest().wireEncode().begin(), nack1.getInterest().wireEncode().end()));
236 lpPacket.set<lp::NackField>(nack1.getHeader());
237
238 transport->receivePacket(lpPacket.wireEncode());
239
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700240 BOOST_CHECK_EQUAL(service->getCounters().nInNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700241 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700242 BOOST_CHECK(receivedNacks.back().getReason() == nack1.getReason());
243 BOOST_CHECK(receivedNacks.back().getInterest() == nack1.getInterest());
Eric Newberrya98bf932015-09-21 00:58:47 -0700244}
245
Eric Newberrya1939ba2015-10-09 12:35:03 -0700246BOOST_AUTO_TEST_CASE(ReceiveIdlePacket)
247{
248 // Initialize with Options that disables all services
249 GenericLinkService::Options options;
250 options.allowLocalFields = false;
251 initialize(options);
252
253 lp::Packet lpPacket;
254 lpPacket.set<lp::SequenceField>(0);
255
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400256 transport->receivePacket(lpPacket.wireEncode());
Eric Newberrya1939ba2015-10-09 12:35:03 -0700257
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700258 // IDLE packet should be ignored, but is not an error
259 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0);
Eric Newberrya1939ba2015-10-09 12:35:03 -0700260 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
261 BOOST_CHECK_EQUAL(receivedData.size(), 0);
262 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
263}
264
Eric Newberrya98bf932015-09-21 00:58:47 -0700265BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive
266
Eric Newberry86d31872015-09-23 16:24:59 -0700267BOOST_AUTO_TEST_SUITE(Fragmentation)
268
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700269BOOST_AUTO_TEST_CASE(FragmentationDisabledExceedMtuDrop)
270{
271 // Initialize with Options that disable fragmentation
272 GenericLinkService::Options options;
273 options.allowFragmentation = false;
274 initialize(options);
275
276 transport->setMtu(55);
277
Junxiao Shi9d727852019-05-14 13:44:22 -0600278 auto data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000279 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700280
281 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
282 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
283}
284
285BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu)
286{
287 // Initialize with Options that enable fragmentation
288 GenericLinkService::Options options;
289 options.allowFragmentation = true;
290 initialize(options);
291
292 transport->setMtu(MTU_UNLIMITED);
293
Junxiao Shi9d727852019-05-14 13:44:22 -0600294 auto data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000295 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700296
297 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
298}
299
300BOOST_AUTO_TEST_CASE(FragmentationUnderMtu)
301{
302 // Initialize with Options that enable fragmentation
303 GenericLinkService::Options options;
304 options.allowFragmentation = true;
305 initialize(options);
306
307 transport->setMtu(105);
308
Junxiao Shi9d727852019-05-14 13:44:22 -0600309 auto data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000310 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700311
312 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
313}
314
315BOOST_AUTO_TEST_CASE(FragmentationOverMtu)
316{
317 // Initialize with Options that enable fragmentation
318 GenericLinkService::Options options;
319 options.allowFragmentation = true;
320 initialize(options);
321
322 transport->setMtu(60);
323
Junxiao Shi9d727852019-05-14 13:44:22 -0600324 auto data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000325 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700326
327 BOOST_CHECK_GT(transport->sentPackets.size(), 1);
328}
329
330BOOST_AUTO_TEST_CASE(ReassembleFragments)
331{
332 // Initialize with Options that enables reassembly
333 GenericLinkService::Options options;
334 options.allowReassembly = true;
335 initialize(options);
336
Junxiao Shi9d727852019-05-14 13:44:22 -0600337 auto interest = makeInterest(
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700338 "/mt7P130BHXmtLm5dwaY5dpUM6SWYNN2B05g7y3UhsQuLvDdnTWdNnTeEiLuW3FAbJRSG3tzQ0UfaSEgG9rvYHmsKtgPMag1Hj4Tr");
339 lp::Packet packet(interest->wireEncode());
340
341 // fragment the packet
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400342 LpFragmenter fragmenter({});
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700343 size_t mtu = 100;
344 bool isOk = false;
345 std::vector<lp::Packet> frags;
346 std::tie(isOk, frags) = fragmenter.fragmentPacket(packet, mtu);
347 BOOST_REQUIRE(isOk);
348 BOOST_CHECK_GT(frags.size(), 1);
349
350 // receive the fragments
351 for (ssize_t fragIndex = frags.size() - 1; fragIndex >= 0; --fragIndex) {
352 size_t sequence = 1000 + fragIndex;
353 frags[fragIndex].add<lp::SequenceField>(sequence);
354
355 transport->receivePacket(frags[fragIndex].wireEncode());
356
357 if (fragIndex > 0) {
358 BOOST_CHECK(receivedInterests.empty());
359 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 1);
360 }
361 else {
362 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
363 BOOST_CHECK_EQUAL(receivedInterests.back(), *interest);
364 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 0);
365 }
366 }
367}
368
Eric Newberry86d31872015-09-23 16:24:59 -0700369BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex)
370{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700371 // Initialize with Options that disables reassembly
372 GenericLinkService::Options options;
373 options.allowReassembly = false;
374 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700375
Junxiao Shi9d727852019-05-14 13:44:22 -0600376 auto interest = makeInterest("/IgFe6NvH");
Eric Newberry86d31872015-09-23 16:24:59 -0700377 lp::Packet packet(interest->wireEncode());
378 packet.set<lp::FragIndexField>(140);
379
380 transport->receivePacket(packet.wireEncode());
381
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700382 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700383 BOOST_CHECK(receivedInterests.empty());
384}
385
386BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount)
387{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700388 // Initialize with Options that disables reassembly
389 GenericLinkService::Options options;
390 options.allowReassembly = false;
391 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700392
Junxiao Shi9d727852019-05-14 13:44:22 -0600393 auto interest = makeInterest("/SeGmEjvIVX");
Eric Newberry86d31872015-09-23 16:24:59 -0700394 lp::Packet packet(interest->wireEncode());
395 packet.set<lp::FragCountField>(276);
396
397 transport->receivePacket(packet.wireEncode());
398
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700399 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700400 BOOST_CHECK(receivedInterests.empty());
401}
402
403BOOST_AUTO_TEST_SUITE_END() // Fragmentation
404
Eric Newberry185ab292017-03-28 06:45:39 +0000405BOOST_AUTO_TEST_SUITE(Reliability)
406
Eric Newberry7b0071e2017-07-03 17:33:31 +0000407BOOST_AUTO_TEST_CASE(SendInterest)
Eric Newberry185ab292017-03-28 06:45:39 +0000408{
409 // Initialize with Options that enables reliability
410 GenericLinkService::Options options;
411 options.allowLocalFields = false;
412 options.reliabilityOptions.isEnabled = true;
413 initialize(options);
414
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400415 auto interest1 = makeInterest("/localhost/test");
ashiqopu075bb7d2019-03-10 01:38:21 +0000416 face->sendInterest(*interest1, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000417
418 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
419 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400420 lp::Packet interest1pkt(transport->sentPackets.back().packet);
Eric Newberry185ab292017-03-28 06:45:39 +0000421 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000422 BOOST_CHECK(interest1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000423}
424
Eric Newberry7b0071e2017-07-03 17:33:31 +0000425BOOST_AUTO_TEST_CASE(SendData)
Eric Newberry185ab292017-03-28 06:45:39 +0000426{
427 // Initialize with Options that enables reliability
428 GenericLinkService::Options options;
429 options.allowLocalFields = false;
430 options.reliabilityOptions.isEnabled = true;
431 initialize(options);
432
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400433 auto data1 = makeData("/localhost/test");
ashiqopu075bb7d2019-03-10 01:38:21 +0000434 face->sendData(*data1, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000435
436 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
437 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400438 lp::Packet data1pkt(transport->sentPackets.back().packet);
Eric Newberry185ab292017-03-28 06:45:39 +0000439 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000440 BOOST_CHECK(data1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000441}
442
Eric Newberry7b0071e2017-07-03 17:33:31 +0000443BOOST_AUTO_TEST_CASE(SendNack)
Eric Newberry185ab292017-03-28 06:45:39 +0000444{
445 // Initialize with Options that enables reliability
446 GenericLinkService::Options options;
447 options.allowLocalFields = false;
448 options.reliabilityOptions.isEnabled = true;
449 initialize(options);
450
Junxiao Shi9d727852019-05-14 13:44:22 -0600451 auto nack1 = makeNack(*makeInterest("/localhost/test", false, nullopt, 323),
452 lp::NackReason::NO_ROUTE);
ashiqopu075bb7d2019-03-10 01:38:21 +0000453 face->sendNack(nack1, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000454
455 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
456 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400457 lp::Packet nack1pkt(transport->sentPackets.back().packet);
Eric Newberry185ab292017-03-28 06:45:39 +0000458 BOOST_CHECK(nack1pkt.has<lp::NackField>());
459 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000460 BOOST_CHECK(nack1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000461}
462
463BOOST_AUTO_TEST_SUITE_END() // Reliability
Eric Newberry86d31872015-09-23 16:24:59 -0700464
Eric Newberryb49313d2017-12-24 20:22:27 -0700465// congestion detection and marking
466BOOST_AUTO_TEST_SUITE(CongestionMark)
467
468BOOST_AUTO_TEST_CASE(NoCongestion)
469{
470 GenericLinkService::Options options;
471 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400472 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700473 initialize(options, MTU_UNLIMITED, 65536);
474 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
475 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
476 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
477
Junxiao Shi9d727852019-05-14 13:44:22 -0600478 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700479
480 // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes
481
482 // no congestion
483 transport->setSendQueueLength(0);
ashiqopu075bb7d2019-03-10 01:38:21 +0000484 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700485 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400486 lp::Packet pkt1(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700487 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
488 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
489 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
490 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
491
492 // no congestion
493 transport->setSendQueueLength(32768);
ashiqopu075bb7d2019-03-10 01:38:21 +0000494 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700495 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400496 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700497 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
498 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
499 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
500 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
501}
502
503BOOST_AUTO_TEST_CASE(CongestionCoDel)
504{
505 GenericLinkService::Options options;
506 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400507 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700508 initialize(options, MTU_UNLIMITED, 65536);
509 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
510 BOOST_CHECK_EQUAL(service->m_lastMarkTime, time::steady_clock::TimePoint::min());
511 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
512 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
513
Junxiao Shi9d727852019-05-14 13:44:22 -0600514 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700515
516 // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes
517
518 // first congested packet, will be marked
519 transport->setSendQueueLength(32769);
ashiqopu075bb7d2019-03-10 01:38:21 +0000520 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700521 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400522 lp::Packet pkt1(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700523 BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1);
524 BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400525 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700526 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
527 time::steady_clock::TimePoint lastMarkTime = time::steady_clock::now();
528 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
529 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
530 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
531
532 // advance clock to half of marking interval cycle
Davide Pesavento14e71f02019-03-28 17:35:25 -0400533 advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700534
535 // second congested packet, but within marking interval, will not be marked
536 transport->setSendQueueLength(33000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000537 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700538 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400539 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700540 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
541 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
542 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
543 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
544 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
545
546 // advance clocks past end of initial interval cycle
Davide Pesavento14e71f02019-03-28 17:35:25 -0400547 this->advanceClocks(51_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700548
549 // first congested packet after waiting marking interval, will be marked
550 transport->setSendQueueLength(40000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000551 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700552 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400553 lp::Packet pkt3(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700554 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1);
555 BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1);
556 time::nanoseconds markingInterval(
557 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
558 std::sqrt(service->m_nMarkedSinceInMarkingState)));
559 nextMarkTime += markingInterval;
560 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
561 lastMarkTime = time::steady_clock::now();
562 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
563 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
564 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
565
566 // advance clock partway through current marking interval
Davide Pesavento14e71f02019-03-28 17:35:25 -0400567 this->advanceClocks(markingInterval - 10_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700568
569 // still congested, but within marking interval cycle
570 transport->setSendQueueLength(38000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000571 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700572 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400573 lp::Packet pkt4(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700574 BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0);
575 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
576 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
577 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
578 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
579
580 // advance clocks past end of current marking interval cycle
Davide Pesavento14e71f02019-03-28 17:35:25 -0400581 this->advanceClocks(11_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700582
583 // still congested, after marking interval cycle
584 transport->setSendQueueLength(39000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000585 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700586 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400587 lp::Packet pkt5(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700588 BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1);
589 BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1);
590 markingInterval = time::nanoseconds(
591 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
592 std::sqrt(service->m_nMarkedSinceInMarkingState)));
593 nextMarkTime += markingInterval;
594 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
595 lastMarkTime = time::steady_clock::now();
596 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
597 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
598 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
599
Davide Pesavento14e71f02019-03-28 17:35:25 -0400600 this->advanceClocks(1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700601
602 // still congested, but within marking interval cycle
603 transport->setSendQueueLength(38000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000604 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700605 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400606 lp::Packet pkt6(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700607 BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0);
608 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
609 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
610 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
611 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
612
613 this->advanceClocks(markingInterval);
614
615 // still congested, after marking interval cycle
616 transport->setSendQueueLength(34000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000617 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700618 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400619 lp::Packet pkt7(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700620 BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1);
621 BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1);
622 markingInterval = time::nanoseconds(
623 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
624 std::sqrt(service->m_nMarkedSinceInMarkingState)));
625 nextMarkTime += markingInterval;
626 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
627 lastMarkTime = time::steady_clock::now();
628 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
629 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4);
630 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
631
632 // no more congestion
633 transport->setSendQueueLength(30000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000634 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700635 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400636 lp::Packet pkt8(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700637 BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0);
638 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
639 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
640 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
641 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
642
Davide Pesavento14e71f02019-03-28 17:35:25 -0400643 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700644
645 // send queue congested again, but can't mark packet because within one full interval of last mark
646 transport->setSendQueueLength(50000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000647 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700648 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400649 lp::Packet pkt9(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700650 BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0);
651 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
652 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
653 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
654 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
655
656 // advance clock past full 100ms interval since last mark
Davide Pesavento14e71f02019-03-28 17:35:25 -0400657 this->advanceClocks(51_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700658
659 transport->setSendQueueLength(40000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000660 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700661 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400662 lp::Packet pkt10(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700663 BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1);
664 BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400665 nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700666 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
667 lastMarkTime = time::steady_clock::now();
668 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
669 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
670 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
671
672 // advance clock partway through 100ms marking interval
Davide Pesavento14e71f02019-03-28 17:35:25 -0400673 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700674
675 // not marked since within 100ms window before can mark again
676 transport->setSendQueueLength(50000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000677 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700678 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400679 lp::Packet pkt11(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700680 BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0);
681 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
682 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
683 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
684 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
685
686 // advance clocks past m_nextMarkTime
Davide Pesavento14e71f02019-03-28 17:35:25 -0400687 this->advanceClocks(51_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700688
689 // markable packet, queue length still above threshold
690 transport->setSendQueueLength(33000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000691 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700692 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400693 lp::Packet pkt12(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700694 BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1);
695 BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1);
696 markingInterval = time::nanoseconds(
697 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
698 std::sqrt(service->m_nMarkedSinceInMarkingState)));
699 nextMarkTime += markingInterval;
700 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
701 lastMarkTime = time::steady_clock::now();
702 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
703 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
704 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
705
706 // no more congestion
707 transport->setSendQueueLength(10000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000708 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700709 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400710 lp::Packet pkt13(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700711 BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0);
712 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
713 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
714 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
715 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
716
717 // advance clocks past one full interval since last mark
Davide Pesavento14e71f02019-03-28 17:35:25 -0400718 this->advanceClocks(101_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700719
720 // start congestion again
721 transport->setSendQueueLength(50000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000722 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700723 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400724 lp::Packet pkt14(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700725 BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 1);
726 BOOST_CHECK_EQUAL(pkt14.get<lp::CongestionMarkField>(), 1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400727 nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700728 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
729 lastMarkTime = time::steady_clock::now();
730 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
731 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
732 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 7);
733
734 // no more congestion, cancel marking interval
735 transport->setSendQueueLength(5000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000736 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700737 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400738 lp::Packet pkt15(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700739 BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0);
740 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
741 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
742 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
743 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 7);
744}
745
746BOOST_AUTO_TEST_CASE(DefaultThreshold)
747{
748 GenericLinkService::Options options;
749 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400750 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700751 initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED);
752 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
753 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
754 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
755
Junxiao Shi9d727852019-05-14 13:44:22 -0600756 auto interest = makeInterest("/12345678");
Eric Newberryb49313d2017-12-24 20:22:27 -0700757
758 // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure
759 // the queue capacity
760
761 // no congestion
762 transport->setSendQueueLength(0);
ashiqopu075bb7d2019-03-10 01:38:21 +0000763 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700764 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400765 lp::Packet pkt1(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700766 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
767 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
768 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
769 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
770
771 // no congestion
772 transport->setSendQueueLength(65536);
ashiqopu075bb7d2019-03-10 01:38:21 +0000773 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700774 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400775 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700776 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
777 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
778 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
779 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
780
781 // first congested (and marked) packet
782 transport->setSendQueueLength(65537);
ashiqopu075bb7d2019-03-10 01:38:21 +0000783 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700784 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400785 lp::Packet pkt3(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700786 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1);
787 BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400788 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700789 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
790 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
791 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
792}
793
794BOOST_AUTO_TEST_SUITE_END() // CongestionMark
795
Eric Newberryee400b52016-11-24 14:12:48 +0000796BOOST_AUTO_TEST_SUITE(LpFields)
Eric Newberrya98bf932015-09-21 00:58:47 -0700797
Eric Newberrya98bf932015-09-21 00:58:47 -0700798BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId)
799{
Eric Newberry86d31872015-09-23 16:24:59 -0700800 // Initialize with Options that enables local fields
801 GenericLinkService::Options options;
802 options.allowLocalFields = true;
803 initialize(options);
804
Junxiao Shi9d727852019-05-14 13:44:22 -0600805 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700806 lp::Packet packet(interest->wireEncode());
807 packet.set<lp::NextHopFaceIdField>(1000);
808
809 transport->receivePacket(packet.wireEncode());
810
811 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +0000812 shared_ptr<lp::NextHopFaceIdTag> tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>();
813 BOOST_REQUIRE(tag != nullptr);
814 BOOST_CHECK_EQUAL(*tag, 1000);
Eric Newberrya98bf932015-09-21 00:58:47 -0700815}
816
817BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled)
818{
Eric Newberry86d31872015-09-23 16:24:59 -0700819 // Initialize with Options that disables local fields
820 GenericLinkService::Options options;
821 options.allowLocalFields = false;
822 initialize(options);
823
Junxiao Shi9d727852019-05-14 13:44:22 -0600824 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700825 lp::Packet packet(interest->wireEncode());
826 packet.set<lp::NextHopFaceIdField>(1000);
827
828 transport->receivePacket(packet.wireEncode());
829
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700830 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700831 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700832}
833
834BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData)
835{
Eric Newberry86d31872015-09-23 16:24:59 -0700836 // Initialize with Options that enables local fields
837 GenericLinkService::Options options;
838 options.allowLocalFields = true;
839 initialize(options);
840
Junxiao Shi9d727852019-05-14 13:44:22 -0600841 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700842 lp::Packet packet(data->wireEncode());
843 packet.set<lp::NextHopFaceIdField>(1000);
844
845 transport->receivePacket(packet.wireEncode());
846
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700847 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700848 BOOST_CHECK(receivedData.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700849}
850
851BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack)
852{
Eric Newberry86d31872015-09-23 16:24:59 -0700853 // Initialize with Options that enables local fields
854 GenericLinkService::Options options;
855 options.allowLocalFields = true;
856 initialize(options);
857
Junxiao Shi9d727852019-05-14 13:44:22 -0600858 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
859 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -0700860 lp::Packet packet;
861 packet.set<lp::FragmentField>(std::make_pair(
862 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
863 packet.set<lp::NackField>(nack.getHeader());
864 packet.set<lp::NextHopFaceIdField>(1000);
865
866 transport->receivePacket(packet.wireEncode());
867
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700868 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700869 BOOST_CHECK(receivedNacks.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700870}
871
Junxiao Shi6eb02712017-05-27 22:48:02 +0000872BOOST_AUTO_TEST_CASE(ReceiveCachePolicy)
Eric Newberrya98bf932015-09-21 00:58:47 -0700873{
Junxiao Shi6eb02712017-05-27 22:48:02 +0000874 // Initialize with Options that disables local fields
Eric Newberry86d31872015-09-23 16:24:59 -0700875 GenericLinkService::Options options;
Junxiao Shi6eb02712017-05-27 22:48:02 +0000876 options.allowLocalFields = false;
Eric Newberry86d31872015-09-23 16:24:59 -0700877 initialize(options);
Junxiao Shi6eb02712017-05-27 22:48:02 +0000878 // CachePolicy is unprivileged and does not require allowLocalFields option.
Eric Newberry86d31872015-09-23 16:24:59 -0700879
Junxiao Shi9d727852019-05-14 13:44:22 -0600880 auto data = makeData("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700881 lp::Packet packet(data->wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000882 packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE));
Eric Newberry86d31872015-09-23 16:24:59 -0700883
884 transport->receivePacket(packet.wireEncode());
885
886 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +0000887 shared_ptr<lp::CachePolicyTag> tag = receivedData.back().getTag<lp::CachePolicyTag>();
888 BOOST_REQUIRE(tag != nullptr);
889 BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700890}
891
Junxiao Shi6eb02712017-05-27 22:48:02 +0000892BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest)
Eric Newberrya98bf932015-09-21 00:58:47 -0700893{
Eric Newberry86d31872015-09-23 16:24:59 -0700894 // Initialize with Options that enables local fields
895 GenericLinkService::Options options;
896 options.allowLocalFields = true;
897 initialize(options);
898
Junxiao Shi9d727852019-05-14 13:44:22 -0600899 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700900 lp::Packet packet(interest->wireEncode());
901 lp::CachePolicy policy;
902 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
903 packet.set<lp::CachePolicyField>(policy);
904
905 transport->receivePacket(packet.wireEncode());
906
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700907 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700908 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700909}
910
Junxiao Shi6eb02712017-05-27 22:48:02 +0000911BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack)
Eric Newberrya98bf932015-09-21 00:58:47 -0700912{
Eric Newberry86d31872015-09-23 16:24:59 -0700913 // Initialize with Options that enables local fields
914 GenericLinkService::Options options;
915 options.allowLocalFields = true;
916 initialize(options);
917
Junxiao Shi9d727852019-05-14 13:44:22 -0600918 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
919 lp::NackReason::NO_ROUTE);
Eric Newberry86d31872015-09-23 16:24:59 -0700920 lp::Packet packet(nack.getInterest().wireEncode());
921 packet.set<lp::NackField>(nack.getHeader());
922 lp::CachePolicy policy;
923 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
924 packet.set<lp::CachePolicyField>(policy);
925
926 transport->receivePacket(packet.wireEncode());
927
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700928 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700929 BOOST_CHECK(receivedNacks.empty());
930}
931
932BOOST_AUTO_TEST_CASE(SendIncomingFaceId)
933{
934 // Initialize with Options that enables local fields
935 GenericLinkService::Options options;
936 options.allowLocalFields = true;
937 initialize(options);
938
Junxiao Shi9d727852019-05-14 13:44:22 -0600939 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +0000940 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -0700941
ashiqopu075bb7d2019-03-10 01:38:21 +0000942 face->sendInterest(*interest, 0);
Eric Newberry86d31872015-09-23 16:24:59 -0700943
944 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
945 lp::Packet sent(transport->sentPackets.back().packet);
946 BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>());
947 BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000);
948}
949
950BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled)
951{
952 // Initialize with Options that disables local fields
953 GenericLinkService::Options options;
954 options.allowLocalFields = false;
955 initialize(options);
956
Junxiao Shi9d727852019-05-14 13:44:22 -0600957 auto interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +0000958 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -0700959
ashiqopu075bb7d2019-03-10 01:38:21 +0000960 face->sendInterest(*interest, 0);
Eric Newberry86d31872015-09-23 16:24:59 -0700961
962 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
963 lp::Packet sent(transport->sentPackets.back().packet);
964 BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>());
965}
966
967BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest)
968{
969 // Initialize with Options that enables local fields
970 GenericLinkService::Options options;
971 options.allowLocalFields = true;
972 initialize(options);
973
Junxiao Shi9d727852019-05-14 13:44:22 -0600974 auto interest = makeInterest("/12345678");
Eric Newberry86d31872015-09-23 16:24:59 -0700975 lp::Packet packet(interest->wireEncode());
976 packet.set<lp::IncomingFaceIdField>(1000);
977
978 transport->receivePacket(packet.wireEncode());
979
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700980 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700981 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +0000982 BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -0700983}
984
985BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData)
986{
987 // Initialize with Options that enables local fields
988 GenericLinkService::Options options;
989 options.allowLocalFields = true;
990 initialize(options);
991
Junxiao Shi9d727852019-05-14 13:44:22 -0600992 auto data = makeData("/z1megUh9Bj");
Eric Newberry86d31872015-09-23 16:24:59 -0700993 lp::Packet packet(data->wireEncode());
994 packet.set<lp::IncomingFaceIdField>(1000);
995
996 transport->receivePacket(packet.wireEncode());
997
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700998 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700999 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001000 BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001001}
1002
1003BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack)
1004{
1005 // Initialize with Options that enables local fields
1006 GenericLinkService::Options options;
1007 options.allowLocalFields = true;
1008 initialize(options);
1009
Junxiao Shi9d727852019-05-14 13:44:22 -06001010 lp::Nack nack = makeNack(*makeInterest("/TPAhdiHz", false, nullopt, 278),
1011 lp::NackReason::CONGESTION);
Eric Newberry86d31872015-09-23 16:24:59 -07001012 lp::Packet packet(nack.getInterest().wireEncode());
1013 packet.set<lp::NackField>(nack.getHeader());
1014 packet.set<lp::IncomingFaceIdField>(1000);
1015
1016 transport->receivePacket(packet.wireEncode());
1017
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001018 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001019 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001020 BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberrya98bf932015-09-21 00:58:47 -07001021}
1022
Eric Newberryee400b52016-11-24 14:12:48 +00001023BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest)
1024{
Junxiao Shi9d727852019-05-14 13:44:22 -06001025 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001026 interest->setTag(make_shared<lp::CongestionMarkTag>(1));
1027
ashiqopu075bb7d2019-03-10 01:38:21 +00001028 face->sendInterest(*interest, 0);
Eric Newberryee400b52016-11-24 14:12:48 +00001029
1030 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1031 lp::Packet sent(transport->sentPackets.back().packet);
1032 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1033 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1);
1034}
1035
1036BOOST_AUTO_TEST_CASE(SendCongestionMarkData)
1037{
Junxiao Shi9d727852019-05-14 13:44:22 -06001038 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001039 data->setTag(make_shared<lp::CongestionMarkTag>(0));
1040
ashiqopu075bb7d2019-03-10 01:38:21 +00001041 face->sendData(*data, 0);
Eric Newberryee400b52016-11-24 14:12:48 +00001042
1043 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1044 lp::Packet sent(transport->sentPackets.back().packet);
1045 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1046 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0);
1047}
1048
1049BOOST_AUTO_TEST_CASE(SendCongestionMarkNack)
1050{
Junxiao Shi9d727852019-05-14 13:44:22 -06001051 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1052 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001053 nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max()));
1054
ashiqopu075bb7d2019-03-10 01:38:21 +00001055 face->sendNack(nack, 0);
Eric Newberryee400b52016-11-24 14:12:48 +00001056
1057 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1058 lp::Packet sent(transport->sentPackets.back().packet);
1059 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1060 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max());
1061}
1062
1063BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest)
1064{
Junxiao Shi9d727852019-05-14 13:44:22 -06001065 auto interest = makeInterest("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001066 lp::Packet packet(interest->wireEncode());
1067 packet.set<lp::CongestionMarkField>(1);
1068
1069 transport->receivePacket(packet.wireEncode());
1070
1071 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
1072 shared_ptr<lp::CongestionMarkTag> tag = receivedInterests.back().getTag<lp::CongestionMarkTag>();
1073 BOOST_REQUIRE(tag != nullptr);
1074 BOOST_CHECK_EQUAL(*tag, 1);
1075}
1076
1077BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData)
1078{
Junxiao Shi9d727852019-05-14 13:44:22 -06001079 auto data = makeData("/12345678");
Eric Newberryee400b52016-11-24 14:12:48 +00001080 lp::Packet packet(data->wireEncode());
1081 packet.set<lp::CongestionMarkField>(1);
1082
1083 transport->receivePacket(packet.wireEncode());
1084
1085 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
1086 shared_ptr<lp::CongestionMarkTag> tag = receivedData.back().getTag<lp::CongestionMarkTag>();
1087 BOOST_REQUIRE(tag != nullptr);
1088 BOOST_CHECK_EQUAL(*tag, 1);
1089}
1090
1091BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack)
1092{
Junxiao Shi9d727852019-05-14 13:44:22 -06001093 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1094 lp::NackReason::NO_ROUTE);
Eric Newberryee400b52016-11-24 14:12:48 +00001095 lp::Packet packet;
1096 packet.set<lp::FragmentField>(std::make_pair(
1097 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1098 packet.set<lp::NackField>(nack.getHeader());
1099 packet.set<lp::CongestionMarkField>(1);
1100
1101 transport->receivePacket(packet.wireEncode());
1102
1103 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
1104 shared_ptr<lp::CongestionMarkTag> tag = receivedNacks.back().getTag<lp::CongestionMarkTag>();
1105 BOOST_REQUIRE(tag != nullptr);
1106 BOOST_CHECK_EQUAL(*tag, 1);
1107}
1108
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001109BOOST_AUTO_TEST_CASE(SendNonDiscovery)
1110{
1111 GenericLinkService::Options options;
1112 options.allowSelfLearning = true;
1113 initialize(options);
1114
Junxiao Shi9d727852019-05-14 13:44:22 -06001115 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001116 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1117
ashiqopu075bb7d2019-03-10 01:38:21 +00001118 face->sendInterest(*interest, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001119
1120 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1121 lp::Packet sent(transport->sentPackets.back().packet);
1122 BOOST_CHECK(sent.has<lp::NonDiscoveryField>());
1123}
1124
1125BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled)
1126{
1127 GenericLinkService::Options options;
1128 options.allowSelfLearning = false;
1129 initialize(options);
1130
Junxiao Shi9d727852019-05-14 13:44:22 -06001131 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001132 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1133
ashiqopu075bb7d2019-03-10 01:38:21 +00001134 face->sendInterest(*interest, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001135
1136 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1137 lp::Packet sent(transport->sentPackets.back().packet);
1138 BOOST_CHECK(!sent.has<lp::NonDiscoveryField>());
1139}
1140
1141BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery)
1142{
1143 GenericLinkService::Options options;
1144 options.allowSelfLearning = true;
1145 initialize(options);
1146
Junxiao Shi9d727852019-05-14 13:44:22 -06001147 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001148 lp::Packet packet(interest->wireEncode());
1149 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1150
1151 transport->receivePacket(packet.wireEncode());
1152
1153 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
1154 shared_ptr<lp::NonDiscoveryTag> tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
1155 BOOST_CHECK(tag != nullptr);
1156}
1157
1158BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled)
1159{
1160 GenericLinkService::Options options;
1161 options.allowSelfLearning = false;
1162 initialize(options);
1163
Junxiao Shi9d727852019-05-14 13:44:22 -06001164 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001165 lp::Packet packet(interest->wireEncode());
1166 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1167
1168 transport->receivePacket(packet.wireEncode());
1169
1170 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1171 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
1172
1173 shared_ptr<lp::NonDiscoveryTag> tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
1174 BOOST_CHECK(tag == nullptr);
1175}
1176
1177BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData)
1178{
1179 GenericLinkService::Options options;
1180 options.allowSelfLearning = true;
1181 initialize(options);
1182
Junxiao Shi9d727852019-05-14 13:44:22 -06001183 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001184 lp::Packet packet(data->wireEncode());
1185 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1186
1187 transport->receivePacket(packet.wireEncode());
1188
1189 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1190 BOOST_CHECK(receivedData.empty());
1191}
1192
1193BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack)
1194{
1195 GenericLinkService::Options options;
1196 options.allowSelfLearning = true;
1197 initialize(options);
1198
Junxiao Shi9d727852019-05-14 13:44:22 -06001199 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1200 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001201 lp::Packet packet;
1202 packet.set<lp::FragmentField>(std::make_pair(
1203 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1204 packet.set<lp::NackField>(nack.getHeader());
1205 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1206
1207 transport->receivePacket(packet.wireEncode());
1208
1209 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1210 BOOST_CHECK(receivedNacks.empty());
1211}
1212
1213BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement)
1214{
1215 GenericLinkService::Options options;
1216 options.allowSelfLearning = true;
1217 initialize(options);
1218
Junxiao Shi9d727852019-05-14 13:44:22 -06001219 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001220 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1221 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001222
ashiqopu075bb7d2019-03-10 01:38:21 +00001223 face->sendData(*data, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001224
1225 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1226 lp::Packet sent(transport->sentPackets.back().packet);
1227 BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>());
1228}
1229
1230BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled)
1231{
1232 GenericLinkService::Options options;
1233 options.allowSelfLearning = false;
1234 initialize(options);
1235
Junxiao Shi9d727852019-05-14 13:44:22 -06001236 auto data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001237 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1238 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001239
ashiqopu075bb7d2019-03-10 01:38:21 +00001240 face->sendData(*data, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001241
1242 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1243 lp::Packet sent(transport->sentPackets.back().packet);
1244 BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>());
1245}
1246
1247BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement)
1248{
1249 GenericLinkService::Options options;
1250 options.allowSelfLearning = true;
1251 initialize(options);
1252
Junxiao Shi9d727852019-05-14 13:44:22 -06001253 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001254 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001255 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1256 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001257
1258 transport->receivePacket(packet.wireEncode());
1259
1260 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
1261 shared_ptr<lp::PrefixAnnouncementTag> tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangbce3cb52018-09-05 20:08:27 -07001262 BOOST_CHECK_EQUAL(tag->get().getPrefixAnn()->getAnnouncedName(), "/local/ndn/prefix");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001263}
1264
1265BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled)
1266{
1267 GenericLinkService::Options options;
1268 options.allowSelfLearning = false;
1269 initialize(options);
1270
Junxiao Shi9d727852019-05-14 13:44:22 -06001271 auto data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001272 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001273 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1274 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001275
1276 transport->receivePacket(packet.wireEncode());
1277
1278 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1279 BOOST_CHECK_EQUAL(receivedData.size(), 1);
1280
Teng Liangbce3cb52018-09-05 20:08:27 -07001281 shared_ptr<lp::PrefixAnnouncementTag> tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001282 BOOST_CHECK(tag == nullptr);
1283}
1284
1285BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest)
1286{
1287 GenericLinkService::Options options;
1288 options.allowSelfLearning = true;
1289 initialize(options);
1290
Junxiao Shi9d727852019-05-14 13:44:22 -06001291 auto interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001292 lp::Packet packet(interest->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001293 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1294 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001295
1296 transport->receivePacket(packet.wireEncode());
1297
1298 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1299 BOOST_CHECK(receivedInterests.empty());
1300}
1301
1302BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack)
1303{
1304 GenericLinkService::Options options;
1305 options.allowSelfLearning = true;
1306 initialize(options);
1307
Junxiao Shi9d727852019-05-14 13:44:22 -06001308 lp::Nack nack = makeNack(*makeInterest("/localhost/test", false, nullopt, 123),
1309 lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001310 lp::Packet packet;
1311 packet.set<lp::FragmentField>(std::make_pair(
1312 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1313 packet.set<lp::NackField>(nack.getHeader());
Teng Liangbce3cb52018-09-05 20:08:27 -07001314 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1315 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001316
1317 transport->receivePacket(packet.wireEncode());
1318
1319 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1320 BOOST_CHECK(receivedNacks.empty());
1321}
1322
Eric Newberryee400b52016-11-24 14:12:48 +00001323BOOST_AUTO_TEST_SUITE_END() // LpFields
Eric Newberrya98bf932015-09-21 00:58:47 -07001324
Eric Newberrya1939ba2015-10-09 12:35:03 -07001325BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets
1326
1327BOOST_AUTO_TEST_CASE(WrongTlvType)
1328{
1329 // Initialize with Options that disables all services
1330 GenericLinkService::Options options;
1331 options.allowLocalFields = false;
1332 initialize(options);
1333
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001334 auto packet = ndn::encoding::makeEmptyBlock(tlv::Name);
1335 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001336
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001337 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001338 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1339 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1340 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1341}
1342
1343BOOST_AUTO_TEST_CASE(Unparsable)
1344{
1345 // Initialize with Options that disables all services
1346 GenericLinkService::Options options;
1347 options.allowLocalFields = false;
1348 initialize(options);
1349
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001350 auto packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x");
Eric Newberrya1939ba2015-10-09 12:35:03 -07001351 BOOST_CHECK_THROW(packet.parse(), tlv::Error);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001352 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001353
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001354 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001355 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1356 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1357 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1358}
1359
1360BOOST_AUTO_TEST_SUITE_END() // Malformed
1361
Eric Newberry86d31872015-09-23 16:24:59 -07001362BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService
1363BOOST_AUTO_TEST_SUITE_END() // Face
Eric Newberrya98bf932015-09-21 00:58:47 -07001364
1365} // namespace tests
1366} // namespace face
1367} // namespace nfd