blob: b467795f9e62f0adfe951c08f7b90acf17e42fda [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 Pesavento7e9d7e42023-11-11 15:00:03 -05003 * Copyright (c) 2014-2023, 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>
Davide Pesavento7e9d7e42023-11-11 15:00:03 -050035#include <ndn-cxx/lp/fields.hpp>
Vince Lehman277ecf02016-02-10 16:37:48 -060036#include <ndn-cxx/lp/packet.hpp>
Junxiao Shic9575a62017-07-01 06:16:02 +000037#include <ndn-cxx/net/ethernet.hpp>
Junxiao Shi20b22972017-05-24 21:04:16 +000038
Davide Pesaventob3570c62022-02-19 19:19:00 -050039namespace ndn::dump::tests {
Vince Lehman277ecf02016-02-10 16:37:48 -060040
Davide Pesaventof9126532018-08-04 18:31:06 -040041namespace endian = boost::endian;
Vince Lehman277ecf02016-02-10 16:37:48 -060042using namespace ndn::tests;
43
44class StdCoutRedirector
45{
46public:
47 StdCoutRedirector(std::ostream& os)
48 {
49 // Redirect std::cout to the specified output stream
50 originalBuffer = std::cout.rdbuf(os.rdbuf());
51 }
52
53 ~StdCoutRedirector()
54 {
55 // Revert state for std::cout
56 std::cout.rdbuf(originalBuffer);
57 }
58
59private:
60 std::streambuf* originalBuffer;
61};
62
Davide Pesavento66777622020-10-09 18:46:03 -040063class NdnDumpFixture
Vince Lehman277ecf02016-02-10 16:37:48 -060064{
65protected:
66 NdnDumpFixture()
67 {
68 dump.m_dataLinkType = DLT_EN10MB;
69 }
70
Junxiao Shi20b22972017-05-24 21:04:16 +000071 template<typename Packet>
Vince Lehman277ecf02016-02-10 16:37:48 -060072 void
73 receive(const Packet& packet)
74 {
Junxiao Shi20b22972017-05-24 21:04:16 +000075 EncodingBuffer buffer(packet.wireEncode());
Davide Pesaventof9126532018-08-04 18:31:06 -040076 receiveEthernet(buffer);
Vince Lehman277ecf02016-02-10 16:37:48 -060077 }
78
79 void
Davide Pesaventof9126532018-08-04 18:31:06 -040080 receiveEthernet(EncodingBuffer& buffer, uint16_t ethertype = s_ethertypeNdn)
Vince Lehman277ecf02016-02-10 16:37:48 -060081 {
Junxiao Shic9575a62017-07-01 06:16:02 +000082 ethernet::Address host;
Vince Lehman277ecf02016-02-10 16:37:48 -060083
84 // Ethernet header
Davide Pesavento59984282022-02-16 22:41:03 -050085 buffer.prependBytes({reinterpret_cast<const uint8_t*>(&ethertype), ethernet::TYPE_LEN});
86 buffer.prependBytes(host);
87 buffer.prependBytes(host);
Vince Lehman277ecf02016-02-10 16:37:48 -060088
Davide Pesaventof9126532018-08-04 18:31:06 -040089 // pcap header
Davide Pesaventoecd44802018-07-23 23:48:10 -040090 pcap_pkthdr pkthdr{};
91 pkthdr.caplen = pkthdr.len = buffer.size();
Vince Lehman277ecf02016-02-10 16:37:48 -060092
93 {
94 StdCoutRedirector redirect(output);
Davide Pesavento59984282022-02-16 22:41:03 -050095 dump.printPacket(&pkthdr, buffer.data());
Vince Lehman277ecf02016-02-10 16:37:48 -060096 }
97 }
98
Davide Pesaventof9126532018-08-04 18:31:06 -040099 void
100 receiveIp4(EncodingBuffer& buffer, const ip* ipHeader)
101 {
Davide Pesavento59984282022-02-16 22:41:03 -0500102 buffer.prependBytes({reinterpret_cast<const uint8_t*>(ipHeader), sizeof(ip)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400103 receiveEthernet(buffer, s_ethertypeIp4);
104 }
105
106 void
107 receiveIp6(EncodingBuffer& buffer, const ip6_hdr* ip6Header)
108 {
Davide Pesavento59984282022-02-16 22:41:03 -0500109 buffer.prependBytes({reinterpret_cast<const uint8_t*>(ip6Header), sizeof(ip6_hdr)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400110 receiveEthernet(buffer, s_ethertypeIp6);
111 }
112
113 void
114 receiveTcp4(EncodingBuffer& buffer, const tcphdr* tcpHeader)
115 {
Davide Pesavento59984282022-02-16 22:41:03 -0500116 buffer.prependBytes({reinterpret_cast<const uint8_t*>(tcpHeader), sizeof(tcphdr)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400117
118 ip ipHeader{};
119 ipHeader.ip_v = 4;
120 ipHeader.ip_hl = 5;
121 ipHeader.ip_len = endian::native_to_big(static_cast<uint16_t>(buffer.size() + sizeof(ipHeader)));
122 ipHeader.ip_ttl = 1;
123 ipHeader.ip_p = IPPROTO_TCP;
124
125 receiveIp4(buffer, &ipHeader);
126 }
127
128 void
129 receiveUdp4(EncodingBuffer& buffer, const udphdr* udpHeader)
130 {
Davide Pesavento59984282022-02-16 22:41:03 -0500131 buffer.prependBytes({reinterpret_cast<const uint8_t*>(udpHeader), sizeof(udphdr)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400132
133 ip ipHeader{};
134 ipHeader.ip_v = 4;
135 ipHeader.ip_hl = 5;
136 ipHeader.ip_len = endian::native_to_big(static_cast<uint16_t>(buffer.size() + sizeof(ipHeader)));
137 ipHeader.ip_ttl = 1;
138 ipHeader.ip_p = IPPROTO_UDP;
139
140 receiveIp4(buffer, &ipHeader);
141 }
142
143 void
144 readFile(const std::string& filename)
145 {
146 StdCoutRedirector redirect(output);
147 dump.inputFile = filename;
148 dump.run();
149 }
150
Vince Lehman277ecf02016-02-10 16:37:48 -0600151protected:
Davide Pesaventoecd44802018-07-23 23:48:10 -0400152 NdnDump dump;
Vince Lehman277ecf02016-02-10 16:37:48 -0600153 boost::test_tools::output_test_stream output;
Davide Pesaventof9126532018-08-04 18:31:06 -0400154
Davide Pesaventob3570c62022-02-19 19:19:00 -0500155 static inline const uint16_t s_ethertypeNdn = endian::native_to_big(ethernet::ETHERTYPE_NDN);
156 static inline const uint16_t s_ethertypeIp4 = endian::native_to_big(uint16_t(ETHERTYPE_IP));
157 static inline const uint16_t s_ethertypeIp6 = endian::native_to_big(uint16_t(ETHERTYPE_IPV6));
Vince Lehman277ecf02016-02-10 16:37:48 -0600158};
159
Davide Pesaventoecd44802018-07-23 23:48:10 -0400160BOOST_AUTO_TEST_SUITE(Dump)
161BOOST_FIXTURE_TEST_SUITE(TestNdnDump, NdnDumpFixture)
Vince Lehman277ecf02016-02-10 16:37:48 -0600162
Davide Pesaventof9126532018-08-04 18:31:06 -0400163BOOST_AUTO_TEST_CASE(Interest)
Vince Lehman277ecf02016-02-10 16:37:48 -0600164{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400165 auto interest = makeInterest("/test", false, DEFAULT_INTEREST_LIFETIME, 1);
166 this->receive(*interest);
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400167 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?Nonce=00000001\n"));
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400168 this->receive(interest->setCanBePrefix(true));
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400169 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?CanBePrefix&Nonce=00000001\n"));
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400170 this->receive(interest->setInterestLifetime(50_ms));
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400171 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?CanBePrefix&Nonce=00000001&Lifetime=50\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600172}
173
Davide Pesaventof9126532018-08-04 18:31:06 -0400174BOOST_AUTO_TEST_CASE(Data)
Vince Lehman277ecf02016-02-10 16:37:48 -0600175{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400176 auto data = makeData("/test");
177 this->receive(*data);
178 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
179 this->receive(data->setContentType(tlv::ContentType_Key));
180 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
181 this->receive(data->setFreshnessPeriod(42_h));
Davide Pesaventof9126532018-08-04 18:31:06 -0400182 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600183}
184
Davide Pesaventof9126532018-08-04 18:31:06 -0400185BOOST_AUTO_TEST_CASE(Nack)
Vince Lehman277ecf02016-02-10 16:37:48 -0600186{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400187 auto interest = makeInterest("/test", false, DEFAULT_INTEREST_LIFETIME, 1);
Junxiao Shi20d5a0b2018-08-14 09:26:11 -0600188 auto nack = makeNack(*interest, lp::NackReason::DUPLICATE);
189 lp::Packet lpPacket(interest->wireEncode());
Vince Lehman277ecf02016-02-10 16:37:48 -0600190 lpPacket.add<lp::NackField>(nack.getHeader());
191
192 this->receive(lpPacket);
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400193 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2, NACK (Duplicate): /test?Nonce=00000001\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600194}
195
Davide Pesaventof9126532018-08-04 18:31:06 -0400196BOOST_AUTO_TEST_CASE(LpFragment)
Vince Lehman277ecf02016-02-10 16:37:48 -0600197{
198 const uint8_t data[10] = {
199 0x06, 0x08, // Data packet
200 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
201 };
202
Junxiao Shi20b22972017-05-24 21:04:16 +0000203 Buffer buffer(data, 4);
Vince Lehman277ecf02016-02-10 16:37:48 -0600204 lp::Packet lpPacket;
205 lpPacket.add<lp::FragmentField>(std::make_pair(buffer.begin(), buffer.end()));
206 lpPacket.add<lp::FragIndexField>(0);
207 lpPacket.add<lp::FragCountField>(2);
208 lpPacket.add<lp::SequenceField>(1000);
209
210 this->receive(lpPacket);
Davide Pesaventof9126532018-08-04 18:31:06 -0400211 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 fragment\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600212}
213
Davide Pesaventof9126532018-08-04 18:31:06 -0400214BOOST_AUTO_TEST_CASE(LpIdle)
Vince Lehman277ecf02016-02-10 16:37:48 -0600215{
216 lp::Packet lpPacket;
Vince Lehman277ecf02016-02-10 16:37:48 -0600217 this->receive(lpPacket);
Davide Pesaventof9126532018-08-04 18:31:06 -0400218 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 idle\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600219}
220
Davide Pesaventof9126532018-08-04 18:31:06 -0400221BOOST_AUTO_TEST_CASE(IncompleteNdnPacket)
Vince Lehman277ecf02016-02-10 16:37:48 -0600222{
223 const uint8_t interest[] = {
224 0x05, 0x0E, // Interest
225 0x07, 0x06, // Name
226 0x08, 0x04, // NameComponent
227 0x74, 0x65, 0x73, 0x74,
228 0x0a, 0x04, // Nonce
229 0x00, 0x00, 0x00, 0x01
230 };
Vince Lehman277ecf02016-02-10 16:37:48 -0600231 EncodingBuffer buffer;
Davide Pesavento59984282022-02-16 22:41:03 -0500232 buffer.prependBytes(make_span(interest).first(4));
Vince Lehman277ecf02016-02-10 16:37:48 -0600233
Davide Pesaventof9126532018-08-04 18:31:06 -0400234 this->receiveEthernet(buffer);
Davide Pesaventof9126532018-08-04 18:31:06 -0400235 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDN truncated packet, length 4\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600236}
237
Davide Pesaventof9126532018-08-04 18:31:06 -0400238BOOST_AUTO_TEST_CASE(UnsupportedNdnPacket)
Vince Lehman277ecf02016-02-10 16:37:48 -0600239{
Junxiao Shi20b22972017-05-24 21:04:16 +0000240 EncodingBuffer buffer(encoding::makeEmptyBlock(tlv::Name));
Davide Pesaventof9126532018-08-04 18:31:06 -0400241 this->receiveEthernet(buffer);
Davide Pesaventof9126532018-08-04 18:31:06 -0400242 BOOST_CHECK(output.is_equal("0.000000 Ethernet, [Unsupported NDN packet type 7]\n"));
243}
244
245BOOST_AUTO_TEST_CASE(UnsupportedEtherType)
246{
247 EncodingBuffer pkt;
248 uint16_t type = ETHERTYPE_ARP;
249 endian::native_to_big_inplace(type);
250
251 this->receiveEthernet(pkt, type);
Davide Pesaventof9126532018-08-04 18:31:06 -0400252 BOOST_CHECK(output.is_equal("0.000000 [Unsupported ethertype 0x806]\n"));
253}
254
255BOOST_AUTO_TEST_CASE(MalformedIpv4Header)
256{
257 dump.wantTimestamp = false;
258
259 uint8_t theAnswer = 42;
260
261 EncodingBuffer pkt1;
Davide Pesavento59984282022-02-16 22:41:03 -0500262 pkt1.prependBytes({theAnswer});
Davide Pesaventof9126532018-08-04 18:31:06 -0400263 this->receiveEthernet(pkt1, s_ethertypeIp4);
264 BOOST_CHECK(output.is_equal("IP truncated header, length 1\n"));
265
266 ip ipHdr2{};
267 ipHdr2.ip_v = 7;
268
269 EncodingBuffer pkt2;
270 this->receiveIp4(pkt2, &ipHdr2);
271 BOOST_CHECK(output.is_equal("IP bad version 7\n"));
272
273 ip ipHdr3{};
274 ipHdr3.ip_v = 4;
275 ipHdr3.ip_hl = 2;
276
277 EncodingBuffer pkt3;
278 this->receiveIp4(pkt3, &ipHdr3);
279 BOOST_CHECK(output.is_equal("IP bad header length 8\n"));
280
281 ip ipHdr4{};
282 ipHdr4.ip_v = 4;
283 ipHdr4.ip_hl = 5;
284 ipHdr4.ip_len = 10;
285 endian::native_to_big_inplace(ipHdr4.ip_len);
286
287 EncodingBuffer pkt4;
288 this->receiveIp4(pkt4, &ipHdr4);
289 BOOST_CHECK(output.is_equal("IP bad length 10\n"));
290
291 ip ipHdr5{};
292 ipHdr5.ip_v = 4;
293 ipHdr5.ip_hl = 5;
294 ipHdr5.ip_len = 1000;
295 endian::native_to_big_inplace(ipHdr5.ip_len);
296
297 EncodingBuffer pkt5;
298 this->receiveIp4(pkt5, &ipHdr5);
299 BOOST_CHECK(output.is_equal("IP truncated packet, 980 bytes missing\n"));
300}
301
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400302BOOST_AUTO_TEST_CASE(MalformedIpv6Header)
303{
304 dump.wantTimestamp = false;
305
306 uint8_t theAnswer = 42;
307
308 EncodingBuffer pkt1;
Davide Pesavento59984282022-02-16 22:41:03 -0500309 pkt1.prependBytes({theAnswer});
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400310 this->receiveEthernet(pkt1, s_ethertypeIp6);
311 BOOST_CHECK(output.is_equal("IP6 truncated header, length 1\n"));
312
313 ip6_hdr ip6Hdr2{};
314 ip6Hdr2.ip6_vfc = 10 << 4;
315
316 EncodingBuffer pkt2;
317 this->receiveIp6(pkt2, &ip6Hdr2);
318 BOOST_CHECK(output.is_equal("IP6 bad version 10\n"));
319
320 ip6_hdr ip6Hdr3{};
321 ip6Hdr3.ip6_vfc = 6 << 4;
322 ip6Hdr3.ip6_plen = 1400;
323 endian::native_to_big_inplace(ip6Hdr3.ip6_plen);
324
325 EncodingBuffer pkt3;
326 this->receiveIp6(pkt3, &ip6Hdr3);
327 BOOST_CHECK(output.is_equal("IP6 truncated payload, 1400 bytes missing\n"));
328}
329
Davide Pesaventof9126532018-08-04 18:31:06 -0400330BOOST_AUTO_TEST_CASE(UnsupportedIpProto)
331{
332 dump.wantTimestamp = false;
333
334 ip ipHdr{};
335 ipHdr.ip_v = 4;
336 ipHdr.ip_hl = 5;
337 ipHdr.ip_len = sizeof(ipHdr);
338 endian::native_to_big_inplace(ipHdr.ip_len);
339 ipHdr.ip_p = IPPROTO_SCTP;
340
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400341 EncodingBuffer pkt1;
342 this->receiveIp4(pkt1, &ipHdr);
Davide Pesaventof9126532018-08-04 18:31:06 -0400343 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 -0400344
345 ip6_hdr ip6Hdr{};
346 ip6Hdr.ip6_vfc = 6 << 4;
347 ip6Hdr.ip6_nxt = IPPROTO_NONE;
348
349 EncodingBuffer pkt2;
350 this->receiveIp6(pkt2, &ip6Hdr);
351 BOOST_CHECK(output.is_equal("IP6 :: > ::, [No next header]\n"));
Davide Pesaventof9126532018-08-04 18:31:06 -0400352}
353
354BOOST_AUTO_TEST_CASE(MalformedTcpHeader)
355{
356 dump.wantTimestamp = false;
357
358 tcphdr tcpHdr1{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500359 tcpHdr1.TH_OFF = 0x2;
Davide Pesaventof9126532018-08-04 18:31:06 -0400360
361 EncodingBuffer pkt1;
362 this->receiveTcp4(pkt1, &tcpHdr1);
363 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, TCP bad header length 8\n"));
364
365 tcphdr tcpHdr2{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500366 tcpHdr2.TH_OFF = 0xf;
Davide Pesaventof9126532018-08-04 18:31:06 -0400367
368 EncodingBuffer pkt2;
369 this->receiveTcp4(pkt2, &tcpHdr2);
370 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, TCP truncated header, 40 bytes missing\n"));
371}
372
373BOOST_AUTO_TEST_CASE(MalformedUdpHeader)
374{
375 dump.wantTimestamp = false;
376
377 udphdr udpHdr1{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500378 udpHdr1.UH_LEN = 3;
379 endian::native_to_big_inplace(udpHdr1.UH_LEN);
Davide Pesaventof9126532018-08-04 18:31:06 -0400380
381 EncodingBuffer pkt1;
382 this->receiveUdp4(pkt1, &udpHdr1);
383 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, UDP bad length 3\n"));
384
385 udphdr udpHdr2{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500386 udpHdr2.UH_LEN = 1000;
387 endian::native_to_big_inplace(udpHdr2.UH_LEN);
Davide Pesaventof9126532018-08-04 18:31:06 -0400388
389 EncodingBuffer pkt2;
390 this->receiveUdp4(pkt2, &udpHdr2);
391 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, UDP truncated packet, 992 bytes missing\n"));
392}
393
394BOOST_AUTO_TEST_CASE(InvalidTlvLength)
395{
396 dump.wantTimestamp = false;
397 this->readFile("tests/dump/invalid-tlv-length.pcap");
398
399 const std::string expected =
400 "IP 128.196.203.36 > 128.187.81.12, TCP, length 147, NDNLPv2 invalid packet: "
401 "TLV-LENGTH of sub-element of type 5 exceeds TLV-VALUE boundary of parent block\n";
402 BOOST_CHECK(output.is_equal(expected));
403}
404
405BOOST_AUTO_TEST_CASE(UnrecognizedLpField)
406{
407 dump.wantTimestamp = false;
408 this->readFile("tests/dump/unrecognized-lp-field.pcap");
409
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400410 const std::string expected =
411 "IP 128.196.203.36 > 128.187.81.12, TCP, length 800, "
412 "NDNLPv2 invalid packet: unrecognized field 4 cannot be ignored\n";
Davide Pesaventoecd44802018-07-23 23:48:10 -0400413 BOOST_CHECK(output.is_equal(expected));
Vince Lehman277ecf02016-02-10 16:37:48 -0600414}
415
Davide Pesaventob5b8f952018-07-26 14:19:16 -0400416BOOST_AUTO_TEST_CASE(NoTimestamp)
417{
418 dump.wantTimestamp = false;
419
420 lp::Packet lpPacket;
421 this->receive(lpPacket);
422
Davide Pesaventof9126532018-08-04 18:31:06 -0400423 BOOST_CHECK(output.is_equal("Ethernet, NDNLPv2 idle\n"));
Davide Pesaventob5b8f952018-07-26 14:19:16 -0400424}
425
Davide Pesaventof9126532018-08-04 18:31:06 -0400426BOOST_AUTO_TEST_CASE(FromFile)
Vince Lehman277ecf02016-02-10 16:37:48 -0600427{
Davide Pesaventoecd44802018-07-23 23:48:10 -0400428 dump.pcapFilter = "";
Davide Pesaventof9126532018-08-04 18:31:06 -0400429 this->readFile("tests/dump/nack.pcap");
Vince Lehman277ecf02016-02-10 16:37:48 -0600430
Davide Pesaventoecd44802018-07-23 23:48:10 -0400431 const std::string expected =
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400432 "1571091605.129263 IP 127.0.0.1 > 127.0.0.1, TCP, length 36, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400433 "INTEREST: /producer/nack/no-route?Nonce=827bcac4\n"
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400434 "1571091605.129702 IP 127.0.0.1 > 127.0.0.1, TCP, length 49, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400435 "NDNLPv2, NACK (NoRoute): /producer/nack/no-route?Nonce=827bcac4\n";
Davide Pesaventoecd44802018-07-23 23:48:10 -0400436 BOOST_CHECK(output.is_equal(expected));
Vince Lehman277ecf02016-02-10 16:37:48 -0600437}
438
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400439BOOST_AUTO_TEST_CASE(LinuxSllTcp4)
440{
441 dump.wantTimestamp = false;
442 this->readFile("tests/dump/linux-sll-tcp4.pcap");
443
444 const std::string expected =
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400445 "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 -0400446 "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 -0400447 BOOST_CHECK(output.is_equal(expected));
448}
449
450BOOST_AUTO_TEST_CASE(LinuxSllUdp4)
451{
452 dump.wantTimestamp = false;
453 this->readFile("tests/dump/linux-sll-udp4.pcap");
454
455 const std::string expected =
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400456 "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 -0400457 "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 -0400458 BOOST_CHECK(output.is_equal(expected));
459}
460
461BOOST_AUTO_TEST_CASE(LinuxSllTcp6)
462{
463 dump.wantTimestamp = false;
464 this->readFile("tests/dump/linux-sll-tcp6.pcap");
465
466 const std::string expected =
467 "IP6 2602:fff6:d:b317::39f8 > 2001:660:3302:282c:160::163, TCP, length 42, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400468 "INTEREST: /ndn/edu/arizona/ping/19573?Nonce=7b9e5b2e\n"
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400469 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, TCP, length 404, "
470 "DATA: /ndn/edu/arizona/ping/19573\n"
471 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, TCP, length 56, "
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400472 "invalid network packet: Unrecognized element of critical type 9\n";
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400473 BOOST_CHECK(output.is_equal(expected));
474}
475
476BOOST_AUTO_TEST_CASE(LinuxSllUdp6)
477{
478 dump.wantTimestamp = false;
479 this->readFile("tests/dump/linux-sll-udp6.pcap");
480
481 const std::string expected =
482 "IP6 2602:fff6:d:b317::39f8 > 2001:660:3302:282c:160::163, UDP, length 39, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400483 "INTEREST: /ndn/edu/arizona/ping/18?Nonce=7e351222\n"
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400484 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, UDP, length 401, "
485 "DATA: /ndn/edu/arizona/ping/18\n"
486 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, UDP, length 56, "
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400487 "invalid network packet: Unrecognized element of critical type 9\n";
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400488 BOOST_CHECK(output.is_equal(expected));
489}
490
Davide Pesaventoecd44802018-07-23 23:48:10 -0400491BOOST_AUTO_TEST_SUITE_END() // TestNdnDump
492BOOST_AUTO_TEST_SUITE_END() // Dump
Vince Lehman277ecf02016-02-10 16:37:48 -0600493
Davide Pesaventob3570c62022-02-19 19:19:00 -0500494} // namespace ndn::dump::tests