blob: f3aa0df6c67187352adafc9c9f1b6a9b35dcbfa9 [file] [log] [blame]
Vince Lehman277ecf02016-02-10 16:37:48 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento60f8cc12018-05-10 22:05:21 -04002/*
Davide Pesavento59984282022-02-16 22:41:03 -05003 * Copyright (c) 2014-2022, University of Memphis,
Davide Pesaventof9126532018-08-04 18:31:06 -04004 * University Pierre & Marie Curie, Sorbonne University.
Vince Lehman277ecf02016-02-10 16:37:48 -06005 *
6 * This file is part of ndn-tools (Named Data Networking Essential Tools).
7 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
8 *
9 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "tools/dump/ndndump.hpp"
22
Davide Pesavento60f8cc12018-05-10 22:05:21 -040023#include "tests/test-common.hpp"
24
Davide Pesaventof9126532018-08-04 18:31:06 -040025#include <net/ethernet.h>
26#include <netinet/ip.h>
27#include <netinet/ip6.h>
28#include <netinet/tcp.h>
29#include <netinet/udp.h>
30
31#include <boost/endian/conversion.hpp>
Davide Pesaventoa8600b02019-12-22 18:52:36 -050032#include <boost/test/tools/output_test_stream.hpp>
Davide Pesaventof9126532018-08-04 18:31:06 -040033
34#include <ndn-cxx/encoding/encoding-buffer.hpp>
Vince Lehman277ecf02016-02-10 16:37:48 -060035#include <ndn-cxx/lp/packet.hpp>
Junxiao Shic9575a62017-07-01 06:16:02 +000036#include <ndn-cxx/net/ethernet.hpp>
Junxiao Shi20b22972017-05-24 21:04:16 +000037
Davide Pesaventob3570c62022-02-19 19:19:00 -050038namespace ndn::dump::tests {
Vince Lehman277ecf02016-02-10 16:37:48 -060039
Davide Pesaventof9126532018-08-04 18:31:06 -040040namespace endian = boost::endian;
Vince Lehman277ecf02016-02-10 16:37:48 -060041using namespace ndn::tests;
42
43class StdCoutRedirector
44{
45public:
46 StdCoutRedirector(std::ostream& os)
47 {
48 // Redirect std::cout to the specified output stream
49 originalBuffer = std::cout.rdbuf(os.rdbuf());
50 }
51
52 ~StdCoutRedirector()
53 {
54 // Revert state for std::cout
55 std::cout.rdbuf(originalBuffer);
56 }
57
58private:
59 std::streambuf* originalBuffer;
60};
61
Davide Pesavento66777622020-10-09 18:46:03 -040062class NdnDumpFixture
Vince Lehman277ecf02016-02-10 16:37:48 -060063{
64protected:
65 NdnDumpFixture()
66 {
67 dump.m_dataLinkType = DLT_EN10MB;
68 }
69
Junxiao Shi20b22972017-05-24 21:04:16 +000070 template<typename Packet>
Vince Lehman277ecf02016-02-10 16:37:48 -060071 void
72 receive(const Packet& packet)
73 {
Junxiao Shi20b22972017-05-24 21:04:16 +000074 EncodingBuffer buffer(packet.wireEncode());
Davide Pesaventof9126532018-08-04 18:31:06 -040075 receiveEthernet(buffer);
Vince Lehman277ecf02016-02-10 16:37:48 -060076 }
77
78 void
Davide Pesaventof9126532018-08-04 18:31:06 -040079 receiveEthernet(EncodingBuffer& buffer, uint16_t ethertype = s_ethertypeNdn)
Vince Lehman277ecf02016-02-10 16:37:48 -060080 {
Junxiao Shic9575a62017-07-01 06:16:02 +000081 ethernet::Address host;
Vince Lehman277ecf02016-02-10 16:37:48 -060082
83 // Ethernet header
Davide Pesavento59984282022-02-16 22:41:03 -050084 buffer.prependBytes({reinterpret_cast<const uint8_t*>(&ethertype), ethernet::TYPE_LEN});
85 buffer.prependBytes(host);
86 buffer.prependBytes(host);
Vince Lehman277ecf02016-02-10 16:37:48 -060087
Davide Pesaventof9126532018-08-04 18:31:06 -040088 // pcap header
Davide Pesaventoecd44802018-07-23 23:48:10 -040089 pcap_pkthdr pkthdr{};
90 pkthdr.caplen = pkthdr.len = buffer.size();
Vince Lehman277ecf02016-02-10 16:37:48 -060091
92 {
93 StdCoutRedirector redirect(output);
Davide Pesavento59984282022-02-16 22:41:03 -050094 dump.printPacket(&pkthdr, buffer.data());
Vince Lehman277ecf02016-02-10 16:37:48 -060095 }
96 }
97
Davide Pesaventof9126532018-08-04 18:31:06 -040098 void
99 receiveIp4(EncodingBuffer& buffer, const ip* ipHeader)
100 {
Davide Pesavento59984282022-02-16 22:41:03 -0500101 buffer.prependBytes({reinterpret_cast<const uint8_t*>(ipHeader), sizeof(ip)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400102 receiveEthernet(buffer, s_ethertypeIp4);
103 }
104
105 void
106 receiveIp6(EncodingBuffer& buffer, const ip6_hdr* ip6Header)
107 {
Davide Pesavento59984282022-02-16 22:41:03 -0500108 buffer.prependBytes({reinterpret_cast<const uint8_t*>(ip6Header), sizeof(ip6_hdr)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400109 receiveEthernet(buffer, s_ethertypeIp6);
110 }
111
112 void
113 receiveTcp4(EncodingBuffer& buffer, const tcphdr* tcpHeader)
114 {
Davide Pesavento59984282022-02-16 22:41:03 -0500115 buffer.prependBytes({reinterpret_cast<const uint8_t*>(tcpHeader), sizeof(tcphdr)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400116
117 ip ipHeader{};
118 ipHeader.ip_v = 4;
119 ipHeader.ip_hl = 5;
120 ipHeader.ip_len = endian::native_to_big(static_cast<uint16_t>(buffer.size() + sizeof(ipHeader)));
121 ipHeader.ip_ttl = 1;
122 ipHeader.ip_p = IPPROTO_TCP;
123
124 receiveIp4(buffer, &ipHeader);
125 }
126
127 void
128 receiveUdp4(EncodingBuffer& buffer, const udphdr* udpHeader)
129 {
Davide Pesavento59984282022-02-16 22:41:03 -0500130 buffer.prependBytes({reinterpret_cast<const uint8_t*>(udpHeader), sizeof(udphdr)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400131
132 ip ipHeader{};
133 ipHeader.ip_v = 4;
134 ipHeader.ip_hl = 5;
135 ipHeader.ip_len = endian::native_to_big(static_cast<uint16_t>(buffer.size() + sizeof(ipHeader)));
136 ipHeader.ip_ttl = 1;
137 ipHeader.ip_p = IPPROTO_UDP;
138
139 receiveIp4(buffer, &ipHeader);
140 }
141
142 void
143 readFile(const std::string& filename)
144 {
145 StdCoutRedirector redirect(output);
146 dump.inputFile = filename;
147 dump.run();
148 }
149
Vince Lehman277ecf02016-02-10 16:37:48 -0600150protected:
Davide Pesaventoecd44802018-07-23 23:48:10 -0400151 NdnDump dump;
Vince Lehman277ecf02016-02-10 16:37:48 -0600152 boost::test_tools::output_test_stream output;
Davide Pesaventof9126532018-08-04 18:31:06 -0400153
Davide Pesaventob3570c62022-02-19 19:19:00 -0500154 static inline const uint16_t s_ethertypeNdn = endian::native_to_big(ethernet::ETHERTYPE_NDN);
155 static inline const uint16_t s_ethertypeIp4 = endian::native_to_big(uint16_t(ETHERTYPE_IP));
156 static inline const uint16_t s_ethertypeIp6 = endian::native_to_big(uint16_t(ETHERTYPE_IPV6));
Vince Lehman277ecf02016-02-10 16:37:48 -0600157};
158
Davide Pesaventoecd44802018-07-23 23:48:10 -0400159BOOST_AUTO_TEST_SUITE(Dump)
160BOOST_FIXTURE_TEST_SUITE(TestNdnDump, NdnDumpFixture)
Vince Lehman277ecf02016-02-10 16:37:48 -0600161
Davide Pesaventof9126532018-08-04 18:31:06 -0400162BOOST_AUTO_TEST_CASE(Interest)
Vince Lehman277ecf02016-02-10 16:37:48 -0600163{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400164 auto interest = makeInterest("/test", false, DEFAULT_INTEREST_LIFETIME, 1);
165 this->receive(*interest);
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400166 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?Nonce=00000001\n"));
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400167 this->receive(interest->setCanBePrefix(true));
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400168 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?CanBePrefix&Nonce=00000001\n"));
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400169 this->receive(interest->setInterestLifetime(50_ms));
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400170 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?CanBePrefix&Nonce=00000001&Lifetime=50\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600171}
172
Davide Pesaventof9126532018-08-04 18:31:06 -0400173BOOST_AUTO_TEST_CASE(Data)
Vince Lehman277ecf02016-02-10 16:37:48 -0600174{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400175 auto data = makeData("/test");
176 this->receive(*data);
177 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
178 this->receive(data->setContentType(tlv::ContentType_Key));
179 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
180 this->receive(data->setFreshnessPeriod(42_h));
Davide Pesaventof9126532018-08-04 18:31:06 -0400181 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600182}
183
Davide Pesaventof9126532018-08-04 18:31:06 -0400184BOOST_AUTO_TEST_CASE(Nack)
Vince Lehman277ecf02016-02-10 16:37:48 -0600185{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400186 auto interest = makeInterest("/test", false, DEFAULT_INTEREST_LIFETIME, 1);
Junxiao Shi20d5a0b2018-08-14 09:26:11 -0600187 auto nack = makeNack(*interest, lp::NackReason::DUPLICATE);
188 lp::Packet lpPacket(interest->wireEncode());
Vince Lehman277ecf02016-02-10 16:37:48 -0600189 lpPacket.add<lp::NackField>(nack.getHeader());
190
191 this->receive(lpPacket);
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400192 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2, NACK (Duplicate): /test?Nonce=00000001\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600193}
194
Davide Pesaventof9126532018-08-04 18:31:06 -0400195BOOST_AUTO_TEST_CASE(LpFragment)
Vince Lehman277ecf02016-02-10 16:37:48 -0600196{
197 const uint8_t data[10] = {
198 0x06, 0x08, // Data packet
199 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
200 };
201
Junxiao Shi20b22972017-05-24 21:04:16 +0000202 Buffer buffer(data, 4);
Vince Lehman277ecf02016-02-10 16:37:48 -0600203 lp::Packet lpPacket;
204 lpPacket.add<lp::FragmentField>(std::make_pair(buffer.begin(), buffer.end()));
205 lpPacket.add<lp::FragIndexField>(0);
206 lpPacket.add<lp::FragCountField>(2);
207 lpPacket.add<lp::SequenceField>(1000);
208
209 this->receive(lpPacket);
Davide Pesaventof9126532018-08-04 18:31:06 -0400210 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 fragment\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600211}
212
Davide Pesaventof9126532018-08-04 18:31:06 -0400213BOOST_AUTO_TEST_CASE(LpIdle)
Vince Lehman277ecf02016-02-10 16:37:48 -0600214{
215 lp::Packet lpPacket;
Vince Lehman277ecf02016-02-10 16:37:48 -0600216 this->receive(lpPacket);
Davide Pesaventof9126532018-08-04 18:31:06 -0400217 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 idle\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600218}
219
Davide Pesaventof9126532018-08-04 18:31:06 -0400220BOOST_AUTO_TEST_CASE(IncompleteNdnPacket)
Vince Lehman277ecf02016-02-10 16:37:48 -0600221{
222 const uint8_t interest[] = {
223 0x05, 0x0E, // Interest
224 0x07, 0x06, // Name
225 0x08, 0x04, // NameComponent
226 0x74, 0x65, 0x73, 0x74,
227 0x0a, 0x04, // Nonce
228 0x00, 0x00, 0x00, 0x01
229 };
Vince Lehman277ecf02016-02-10 16:37:48 -0600230 EncodingBuffer buffer;
Davide Pesavento59984282022-02-16 22:41:03 -0500231 buffer.prependBytes(make_span(interest).first(4));
Vince Lehman277ecf02016-02-10 16:37:48 -0600232
Davide Pesaventof9126532018-08-04 18:31:06 -0400233 this->receiveEthernet(buffer);
Davide Pesaventof9126532018-08-04 18:31:06 -0400234 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDN truncated packet, length 4\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600235}
236
Davide Pesaventof9126532018-08-04 18:31:06 -0400237BOOST_AUTO_TEST_CASE(UnsupportedNdnPacket)
Vince Lehman277ecf02016-02-10 16:37:48 -0600238{
Junxiao Shi20b22972017-05-24 21:04:16 +0000239 EncodingBuffer buffer(encoding::makeEmptyBlock(tlv::Name));
Davide Pesaventof9126532018-08-04 18:31:06 -0400240 this->receiveEthernet(buffer);
Davide Pesaventof9126532018-08-04 18:31:06 -0400241 BOOST_CHECK(output.is_equal("0.000000 Ethernet, [Unsupported NDN packet type 7]\n"));
242}
243
244BOOST_AUTO_TEST_CASE(UnsupportedEtherType)
245{
246 EncodingBuffer pkt;
247 uint16_t type = ETHERTYPE_ARP;
248 endian::native_to_big_inplace(type);
249
250 this->receiveEthernet(pkt, type);
Davide Pesaventof9126532018-08-04 18:31:06 -0400251 BOOST_CHECK(output.is_equal("0.000000 [Unsupported ethertype 0x806]\n"));
252}
253
254BOOST_AUTO_TEST_CASE(MalformedIpv4Header)
255{
256 dump.wantTimestamp = false;
257
258 uint8_t theAnswer = 42;
259
260 EncodingBuffer pkt1;
Davide Pesavento59984282022-02-16 22:41:03 -0500261 pkt1.prependBytes({theAnswer});
Davide Pesaventof9126532018-08-04 18:31:06 -0400262 this->receiveEthernet(pkt1, s_ethertypeIp4);
263 BOOST_CHECK(output.is_equal("IP truncated header, length 1\n"));
264
265 ip ipHdr2{};
266 ipHdr2.ip_v = 7;
267
268 EncodingBuffer pkt2;
269 this->receiveIp4(pkt2, &ipHdr2);
270 BOOST_CHECK(output.is_equal("IP bad version 7\n"));
271
272 ip ipHdr3{};
273 ipHdr3.ip_v = 4;
274 ipHdr3.ip_hl = 2;
275
276 EncodingBuffer pkt3;
277 this->receiveIp4(pkt3, &ipHdr3);
278 BOOST_CHECK(output.is_equal("IP bad header length 8\n"));
279
280 ip ipHdr4{};
281 ipHdr4.ip_v = 4;
282 ipHdr4.ip_hl = 5;
283 ipHdr4.ip_len = 10;
284 endian::native_to_big_inplace(ipHdr4.ip_len);
285
286 EncodingBuffer pkt4;
287 this->receiveIp4(pkt4, &ipHdr4);
288 BOOST_CHECK(output.is_equal("IP bad length 10\n"));
289
290 ip ipHdr5{};
291 ipHdr5.ip_v = 4;
292 ipHdr5.ip_hl = 5;
293 ipHdr5.ip_len = 1000;
294 endian::native_to_big_inplace(ipHdr5.ip_len);
295
296 EncodingBuffer pkt5;
297 this->receiveIp4(pkt5, &ipHdr5);
298 BOOST_CHECK(output.is_equal("IP truncated packet, 980 bytes missing\n"));
299}
300
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400301BOOST_AUTO_TEST_CASE(MalformedIpv6Header)
302{
303 dump.wantTimestamp = false;
304
305 uint8_t theAnswer = 42;
306
307 EncodingBuffer pkt1;
Davide Pesavento59984282022-02-16 22:41:03 -0500308 pkt1.prependBytes({theAnswer});
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400309 this->receiveEthernet(pkt1, s_ethertypeIp6);
310 BOOST_CHECK(output.is_equal("IP6 truncated header, length 1\n"));
311
312 ip6_hdr ip6Hdr2{};
313 ip6Hdr2.ip6_vfc = 10 << 4;
314
315 EncodingBuffer pkt2;
316 this->receiveIp6(pkt2, &ip6Hdr2);
317 BOOST_CHECK(output.is_equal("IP6 bad version 10\n"));
318
319 ip6_hdr ip6Hdr3{};
320 ip6Hdr3.ip6_vfc = 6 << 4;
321 ip6Hdr3.ip6_plen = 1400;
322 endian::native_to_big_inplace(ip6Hdr3.ip6_plen);
323
324 EncodingBuffer pkt3;
325 this->receiveIp6(pkt3, &ip6Hdr3);
326 BOOST_CHECK(output.is_equal("IP6 truncated payload, 1400 bytes missing\n"));
327}
328
Davide Pesaventof9126532018-08-04 18:31:06 -0400329BOOST_AUTO_TEST_CASE(UnsupportedIpProto)
330{
331 dump.wantTimestamp = false;
332
333 ip ipHdr{};
334 ipHdr.ip_v = 4;
335 ipHdr.ip_hl = 5;
336 ipHdr.ip_len = sizeof(ipHdr);
337 endian::native_to_big_inplace(ipHdr.ip_len);
338 ipHdr.ip_p = IPPROTO_SCTP;
339
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400340 EncodingBuffer pkt1;
341 this->receiveIp4(pkt1, &ipHdr);
Davide Pesaventof9126532018-08-04 18:31:06 -0400342 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, [Unsupported IP proto 132]\n"));
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400343
344 ip6_hdr ip6Hdr{};
345 ip6Hdr.ip6_vfc = 6 << 4;
346 ip6Hdr.ip6_nxt = IPPROTO_NONE;
347
348 EncodingBuffer pkt2;
349 this->receiveIp6(pkt2, &ip6Hdr);
350 BOOST_CHECK(output.is_equal("IP6 :: > ::, [No next header]\n"));
Davide Pesaventof9126532018-08-04 18:31:06 -0400351}
352
353BOOST_AUTO_TEST_CASE(MalformedTcpHeader)
354{
355 dump.wantTimestamp = false;
356
357 tcphdr tcpHdr1{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500358 tcpHdr1.TH_OFF = 0x2;
Davide Pesaventof9126532018-08-04 18:31:06 -0400359
360 EncodingBuffer pkt1;
361 this->receiveTcp4(pkt1, &tcpHdr1);
362 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, TCP bad header length 8\n"));
363
364 tcphdr tcpHdr2{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500365 tcpHdr2.TH_OFF = 0xf;
Davide Pesaventof9126532018-08-04 18:31:06 -0400366
367 EncodingBuffer pkt2;
368 this->receiveTcp4(pkt2, &tcpHdr2);
369 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, TCP truncated header, 40 bytes missing\n"));
370}
371
372BOOST_AUTO_TEST_CASE(MalformedUdpHeader)
373{
374 dump.wantTimestamp = false;
375
376 udphdr udpHdr1{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500377 udpHdr1.UH_LEN = 3;
378 endian::native_to_big_inplace(udpHdr1.UH_LEN);
Davide Pesaventof9126532018-08-04 18:31:06 -0400379
380 EncodingBuffer pkt1;
381 this->receiveUdp4(pkt1, &udpHdr1);
382 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, UDP bad length 3\n"));
383
384 udphdr udpHdr2{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500385 udpHdr2.UH_LEN = 1000;
386 endian::native_to_big_inplace(udpHdr2.UH_LEN);
Davide Pesaventof9126532018-08-04 18:31:06 -0400387
388 EncodingBuffer pkt2;
389 this->receiveUdp4(pkt2, &udpHdr2);
390 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, UDP truncated packet, 992 bytes missing\n"));
391}
392
393BOOST_AUTO_TEST_CASE(InvalidTlvLength)
394{
395 dump.wantTimestamp = false;
396 this->readFile("tests/dump/invalid-tlv-length.pcap");
397
398 const std::string expected =
399 "IP 128.196.203.36 > 128.187.81.12, TCP, length 147, NDNLPv2 invalid packet: "
400 "TLV-LENGTH of sub-element of type 5 exceeds TLV-VALUE boundary of parent block\n";
401 BOOST_CHECK(output.is_equal(expected));
402}
403
404BOOST_AUTO_TEST_CASE(UnrecognizedLpField)
405{
406 dump.wantTimestamp = false;
407 this->readFile("tests/dump/unrecognized-lp-field.pcap");
408
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400409 const std::string expected =
410 "IP 128.196.203.36 > 128.187.81.12, TCP, length 800, "
411 "NDNLPv2 invalid packet: unrecognized field 4 cannot be ignored\n";
Davide Pesaventoecd44802018-07-23 23:48:10 -0400412 BOOST_CHECK(output.is_equal(expected));
Vince Lehman277ecf02016-02-10 16:37:48 -0600413}
414
Davide Pesaventob5b8f952018-07-26 14:19:16 -0400415BOOST_AUTO_TEST_CASE(NoTimestamp)
416{
417 dump.wantTimestamp = false;
418
419 lp::Packet lpPacket;
420 this->receive(lpPacket);
421
Davide Pesaventof9126532018-08-04 18:31:06 -0400422 BOOST_CHECK(output.is_equal("Ethernet, NDNLPv2 idle\n"));
Davide Pesaventob5b8f952018-07-26 14:19:16 -0400423}
424
Davide Pesaventof9126532018-08-04 18:31:06 -0400425BOOST_AUTO_TEST_CASE(FromFile)
Vince Lehman277ecf02016-02-10 16:37:48 -0600426{
Davide Pesaventoecd44802018-07-23 23:48:10 -0400427 dump.pcapFilter = "";
Davide Pesaventof9126532018-08-04 18:31:06 -0400428 this->readFile("tests/dump/nack.pcap");
Vince Lehman277ecf02016-02-10 16:37:48 -0600429
Davide Pesaventoecd44802018-07-23 23:48:10 -0400430 const std::string expected =
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400431 "1571091605.129263 IP 127.0.0.1 > 127.0.0.1, TCP, length 36, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400432 "INTEREST: /producer/nack/no-route?Nonce=827bcac4\n"
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400433 "1571091605.129702 IP 127.0.0.1 > 127.0.0.1, TCP, length 49, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400434 "NDNLPv2, NACK (NoRoute): /producer/nack/no-route?Nonce=827bcac4\n";
Davide Pesaventoecd44802018-07-23 23:48:10 -0400435 BOOST_CHECK(output.is_equal(expected));
Vince Lehman277ecf02016-02-10 16:37:48 -0600436}
437
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400438BOOST_AUTO_TEST_CASE(LinuxSllTcp4)
439{
440 dump.wantTimestamp = false;
441 this->readFile("tests/dump/linux-sll-tcp4.pcap");
442
443 const std::string expected =
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400444 "IP 162.211.64.84 > 131.179.196.46, TCP, length 41, INTEREST: /ndn/edu/arizona/ping/8202?Nonce=cf062c3f\n"
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400445 "IP 131.179.196.46 > 162.211.64.84, TCP, length 403, DATA: /ndn/edu/arizona/ping/8202\n";
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400446 BOOST_CHECK(output.is_equal(expected));
447}
448
449BOOST_AUTO_TEST_CASE(LinuxSllUdp4)
450{
451 dump.wantTimestamp = false;
452 this->readFile("tests/dump/linux-sll-udp4.pcap");
453
454 const std::string expected =
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400455 "IP 162.211.64.84 > 131.179.196.46, UDP, length 42, INTEREST: /ndn/edu/arizona/ping/31044?Nonce=f33c0bbd\n"
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400456 "IP 131.179.196.46 > 162.211.64.84, UDP, length 404, DATA: /ndn/edu/arizona/ping/31044\n";
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400457 BOOST_CHECK(output.is_equal(expected));
458}
459
460BOOST_AUTO_TEST_CASE(LinuxSllTcp6)
461{
462 dump.wantTimestamp = false;
463 this->readFile("tests/dump/linux-sll-tcp6.pcap");
464
465 const std::string expected =
466 "IP6 2602:fff6:d:b317::39f8 > 2001:660:3302:282c:160::163, TCP, length 42, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400467 "INTEREST: /ndn/edu/arizona/ping/19573?Nonce=7b9e5b2e\n"
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400468 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, TCP, length 404, "
469 "DATA: /ndn/edu/arizona/ping/19573\n"
470 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, TCP, length 56, "
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400471 "invalid network packet: Unrecognized element of critical type 9\n";
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400472 BOOST_CHECK(output.is_equal(expected));
473}
474
475BOOST_AUTO_TEST_CASE(LinuxSllUdp6)
476{
477 dump.wantTimestamp = false;
478 this->readFile("tests/dump/linux-sll-udp6.pcap");
479
480 const std::string expected =
481 "IP6 2602:fff6:d:b317::39f8 > 2001:660:3302:282c:160::163, UDP, length 39, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400482 "INTEREST: /ndn/edu/arizona/ping/18?Nonce=7e351222\n"
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400483 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, UDP, length 401, "
484 "DATA: /ndn/edu/arizona/ping/18\n"
485 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, UDP, length 56, "
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400486 "invalid network packet: Unrecognized element of critical type 9\n";
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400487 BOOST_CHECK(output.is_equal(expected));
488}
489
Davide Pesaventoecd44802018-07-23 23:48:10 -0400490BOOST_AUTO_TEST_SUITE_END() // TestNdnDump
491BOOST_AUTO_TEST_SUITE_END() // Dump
Vince Lehman277ecf02016-02-10 16:37:48 -0600492
Davide Pesaventob3570c62022-02-19 19:19:00 -0500493} // namespace ndn::dump::tests