blob: dfb048cde98e25a959852746654435f00facd655 [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry7b0071e2017-07-03 17:33:31 +00002/*
Eric Newberryb49313d2017-12-24 20:22:27 -07003 * Copyright (c) 2014-2018, 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
Eric Newberryb49313d2017-12-24 20:22:27 -070029#include "dummy-transport.hpp"
Davide Pesavento0064c1d2018-03-03 18:43:53 -050030#include "tests/test-common.hpp"
Eric Newberryb49313d2017-12-24 20:22:27 -070031
Teng Liangfdcbb4d2018-01-27 16:01:35 -070032#include <ndn-cxx/lp/empty-value.hpp>
33#include <ndn-cxx/lp/prefix-announcement.hpp>
Eric Newberryb49313d2017-12-24 20:22:27 -070034#include <ndn-cxx/lp/tags.hpp>
Eric Newberrya98bf932015-09-21 00:58:47 -070035
36namespace nfd {
37namespace face {
38namespace tests {
39
40using namespace nfd::tests;
41
Teng Liangfdcbb4d2018-01-27 16:01:35 -070042static lp::PrefixAnnouncement
43makePrefixAnnouncement(Name announcedName)
44{
45 Name paName = Name("self-learning").append(announcedName).appendVersion();
46 return lp::PrefixAnnouncement(makeData(paName));
47}
48
Eric Newberrya98bf932015-09-21 00:58:47 -070049BOOST_AUTO_TEST_SUITE(Face)
50
Junxiao Shicde37ad2015-12-24 01:02:05 -070051using nfd::Face;
52
Eric Newberryb49313d2017-12-24 20:22:27 -070053class GenericLinkServiceFixture : public UnitTestTimeFixture
Eric Newberrya98bf932015-09-21 00:58:47 -070054{
55protected:
56 GenericLinkServiceFixture()
57 : service(nullptr)
58 , transport(nullptr)
59 {
Eric Newberry86d31872015-09-23 16:24:59 -070060 this->initialize(GenericLinkService::Options());
Eric Newberrya98bf932015-09-21 00:58:47 -070061 // By default, GenericLinkService is created with default options.
62 // Test cases may invoke .initialize with alternate options.
63 }
64
65 void
Eric Newberryb49313d2017-12-24 20:22:27 -070066 initialize(const GenericLinkService::Options& options,
67 ssize_t mtu = MTU_UNLIMITED,
68 ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED)
Eric Newberrya98bf932015-09-21 00:58:47 -070069 {
Junxiao Shicde37ad2015-12-24 01:02:05 -070070 face.reset(new Face(make_unique<GenericLinkService>(options),
Eric Newberry185ab292017-03-28 06:45:39 +000071 make_unique<DummyTransport>("dummy://",
72 "dummy://",
73 ndn::nfd::FACE_SCOPE_NON_LOCAL,
74 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
75 ndn::nfd::LINK_TYPE_POINT_TO_POINT,
Eric Newberryb49313d2017-12-24 20:22:27 -070076 mtu,
77 sendQueueCapacity)));
Eric Newberrya98bf932015-09-21 00:58:47 -070078 service = static_cast<GenericLinkService*>(face->getLinkService());
79 transport = static_cast<DummyTransport*>(face->getTransport());
80
81 face->afterReceiveInterest.connect(
82 [this] (const Interest& interest) { receivedInterests.push_back(interest); });
83 face->afterReceiveData.connect(
84 [this] (const Data& data) { receivedData.push_back(data); });
85 face->afterReceiveNack.connect(
86 [this] (const lp::Nack& nack) { receivedNacks.push_back(nack); });
87 }
88
89protected:
Junxiao Shicde37ad2015-12-24 01:02:05 -070090 unique_ptr<Face> face;
Eric Newberrya98bf932015-09-21 00:58:47 -070091 GenericLinkService* service;
92 DummyTransport* transport;
93 std::vector<Interest> receivedInterests;
94 std::vector<Data> receivedData;
95 std::vector<lp::Nack> receivedNacks;
96};
97
98BOOST_FIXTURE_TEST_SUITE(TestGenericLinkService, GenericLinkServiceFixture)
99
100
101BOOST_AUTO_TEST_SUITE(SimpleSendReceive) // send and receive without other fields
102
103BOOST_AUTO_TEST_CASE(SendInterest)
104{
Eric Newberry86d31872015-09-23 16:24:59 -0700105 // Initialize with Options that disables all services
106 GenericLinkService::Options options;
107 options.allowLocalFields = false;
108 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700109
110 shared_ptr<Interest> interest1 = makeInterest("/localhost/test");
111
112 face->sendInterest(*interest1);
113
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700114 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700115 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700116 lp::Packet interest1pkt;
117 BOOST_REQUIRE_NO_THROW(interest1pkt.wireDecode(transport->sentPackets.back().packet));
118 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
119 BOOST_CHECK(!interest1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700120}
121
122BOOST_AUTO_TEST_CASE(SendData)
123{
Eric Newberry86d31872015-09-23 16:24:59 -0700124 // Initialize with Options that disables all services
125 GenericLinkService::Options options;
126 options.allowLocalFields = false;
127 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700128
129 shared_ptr<Data> data1 = makeData("/localhost/test");
130
131 face->sendData(*data1);
132
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700133 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700134 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700135 lp::Packet data1pkt;
136 BOOST_REQUIRE_NO_THROW(data1pkt.wireDecode(transport->sentPackets.back().packet));
137 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
138 BOOST_CHECK(!data1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700139}
140
141BOOST_AUTO_TEST_CASE(SendNack)
142{
Eric Newberry86d31872015-09-23 16:24:59 -0700143 // Initialize with Options that disables all services
144 GenericLinkService::Options options;
145 options.allowLocalFields = false;
146 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700147
148 lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
149
150 face->sendNack(nack1);
151
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700152 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700153 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
154 lp::Packet nack1pkt;
155 BOOST_REQUIRE_NO_THROW(nack1pkt.wireDecode(transport->sentPackets.back().packet));
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700156 BOOST_CHECK(nack1pkt.has<lp::NackField>());
157 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
158 BOOST_CHECK(!nack1pkt.has<lp::SequenceField>());
Eric Newberrya98bf932015-09-21 00:58:47 -0700159}
160
161BOOST_AUTO_TEST_CASE(ReceiveBareInterest)
162{
Eric Newberry86d31872015-09-23 16:24:59 -0700163 // Initialize with Options that disables all services
164 GenericLinkService::Options options;
165 options.allowLocalFields = false;
166 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700167
168 shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR");
169
170 transport->receivePacket(interest1->wireEncode());
171
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700172 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700173 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
174 BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
175}
176
177BOOST_AUTO_TEST_CASE(ReceiveInterest)
178{
Eric Newberry86d31872015-09-23 16:24:59 -0700179 // Initialize with Options that disables all services
180 GenericLinkService::Options options;
181 options.allowLocalFields = false;
182 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700183
184 shared_ptr<Interest> interest1 = makeInterest("/23Rd9hEiR");
185 lp::Packet lpPacket;
186 lpPacket.set<lp::FragmentField>(std::make_pair(
187 interest1->wireEncode().begin(), interest1->wireEncode().end()));
188 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
189
190 transport->receivePacket(lpPacket.wireEncode());
191
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700192 BOOST_CHECK_EQUAL(service->getCounters().nInInterests, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700193 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
194 BOOST_CHECK_EQUAL(receivedInterests.back(), *interest1);
195}
196
197BOOST_AUTO_TEST_CASE(ReceiveBareData)
198{
Eric Newberry86d31872015-09-23 16:24:59 -0700199 // Initialize with Options that disables all services
200 GenericLinkService::Options options;
201 options.allowLocalFields = false;
202 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700203
204 shared_ptr<Data> data1 = makeData("/12345678");
205
206 transport->receivePacket(data1->wireEncode());
207
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700208 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700209 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
210 BOOST_CHECK_EQUAL(receivedData.back(), *data1);
211}
212
213BOOST_AUTO_TEST_CASE(ReceiveData)
214{
Eric Newberry86d31872015-09-23 16:24:59 -0700215 // Initialize with Options that disables all services
216 GenericLinkService::Options options;
217 options.allowLocalFields = false;
218 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700219
220 shared_ptr<Data> data1 = makeData("/12345689");
221 lp::Packet lpPacket;
222 lpPacket.set<lp::FragmentField>(std::make_pair(
223 data1->wireEncode().begin(), data1->wireEncode().end()));
224 lpPacket.set<lp::SequenceField>(0); // force LpPacket encoding
225
226 transport->receivePacket(lpPacket.wireEncode());
227
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700228 BOOST_CHECK_EQUAL(service->getCounters().nInData, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700229 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
230 BOOST_CHECK_EQUAL(receivedData.back(), *data1);
231}
232
233BOOST_AUTO_TEST_CASE(ReceiveNack)
234{
Eric Newberry86d31872015-09-23 16:24:59 -0700235 // Initialize with Options that disables all services
236 GenericLinkService::Options options;
237 options.allowLocalFields = false;
238 initialize(options);
Eric Newberrya98bf932015-09-21 00:58:47 -0700239
240 lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
241 lp::Packet lpPacket;
242 lpPacket.set<lp::FragmentField>(std::make_pair(
243 nack1.getInterest().wireEncode().begin(), nack1.getInterest().wireEncode().end()));
244 lpPacket.set<lp::NackField>(nack1.getHeader());
245
246 transport->receivePacket(lpPacket.wireEncode());
247
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700248 BOOST_CHECK_EQUAL(service->getCounters().nInNacks, 1);
Eric Newberrya98bf932015-09-21 00:58:47 -0700249 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700250 BOOST_CHECK(receivedNacks.back().getReason() == nack1.getReason());
251 BOOST_CHECK(receivedNacks.back().getInterest() == nack1.getInterest());
Eric Newberrya98bf932015-09-21 00:58:47 -0700252}
253
Eric Newberrya1939ba2015-10-09 12:35:03 -0700254BOOST_AUTO_TEST_CASE(ReceiveIdlePacket)
255{
256 // Initialize with Options that disables all services
257 GenericLinkService::Options options;
258 options.allowLocalFields = false;
259 initialize(options);
260
261 lp::Packet lpPacket;
262 lpPacket.set<lp::SequenceField>(0);
263
264 BOOST_CHECK_NO_THROW(transport->receivePacket(lpPacket.wireEncode()));
265
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700266 // IDLE packet should be ignored, but is not an error
267 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0);
Eric Newberrya1939ba2015-10-09 12:35:03 -0700268 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
269 BOOST_CHECK_EQUAL(receivedData.size(), 0);
270 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
271}
272
Eric Newberrya98bf932015-09-21 00:58:47 -0700273BOOST_AUTO_TEST_SUITE_END() // SimpleSendReceive
274
Eric Newberry86d31872015-09-23 16:24:59 -0700275BOOST_AUTO_TEST_SUITE(Fragmentation)
276
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700277BOOST_AUTO_TEST_CASE(FragmentationDisabledExceedMtuDrop)
278{
279 // Initialize with Options that disable fragmentation
280 GenericLinkService::Options options;
281 options.allowFragmentation = false;
282 initialize(options);
283
284 transport->setMtu(55);
285
286 shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789");
287 face->sendData(*data);
288
289 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
290 BOOST_CHECK_EQUAL(service->getCounters().nOutOverMtu, 1);
291}
292
293BOOST_AUTO_TEST_CASE(FragmentationUnlimitedMtu)
294{
295 // Initialize with Options that enable fragmentation
296 GenericLinkService::Options options;
297 options.allowFragmentation = true;
298 initialize(options);
299
300 transport->setMtu(MTU_UNLIMITED);
301
302 shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789");
303 face->sendData(*data);
304
305 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
306}
307
308BOOST_AUTO_TEST_CASE(FragmentationUnderMtu)
309{
310 // Initialize with Options that enable fragmentation
311 GenericLinkService::Options options;
312 options.allowFragmentation = true;
313 initialize(options);
314
315 transport->setMtu(105);
316
317 shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789");
318 face->sendData(*data);
319
320 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
321}
322
323BOOST_AUTO_TEST_CASE(FragmentationOverMtu)
324{
325 // Initialize with Options that enable fragmentation
326 GenericLinkService::Options options;
327 options.allowFragmentation = true;
328 initialize(options);
329
330 transport->setMtu(60);
331
332 shared_ptr<Data> data = makeData("/test/data/123456789/987654321/123456789");
333 face->sendData(*data);
334
335 BOOST_CHECK_GT(transport->sentPackets.size(), 1);
336}
337
338BOOST_AUTO_TEST_CASE(ReassembleFragments)
339{
340 // Initialize with Options that enables reassembly
341 GenericLinkService::Options options;
342 options.allowReassembly = true;
343 initialize(options);
344
345 shared_ptr<Interest> interest = makeInterest(
346 "/mt7P130BHXmtLm5dwaY5dpUM6SWYNN2B05g7y3UhsQuLvDdnTWdNnTeEiLuW3FAbJRSG3tzQ0UfaSEgG9rvYHmsKtgPMag1Hj4Tr");
347 lp::Packet packet(interest->wireEncode());
348
349 // fragment the packet
350 LpFragmenter fragmenter;
351 size_t mtu = 100;
352 bool isOk = false;
353 std::vector<lp::Packet> frags;
354 std::tie(isOk, frags) = fragmenter.fragmentPacket(packet, mtu);
355 BOOST_REQUIRE(isOk);
356 BOOST_CHECK_GT(frags.size(), 1);
357
358 // receive the fragments
359 for (ssize_t fragIndex = frags.size() - 1; fragIndex >= 0; --fragIndex) {
360 size_t sequence = 1000 + fragIndex;
361 frags[fragIndex].add<lp::SequenceField>(sequence);
362
363 transport->receivePacket(frags[fragIndex].wireEncode());
364
365 if (fragIndex > 0) {
366 BOOST_CHECK(receivedInterests.empty());
367 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 1);
368 }
369 else {
370 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
371 BOOST_CHECK_EQUAL(receivedInterests.back(), *interest);
372 BOOST_CHECK_EQUAL(service->getCounters().nReassembling, 0);
373 }
374 }
375}
376
Eric Newberry86d31872015-09-23 16:24:59 -0700377BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragIndex)
378{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700379 // Initialize with Options that disables reassembly
380 GenericLinkService::Options options;
381 options.allowReassembly = false;
382 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700383
384 shared_ptr<Interest> interest = makeInterest("/IgFe6NvH");
385 lp::Packet packet(interest->wireEncode());
386 packet.set<lp::FragIndexField>(140);
387
388 transport->receivePacket(packet.wireEncode());
389
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700390 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700391 BOOST_CHECK(receivedInterests.empty());
392}
393
394BOOST_AUTO_TEST_CASE(ReassemblyDisabledDropFragCount)
395{
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700396 // Initialize with Options that disables reassembly
397 GenericLinkService::Options options;
398 options.allowReassembly = false;
399 initialize(options);
Eric Newberry86d31872015-09-23 16:24:59 -0700400
401 shared_ptr<Interest> interest = makeInterest("/SeGmEjvIVX");
402 lp::Packet packet(interest->wireEncode());
403 packet.set<lp::FragCountField>(276);
404
405 transport->receivePacket(packet.wireEncode());
406
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700407 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700408 BOOST_CHECK(receivedInterests.empty());
409}
410
411BOOST_AUTO_TEST_SUITE_END() // Fragmentation
412
Eric Newberry185ab292017-03-28 06:45:39 +0000413BOOST_AUTO_TEST_SUITE(Reliability)
414
Eric Newberry7b0071e2017-07-03 17:33:31 +0000415BOOST_AUTO_TEST_CASE(SendInterest)
Eric Newberry185ab292017-03-28 06:45:39 +0000416{
417 // Initialize with Options that enables reliability
418 GenericLinkService::Options options;
419 options.allowLocalFields = false;
420 options.reliabilityOptions.isEnabled = true;
421 initialize(options);
422
423 shared_ptr<Interest> interest1 = makeInterest("/localhost/test");
424
425 face->sendInterest(*interest1);
426
427 BOOST_CHECK_EQUAL(service->getCounters().nOutInterests, 1);
428 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
429 lp::Packet interest1pkt;
430 BOOST_REQUIRE_NO_THROW(interest1pkt.wireDecode(transport->sentPackets.back().packet));
431 BOOST_CHECK(interest1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000432 BOOST_CHECK(interest1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000433}
434
Eric Newberry7b0071e2017-07-03 17:33:31 +0000435BOOST_AUTO_TEST_CASE(SendData)
Eric Newberry185ab292017-03-28 06:45:39 +0000436{
437 // Initialize with Options that enables reliability
438 GenericLinkService::Options options;
439 options.allowLocalFields = false;
440 options.reliabilityOptions.isEnabled = true;
441 initialize(options);
442
443 shared_ptr<Data> data1 = makeData("/localhost/test");
444
445 face->sendData(*data1);
446
447 BOOST_CHECK_EQUAL(service->getCounters().nOutData, 1);
448 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
449 lp::Packet data1pkt;
450 BOOST_REQUIRE_NO_THROW(data1pkt.wireDecode(transport->sentPackets.back().packet));
451 BOOST_CHECK(data1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000452 BOOST_CHECK(data1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000453}
454
Eric Newberry7b0071e2017-07-03 17:33:31 +0000455BOOST_AUTO_TEST_CASE(SendNack)
Eric Newberry185ab292017-03-28 06:45:39 +0000456{
457 // Initialize with Options that enables reliability
458 GenericLinkService::Options options;
459 options.allowLocalFields = false;
460 options.reliabilityOptions.isEnabled = true;
461 initialize(options);
462
463 lp::Nack nack1 = makeNack("/localhost/test", 323, lp::NackReason::NO_ROUTE);
464
465 face->sendNack(nack1);
466
467 BOOST_CHECK_EQUAL(service->getCounters().nOutNacks, 1);
468 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
469 lp::Packet nack1pkt;
470 BOOST_REQUIRE_NO_THROW(nack1pkt.wireDecode(transport->sentPackets.back().packet));
471 BOOST_CHECK(nack1pkt.has<lp::NackField>());
472 BOOST_CHECK(nack1pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000473 BOOST_CHECK(nack1pkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000474}
475
476BOOST_AUTO_TEST_SUITE_END() // Reliability
Eric Newberry86d31872015-09-23 16:24:59 -0700477
Eric Newberryb49313d2017-12-24 20:22:27 -0700478// congestion detection and marking
479BOOST_AUTO_TEST_SUITE(CongestionMark)
480
481BOOST_AUTO_TEST_CASE(NoCongestion)
482{
483 GenericLinkService::Options options;
484 options.allowCongestionMarking = true;
485 options.baseCongestionMarkingInterval = time::milliseconds(100);
486 initialize(options, MTU_UNLIMITED, 65536);
487 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
488 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
489 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
490
491 shared_ptr<Interest> interest = makeInterest("/12345678");
492
493 // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes
494
495 // no congestion
496 transport->setSendQueueLength(0);
497 face->sendInterest(*interest);
498 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
499 lp::Packet pkt1;
500 BOOST_REQUIRE_NO_THROW(pkt1.wireDecode(transport->sentPackets.back().packet));
501 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
502 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
503 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
504 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
505
506 // no congestion
507 transport->setSendQueueLength(32768);
508 face->sendInterest(*interest);
509 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
510 lp::Packet pkt2;
511 BOOST_REQUIRE_NO_THROW(pkt2.wireDecode(transport->sentPackets.back().packet));
512 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
513 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
514 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
515 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
516}
517
518BOOST_AUTO_TEST_CASE(CongestionCoDel)
519{
520 GenericLinkService::Options options;
521 options.allowCongestionMarking = true;
522 options.baseCongestionMarkingInterval = time::milliseconds(100);
523 initialize(options, MTU_UNLIMITED, 65536);
524 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
525 BOOST_CHECK_EQUAL(service->m_lastMarkTime, time::steady_clock::TimePoint::min());
526 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
527 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
528
529 shared_ptr<Interest> interest = makeInterest("/12345678");
530
531 // congestion threshold will be 32768 bytes, since min(65536, 65536 / 2) = 32768 bytes
532
533 // first congested packet, will be marked
534 transport->setSendQueueLength(32769);
535 face->sendInterest(*interest);
536 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
537 lp::Packet pkt1;
538 BOOST_REQUIRE_NO_THROW(pkt1.wireDecode(transport->sentPackets.back().packet));
539 BOOST_REQUIRE_EQUAL(pkt1.count<lp::CongestionMarkField>(), 1);
540 BOOST_CHECK_EQUAL(pkt1.get<lp::CongestionMarkField>(), 1);
541 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + time::milliseconds(100);
542 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
543 time::steady_clock::TimePoint lastMarkTime = time::steady_clock::now();
544 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
545 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
546 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
547
548 // advance clock to half of marking interval cycle
549 advanceClocks(time::milliseconds(50));
550
551 // second congested packet, but within marking interval, will not be marked
552 transport->setSendQueueLength(33000);
553 face->sendInterest(*interest);
554 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
555 lp::Packet pkt2;
556 BOOST_REQUIRE_NO_THROW(pkt2.wireDecode(transport->sentPackets.back().packet));
557 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
558 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
559 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
560 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
561 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
562
563 // advance clocks past end of initial interval cycle
564 this->advanceClocks(time::milliseconds(51));
565
566 // first congested packet after waiting marking interval, will be marked
567 transport->setSendQueueLength(40000);
568 face->sendInterest(*interest);
569 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
570 lp::Packet pkt3;
571 BOOST_REQUIRE_NO_THROW(pkt3.wireDecode(transport->sentPackets.back().packet));
572 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1);
573 BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1);
574 time::nanoseconds markingInterval(
575 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
576 std::sqrt(service->m_nMarkedSinceInMarkingState)));
577 nextMarkTime += markingInterval;
578 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
579 lastMarkTime = time::steady_clock::now();
580 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
581 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
582 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
583
584 // advance clock partway through current marking interval
585 this->advanceClocks(markingInterval - time::milliseconds(10));
586
587 // still congested, but within marking interval cycle
588 transport->setSendQueueLength(38000);
589 face->sendInterest(*interest);
590 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 4);
591 lp::Packet pkt4;
592 BOOST_REQUIRE_NO_THROW(pkt4.wireDecode(transport->sentPackets.back().packet));
593 BOOST_CHECK_EQUAL(pkt4.count<lp::CongestionMarkField>(), 0);
594 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
595 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
596 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
597 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 2);
598
599 // advance clocks past end of current marking interval cycle
600 this->advanceClocks(time::milliseconds(11));
601
602 // still congested, after marking interval cycle
603 transport->setSendQueueLength(39000);
604 face->sendInterest(*interest);
605 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
606 lp::Packet pkt5;
607 BOOST_REQUIRE_NO_THROW(pkt5.wireDecode(transport->sentPackets.back().packet));
608 BOOST_REQUIRE_EQUAL(pkt5.count<lp::CongestionMarkField>(), 1);
609 BOOST_CHECK_EQUAL(pkt5.get<lp::CongestionMarkField>(), 1);
610 markingInterval = time::nanoseconds(
611 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
612 std::sqrt(service->m_nMarkedSinceInMarkingState)));
613 nextMarkTime += markingInterval;
614 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
615 lastMarkTime = time::steady_clock::now();
616 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
617 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
618 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
619
620 this->advanceClocks(time::milliseconds(1));
621
622 // still congested, but within marking interval cycle
623 transport->setSendQueueLength(38000);
624 face->sendInterest(*interest);
625 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 6);
626 lp::Packet pkt6;
627 BOOST_REQUIRE_NO_THROW(pkt6.wireDecode(transport->sentPackets.back().packet));
628 BOOST_CHECK_EQUAL(pkt6.count<lp::CongestionMarkField>(), 0);
629 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
630 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
631 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 3);
632 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 3);
633
634 this->advanceClocks(markingInterval);
635
636 // still congested, after marking interval cycle
637 transport->setSendQueueLength(34000);
638 face->sendInterest(*interest);
639 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 7);
640 lp::Packet pkt7;
641 BOOST_REQUIRE_NO_THROW(pkt7.wireDecode(transport->sentPackets.back().packet));
642 BOOST_REQUIRE_EQUAL(pkt7.count<lp::CongestionMarkField>(), 1);
643 BOOST_CHECK_EQUAL(pkt7.get<lp::CongestionMarkField>(), 1);
644 markingInterval = time::nanoseconds(
645 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
646 std::sqrt(service->m_nMarkedSinceInMarkingState)));
647 nextMarkTime += markingInterval;
648 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
649 lastMarkTime = time::steady_clock::now();
650 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
651 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 4);
652 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
653
654 // no more congestion
655 transport->setSendQueueLength(30000);
656 face->sendInterest(*interest);
657 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 8);
658 lp::Packet pkt8;
659 BOOST_REQUIRE_NO_THROW(pkt8.wireDecode(transport->sentPackets.back().packet));
660 BOOST_CHECK_EQUAL(pkt8.count<lp::CongestionMarkField>(), 0);
661 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
662 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
663 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
664 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
665
666 this->advanceClocks(time::milliseconds(50));
667
668 // send queue congested again, but can't mark packet because within one full interval of last mark
669 transport->setSendQueueLength(50000);
670 face->sendInterest(*interest);
671 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 9);
672 lp::Packet pkt9;
673 BOOST_REQUIRE_NO_THROW(pkt9.wireDecode(transport->sentPackets.back().packet));
674 BOOST_CHECK_EQUAL(pkt9.count<lp::CongestionMarkField>(), 0);
675 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
676 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
677 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
678 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 4);
679
680 // advance clock past full 100ms interval since last mark
681 this->advanceClocks(time::milliseconds(51));
682
683 transport->setSendQueueLength(40000);
684 face->sendInterest(*interest);
685 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10);
686 lp::Packet pkt10;
687 BOOST_REQUIRE_NO_THROW(pkt10.wireDecode(transport->sentPackets.back().packet));
688 BOOST_REQUIRE_EQUAL(pkt10.count<lp::CongestionMarkField>(), 1);
689 BOOST_CHECK_EQUAL(pkt10.get<lp::CongestionMarkField>(), 1);
690 nextMarkTime = time::steady_clock::now() + time::milliseconds(100);
691 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
692 lastMarkTime = time::steady_clock::now();
693 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
694 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
695 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
696
697 // advance clock partway through 100ms marking interval
698 this->advanceClocks(time::milliseconds(50));
699
700 // not marked since within 100ms window before can mark again
701 transport->setSendQueueLength(50000);
702 face->sendInterest(*interest);
703 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 11);
704 lp::Packet pkt11;
705 BOOST_REQUIRE_NO_THROW(pkt11.wireDecode(transport->sentPackets.back().packet));
706 BOOST_CHECK_EQUAL(pkt11.count<lp::CongestionMarkField>(), 0);
707 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
708 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
709 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
710 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 5);
711
712 // advance clocks past m_nextMarkTime
713 this->advanceClocks(time::milliseconds(51));
714
715 // markable packet, queue length still above threshold
716 transport->setSendQueueLength(33000);
717 face->sendInterest(*interest);
718 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 12);
719 lp::Packet pkt12;
720 BOOST_REQUIRE_NO_THROW(pkt12.wireDecode(transport->sentPackets.back().packet));
721 BOOST_REQUIRE_EQUAL(pkt12.count<lp::CongestionMarkField>(), 1);
722 BOOST_CHECK_EQUAL(pkt12.get<lp::CongestionMarkField>(), 1);
723 markingInterval = time::nanoseconds(
724 static_cast<time::nanoseconds::rep>(options.baseCongestionMarkingInterval.count() /
725 std::sqrt(service->m_nMarkedSinceInMarkingState)));
726 nextMarkTime += markingInterval;
727 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
728 lastMarkTime = time::steady_clock::now();
729 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
730 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 2);
731 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 6);
732
733 // no more congestion
734 transport->setSendQueueLength(10000);
735 face->sendInterest(*interest);
736 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 13);
737 lp::Packet pkt13;
738 BOOST_REQUIRE_NO_THROW(pkt13.wireDecode(transport->sentPackets.back().packet));
739 BOOST_CHECK_EQUAL(pkt13.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, 6);
744
745 // advance clocks past one full interval since last mark
746 this->advanceClocks(time::milliseconds(101));
747
748 // start congestion again
749 transport->setSendQueueLength(50000);
750 face->sendInterest(*interest);
751 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 14);
752 lp::Packet pkt14;
753 BOOST_REQUIRE_NO_THROW(pkt14.wireDecode(transport->sentPackets.back().packet));
754 BOOST_REQUIRE_EQUAL(pkt14.count<lp::CongestionMarkField>(), 1);
755 BOOST_CHECK_EQUAL(pkt14.get<lp::CongestionMarkField>(), 1);
756 nextMarkTime = time::steady_clock::now() + time::milliseconds(100);
757 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
758 lastMarkTime = time::steady_clock::now();
759 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
760 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
761 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 7);
762
763 // no more congestion, cancel marking interval
764 transport->setSendQueueLength(5000);
765 face->sendInterest(*interest);
766 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 15);
767 lp::Packet pkt15;
768 BOOST_REQUIRE_NO_THROW(pkt15.wireDecode(transport->sentPackets.back().packet));
769 BOOST_CHECK_EQUAL(pkt15.count<lp::CongestionMarkField>(), 0);
770 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
771 BOOST_CHECK_EQUAL(service->m_lastMarkTime, lastMarkTime);
772 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
773 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 7);
774}
775
776BOOST_AUTO_TEST_CASE(DefaultThreshold)
777{
778 GenericLinkService::Options options;
779 options.allowCongestionMarking = true;
780 options.baseCongestionMarkingInterval = time::milliseconds(100);
781 initialize(options, MTU_UNLIMITED, QUEUE_UNSUPPORTED);
782 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
783 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
784 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
785
786 shared_ptr<Interest> interest = makeInterest("/12345678");
787
788 // congestion threshold will be 65536 bytes, since the transport reports that it cannot measure
789 // the queue capacity
790
791 // no congestion
792 transport->setSendQueueLength(0);
793 face->sendInterest(*interest);
794 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
795 lp::Packet pkt1;
796 BOOST_REQUIRE_NO_THROW(pkt1.wireDecode(transport->sentPackets.back().packet));
797 BOOST_CHECK_EQUAL(pkt1.count<lp::CongestionMarkField>(), 0);
798 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
799 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
800 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
801
802 // no congestion
803 transport->setSendQueueLength(65536);
804 face->sendInterest(*interest);
805 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
806 lp::Packet pkt2;
807 BOOST_REQUIRE_NO_THROW(pkt2.wireDecode(transport->sentPackets.back().packet));
808 BOOST_CHECK_EQUAL(pkt2.count<lp::CongestionMarkField>(), 0);
809 BOOST_CHECK_EQUAL(service->m_nextMarkTime, time::steady_clock::TimePoint::max());
810 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 0);
811 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 0);
812
813 // first congested (and marked) packet
814 transport->setSendQueueLength(65537);
815 face->sendInterest(*interest);
816 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 3);
817 lp::Packet pkt3;
818 BOOST_REQUIRE_NO_THROW(pkt3.wireDecode(transport->sentPackets.back().packet));
819 BOOST_REQUIRE_EQUAL(pkt3.count<lp::CongestionMarkField>(), 1);
820 BOOST_CHECK_EQUAL(pkt3.get<lp::CongestionMarkField>(), 1);
821 time::steady_clock::TimePoint nextMarkTime = time::steady_clock::now() + time::milliseconds(100);
822 BOOST_CHECK_EQUAL(service->m_nextMarkTime, nextMarkTime);
823 BOOST_CHECK_EQUAL(service->m_nMarkedSinceInMarkingState, 1);
824 BOOST_CHECK_EQUAL(service->getCounters().nCongestionMarked, 1);
825}
826
827BOOST_AUTO_TEST_SUITE_END() // CongestionMark
828
Eric Newberryee400b52016-11-24 14:12:48 +0000829BOOST_AUTO_TEST_SUITE(LpFields)
Eric Newberrya98bf932015-09-21 00:58:47 -0700830
Eric Newberrya98bf932015-09-21 00:58:47 -0700831BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceId)
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<Interest> interest = makeInterest("/12345678");
839 lp::Packet packet(interest->wireEncode());
840 packet.set<lp::NextHopFaceIdField>(1000);
841
842 transport->receivePacket(packet.wireEncode());
843
844 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +0000845 shared_ptr<lp::NextHopFaceIdTag> tag = receivedInterests.back().getTag<lp::NextHopFaceIdTag>();
846 BOOST_REQUIRE(tag != nullptr);
847 BOOST_CHECK_EQUAL(*tag, 1000);
Eric Newberrya98bf932015-09-21 00:58:47 -0700848}
849
850BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDisabled)
851{
Eric Newberry86d31872015-09-23 16:24:59 -0700852 // Initialize with Options that disables local fields
853 GenericLinkService::Options options;
854 options.allowLocalFields = false;
855 initialize(options);
856
857 shared_ptr<Interest> interest = makeInterest("/12345678");
858 lp::Packet packet(interest->wireEncode());
859 packet.set<lp::NextHopFaceIdField>(1000);
860
861 transport->receivePacket(packet.wireEncode());
862
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700863 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -0700864 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700865}
866
867BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropData)
868{
Eric Newberry86d31872015-09-23 16:24:59 -0700869 // Initialize with Options that enables local fields
870 GenericLinkService::Options options;
871 options.allowLocalFields = true;
872 initialize(options);
873
874 shared_ptr<Data> data = makeData("/12345678");
875 lp::Packet packet(data->wireEncode());
876 packet.set<lp::NextHopFaceIdField>(1000);
877
878 transport->receivePacket(packet.wireEncode());
879
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700880 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700881 BOOST_CHECK(receivedData.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700882}
883
884BOOST_AUTO_TEST_CASE(ReceiveNextHopFaceIdDropNack)
885{
Eric Newberry86d31872015-09-23 16:24:59 -0700886 // Initialize with Options that enables local fields
887 GenericLinkService::Options options;
888 options.allowLocalFields = true;
889 initialize(options);
890
891 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
892 lp::Packet packet;
893 packet.set<lp::FragmentField>(std::make_pair(
894 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
895 packet.set<lp::NackField>(nack.getHeader());
896 packet.set<lp::NextHopFaceIdField>(1000);
897
898 transport->receivePacket(packet.wireEncode());
899
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700900 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700901 BOOST_CHECK(receivedNacks.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700902}
903
Junxiao Shi6eb02712017-05-27 22:48:02 +0000904BOOST_AUTO_TEST_CASE(ReceiveCachePolicy)
Eric Newberrya98bf932015-09-21 00:58:47 -0700905{
Junxiao Shi6eb02712017-05-27 22:48:02 +0000906 // Initialize with Options that disables local fields
Eric Newberry86d31872015-09-23 16:24:59 -0700907 GenericLinkService::Options options;
Junxiao Shi6eb02712017-05-27 22:48:02 +0000908 options.allowLocalFields = false;
Eric Newberry86d31872015-09-23 16:24:59 -0700909 initialize(options);
Junxiao Shi6eb02712017-05-27 22:48:02 +0000910 // CachePolicy is unprivileged and does not require allowLocalFields option.
Eric Newberry86d31872015-09-23 16:24:59 -0700911
912 shared_ptr<Data> data = makeData("/12345678");
913 lp::Packet packet(data->wireEncode());
Junxiao Shi0de23a22015-12-03 20:07:02 +0000914 packet.set<lp::CachePolicyField>(lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE));
Eric Newberry86d31872015-09-23 16:24:59 -0700915
916 transport->receivePacket(packet.wireEncode());
917
918 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +0000919 shared_ptr<lp::CachePolicyTag> tag = receivedData.back().getTag<lp::CachePolicyTag>();
920 BOOST_REQUIRE(tag != nullptr);
921 BOOST_CHECK_EQUAL(tag->get().getPolicy(), lp::CachePolicyType::NO_CACHE);
Eric Newberrya98bf932015-09-21 00:58:47 -0700922}
923
Junxiao Shi6eb02712017-05-27 22:48:02 +0000924BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropInterest)
Eric Newberrya98bf932015-09-21 00:58:47 -0700925{
Eric Newberry86d31872015-09-23 16:24:59 -0700926 // Initialize with Options that enables local fields
927 GenericLinkService::Options options;
928 options.allowLocalFields = true;
929 initialize(options);
930
931 shared_ptr<Interest> interest = makeInterest("/12345678");
932 lp::Packet packet(interest->wireEncode());
933 lp::CachePolicy policy;
934 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
935 packet.set<lp::CachePolicyField>(policy);
936
937 transport->receivePacket(packet.wireEncode());
938
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700939 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700940 BOOST_CHECK(receivedInterests.empty());
Eric Newberrya98bf932015-09-21 00:58:47 -0700941}
942
Junxiao Shi6eb02712017-05-27 22:48:02 +0000943BOOST_AUTO_TEST_CASE(ReceiveCachePolicyDropNack)
Eric Newberrya98bf932015-09-21 00:58:47 -0700944{
Eric Newberry86d31872015-09-23 16:24:59 -0700945 // Initialize with Options that enables local fields
946 GenericLinkService::Options options;
947 options.allowLocalFields = true;
948 initialize(options);
949
950 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
951 lp::Packet packet(nack.getInterest().wireEncode());
952 packet.set<lp::NackField>(nack.getHeader());
953 lp::CachePolicy policy;
954 policy.setPolicy(lp::CachePolicyType::NO_CACHE);
955 packet.set<lp::CachePolicyField>(policy);
956
957 transport->receivePacket(packet.wireEncode());
958
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700959 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
Eric Newberry86d31872015-09-23 16:24:59 -0700960 BOOST_CHECK(receivedNacks.empty());
961}
962
963BOOST_AUTO_TEST_CASE(SendIncomingFaceId)
964{
965 // Initialize with Options that enables local fields
966 GenericLinkService::Options options;
967 options.allowLocalFields = true;
968 initialize(options);
969
970 shared_ptr<Interest> interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +0000971 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -0700972
973 face->sendInterest(*interest);
974
975 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
976 lp::Packet sent(transport->sentPackets.back().packet);
977 BOOST_REQUIRE(sent.has<lp::IncomingFaceIdField>());
978 BOOST_CHECK_EQUAL(sent.get<lp::IncomingFaceIdField>(), 1000);
979}
980
981BOOST_AUTO_TEST_CASE(SendIncomingFaceIdDisabled)
982{
983 // Initialize with Options that disables local fields
984 GenericLinkService::Options options;
985 options.allowLocalFields = false;
986 initialize(options);
987
988 shared_ptr<Interest> interest = makeInterest("/12345678");
Junxiao Shi0de23a22015-12-03 20:07:02 +0000989 interest->setTag(make_shared<lp::IncomingFaceIdTag>(1000));
Eric Newberry86d31872015-09-23 16:24:59 -0700990
991 face->sendInterest(*interest);
992
993 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
994 lp::Packet sent(transport->sentPackets.back().packet);
995 BOOST_CHECK(!sent.has<lp::IncomingFaceIdField>());
996}
997
998BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreInterest)
999{
1000 // Initialize with Options that enables local fields
1001 GenericLinkService::Options options;
1002 options.allowLocalFields = true;
1003 initialize(options);
1004
1005 shared_ptr<Interest> interest = makeInterest("/12345678");
1006 lp::Packet packet(interest->wireEncode());
1007 packet.set<lp::IncomingFaceIdField>(1000);
1008
1009 transport->receivePacket(packet.wireEncode());
1010
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001011 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001012 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001013 BOOST_CHECK(receivedInterests.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001014}
1015
1016BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreData)
1017{
1018 // Initialize with Options that enables local fields
1019 GenericLinkService::Options options;
1020 options.allowLocalFields = true;
1021 initialize(options);
1022
1023 shared_ptr<Data> data = makeData("/z1megUh9Bj");
1024 lp::Packet packet(data->wireEncode());
1025 packet.set<lp::IncomingFaceIdField>(1000);
1026
1027 transport->receivePacket(packet.wireEncode());
1028
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001029 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001030 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001031 BOOST_CHECK(receivedData.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberry86d31872015-09-23 16:24:59 -07001032}
1033
1034BOOST_AUTO_TEST_CASE(ReceiveIncomingFaceIdIgnoreNack)
1035{
1036 // Initialize with Options that enables local fields
1037 GenericLinkService::Options options;
1038 options.allowLocalFields = true;
1039 initialize(options);
1040
1041 lp::Nack nack = makeNack("/TPAhdiHz", 278, lp::NackReason::CONGESTION);
1042 lp::Packet packet(nack.getInterest().wireEncode());
1043 packet.set<lp::NackField>(nack.getHeader());
1044 packet.set<lp::IncomingFaceIdField>(1000);
1045
1046 transport->receivePacket(packet.wireEncode());
1047
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001048 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
Eric Newberry86d31872015-09-23 16:24:59 -07001049 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
Junxiao Shi0de23a22015-12-03 20:07:02 +00001050 BOOST_CHECK(receivedNacks.back().getTag<lp::IncomingFaceIdTag>() == nullptr);
Eric Newberrya98bf932015-09-21 00:58:47 -07001051}
1052
Eric Newberryee400b52016-11-24 14:12:48 +00001053BOOST_AUTO_TEST_CASE(SendCongestionMarkInterest)
1054{
1055 shared_ptr<Interest> interest = makeInterest("/12345678");
1056 interest->setTag(make_shared<lp::CongestionMarkTag>(1));
1057
1058 face->sendInterest(*interest);
1059
1060 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1061 lp::Packet sent(transport->sentPackets.back().packet);
1062 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1063 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 1);
1064}
1065
1066BOOST_AUTO_TEST_CASE(SendCongestionMarkData)
1067{
1068 shared_ptr<Data> data = makeData("/12345678");
1069 data->setTag(make_shared<lp::CongestionMarkTag>(0));
1070
1071 face->sendData(*data);
1072
1073 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1074 lp::Packet sent(transport->sentPackets.back().packet);
1075 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1076 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), 0);
1077}
1078
1079BOOST_AUTO_TEST_CASE(SendCongestionMarkNack)
1080{
1081 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
1082 nack.setTag(make_shared<lp::CongestionMarkTag>(std::numeric_limits<uint64_t>::max()));
1083
1084 face->sendNack(nack);
1085
1086 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1087 lp::Packet sent(transport->sentPackets.back().packet);
1088 BOOST_REQUIRE(sent.has<lp::CongestionMarkField>());
1089 BOOST_CHECK_EQUAL(sent.get<lp::CongestionMarkField>(), std::numeric_limits<uint64_t>::max());
1090}
1091
1092BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkInterest)
1093{
1094 shared_ptr<Interest> interest = makeInterest("/12345678");
1095 lp::Packet packet(interest->wireEncode());
1096 packet.set<lp::CongestionMarkField>(1);
1097
1098 transport->receivePacket(packet.wireEncode());
1099
1100 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
1101 shared_ptr<lp::CongestionMarkTag> tag = receivedInterests.back().getTag<lp::CongestionMarkTag>();
1102 BOOST_REQUIRE(tag != nullptr);
1103 BOOST_CHECK_EQUAL(*tag, 1);
1104}
1105
1106BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkData)
1107{
1108 shared_ptr<Data> data = makeData("/12345678");
1109 lp::Packet packet(data->wireEncode());
1110 packet.set<lp::CongestionMarkField>(1);
1111
1112 transport->receivePacket(packet.wireEncode());
1113
1114 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
1115 shared_ptr<lp::CongestionMarkTag> tag = receivedData.back().getTag<lp::CongestionMarkTag>();
1116 BOOST_REQUIRE(tag != nullptr);
1117 BOOST_CHECK_EQUAL(*tag, 1);
1118}
1119
1120BOOST_AUTO_TEST_CASE(ReceiveCongestionMarkNack)
1121{
1122 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
1123 lp::Packet packet;
1124 packet.set<lp::FragmentField>(std::make_pair(
1125 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1126 packet.set<lp::NackField>(nack.getHeader());
1127 packet.set<lp::CongestionMarkField>(1);
1128
1129 transport->receivePacket(packet.wireEncode());
1130
1131 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
1132 shared_ptr<lp::CongestionMarkTag> tag = receivedNacks.back().getTag<lp::CongestionMarkTag>();
1133 BOOST_REQUIRE(tag != nullptr);
1134 BOOST_CHECK_EQUAL(*tag, 1);
1135}
1136
Teng Liangfdcbb4d2018-01-27 16:01:35 -07001137BOOST_AUTO_TEST_CASE(SendNonDiscovery)
1138{
1139 GenericLinkService::Options options;
1140 options.allowSelfLearning = true;
1141 initialize(options);
1142
1143 shared_ptr<Interest> interest = makeInterest("/12345678");
1144 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1145
1146 face->sendInterest(*interest);
1147
1148 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1149 lp::Packet sent(transport->sentPackets.back().packet);
1150 BOOST_CHECK(sent.has<lp::NonDiscoveryField>());
1151}
1152
1153BOOST_AUTO_TEST_CASE(SendNonDiscoveryDisabled)
1154{
1155 GenericLinkService::Options options;
1156 options.allowSelfLearning = false;
1157 initialize(options);
1158
1159 shared_ptr<Interest> interest = makeInterest("/12345678");
1160 interest->setTag(make_shared<lp::NonDiscoveryTag>(lp::EmptyValue{}));
1161
1162 face->sendInterest(*interest);
1163
1164 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1165 lp::Packet sent(transport->sentPackets.back().packet);
1166 BOOST_CHECK(!sent.has<lp::NonDiscoveryField>());
1167}
1168
1169BOOST_AUTO_TEST_CASE(ReceiveNonDiscovery)
1170{
1171 GenericLinkService::Options options;
1172 options.allowSelfLearning = true;
1173 initialize(options);
1174
1175 shared_ptr<Interest> interest = makeInterest("/12345678");
1176 lp::Packet packet(interest->wireEncode());
1177 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1178
1179 transport->receivePacket(packet.wireEncode());
1180
1181 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
1182 shared_ptr<lp::NonDiscoveryTag> tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
1183 BOOST_CHECK(tag != nullptr);
1184}
1185
1186BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDisabled)
1187{
1188 GenericLinkService::Options options;
1189 options.allowSelfLearning = false;
1190 initialize(options);
1191
1192 shared_ptr<Interest> interest = makeInterest("/12345678");
1193 lp::Packet packet(interest->wireEncode());
1194 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1195
1196 transport->receivePacket(packet.wireEncode());
1197
1198 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1199 BOOST_CHECK_EQUAL(receivedInterests.size(), 1);
1200
1201 shared_ptr<lp::NonDiscoveryTag> tag = receivedInterests.back().getTag<lp::NonDiscoveryTag>();
1202 BOOST_CHECK(tag == nullptr);
1203}
1204
1205BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropData)
1206{
1207 GenericLinkService::Options options;
1208 options.allowSelfLearning = true;
1209 initialize(options);
1210
1211 shared_ptr<Data> data = makeData("/12345678");
1212 lp::Packet packet(data->wireEncode());
1213 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1214
1215 transport->receivePacket(packet.wireEncode());
1216
1217 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1218 BOOST_CHECK(receivedData.empty());
1219}
1220
1221BOOST_AUTO_TEST_CASE(ReceiveNonDiscoveryDropNack)
1222{
1223 GenericLinkService::Options options;
1224 options.allowSelfLearning = true;
1225 initialize(options);
1226
1227 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
1228 lp::Packet packet;
1229 packet.set<lp::FragmentField>(std::make_pair(
1230 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1231 packet.set<lp::NackField>(nack.getHeader());
1232 packet.set<lp::NonDiscoveryField>(lp::EmptyValue{});
1233
1234 transport->receivePacket(packet.wireEncode());
1235
1236 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1237 BOOST_CHECK(receivedNacks.empty());
1238}
1239
1240BOOST_AUTO_TEST_CASE(SendPrefixAnnouncement)
1241{
1242 GenericLinkService::Options options;
1243 options.allowSelfLearning = true;
1244 initialize(options);
1245
1246 shared_ptr<Data> data = makeData("/12345678");
1247 lp::PrefixAnnouncement pa = makePrefixAnnouncement("/local/ndn/prefix");
1248 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pa));
1249
1250 face->sendData(*data);
1251
1252 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1253 lp::Packet sent(transport->sentPackets.back().packet);
1254 BOOST_CHECK(sent.has<lp::PrefixAnnouncementField>());
1255}
1256
1257BOOST_AUTO_TEST_CASE(SendPrefixAnnouncementDisabled)
1258{
1259 GenericLinkService::Options options;
1260 options.allowSelfLearning = false;
1261 initialize(options);
1262
1263 shared_ptr<Data> data = makeData("/12345678");
1264 lp::PrefixAnnouncement pa = makePrefixAnnouncement("/local/ndn/prefix");
1265 data->setTag(make_shared<lp::PrefixAnnouncementTag>(pa));
1266
1267 face->sendData(*data);
1268
1269 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
1270 lp::Packet sent(transport->sentPackets.back().packet);
1271 BOOST_CHECK(!sent.has<lp::PrefixAnnouncementField>());
1272}
1273
1274BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncement)
1275{
1276 GenericLinkService::Options options;
1277 options.allowSelfLearning = true;
1278 initialize(options);
1279
1280 shared_ptr<Data> data = makeData("/12345678");
1281 lp::PrefixAnnouncement pa = makePrefixAnnouncement("/local/ndn/prefix");
1282 lp::Packet packet(data->wireEncode());
1283 packet.set<lp::PrefixAnnouncementField>(pa);
1284
1285 transport->receivePacket(packet.wireEncode());
1286
1287 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
1288 shared_ptr<lp::PrefixAnnouncementTag> tag = receivedData.back().getTag<lp::PrefixAnnouncementTag>();
1289 BOOST_REQUIRE_EQUAL(tag->get().getAnnouncedName(), "/local/ndn/prefix");
1290}
1291
1292BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDisabled)
1293{
1294 GenericLinkService::Options options;
1295 options.allowSelfLearning = false;
1296 initialize(options);
1297
1298 shared_ptr<Data> data = makeData("/12345678");
1299 lp::PrefixAnnouncement pa = makePrefixAnnouncement("/local/ndn/prefix");
1300 lp::Packet packet(data->wireEncode());
1301 packet.set<lp::PrefixAnnouncementField>(pa);
1302
1303 transport->receivePacket(packet.wireEncode());
1304
1305 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 0); // not an error
1306 BOOST_CHECK_EQUAL(receivedData.size(), 1);
1307
1308 shared_ptr<lp::NonDiscoveryTag> tag = receivedData.back().getTag<lp::NonDiscoveryTag>();
1309 BOOST_CHECK(tag == nullptr);
1310}
1311
1312BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropInterest)
1313{
1314 GenericLinkService::Options options;
1315 options.allowSelfLearning = true;
1316 initialize(options);
1317
1318 shared_ptr<Interest> interest = makeInterest("/12345678");
1319 lp::PrefixAnnouncement pa = makePrefixAnnouncement("/local/ndn/prefix");
1320 lp::Packet packet(interest->wireEncode());
1321 packet.set<lp::PrefixAnnouncementField>(pa);
1322
1323 transport->receivePacket(packet.wireEncode());
1324
1325 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1326 BOOST_CHECK(receivedInterests.empty());
1327}
1328
1329BOOST_AUTO_TEST_CASE(ReceivePrefixAnnouncementDropNack)
1330{
1331 GenericLinkService::Options options;
1332 options.allowSelfLearning = true;
1333 initialize(options);
1334
1335 lp::Nack nack = makeNack("/localhost/test", 123, lp::NackReason::NO_ROUTE);
1336 lp::PrefixAnnouncement pa = makePrefixAnnouncement("/local/ndn/prefix");
1337 lp::Packet packet;
1338 packet.set<lp::FragmentField>(std::make_pair(
1339 nack.getInterest().wireEncode().begin(), nack.getInterest().wireEncode().end()));
1340 packet.set<lp::NackField>(nack.getHeader());
1341 packet.set<lp::PrefixAnnouncementField>(pa);
1342
1343 transport->receivePacket(packet.wireEncode());
1344
1345 BOOST_CHECK_EQUAL(service->getCounters().nInNetInvalid, 1);
1346 BOOST_CHECK(receivedNacks.empty());
1347}
1348
Eric Newberryee400b52016-11-24 14:12:48 +00001349BOOST_AUTO_TEST_SUITE_END() // LpFields
Eric Newberrya98bf932015-09-21 00:58:47 -07001350
Eric Newberrya1939ba2015-10-09 12:35:03 -07001351BOOST_AUTO_TEST_SUITE(Malformed) // receive malformed packets
1352
1353BOOST_AUTO_TEST_CASE(WrongTlvType)
1354{
1355 // Initialize with Options that disables all services
1356 GenericLinkService::Options options;
1357 options.allowLocalFields = false;
1358 initialize(options);
1359
1360 Block packet = ndn::encoding::makeEmptyBlock(tlv::Name);
1361
1362 BOOST_CHECK_NO_THROW(transport->receivePacket(packet));
1363
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001364 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001365 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1366 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1367 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1368}
1369
1370BOOST_AUTO_TEST_CASE(Unparsable)
1371{
1372 // Initialize with Options that disables all services
1373 GenericLinkService::Options options;
1374 options.allowLocalFields = false;
1375 initialize(options);
1376
1377 Block packet = ndn::encoding::makeStringBlock(lp::tlv::LpPacket, "x");
1378 BOOST_CHECK_THROW(packet.parse(), tlv::Error);
1379
1380 BOOST_CHECK_NO_THROW(transport->receivePacket(packet));
1381
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001382 BOOST_CHECK_EQUAL(service->getCounters().nInLpInvalid, 1);
Eric Newberrya1939ba2015-10-09 12:35:03 -07001383 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
1384 BOOST_CHECK_EQUAL(receivedData.size(), 0);
1385 BOOST_CHECK_EQUAL(receivedNacks.size(), 0);
1386}
1387
1388BOOST_AUTO_TEST_SUITE_END() // Malformed
1389
1390
Eric Newberry86d31872015-09-23 16:24:59 -07001391BOOST_AUTO_TEST_SUITE_END() // TestGenericLinkService
1392BOOST_AUTO_TEST_SUITE_END() // Face
Eric Newberrya98bf932015-09-21 00:58:47 -07001393
1394} // namespace tests
1395} // namespace face
1396} // namespace nfd