blob: 217dc10e4c8eba8df9d88ed03ecac2cf2d84cfef [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#if BOOST_VERSION >= 105900
33#include <boost/test/tools/output_test_stream.hpp>
34#else
35#include <boost/test/output_test_stream.hpp>
36#endif
Davide Pesaventof9126532018-08-04 18:31:06 -040037
38#include <ndn-cxx/encoding/encoding-buffer.hpp>
Vince Lehman277ecf02016-02-10 16:37:48 -060039#include <ndn-cxx/lp/packet.hpp>
Junxiao Shic9575a62017-07-01 06:16:02 +000040#include <ndn-cxx/net/ethernet.hpp>
Junxiao Shi20b22972017-05-24 21:04:16 +000041
Vince Lehman277ecf02016-02-10 16:37:48 -060042namespace ndn {
43namespace dump {
44namespace tests {
45
Davide Pesaventof9126532018-08-04 18:31:06 -040046namespace endian = boost::endian;
Vince Lehman277ecf02016-02-10 16:37:48 -060047using namespace ndn::tests;
48
49class StdCoutRedirector
50{
51public:
52 StdCoutRedirector(std::ostream& os)
53 {
54 // Redirect std::cout to the specified output stream
55 originalBuffer = std::cout.rdbuf(os.rdbuf());
56 }
57
58 ~StdCoutRedirector()
59 {
60 // Revert state for std::cout
61 std::cout.rdbuf(originalBuffer);
62 }
63
64private:
65 std::streambuf* originalBuffer;
66};
67
Davide Pesavento66777622020-10-09 18:46:03 -040068class NdnDumpFixture
Vince Lehman277ecf02016-02-10 16:37:48 -060069{
70protected:
71 NdnDumpFixture()
72 {
73 dump.m_dataLinkType = DLT_EN10MB;
74 }
75
Junxiao Shi20b22972017-05-24 21:04:16 +000076 template<typename Packet>
Vince Lehman277ecf02016-02-10 16:37:48 -060077 void
78 receive(const Packet& packet)
79 {
Junxiao Shi20b22972017-05-24 21:04:16 +000080 EncodingBuffer buffer(packet.wireEncode());
Davide Pesaventof9126532018-08-04 18:31:06 -040081 receiveEthernet(buffer);
Vince Lehman277ecf02016-02-10 16:37:48 -060082 }
83
84 void
Davide Pesaventof9126532018-08-04 18:31:06 -040085 receiveEthernet(EncodingBuffer& buffer, uint16_t ethertype = s_ethertypeNdn)
Vince Lehman277ecf02016-02-10 16:37:48 -060086 {
Junxiao Shic9575a62017-07-01 06:16:02 +000087 ethernet::Address host;
Vince Lehman277ecf02016-02-10 16:37:48 -060088
89 // Ethernet header
Davide Pesavento59984282022-02-16 22:41:03 -050090 buffer.prependBytes({reinterpret_cast<const uint8_t*>(&ethertype), ethernet::TYPE_LEN});
91 buffer.prependBytes(host);
92 buffer.prependBytes(host);
Vince Lehman277ecf02016-02-10 16:37:48 -060093
Davide Pesaventof9126532018-08-04 18:31:06 -040094 // pcap header
Davide Pesaventoecd44802018-07-23 23:48:10 -040095 pcap_pkthdr pkthdr{};
96 pkthdr.caplen = pkthdr.len = buffer.size();
Vince Lehman277ecf02016-02-10 16:37:48 -060097
98 {
99 StdCoutRedirector redirect(output);
Davide Pesavento59984282022-02-16 22:41:03 -0500100 dump.printPacket(&pkthdr, buffer.data());
Vince Lehman277ecf02016-02-10 16:37:48 -0600101 }
102 }
103
Davide Pesaventof9126532018-08-04 18:31:06 -0400104 void
105 receiveIp4(EncodingBuffer& buffer, const ip* ipHeader)
106 {
Davide Pesavento59984282022-02-16 22:41:03 -0500107 buffer.prependBytes({reinterpret_cast<const uint8_t*>(ipHeader), sizeof(ip)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400108 receiveEthernet(buffer, s_ethertypeIp4);
109 }
110
111 void
112 receiveIp6(EncodingBuffer& buffer, const ip6_hdr* ip6Header)
113 {
Davide Pesavento59984282022-02-16 22:41:03 -0500114 buffer.prependBytes({reinterpret_cast<const uint8_t*>(ip6Header), sizeof(ip6_hdr)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400115 receiveEthernet(buffer, s_ethertypeIp6);
116 }
117
118 void
119 receiveTcp4(EncodingBuffer& buffer, const tcphdr* tcpHeader)
120 {
Davide Pesavento59984282022-02-16 22:41:03 -0500121 buffer.prependBytes({reinterpret_cast<const uint8_t*>(tcpHeader), sizeof(tcphdr)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400122
123 ip ipHeader{};
124 ipHeader.ip_v = 4;
125 ipHeader.ip_hl = 5;
126 ipHeader.ip_len = endian::native_to_big(static_cast<uint16_t>(buffer.size() + sizeof(ipHeader)));
127 ipHeader.ip_ttl = 1;
128 ipHeader.ip_p = IPPROTO_TCP;
129
130 receiveIp4(buffer, &ipHeader);
131 }
132
133 void
134 receiveUdp4(EncodingBuffer& buffer, const udphdr* udpHeader)
135 {
Davide Pesavento59984282022-02-16 22:41:03 -0500136 buffer.prependBytes({reinterpret_cast<const uint8_t*>(udpHeader), sizeof(udphdr)});
Davide Pesaventof9126532018-08-04 18:31:06 -0400137
138 ip ipHeader{};
139 ipHeader.ip_v = 4;
140 ipHeader.ip_hl = 5;
141 ipHeader.ip_len = endian::native_to_big(static_cast<uint16_t>(buffer.size() + sizeof(ipHeader)));
142 ipHeader.ip_ttl = 1;
143 ipHeader.ip_p = IPPROTO_UDP;
144
145 receiveIp4(buffer, &ipHeader);
146 }
147
148 void
149 readFile(const std::string& filename)
150 {
151 StdCoutRedirector redirect(output);
152 dump.inputFile = filename;
153 dump.run();
154 }
155
Vince Lehman277ecf02016-02-10 16:37:48 -0600156protected:
Davide Pesaventoecd44802018-07-23 23:48:10 -0400157 NdnDump dump;
Vince Lehman277ecf02016-02-10 16:37:48 -0600158 boost::test_tools::output_test_stream output;
Davide Pesaventof9126532018-08-04 18:31:06 -0400159
160 static const uint16_t s_ethertypeNdn;
161 static const uint16_t s_ethertypeIp4;
162 static const uint16_t s_ethertypeIp6;
Vince Lehman277ecf02016-02-10 16:37:48 -0600163};
164
Davide Pesaventof9126532018-08-04 18:31:06 -0400165const uint16_t NdnDumpFixture::s_ethertypeNdn = endian::native_to_big(ethernet::ETHERTYPE_NDN);
166const uint16_t NdnDumpFixture::s_ethertypeIp4 = endian::native_to_big(uint16_t(ETHERTYPE_IP));
167const uint16_t NdnDumpFixture::s_ethertypeIp6 = endian::native_to_big(uint16_t(ETHERTYPE_IPV6));
168
Davide Pesaventoecd44802018-07-23 23:48:10 -0400169BOOST_AUTO_TEST_SUITE(Dump)
170BOOST_FIXTURE_TEST_SUITE(TestNdnDump, NdnDumpFixture)
Vince Lehman277ecf02016-02-10 16:37:48 -0600171
Davide Pesaventof9126532018-08-04 18:31:06 -0400172BOOST_AUTO_TEST_CASE(Interest)
Vince Lehman277ecf02016-02-10 16:37:48 -0600173{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400174 auto interest = makeInterest("/test", false, DEFAULT_INTEREST_LIFETIME, 1);
175 this->receive(*interest);
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400176 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?Nonce=00000001\n"));
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400177 this->receive(interest->setCanBePrefix(true));
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400178 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?CanBePrefix&Nonce=00000001\n"));
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400179 this->receive(interest->setInterestLifetime(50_ms));
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400180 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?CanBePrefix&Nonce=00000001&Lifetime=50\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600181}
182
Davide Pesaventof9126532018-08-04 18:31:06 -0400183BOOST_AUTO_TEST_CASE(Data)
Vince Lehman277ecf02016-02-10 16:37:48 -0600184{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400185 auto data = makeData("/test");
186 this->receive(*data);
187 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
188 this->receive(data->setContentType(tlv::ContentType_Key));
189 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
190 this->receive(data->setFreshnessPeriod(42_h));
Davide Pesaventof9126532018-08-04 18:31:06 -0400191 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600192}
193
Davide Pesaventof9126532018-08-04 18:31:06 -0400194BOOST_AUTO_TEST_CASE(Nack)
Vince Lehman277ecf02016-02-10 16:37:48 -0600195{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400196 auto interest = makeInterest("/test", false, DEFAULT_INTEREST_LIFETIME, 1);
Junxiao Shi20d5a0b2018-08-14 09:26:11 -0600197 auto nack = makeNack(*interest, lp::NackReason::DUPLICATE);
198 lp::Packet lpPacket(interest->wireEncode());
Vince Lehman277ecf02016-02-10 16:37:48 -0600199 lpPacket.add<lp::NackField>(nack.getHeader());
200
201 this->receive(lpPacket);
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400202 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2, NACK (Duplicate): /test?Nonce=00000001\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600203}
204
Davide Pesaventof9126532018-08-04 18:31:06 -0400205BOOST_AUTO_TEST_CASE(LpFragment)
Vince Lehman277ecf02016-02-10 16:37:48 -0600206{
207 const uint8_t data[10] = {
208 0x06, 0x08, // Data packet
209 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
210 };
211
Junxiao Shi20b22972017-05-24 21:04:16 +0000212 Buffer buffer(data, 4);
Vince Lehman277ecf02016-02-10 16:37:48 -0600213 lp::Packet lpPacket;
214 lpPacket.add<lp::FragmentField>(std::make_pair(buffer.begin(), buffer.end()));
215 lpPacket.add<lp::FragIndexField>(0);
216 lpPacket.add<lp::FragCountField>(2);
217 lpPacket.add<lp::SequenceField>(1000);
218
219 this->receive(lpPacket);
Davide Pesaventof9126532018-08-04 18:31:06 -0400220 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 fragment\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600221}
222
Davide Pesaventof9126532018-08-04 18:31:06 -0400223BOOST_AUTO_TEST_CASE(LpIdle)
Vince Lehman277ecf02016-02-10 16:37:48 -0600224{
225 lp::Packet lpPacket;
Vince Lehman277ecf02016-02-10 16:37:48 -0600226 this->receive(lpPacket);
Davide Pesaventof9126532018-08-04 18:31:06 -0400227 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 idle\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600228}
229
Davide Pesaventof9126532018-08-04 18:31:06 -0400230BOOST_AUTO_TEST_CASE(IncompleteNdnPacket)
Vince Lehman277ecf02016-02-10 16:37:48 -0600231{
232 const uint8_t interest[] = {
233 0x05, 0x0E, // Interest
234 0x07, 0x06, // Name
235 0x08, 0x04, // NameComponent
236 0x74, 0x65, 0x73, 0x74,
237 0x0a, 0x04, // Nonce
238 0x00, 0x00, 0x00, 0x01
239 };
Vince Lehman277ecf02016-02-10 16:37:48 -0600240 EncodingBuffer buffer;
Davide Pesavento59984282022-02-16 22:41:03 -0500241 buffer.prependBytes(make_span(interest).first(4));
Vince Lehman277ecf02016-02-10 16:37:48 -0600242
Davide Pesaventof9126532018-08-04 18:31:06 -0400243 this->receiveEthernet(buffer);
Davide Pesaventof9126532018-08-04 18:31:06 -0400244 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDN truncated packet, length 4\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600245}
246
Davide Pesaventof9126532018-08-04 18:31:06 -0400247BOOST_AUTO_TEST_CASE(UnsupportedNdnPacket)
Vince Lehman277ecf02016-02-10 16:37:48 -0600248{
Junxiao Shi20b22972017-05-24 21:04:16 +0000249 EncodingBuffer buffer(encoding::makeEmptyBlock(tlv::Name));
Davide Pesaventof9126532018-08-04 18:31:06 -0400250 this->receiveEthernet(buffer);
Davide Pesaventof9126532018-08-04 18:31:06 -0400251 BOOST_CHECK(output.is_equal("0.000000 Ethernet, [Unsupported NDN packet type 7]\n"));
252}
253
254BOOST_AUTO_TEST_CASE(UnsupportedEtherType)
255{
256 EncodingBuffer pkt;
257 uint16_t type = ETHERTYPE_ARP;
258 endian::native_to_big_inplace(type);
259
260 this->receiveEthernet(pkt, type);
Davide Pesaventof9126532018-08-04 18:31:06 -0400261 BOOST_CHECK(output.is_equal("0.000000 [Unsupported ethertype 0x806]\n"));
262}
263
264BOOST_AUTO_TEST_CASE(MalformedIpv4Header)
265{
266 dump.wantTimestamp = false;
267
268 uint8_t theAnswer = 42;
269
270 EncodingBuffer pkt1;
Davide Pesavento59984282022-02-16 22:41:03 -0500271 pkt1.prependBytes({theAnswer});
Davide Pesaventof9126532018-08-04 18:31:06 -0400272 this->receiveEthernet(pkt1, s_ethertypeIp4);
273 BOOST_CHECK(output.is_equal("IP truncated header, length 1\n"));
274
275 ip ipHdr2{};
276 ipHdr2.ip_v = 7;
277
278 EncodingBuffer pkt2;
279 this->receiveIp4(pkt2, &ipHdr2);
280 BOOST_CHECK(output.is_equal("IP bad version 7\n"));
281
282 ip ipHdr3{};
283 ipHdr3.ip_v = 4;
284 ipHdr3.ip_hl = 2;
285
286 EncodingBuffer pkt3;
287 this->receiveIp4(pkt3, &ipHdr3);
288 BOOST_CHECK(output.is_equal("IP bad header length 8\n"));
289
290 ip ipHdr4{};
291 ipHdr4.ip_v = 4;
292 ipHdr4.ip_hl = 5;
293 ipHdr4.ip_len = 10;
294 endian::native_to_big_inplace(ipHdr4.ip_len);
295
296 EncodingBuffer pkt4;
297 this->receiveIp4(pkt4, &ipHdr4);
298 BOOST_CHECK(output.is_equal("IP bad length 10\n"));
299
300 ip ipHdr5{};
301 ipHdr5.ip_v = 4;
302 ipHdr5.ip_hl = 5;
303 ipHdr5.ip_len = 1000;
304 endian::native_to_big_inplace(ipHdr5.ip_len);
305
306 EncodingBuffer pkt5;
307 this->receiveIp4(pkt5, &ipHdr5);
308 BOOST_CHECK(output.is_equal("IP truncated packet, 980 bytes missing\n"));
309}
310
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400311BOOST_AUTO_TEST_CASE(MalformedIpv6Header)
312{
313 dump.wantTimestamp = false;
314
315 uint8_t theAnswer = 42;
316
317 EncodingBuffer pkt1;
Davide Pesavento59984282022-02-16 22:41:03 -0500318 pkt1.prependBytes({theAnswer});
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400319 this->receiveEthernet(pkt1, s_ethertypeIp6);
320 BOOST_CHECK(output.is_equal("IP6 truncated header, length 1\n"));
321
322 ip6_hdr ip6Hdr2{};
323 ip6Hdr2.ip6_vfc = 10 << 4;
324
325 EncodingBuffer pkt2;
326 this->receiveIp6(pkt2, &ip6Hdr2);
327 BOOST_CHECK(output.is_equal("IP6 bad version 10\n"));
328
329 ip6_hdr ip6Hdr3{};
330 ip6Hdr3.ip6_vfc = 6 << 4;
331 ip6Hdr3.ip6_plen = 1400;
332 endian::native_to_big_inplace(ip6Hdr3.ip6_plen);
333
334 EncodingBuffer pkt3;
335 this->receiveIp6(pkt3, &ip6Hdr3);
336 BOOST_CHECK(output.is_equal("IP6 truncated payload, 1400 bytes missing\n"));
337}
338
Davide Pesaventof9126532018-08-04 18:31:06 -0400339BOOST_AUTO_TEST_CASE(UnsupportedIpProto)
340{
341 dump.wantTimestamp = false;
342
343 ip ipHdr{};
344 ipHdr.ip_v = 4;
345 ipHdr.ip_hl = 5;
346 ipHdr.ip_len = sizeof(ipHdr);
347 endian::native_to_big_inplace(ipHdr.ip_len);
348 ipHdr.ip_p = IPPROTO_SCTP;
349
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400350 EncodingBuffer pkt1;
351 this->receiveIp4(pkt1, &ipHdr);
Davide Pesaventof9126532018-08-04 18:31:06 -0400352 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 -0400353
354 ip6_hdr ip6Hdr{};
355 ip6Hdr.ip6_vfc = 6 << 4;
356 ip6Hdr.ip6_nxt = IPPROTO_NONE;
357
358 EncodingBuffer pkt2;
359 this->receiveIp6(pkt2, &ip6Hdr);
360 BOOST_CHECK(output.is_equal("IP6 :: > ::, [No next header]\n"));
Davide Pesaventof9126532018-08-04 18:31:06 -0400361}
362
363BOOST_AUTO_TEST_CASE(MalformedTcpHeader)
364{
365 dump.wantTimestamp = false;
366
367 tcphdr tcpHdr1{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500368 tcpHdr1.TH_OFF = 0x2;
Davide Pesaventof9126532018-08-04 18:31:06 -0400369
370 EncodingBuffer pkt1;
371 this->receiveTcp4(pkt1, &tcpHdr1);
372 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, TCP bad header length 8\n"));
373
374 tcphdr tcpHdr2{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500375 tcpHdr2.TH_OFF = 0xf;
Davide Pesaventof9126532018-08-04 18:31:06 -0400376
377 EncodingBuffer pkt2;
378 this->receiveTcp4(pkt2, &tcpHdr2);
379 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, TCP truncated header, 40 bytes missing\n"));
380}
381
382BOOST_AUTO_TEST_CASE(MalformedUdpHeader)
383{
384 dump.wantTimestamp = false;
385
386 udphdr udpHdr1{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500387 udpHdr1.UH_LEN = 3;
388 endian::native_to_big_inplace(udpHdr1.UH_LEN);
Davide Pesaventof9126532018-08-04 18:31:06 -0400389
390 EncodingBuffer pkt1;
391 this->receiveUdp4(pkt1, &udpHdr1);
392 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, UDP bad length 3\n"));
393
394 udphdr udpHdr2{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500395 udpHdr2.UH_LEN = 1000;
396 endian::native_to_big_inplace(udpHdr2.UH_LEN);
Davide Pesaventof9126532018-08-04 18:31:06 -0400397
398 EncodingBuffer pkt2;
399 this->receiveUdp4(pkt2, &udpHdr2);
400 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, UDP truncated packet, 992 bytes missing\n"));
401}
402
403BOOST_AUTO_TEST_CASE(InvalidTlvLength)
404{
405 dump.wantTimestamp = false;
406 this->readFile("tests/dump/invalid-tlv-length.pcap");
407
408 const std::string expected =
409 "IP 128.196.203.36 > 128.187.81.12, TCP, length 147, NDNLPv2 invalid packet: "
410 "TLV-LENGTH of sub-element of type 5 exceeds TLV-VALUE boundary of parent block\n";
411 BOOST_CHECK(output.is_equal(expected));
412}
413
414BOOST_AUTO_TEST_CASE(UnrecognizedLpField)
415{
416 dump.wantTimestamp = false;
417 this->readFile("tests/dump/unrecognized-lp-field.pcap");
418
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400419 const std::string expected =
420 "IP 128.196.203.36 > 128.187.81.12, TCP, length 800, "
421 "NDNLPv2 invalid packet: unrecognized field 4 cannot be ignored\n";
Davide Pesaventoecd44802018-07-23 23:48:10 -0400422 BOOST_CHECK(output.is_equal(expected));
Vince Lehman277ecf02016-02-10 16:37:48 -0600423}
424
Davide Pesaventob5b8f952018-07-26 14:19:16 -0400425BOOST_AUTO_TEST_CASE(NoTimestamp)
426{
427 dump.wantTimestamp = false;
428
429 lp::Packet lpPacket;
430 this->receive(lpPacket);
431
Davide Pesaventof9126532018-08-04 18:31:06 -0400432 BOOST_CHECK(output.is_equal("Ethernet, NDNLPv2 idle\n"));
Davide Pesaventob5b8f952018-07-26 14:19:16 -0400433}
434
Davide Pesaventof9126532018-08-04 18:31:06 -0400435BOOST_AUTO_TEST_CASE(FromFile)
Vince Lehman277ecf02016-02-10 16:37:48 -0600436{
Davide Pesaventoecd44802018-07-23 23:48:10 -0400437 dump.pcapFilter = "";
Davide Pesaventof9126532018-08-04 18:31:06 -0400438 this->readFile("tests/dump/nack.pcap");
Vince Lehman277ecf02016-02-10 16:37:48 -0600439
Davide Pesaventoecd44802018-07-23 23:48:10 -0400440 const std::string expected =
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400441 "1571091605.129263 IP 127.0.0.1 > 127.0.0.1, TCP, length 36, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400442 "INTEREST: /producer/nack/no-route?Nonce=827bcac4\n"
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400443 "1571091605.129702 IP 127.0.0.1 > 127.0.0.1, TCP, length 49, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400444 "NDNLPv2, NACK (NoRoute): /producer/nack/no-route?Nonce=827bcac4\n";
Davide Pesaventoecd44802018-07-23 23:48:10 -0400445 BOOST_CHECK(output.is_equal(expected));
Vince Lehman277ecf02016-02-10 16:37:48 -0600446}
447
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400448BOOST_AUTO_TEST_CASE(LinuxSllTcp4)
449{
450 dump.wantTimestamp = false;
451 this->readFile("tests/dump/linux-sll-tcp4.pcap");
452
453 const std::string expected =
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400454 "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 -0400455 "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 -0400456 BOOST_CHECK(output.is_equal(expected));
457}
458
459BOOST_AUTO_TEST_CASE(LinuxSllUdp4)
460{
461 dump.wantTimestamp = false;
462 this->readFile("tests/dump/linux-sll-udp4.pcap");
463
464 const std::string expected =
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400465 "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 -0400466 "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 -0400467 BOOST_CHECK(output.is_equal(expected));
468}
469
470BOOST_AUTO_TEST_CASE(LinuxSllTcp6)
471{
472 dump.wantTimestamp = false;
473 this->readFile("tests/dump/linux-sll-tcp6.pcap");
474
475 const std::string expected =
476 "IP6 2602:fff6:d:b317::39f8 > 2001:660:3302:282c:160::163, TCP, length 42, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400477 "INTEREST: /ndn/edu/arizona/ping/19573?Nonce=7b9e5b2e\n"
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400478 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, TCP, length 404, "
479 "DATA: /ndn/edu/arizona/ping/19573\n"
480 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, TCP, length 56, "
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400481 "invalid network packet: Unrecognized element of critical type 9\n";
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400482 BOOST_CHECK(output.is_equal(expected));
483}
484
485BOOST_AUTO_TEST_CASE(LinuxSllUdp6)
486{
487 dump.wantTimestamp = false;
488 this->readFile("tests/dump/linux-sll-udp6.pcap");
489
490 const std::string expected =
491 "IP6 2602:fff6:d:b317::39f8 > 2001:660:3302:282c:160::163, UDP, length 39, "
Davide Pesavento4ab5eed2020-03-12 20:50:04 -0400492 "INTEREST: /ndn/edu/arizona/ping/18?Nonce=7e351222\n"
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400493 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, UDP, length 401, "
494 "DATA: /ndn/edu/arizona/ping/18\n"
495 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, UDP, length 56, "
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400496 "invalid network packet: Unrecognized element of critical type 9\n";
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400497 BOOST_CHECK(output.is_equal(expected));
498}
499
Davide Pesaventoecd44802018-07-23 23:48:10 -0400500BOOST_AUTO_TEST_SUITE_END() // TestNdnDump
501BOOST_AUTO_TEST_SUITE_END() // Dump
Vince Lehman277ecf02016-02-10 16:37:48 -0600502
503} // namespace tests
504} // namespace dump
505} // namespace ndn