blob: fc5efc28a4b53d99fa925729dd1063c2c02ee884 [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
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400142 auto nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
ashiqopu075bb7d2019-03-10 01:38:21 +0000143 face->sendNack(nack1, 0);
Eric Newberrya98bf932015-09-21 00:58:47 -0700144
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700145 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700146 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400147 lp::Packet nack1pkt(transport->sentPackets.back().packet);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700148 BOOST_CHECK(nack1pkt.has<lp::NackField>());
149 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
150 BOOST_CHECK(!nack1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700151}
152
153BOOST_AUTO_TEST_CASE(ReceiveBareInterest)
154{
Eric Newberry86d31872015-09-23 16:24:59 -0700155 // Initialize with Options that disables all services
156 GenericLinkService::Options options;
157 options.allowLocalFields = false;
158 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700159
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400160 auto interest1 = makeInterest("/23Rd9hEiR");
Eric Newberrya98bf932015-09-21 00:58:47 -0700161 transport->receivePacket(interest1->wireEncode());
162
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700163 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700164 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
165 BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
166}
167
168BOOST_AUTO_TEST_CASE(ReceiveInterest)
169{
Eric Newberry86d31872015-09-23 16:24:59 -0700170 // Initialize with Options that disables all services
171 GenericLinkService::Options options;
172 options.allowLocalFields = false;
173 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700174
175 shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR");
176 lp::Packet lpPacket;
177 lpPacket.set<lp::FragmentField>(std::make_pair(
178 interest1->wireEncode().begin(), interest1->wireEncode().end()));
179 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
180
181 transport->receivePacket(lpPacket.wireEncode());
182
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700183 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700184 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
185 BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
186}
187
188BOOST_AUTO_TEST_CASE(ReceiveBareData)
189{
Eric Newberry86d31872015-09-23 16:24:59 -0700190 // Initialize with Options that disables all services
191 GenericLinkService::Options options;
192 options.allowLocalFields = false;
193 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700194
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400195 auto data1 = makeData("/12345678");
Eric Newberrya98bf932015-09-21 00:58:47 -0700196 transport->receivePacket(data1->wireEncode());
197
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700198 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700199 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
200 BOOST_CHECK_EQUAL(receivedData.back(), *data1);
201}
202
203BOOST_AUTO_TEST_CASE(ReceiveData)
204{
Eric Newberry86d31872015-09-23 16:24:59 -0700205 // Initialize with Options that disables all services
206 GenericLinkService::Options options;
207 options.allowLocalFields = false;
208 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700209
210 shared_ptr<Data> data1 = makeData("/12345689");
211 lp::Packet lpPacket;
212 lpPacket.set<lp::FragmentField>(std::make_pair(
213 data1->wireEncode().begin(), data1->wireEncode().end()));
214 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
215
216 transport->receivePacket(lpPacket.wireEncode());
217
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700218 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700219 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
220 BOOST_CHECK_EQUAL(receivedData.back(), *data1);
221}
222
223BOOST_AUTO_TEST_CASE(ReceiveNack)
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
230 lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
231 lp::Packet lpPacket;
232 lpPacket.set<lp::FragmentField>(std::make_pair(
233 nack1.getInterest().wireEncode().begin(), nack1.getInterest().wireEncode().end()));
234 lpPacket.set<lp::NackField>(nack1.getHeader());
235
236 transport->receivePacket(lpPacket.wireEncode());
237
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700238 BOOST_CHECK_EQUAL(service->getCounters().nInNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700239 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700240 BOOST_CHECK(receivedNacks.back().getReason() == nack1.getReason());
241 BOOST_CHECK(receivedNacks.back().getInterest() == nack1.getInterest());
Eric Newberrya98bf932015-09-21 00:58:47 -0700242}
243
Eric Newberrya1939ba2015-10-09 12:35:03 -0700244BOOST_AUTO_TEST_CASE(ReceiveIdlePacket)
245{
246 // Initialize with Options that disables all services
247 GenericLinkService::Options options;
248 options.allowLocalFields = false;
249 initialize(options);
250
251 lp::Packet lpPacket;
252 lpPacket.set<lp::SequenceField>(0);
253
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400254 transport->receivePacket(lpPacket.wireEncode());
Eric Newberrya1939ba2015-10-09 12:35:03 -0700255
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700256 // IDLE packet should be ignored, but is not an error
257 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0);
Eric Newberrya1939ba2015-10-09 12:35:03 -0700258 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
259 BOOST_CHECK_EQUAL(receivedData.size(), 0);
260 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
261}
262
Eric Newberrya98bf932015-09-21 00:58:47 -0700263BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive
264
Eric Newberry86d31872015-09-23 16:24:59 -0700265BOOST_AUTO_TEST_SUITE(Fragmentation)
266
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700267BOOST_AUTO_TEST_CASE(FragmentationDisabledExceedMtuDrop)
268{
269 // Initialize with Options that disable fragmentation
270 GenericLinkService::Options options;
271 options.allowFragmentation = false;
272 initialize(options);
273
274 transport->setMtu(55);
275
276 shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000277 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700278
279 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
280 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
281}
282
283BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu)
284{
285 // Initialize with Options that enable fragmentation
286 GenericLinkService::Options options;
287 options.allowFragmentation = true;
288 initialize(options);
289
290 transport->setMtu(MTU_UNLIMITED);
291
292 shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000293 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700294
295 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
296}
297
298BOOST_AUTO_TEST_CASE(FragmentationUnderMtu)
299{
300 // Initialize with Options that enable fragmentation
301 GenericLinkService::Options options;
302 options.allowFragmentation = true;
303 initialize(options);
304
305 transport->setMtu(105);
306
307 shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000308 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700309
310 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
311}
312
313BOOST_AUTO_TEST_CASE(FragmentationOverMtu)
314{
315 // Initialize with Options that enable fragmentation
316 GenericLinkService::Options options;
317 options.allowFragmentation = true;
318 initialize(options);
319
320 transport->setMtu(60);
321
322 shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789");
ashiqopu075bb7d2019-03-10 01:38:21 +0000323 face->sendData(*data, 0);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700324
325 BOOST_CHECK_GT(transport->sentPackets.size(), 1);
326}
327
328BOOST_AUTO_TEST_CASE(ReassembleFragments)
329{
330 // Initialize with Options that enables reassembly
331 GenericLinkService::Options options;
332 options.allowReassembly = true;
333 initialize(options);
334
335 shared_ptr<Interest> interest = makeInterest(
336 "/mt7P130BHXmtLm5dwaY5dpUM6SWYNN2B05g7y3UhsQuLvDdnTWdNnTeEiLuW3FAbJRSG3tzQ0UfaSEgG9rvYHmsKtgPMag1Hj4Tr");
337 lp::Packet packet(interest->wireEncode());
338
339 // fragment the packet
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400340 LpFragmenter fragmenter({});
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700341 size_t mtu = 100;
342 bool isOk = false;
343 std::vector<lp::Packet> frags;
344 std::tie(isOk, frags) = fragmenter.fragmentPacket(packet, mtu);
345 BOOST_REQUIRE(isOk);
346 BOOST_CHECK_GT(frags.size(), 1);
347
348 // receive the fragments
349 for (ssize_t fragIndex = frags.size() - 1; fragIndex >= 0; --fragIndex) {
350 size_t sequence = 1000 + fragIndex;
351 frags[fragIndex].add<lp::SequenceField>(sequence);
352
353 transport->receivePacket(frags[fragIndex].wireEncode());
354
355 if (fragIndex > 0) {
356 BOOST_CHECK(receivedInterests.empty());
357 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 1);
358 }
359 else {
360 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
361 BOOST_CHECK_EQUAL(receivedInterests.back(), *interest);
362 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 0);
363 }
364 }
365}
366
Eric Newberry86d31872015-09-23 16:24:59 -0700367BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex)
368{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700369 // Initialize with Options that disables reassembly
370 GenericLinkService::Options options;
371 options.allowReassembly = false;
372 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700373
374 shared_ptr<Interest> interest = makeInterest("/IgFe6NvH");
375 lp::Packet packet(interest->wireEncode());
376 packet.set<lp::FragIndexField>(140);
377
378 transport->receivePacket(packet.wireEncode());
379
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700380 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700381 BOOST_CHECK(receivedInterests.empty());
382}
383
384BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount)
385{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700386 // Initialize with Options that disables reassembly
387 GenericLinkService::Options options;
388 options.allowReassembly = false;
389 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700390
391 shared_ptr<Interest> interest = makeInterest("/SeGmEjvIVX");
392 lp::Packet packet(interest->wireEncode());
393 packet.set<lp::FragCountField>(276);
394
395 transport->receivePacket(packet.wireEncode());
396
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700397 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700398 BOOST_CHECK(receivedInterests.empty());
399}
400
401BOOST_AUTO_TEST_SUITE_END() // Fragmentation
402
Eric Newberry185ab292017-03-28 06:45:39 +0000403BOOST_AUTO_TEST_SUITE(Reliability)
404
Eric Newberry7b0071e2017-07-03 17:33:31 +0000405BOOST_AUTO_TEST_CASE(SendInterest)
Eric Newberry185ab292017-03-28 06:45:39 +0000406{
407 // Initialize with Options that enables reliability
408 GenericLinkService::Options options;
409 options.allowLocalFields = false;
410 options.reliabilityOptions.isEnabled = true;
411 initialize(options);
412
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400413 auto interest1 = makeInterest("/localhost/test");
ashiqopu075bb7d2019-03-10 01:38:21 +0000414 face->sendInterest(*interest1, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000415
416 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
417 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400418 lp::Packet interest1pkt(transport->sentPackets.back().packet);
Eric Newberry185ab292017-03-28 06:45:39 +0000419 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000420 BOOST_CHECK(interest1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000421}
422
Eric Newberry7b0071e2017-07-03 17:33:31 +0000423BOOST_AUTO_TEST_CASE(SendData)
Eric Newberry185ab292017-03-28 06:45:39 +0000424{
425 // Initialize with Options that enables reliability
426 GenericLinkService::Options options;
427 options.allowLocalFields = false;
428 options.reliabilityOptions.isEnabled = true;
429 initialize(options);
430
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400431 auto data1 = makeData("/localhost/test");
ashiqopu075bb7d2019-03-10 01:38:21 +0000432 face->sendData(*data1, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000433
434 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
435 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400436 lp::Packet data1pkt(transport->sentPackets.back().packet);
Eric Newberry185ab292017-03-28 06:45:39 +0000437 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000438 BOOST_CHECK(data1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000439}
440
Eric Newberry7b0071e2017-07-03 17:33:31 +0000441BOOST_AUTO_TEST_CASE(SendNack)
Eric Newberry185ab292017-03-28 06:45:39 +0000442{
443 // Initialize with Options that enables reliability
444 GenericLinkService::Options options;
445 options.allowLocalFields = false;
446 options.reliabilityOptions.isEnabled = true;
447 initialize(options);
448
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400449 auto nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
ashiqopu075bb7d2019-03-10 01:38:21 +0000450 face->sendNack(nack1, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000451
452 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
453 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400454 lp::Packet nack1pkt(transport->sentPackets.back().packet);
Eric Newberry185ab292017-03-28 06:45:39 +0000455 BOOST_CHECK(nack1pkt.has<lp::NackField>());
456 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000457 BOOST_CHECK(nack1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000458}
459
460BOOST_AUTO_TEST_SUITE_END() // Reliability
Eric Newberry86d31872015-09-23 16:24:59 -0700461
Eric Newberryb49313d2017-12-24 20:22:27 -0700462// congestion detection and marking
463BOOST_AUTO_TEST_SUITE(CongestionMark)
464
465BOOST_AUTO_TEST_CASE(NoCongestion)
466{
467 GenericLinkService::Options options;
468 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400469 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700470 initialize(options, MTU_UNLIMITED, 65536);
471 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
472 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
473 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
474
475 shared_ptr<Interest> interest = makeInterest("/12345678");
476
477 // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes
478
479 // no congestion
480 transport->setSendQueueLength(0);
ashiqopu075bb7d2019-03-10 01:38:21 +0000481 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700482 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400483 lp::Packet pkt1(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700484 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
485 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
486 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
487 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
488
489 // no congestion
490 transport->setSendQueueLength(32768);
ashiqopu075bb7d2019-03-10 01:38:21 +0000491 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700492 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400493 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700494 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
495 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
496 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
497 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
498}
499
500BOOST_AUTO_TEST_CASE(CongestionCoDel)
501{
502 GenericLinkService::Options options;
503 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400504 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700505 initialize(options, MTU_UNLIMITED, 65536);
506 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
507 BOOST_CHECK_EQUAL(service->m_lastMarkTime, time::steady_clock::TimePoint::min());
508 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
509 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
510
511 shared_ptr<Interest> interest = makeInterest("/12345678");
512
513 // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes
514
515 // first congested packet, will be marked
516 transport->setSendQueueLength(32769);
ashiqopu075bb7d2019-03-10 01:38:21 +0000517 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700518 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400519 lp::Packet pkt1(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700520 BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1);
521 BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400522 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700523 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
524 time::steady_clock::TimePoint lastMarkTime = time::steady_clock::now();
525 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
526 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
527 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
528
529 // advance clock to half of marking interval cycle
Davide Pesavento14e71f02019-03-28 17:35:25 -0400530 advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700531
532 // second congested packet, but within marking interval, will not be marked
533 transport->setSendQueueLength(33000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000534 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700535 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400536 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700537 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
538 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
539 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
540 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
541 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
542
543 // advance clocks past end of initial interval cycle
Davide Pesavento14e71f02019-03-28 17:35:25 -0400544 this->advanceClocks(51_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700545
546 // first congested packet after waiting marking interval, will be marked
547 transport->setSendQueueLength(40000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000548 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700549 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400550 lp::Packet pkt3(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700551 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1);
552 BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1);
553 time::nanoseconds markingInterval(
554 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
555 std::sqrt(service->m_nMarkedSinceInMarkingState)));
556 nextMarkTime += markingInterval;
557 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
558 lastMarkTime = time::steady_clock::now();
559 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
560 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
561 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
562
563 // advance clock partway through current marking interval
Davide Pesavento14e71f02019-03-28 17:35:25 -0400564 this->advanceClocks(markingInterval - 10_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700565
566 // still congested, but within marking interval cycle
567 transport->setSendQueueLength(38000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000568 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700569 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400570 lp::Packet pkt4(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700571 BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0);
572 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
573 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
574 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
575 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
576
577 // advance clocks past end of current marking interval cycle
Davide Pesavento14e71f02019-03-28 17:35:25 -0400578 this->advanceClocks(11_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700579
580 // still congested, after marking interval cycle
581 transport->setSendQueueLength(39000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000582 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700583 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400584 lp::Packet pkt5(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700585 BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1);
586 BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1);
587 markingInterval = time::nanoseconds(
588 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
589 std::sqrt(service->m_nMarkedSinceInMarkingState)));
590 nextMarkTime += markingInterval;
591 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
592 lastMarkTime = time::steady_clock::now();
593 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
594 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
595 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
596
Davide Pesavento14e71f02019-03-28 17:35:25 -0400597 this->advanceClocks(1_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700598
599 // still congested, but within marking interval cycle
600 transport->setSendQueueLength(38000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000601 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700602 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400603 lp::Packet pkt6(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700604 BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0);
605 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
606 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
607 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
608 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
609
610 this->advanceClocks(markingInterval);
611
612 // still congested, after marking interval cycle
613 transport->setSendQueueLength(34000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000614 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700615 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400616 lp::Packet pkt7(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700617 BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1);
618 BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1);
619 markingInterval = time::nanoseconds(
620 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
621 std::sqrt(service->m_nMarkedSinceInMarkingState)));
622 nextMarkTime += markingInterval;
623 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
624 lastMarkTime = time::steady_clock::now();
625 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
626 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4);
627 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
628
629 // no more congestion
630 transport->setSendQueueLength(30000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000631 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700632 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400633 lp::Packet pkt8(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700634 BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0);
635 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
636 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
637 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
638 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
639
Davide Pesavento14e71f02019-03-28 17:35:25 -0400640 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700641
642 // send queue congested again, but can't mark packet because within one full interval of last mark
643 transport->setSendQueueLength(50000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000644 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700645 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400646 lp::Packet pkt9(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700647 BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0);
648 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
649 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
650 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
651 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
652
653 // advance clock past full 100ms interval since last mark
Davide Pesavento14e71f02019-03-28 17:35:25 -0400654 this->advanceClocks(51_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700655
656 transport->setSendQueueLength(40000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000657 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700658 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400659 lp::Packet pkt10(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700660 BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1);
661 BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400662 nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700663 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
664 lastMarkTime = time::steady_clock::now();
665 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
666 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
667 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
668
669 // advance clock partway through 100ms marking interval
Davide Pesavento14e71f02019-03-28 17:35:25 -0400670 this->advanceClocks(50_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700671
672 // not marked since within 100ms window before can mark again
673 transport->setSendQueueLength(50000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000674 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700675 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400676 lp::Packet pkt11(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700677 BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0);
678 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
679 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
680 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
681 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
682
683 // advance clocks past m_nextMarkTime
Davide Pesavento14e71f02019-03-28 17:35:25 -0400684 this->advanceClocks(51_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700685
686 // markable packet, queue length still above threshold
687 transport->setSendQueueLength(33000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000688 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700689 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400690 lp::Packet pkt12(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700691 BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1);
692 BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1);
693 markingInterval = time::nanoseconds(
694 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
695 std::sqrt(service->m_nMarkedSinceInMarkingState)));
696 nextMarkTime += markingInterval;
697 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
698 lastMarkTime = time::steady_clock::now();
699 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
700 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
701 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
702
703 // no more congestion
704 transport->setSendQueueLength(10000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000705 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700706 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400707 lp::Packet pkt13(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700708 BOOST_CHECK_EQUAL(pkt13.count<lp::CongestionMarkField>(), 0);
709 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
710 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
711 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
712 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
713
714 // advance clocks past one full interval since last mark
Davide Pesavento14e71f02019-03-28 17:35:25 -0400715 this->advanceClocks(101_ms);
Eric Newberryb49313d2017-12-24 20:22:27 -0700716
717 // start congestion again
718 transport->setSendQueueLength(50000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000719 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700720 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400721 lp::Packet pkt14(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700722 BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 1);
723 BOOST_CHECK_EQUAL(pkt14.get<lp::CongestionMarkField>(), 1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400724 nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700725 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
726 lastMarkTime = time::steady_clock::now();
727 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
728 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
729 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 7);
730
731 // no more congestion, cancel marking interval
732 transport->setSendQueueLength(5000);
ashiqopu075bb7d2019-03-10 01:38:21 +0000733 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700734 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400735 lp::Packet pkt15(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700736 BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0);
737 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
738 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
739 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
740 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 7);
741}
742
743BOOST_AUTO_TEST_CASE(DefaultThreshold)
744{
745 GenericLinkService::Options options;
746 options.allowCongestionMarking = true;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400747 options.baseCongestionMarkingInterval = 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700748 initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED);
749 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
750 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
751 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
752
753 shared_ptr<Interest> interest = makeInterest("/12345678");
754
755 // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure
756 // the queue capacity
757
758 // no congestion
759 transport->setSendQueueLength(0);
ashiqopu075bb7d2019-03-10 01:38:21 +0000760 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700761 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400762 lp::Packet pkt1(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700763 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
764 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
765 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
766 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
767
768 // no congestion
769 transport->setSendQueueLength(65536);
ashiqopu075bb7d2019-03-10 01:38:21 +0000770 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700771 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400772 lp::Packet pkt2(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700773 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
774 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
775 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
776 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
777
778 // first congested (and marked) packet
779 transport->setSendQueueLength(65537);
ashiqopu075bb7d2019-03-10 01:38:21 +0000780 face->sendInterest(*interest, 0);
Eric Newberryb49313d2017-12-24 20:22:27 -0700781 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -0400782 lp::Packet pkt3(transport->sentPackets.back().packet);
Eric Newberryb49313d2017-12-24 20:22:27 -0700783 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1);
784 BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400785 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + 100_ms;
Eric Newberryb49313d2017-12-24 20:22:27 -0700786 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
787 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
788 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
789}
790
791BOOST_AUTO_TEST_SUITE_END() // CongestionMark
792
Eric Newberryee400b52016-11-24 14:12:48 +0000793BOOST_AUTO_TEST_SUITE(LpFields)
Eric Newberrya98bf932015-09-21 00:58:47 -0700794
Eric Newberrya98bf932015-09-21 00:58:47 -0700795BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId)
796{
Eric Newberry86d31872015-09-23 16:24:59 -0700797 // Initialize with Options that enables local fields
798 GenericLinkService::Options options;
799 options.allowLocalFields = true;
800 initialize(options);
801
802 shared_ptr<Interest> interest = makeInterest("/12345678");
803 lp::Packet packet(interest->wireEncode());
804 packet.set<lp::NextHopFaceIdField>(1000);
805
806 transport->receivePacket(packet.wireEncode());
807
808 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +0000809 shared_ptr<lp::NextHopFaceIdTag> tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>();
810 BOOST_REQUIRE(tag != nullptr);
811 BOOST_CHECK_EQUAL(*tag, 1000);
Eric Newberrya98bf932015-09-21 00:58:47 -0700812}
813
814BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled)
815{
Eric Newberry86d31872015-09-23 16:24:59 -0700816 // Initialize with Options that disables local fields
817 GenericLinkService::Options options;
818 options.allowLocalFields = false;
819 initialize(options);
820
821 shared_ptr<Interest> interest = makeInterest("/12345678");
822 lp::Packet packet(interest->wireEncode());
823 packet.set<lp::NextHopFaceIdField>(1000);
824
825 transport->receivePacket(packet.wireEncode());
826
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700827 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700828 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700829}
830
831BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData)
832{
Eric Newberry86d31872015-09-23 16:24:59 -0700833 // Initialize with Options that enables local fields
834 GenericLinkService::Options options;
835 options.allowLocalFields = true;
836 initialize(options);
837
838 shared_ptr<Data> data = makeData("/12345678");
839 lp::Packet packet(data->wireEncode());
840 packet.set<lp::NextHopFaceIdField>(1000);
841
842 transport->receivePacket(packet.wireEncode());
843
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700844 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700845 BOOST_CHECK(receivedData.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700846}
847
848BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack)
849{
Eric Newberry86d31872015-09-23 16:24:59 -0700850 // Initialize with Options that enables local fields
851 GenericLinkService::Options options;
852 options.allowLocalFields = true;
853 initialize(options);
854
855 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
856 lp::Packet packet;
857 packet.set<lp::FragmentField>(std::make_pair(
858 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
859 packet.set<lp::NackField>(nack.getHeader());
860 packet.set<lp::NextHopFaceIdField>(1000);
861
862 transport->receivePacket(packet.wireEncode());
863
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700864 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700865 BOOST_CHECK(receivedNacks.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700866}
867
Junxiao Shi6eb02712017-05-27 22:48:02 +0000868BOOST_AUTO_TEST_CASE(ReceiveCachePolicy)
Eric Newberrya98bf932015-09-21 00:58:47 -0700869{
Junxiao Shi6eb02712017-05-27 22:48:02 +0000870 // Initialize with Options that disables local fields
Eric Newberry86d31872015-09-23 16:24:59 -0700871 GenericLinkService::Options options;
Junxiao Shi6eb02712017-05-27 22:48:02 +0000872 options.allowLocalFields = false;
Eric Newberry86d31872015-09-23 16:24:59 -0700873 initialize(options);
Junxiao Shi6eb02712017-05-27 22:48:02 +0000874 // CachePolicy is unprivileged and does not require allowLocalFields option.
Eric Newberry86d31872015-09-23 16:24:59 -0700875
876 shared_ptr<Data> data = makeData("/12345678");
877 lp::Packet packet(data->wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000878 packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE));
Eric Newberry86d31872015-09-23 16:24:59 -0700879
880 transport->receivePacket(packet.wireEncode());
881
882 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +0000883 shared_ptr<lp::CachePolicyTag> tag = receivedData.back().getTag<lp::CachePolicyTag>();
884 BOOST_REQUIRE(tag != nullptr);
885 BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700886}
887
Junxiao Shi6eb02712017-05-27 22:48:02 +0000888BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest)
Eric Newberrya98bf932015-09-21 00:58:47 -0700889{
Eric Newberry86d31872015-09-23 16:24:59 -0700890 // Initialize with Options that enables local fields
891 GenericLinkService::Options options;
892 options.allowLocalFields = true;
893 initialize(options);
894
895 shared_ptr<Interest> interest = makeInterest("/12345678");
896 lp::Packet packet(interest->wireEncode());
897 lp::CachePolicy policy;
898 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
899 packet.set<lp::CachePolicyField>(policy);
900
901 transport->receivePacket(packet.wireEncode());
902
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700903 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700904 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700905}
906
Junxiao Shi6eb02712017-05-27 22:48:02 +0000907BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack)
Eric Newberrya98bf932015-09-21 00:58:47 -0700908{
Eric Newberry86d31872015-09-23 16:24:59 -0700909 // Initialize with Options that enables local fields
910 GenericLinkService::Options options;
911 options.allowLocalFields = true;
912 initialize(options);
913
914 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
915 lp::Packet packet(nack.getInterest().wireEncode());
916 packet.set<lp::NackField>(nack.getHeader());
917 lp::CachePolicy policy;
918 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
919 packet.set<lp::CachePolicyField>(policy);
920
921 transport->receivePacket(packet.wireEncode());
922
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700923 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700924 BOOST_CHECK(receivedNacks.empty());
925}
926
927BOOST_AUTO_TEST_CASE(SendIncomingFaceId)
928{
929 // Initialize with Options that enables local fields
930 GenericLinkService::Options options;
931 options.allowLocalFields = true;
932 initialize(options);
933
934 shared_ptr<Interest> interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +0000935 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -0700936
ashiqopu075bb7d2019-03-10 01:38:21 +0000937 face->sendInterest(*interest, 0);
Eric Newberry86d31872015-09-23 16:24:59 -0700938
939 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
940 lp::Packet sent(transport->sentPackets.back().packet);
941 BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>());
942 BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000);
943}
944
945BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled)
946{
947 // Initialize with Options that disables local fields
948 GenericLinkService::Options options;
949 options.allowLocalFields = false;
950 initialize(options);
951
952 shared_ptr<Interest> interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +0000953 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -0700954
ashiqopu075bb7d2019-03-10 01:38:21 +0000955 face->sendInterest(*interest, 0);
Eric Newberry86d31872015-09-23 16:24:59 -0700956
957 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
958 lp::Packet sent(transport->sentPackets.back().packet);
959 BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>());
960}
961
962BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest)
963{
964 // Initialize with Options that enables local fields
965 GenericLinkService::Options options;
966 options.allowLocalFields = true;
967 initialize(options);
968
969 shared_ptr<Interest> interest = makeInterest("/12345678");
970 lp::Packet packet(interest->wireEncode());
971 packet.set<lp::IncomingFaceIdField>(1000);
972
973 transport->receivePacket(packet.wireEncode());
974
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700975 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700976 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +0000977 BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -0700978}
979
980BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData)
981{
982 // Initialize with Options that enables local fields
983 GenericLinkService::Options options;
984 options.allowLocalFields = true;
985 initialize(options);
986
987 shared_ptr<Data> data = makeData("/z1megUh9Bj");
988 lp::Packet packet(data->wireEncode());
989 packet.set<lp::IncomingFaceIdField>(1000);
990
991 transport->receivePacket(packet.wireEncode());
992
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700993 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700994 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +0000995 BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -0700996}
997
998BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack)
999{
1000 // Initialize with Options that enables local fields
1001 GenericLinkService::Options options;
1002 options.allowLocalFields = true;
1003 initialize(options);
1004
1005 lp::Nack nack = makeNack("/TPAhdiHz", 278, lp::NackReason::CONGESTION);
1006 lp::Packet packet(nack.getInterest().wireEncode());
1007 packet.set<lp::NackField>(nack.getHeader());
1008 packet.set<lp::IncomingFaceIdField>(1000);
1009
1010 transport->receivePacket(packet.wireEncode());
1011
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001012 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001013 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001014 BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberrya98bf932015-09-21 00:58:47 -07001015}
1016
Eric Newberryee400b52016-11-24 14:12:48 +00001017BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest)
1018{
1019 shared_ptr<Interest> interest = makeInterest("/12345678");
1020 interest->setTag(make_shared<lp::CongestionMarkTag>(1));
1021
ashiqopu075bb7d2019-03-10 01:38:21 +00001022 face->sendInterest(*interest, 0);
Eric Newberryee400b52016-11-24 14:12:48 +00001023
1024 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1025 lp::Packet sent(transport->sentPackets.back().packet);
1026 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1027 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1);
1028}
1029
1030BOOST_AUTO_TEST_CASE(SendCongestionMarkData)
1031{
1032 shared_ptr<Data> data = makeData("/12345678");
1033 data->setTag(make_shared<lp::CongestionMarkTag>(0));
1034
ashiqopu075bb7d2019-03-10 01:38:21 +00001035 face->sendData(*data, 0);
Eric Newberryee400b52016-11-24 14:12:48 +00001036
1037 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1038 lp::Packet sent(transport->sentPackets.back().packet);
1039 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1040 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0);
1041}
1042
1043BOOST_AUTO_TEST_CASE(SendCongestionMarkNack)
1044{
1045 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
1046 nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max()));
1047
ashiqopu075bb7d2019-03-10 01:38:21 +00001048 face->sendNack(nack, 0);
Eric Newberryee400b52016-11-24 14:12:48 +00001049
1050 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1051 lp::Packet sent(transport->sentPackets.back().packet);
1052 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1053 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max());
1054}
1055
1056BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest)
1057{
1058 shared_ptr<Interest> interest = makeInterest("/12345678");
1059 lp::Packet packet(interest->wireEncode());
1060 packet.set<lp::CongestionMarkField>(1);
1061
1062 transport->receivePacket(packet.wireEncode());
1063
1064 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
1065 shared_ptr<lp::CongestionMarkTag> tag = receivedInterests.back().getTag<lp::CongestionMarkTag>();
1066 BOOST_REQUIRE(tag != nullptr);
1067 BOOST_CHECK_EQUAL(*tag, 1);
1068}
1069
1070BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData)
1071{
1072 shared_ptr<Data> data = makeData("/12345678");
1073 lp::Packet packet(data->wireEncode());
1074 packet.set<lp::CongestionMarkField>(1);
1075
1076 transport->receivePacket(packet.wireEncode());
1077
1078 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
1079 shared_ptr<lp::CongestionMarkTag> tag = receivedData.back().getTag<lp::CongestionMarkTag>();
1080 BOOST_REQUIRE(tag != nullptr);
1081 BOOST_CHECK_EQUAL(*tag, 1);
1082}
1083
1084BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack)
1085{
1086 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
1087 lp::Packet packet;
1088 packet.set<lp::FragmentField>(std::make_pair(
1089 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1090 packet.set<lp::NackField>(nack.getHeader());
1091 packet.set<lp::CongestionMarkField>(1);
1092
1093 transport->receivePacket(packet.wireEncode());
1094
1095 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
1096 shared_ptr<lp::CongestionMarkTag> tag = receivedNacks.back().getTag<lp::CongestionMarkTag>();
1097 BOOST_REQUIRE(tag != nullptr);
1098 BOOST_CHECK_EQUAL(*tag, 1);
1099}
1100
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001101BOOST_AUTO_TEST_CASE(SendNonDiscovery)
1102{
1103 GenericLinkService::Options options;
1104 options.allowSelfLearning = true;
1105 initialize(options);
1106
1107 shared_ptr<Interest> interest = makeInterest("/12345678");
1108 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1109
ashiqopu075bb7d2019-03-10 01:38:21 +00001110 face->sendInterest(*interest, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001111
1112 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1113 lp::Packet sent(transport->sentPackets.back().packet);
1114 BOOST_CHECK(sent.has<lp::NonDiscoveryField>());
1115}
1116
1117BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled)
1118{
1119 GenericLinkService::Options options;
1120 options.allowSelfLearning = false;
1121 initialize(options);
1122
1123 shared_ptr<Interest> interest = makeInterest("/12345678");
1124 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1125
ashiqopu075bb7d2019-03-10 01:38:21 +00001126 face->sendInterest(*interest, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001127
1128 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1129 lp::Packet sent(transport->sentPackets.back().packet);
1130 BOOST_CHECK(!sent.has<lp::NonDiscoveryField>());
1131}
1132
1133BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery)
1134{
1135 GenericLinkService::Options options;
1136 options.allowSelfLearning = true;
1137 initialize(options);
1138
1139 shared_ptr<Interest> interest = makeInterest("/12345678");
1140 lp::Packet packet(interest->wireEncode());
1141 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1142
1143 transport->receivePacket(packet.wireEncode());
1144
1145 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
1146 shared_ptr<lp::NonDiscoveryTag> tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
1147 BOOST_CHECK(tag != nullptr);
1148}
1149
1150BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled)
1151{
1152 GenericLinkService::Options options;
1153 options.allowSelfLearning = false;
1154 initialize(options);
1155
1156 shared_ptr<Interest> interest = makeInterest("/12345678");
1157 lp::Packet packet(interest->wireEncode());
1158 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1159
1160 transport->receivePacket(packet.wireEncode());
1161
1162 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1163 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
1164
1165 shared_ptr<lp::NonDiscoveryTag> tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
1166 BOOST_CHECK(tag == nullptr);
1167}
1168
1169BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData)
1170{
1171 GenericLinkService::Options options;
1172 options.allowSelfLearning = true;
1173 initialize(options);
1174
1175 shared_ptr<Data> data = makeData("/12345678");
1176 lp::Packet packet(data->wireEncode());
1177 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1178
1179 transport->receivePacket(packet.wireEncode());
1180
1181 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1182 BOOST_CHECK(receivedData.empty());
1183}
1184
1185BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack)
1186{
1187 GenericLinkService::Options options;
1188 options.allowSelfLearning = true;
1189 initialize(options);
1190
1191 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
1192 lp::Packet packet;
1193 packet.set<lp::FragmentField>(std::make_pair(
1194 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1195 packet.set<lp::NackField>(nack.getHeader());
1196 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1197
1198 transport->receivePacket(packet.wireEncode());
1199
1200 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1201 BOOST_CHECK(receivedNacks.empty());
1202}
1203
1204BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement)
1205{
1206 GenericLinkService::Options options;
1207 options.allowSelfLearning = true;
1208 initialize(options);
1209
1210 shared_ptr<Data> data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001211 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1212 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001213
ashiqopu075bb7d2019-03-10 01:38:21 +00001214 face->sendData(*data, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001215
1216 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1217 lp::Packet sent(transport->sentPackets.back().packet);
1218 BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>());
1219}
1220
1221BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled)
1222{
1223 GenericLinkService::Options options;
1224 options.allowSelfLearning = false;
1225 initialize(options);
1226
1227 shared_ptr<Data> data = makeData("/12345678");
Teng Liangbce3cb52018-09-05 20:08:27 -07001228 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1229 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pah));
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001230
ashiqopu075bb7d2019-03-10 01:38:21 +00001231 face->sendData(*data, 0);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001232
1233 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1234 lp::Packet sent(transport->sentPackets.back().packet);
1235 BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>());
1236}
1237
1238BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement)
1239{
1240 GenericLinkService::Options options;
1241 options.allowSelfLearning = true;
1242 initialize(options);
1243
1244 shared_ptr<Data> data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001245 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001246 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1247 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001248
1249 transport->receivePacket(packet.wireEncode());
1250
1251 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
1252 shared_ptr<lp::PrefixAnnouncementTag> tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangbce3cb52018-09-05 20:08:27 -07001253 BOOST_CHECK_EQUAL(tag->get().getPrefixAnn()->getAnnouncedName(), "/local/ndn/prefix");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001254}
1255
1256BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled)
1257{
1258 GenericLinkService::Options options;
1259 options.allowSelfLearning = false;
1260 initialize(options);
1261
1262 shared_ptr<Data> data = makeData("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001263 lp::Packet packet(data->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001264 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1265 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001266
1267 transport->receivePacket(packet.wireEncode());
1268
1269 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1270 BOOST_CHECK_EQUAL(receivedData.size(), 1);
1271
Teng Liangbce3cb52018-09-05 20:08:27 -07001272 shared_ptr<lp::PrefixAnnouncementTag> tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001273 BOOST_CHECK(tag == nullptr);
1274}
1275
1276BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest)
1277{
1278 GenericLinkService::Options options;
1279 options.allowSelfLearning = true;
1280 initialize(options);
1281
1282 shared_ptr<Interest> interest = makeInterest("/12345678");
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001283 lp::Packet packet(interest->wireEncode());
Teng Liangbce3cb52018-09-05 20:08:27 -07001284 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1285 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001286
1287 transport->receivePacket(packet.wireEncode());
1288
1289 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1290 BOOST_CHECK(receivedInterests.empty());
1291}
1292
1293BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack)
1294{
1295 GenericLinkService::Options options;
1296 options.allowSelfLearning = true;
1297 initialize(options);
1298
1299 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001300 lp::Packet packet;
1301 packet.set<lp::FragmentField>(std::make_pair(
1302 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1303 packet.set<lp::NackField>(nack.getHeader());
Teng Liangbce3cb52018-09-05 20:08:27 -07001304 auto pah = makePrefixAnnHeader("/local/ndn/prefix");
1305 packet.set<lp::PrefixAnnouncementField>(pah);
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001306
1307 transport->receivePacket(packet.wireEncode());
1308
1309 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1310 BOOST_CHECK(receivedNacks.empty());
1311}
1312
Eric Newberryee400b52016-11-24 14:12:48 +00001313BOOST_AUTO_TEST_SUITE_END() // LpFields
Eric Newberrya98bf932015-09-21 00:58:47 -07001314
Eric Newberrya1939ba2015-10-09 12:35:03 -07001315BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets
1316
1317BOOST_AUTO_TEST_CASE(WrongTlvType)
1318{
1319 // Initialize with Options that disables all services
1320 GenericLinkService::Options options;
1321 options.allowLocalFields = false;
1322 initialize(options);
1323
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001324 auto packet = ndn::encoding::makeEmptyBlock(tlv::Name);
1325 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001326
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001327 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001328 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1329 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1330 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1331}
1332
1333BOOST_AUTO_TEST_CASE(Unparsable)
1334{
1335 // Initialize with Options that disables all services
1336 GenericLinkService::Options options;
1337 options.allowLocalFields = false;
1338 initialize(options);
1339
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001340 auto packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x");
Eric Newberrya1939ba2015-10-09 12:35:03 -07001341 BOOST_CHECK_THROW(packet.parse(), tlv::Error);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -04001342 transport->receivePacket(packet);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001343
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001344 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001345 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1346 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1347 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1348}
1349
1350BOOST_AUTO_TEST_SUITE_END() // Malformed
1351
Eric Newberry86d31872015-09-23 16:24:59 -07001352BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService
1353BOOST_AUTO_TEST_SUITE_END() // Face
Eric Newberrya98bf932015-09-21 00:58:47 -07001354
1355} // namespace tests
1356} // namespace face
1357} // namespace nfd