blob: 59a887978da9af7a92ef6eddf717a7fdd181f880 [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 Pesavento7b9837b2019-02-23 19:07:50 -05003 * Copyright (c) 2014-2019, 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/identity-management-fixture.hpp"
24#include "tests/test-common.hpp"
25
Davide Pesaventof9126532018-08-04 18:31:06 -040026#include <net/ethernet.h>
27#include <netinet/ip.h>
28#include <netinet/ip6.h>
29#include <netinet/tcp.h>
30#include <netinet/udp.h>
31
32#include <boost/endian/conversion.hpp>
Davide Pesaventoa8600b02019-12-22 18:52:36 -050033#if BOOST_VERSION >= 105900
34#include <boost/test/tools/output_test_stream.hpp>
35#else
36#include <boost/test/output_test_stream.hpp>
37#endif
Davide Pesaventof9126532018-08-04 18:31:06 -040038
39#include <ndn-cxx/encoding/encoding-buffer.hpp>
Vince Lehman277ecf02016-02-10 16:37:48 -060040#include <ndn-cxx/lp/packet.hpp>
Junxiao Shic9575a62017-07-01 06:16:02 +000041#include <ndn-cxx/net/ethernet.hpp>
Junxiao Shi20b22972017-05-24 21:04:16 +000042
Vince Lehman277ecf02016-02-10 16:37:48 -060043namespace ndn {
44namespace dump {
45namespace tests {
46
Davide Pesaventof9126532018-08-04 18:31:06 -040047namespace endian = boost::endian;
Vince Lehman277ecf02016-02-10 16:37:48 -060048using namespace ndn::tests;
49
50class StdCoutRedirector
51{
52public:
53 StdCoutRedirector(std::ostream& os)
54 {
55 // Redirect std::cout to the specified output stream
56 originalBuffer = std::cout.rdbuf(os.rdbuf());
57 }
58
59 ~StdCoutRedirector()
60 {
61 // Revert state for std::cout
62 std::cout.rdbuf(originalBuffer);
63 }
64
65private:
66 std::streambuf* originalBuffer;
67};
68
Junxiao Shi20b22972017-05-24 21:04:16 +000069class NdnDumpFixture : public IdentityManagementFixture
Vince Lehman277ecf02016-02-10 16:37:48 -060070{
71protected:
72 NdnDumpFixture()
73 {
74 dump.m_dataLinkType = DLT_EN10MB;
75 }
76
Junxiao Shi20b22972017-05-24 21:04:16 +000077 template<typename Packet>
Vince Lehman277ecf02016-02-10 16:37:48 -060078 void
79 receive(const Packet& packet)
80 {
Junxiao Shi20b22972017-05-24 21:04:16 +000081 EncodingBuffer buffer(packet.wireEncode());
Davide Pesaventof9126532018-08-04 18:31:06 -040082 receiveEthernet(buffer);
Vince Lehman277ecf02016-02-10 16:37:48 -060083 }
84
85 void
Davide Pesaventof9126532018-08-04 18:31:06 -040086 receiveEthernet(EncodingBuffer& buffer, uint16_t ethertype = s_ethertypeNdn)
Vince Lehman277ecf02016-02-10 16:37:48 -060087 {
Junxiao Shic9575a62017-07-01 06:16:02 +000088 ethernet::Address host;
Vince Lehman277ecf02016-02-10 16:37:48 -060089
90 // Ethernet header
Davide Pesaventof9126532018-08-04 18:31:06 -040091 buffer.prependByteArray(reinterpret_cast<const uint8_t*>(&ethertype), ethernet::TYPE_LEN);
Vince Lehman277ecf02016-02-10 16:37:48 -060092 buffer.prependByteArray(host.data(), host.size());
93 buffer.prependByteArray(host.data(), host.size());
94
Davide Pesaventof9126532018-08-04 18:31:06 -040095 // pcap header
Davide Pesaventoecd44802018-07-23 23:48:10 -040096 pcap_pkthdr pkthdr{};
97 pkthdr.caplen = pkthdr.len = buffer.size();
Vince Lehman277ecf02016-02-10 16:37:48 -060098
99 {
100 StdCoutRedirector redirect(output);
Davide Pesaventoecd44802018-07-23 23:48:10 -0400101 dump.printPacket(&pkthdr, buffer.buf());
Vince Lehman277ecf02016-02-10 16:37:48 -0600102 }
103 }
104
Davide Pesaventof9126532018-08-04 18:31:06 -0400105 void
106 receiveIp4(EncodingBuffer& buffer, const ip* ipHeader)
107 {
108 buffer.prependByteArray(reinterpret_cast<const uint8_t*>(ipHeader), sizeof(ip));
109 receiveEthernet(buffer, s_ethertypeIp4);
110 }
111
112 void
113 receiveIp6(EncodingBuffer& buffer, const ip6_hdr* ip6Header)
114 {
115 buffer.prependByteArray(reinterpret_cast<const uint8_t*>(ip6Header), sizeof(ip6_hdr));
116 receiveEthernet(buffer, s_ethertypeIp6);
117 }
118
119 void
120 receiveTcp4(EncodingBuffer& buffer, const tcphdr* tcpHeader)
121 {
122 buffer.prependByteArray(reinterpret_cast<const uint8_t*>(tcpHeader), sizeof(tcphdr));
123
124 ip ipHeader{};
125 ipHeader.ip_v = 4;
126 ipHeader.ip_hl = 5;
127 ipHeader.ip_len = endian::native_to_big(static_cast<uint16_t>(buffer.size() + sizeof(ipHeader)));
128 ipHeader.ip_ttl = 1;
129 ipHeader.ip_p = IPPROTO_TCP;
130
131 receiveIp4(buffer, &ipHeader);
132 }
133
134 void
135 receiveUdp4(EncodingBuffer& buffer, const udphdr* udpHeader)
136 {
137 buffer.prependByteArray(reinterpret_cast<const uint8_t*>(udpHeader), sizeof(udphdr));
138
139 ip ipHeader{};
140 ipHeader.ip_v = 4;
141 ipHeader.ip_hl = 5;
142 ipHeader.ip_len = endian::native_to_big(static_cast<uint16_t>(buffer.size() + sizeof(ipHeader)));
143 ipHeader.ip_ttl = 1;
144 ipHeader.ip_p = IPPROTO_UDP;
145
146 receiveIp4(buffer, &ipHeader);
147 }
148
149 void
150 readFile(const std::string& filename)
151 {
152 StdCoutRedirector redirect(output);
153 dump.inputFile = filename;
154 dump.run();
155 }
156
Vince Lehman277ecf02016-02-10 16:37:48 -0600157protected:
Davide Pesaventoecd44802018-07-23 23:48:10 -0400158 NdnDump dump;
Vince Lehman277ecf02016-02-10 16:37:48 -0600159 boost::test_tools::output_test_stream output;
Davide Pesaventof9126532018-08-04 18:31:06 -0400160
161 static const uint16_t s_ethertypeNdn;
162 static const uint16_t s_ethertypeIp4;
163 static const uint16_t s_ethertypeIp6;
Vince Lehman277ecf02016-02-10 16:37:48 -0600164};
165
Davide Pesaventof9126532018-08-04 18:31:06 -0400166const uint16_t NdnDumpFixture::s_ethertypeNdn = endian::native_to_big(ethernet::ETHERTYPE_NDN);
167const uint16_t NdnDumpFixture::s_ethertypeIp4 = endian::native_to_big(uint16_t(ETHERTYPE_IP));
168const uint16_t NdnDumpFixture::s_ethertypeIp6 = endian::native_to_big(uint16_t(ETHERTYPE_IPV6));
169
Davide Pesaventoecd44802018-07-23 23:48:10 -0400170BOOST_AUTO_TEST_SUITE(Dump)
171BOOST_FIXTURE_TEST_SUITE(TestNdnDump, NdnDumpFixture)
Vince Lehman277ecf02016-02-10 16:37:48 -0600172
Davide Pesaventof9126532018-08-04 18:31:06 -0400173BOOST_AUTO_TEST_CASE(Interest)
Vince Lehman277ecf02016-02-10 16:37:48 -0600174{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400175 auto interest = makeInterest("/test", false, DEFAULT_INTEREST_LIFETIME, 1);
176 this->receive(*interest);
177 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?Nonce=1\n"));
178 this->receive(interest->setCanBePrefix(true));
179 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?CanBePrefix&Nonce=1\n"));
180 this->receive(interest->setInterestLifetime(50_ms));
181 BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?CanBePrefix&Nonce=1&Lifetime=50\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600182}
183
Davide Pesaventof9126532018-08-04 18:31:06 -0400184BOOST_AUTO_TEST_CASE(Data)
Vince Lehman277ecf02016-02-10 16:37:48 -0600185{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400186 auto data = makeData("/test");
187 this->receive(*data);
188 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
189 this->receive(data->setContentType(tlv::ContentType_Key));
190 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
191 this->receive(data->setFreshnessPeriod(42_h));
Davide Pesaventof9126532018-08-04 18:31:06 -0400192 BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600193}
194
Davide Pesaventof9126532018-08-04 18:31:06 -0400195BOOST_AUTO_TEST_CASE(Nack)
Vince Lehman277ecf02016-02-10 16:37:48 -0600196{
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400197 auto interest = makeInterest("/test", false, DEFAULT_INTEREST_LIFETIME, 1);
Junxiao Shi20d5a0b2018-08-14 09:26:11 -0600198 auto nack = makeNack(*interest, lp::NackReason::DUPLICATE);
199 lp::Packet lpPacket(interest->wireEncode());
Vince Lehman277ecf02016-02-10 16:37:48 -0600200 lpPacket.add<lp::NackField>(nack.getHeader());
201
202 this->receive(lpPacket);
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400203 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2, NACK (Duplicate): /test?Nonce=1\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600204}
205
Davide Pesaventof9126532018-08-04 18:31:06 -0400206BOOST_AUTO_TEST_CASE(LpFragment)
Vince Lehman277ecf02016-02-10 16:37:48 -0600207{
208 const uint8_t data[10] = {
209 0x06, 0x08, // Data packet
210 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
211 };
212
Junxiao Shi20b22972017-05-24 21:04:16 +0000213 Buffer buffer(data, 4);
Vince Lehman277ecf02016-02-10 16:37:48 -0600214 lp::Packet lpPacket;
215 lpPacket.add<lp::FragmentField>(std::make_pair(buffer.begin(), buffer.end()));
216 lpPacket.add<lp::FragIndexField>(0);
217 lpPacket.add<lp::FragCountField>(2);
218 lpPacket.add<lp::SequenceField>(1000);
219
220 this->receive(lpPacket);
Davide Pesaventof9126532018-08-04 18:31:06 -0400221 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 fragment\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600222}
223
Davide Pesaventof9126532018-08-04 18:31:06 -0400224BOOST_AUTO_TEST_CASE(LpIdle)
Vince Lehman277ecf02016-02-10 16:37:48 -0600225{
226 lp::Packet lpPacket;
Vince Lehman277ecf02016-02-10 16:37:48 -0600227 this->receive(lpPacket);
Davide Pesaventof9126532018-08-04 18:31:06 -0400228 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 idle\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600229}
230
Davide Pesaventof9126532018-08-04 18:31:06 -0400231BOOST_AUTO_TEST_CASE(IncompleteNdnPacket)
Vince Lehman277ecf02016-02-10 16:37:48 -0600232{
233 const uint8_t interest[] = {
234 0x05, 0x0E, // Interest
235 0x07, 0x06, // Name
236 0x08, 0x04, // NameComponent
237 0x74, 0x65, 0x73, 0x74,
238 0x0a, 0x04, // Nonce
239 0x00, 0x00, 0x00, 0x01
240 };
Vince Lehman277ecf02016-02-10 16:37:48 -0600241 EncodingBuffer buffer;
242 buffer.prependByteArray(interest, 4);
243
Davide Pesaventof9126532018-08-04 18:31:06 -0400244 this->receiveEthernet(buffer);
Davide Pesaventof9126532018-08-04 18:31:06 -0400245 BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDN truncated packet, length 4\n"));
Vince Lehman277ecf02016-02-10 16:37:48 -0600246}
247
Davide Pesaventof9126532018-08-04 18:31:06 -0400248BOOST_AUTO_TEST_CASE(UnsupportedNdnPacket)
Vince Lehman277ecf02016-02-10 16:37:48 -0600249{
Junxiao Shi20b22972017-05-24 21:04:16 +0000250 EncodingBuffer buffer(encoding::makeEmptyBlock(tlv::Name));
Davide Pesaventof9126532018-08-04 18:31:06 -0400251 this->receiveEthernet(buffer);
Davide Pesaventof9126532018-08-04 18:31:06 -0400252 BOOST_CHECK(output.is_equal("0.000000 Ethernet, [Unsupported NDN packet type 7]\n"));
253}
254
255BOOST_AUTO_TEST_CASE(UnsupportedEtherType)
256{
257 EncodingBuffer pkt;
258 uint16_t type = ETHERTYPE_ARP;
259 endian::native_to_big_inplace(type);
260
261 this->receiveEthernet(pkt, type);
Davide Pesaventof9126532018-08-04 18:31:06 -0400262 BOOST_CHECK(output.is_equal("0.000000 [Unsupported ethertype 0x806]\n"));
263}
264
265BOOST_AUTO_TEST_CASE(MalformedIpv4Header)
266{
267 dump.wantTimestamp = false;
268
269 uint8_t theAnswer = 42;
270
271 EncodingBuffer pkt1;
272 pkt1.prependByte(theAnswer);
273 this->receiveEthernet(pkt1, s_ethertypeIp4);
274 BOOST_CHECK(output.is_equal("IP truncated header, length 1\n"));
275
276 ip ipHdr2{};
277 ipHdr2.ip_v = 7;
278
279 EncodingBuffer pkt2;
280 this->receiveIp4(pkt2, &ipHdr2);
281 BOOST_CHECK(output.is_equal("IP bad version 7\n"));
282
283 ip ipHdr3{};
284 ipHdr3.ip_v = 4;
285 ipHdr3.ip_hl = 2;
286
287 EncodingBuffer pkt3;
288 this->receiveIp4(pkt3, &ipHdr3);
289 BOOST_CHECK(output.is_equal("IP bad header length 8\n"));
290
291 ip ipHdr4{};
292 ipHdr4.ip_v = 4;
293 ipHdr4.ip_hl = 5;
294 ipHdr4.ip_len = 10;
295 endian::native_to_big_inplace(ipHdr4.ip_len);
296
297 EncodingBuffer pkt4;
298 this->receiveIp4(pkt4, &ipHdr4);
299 BOOST_CHECK(output.is_equal("IP bad length 10\n"));
300
301 ip ipHdr5{};
302 ipHdr5.ip_v = 4;
303 ipHdr5.ip_hl = 5;
304 ipHdr5.ip_len = 1000;
305 endian::native_to_big_inplace(ipHdr5.ip_len);
306
307 EncodingBuffer pkt5;
308 this->receiveIp4(pkt5, &ipHdr5);
309 BOOST_CHECK(output.is_equal("IP truncated packet, 980 bytes missing\n"));
310}
311
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400312BOOST_AUTO_TEST_CASE(MalformedIpv6Header)
313{
314 dump.wantTimestamp = false;
315
316 uint8_t theAnswer = 42;
317
318 EncodingBuffer pkt1;
319 pkt1.prependByte(theAnswer);
320 this->receiveEthernet(pkt1, s_ethertypeIp6);
321 BOOST_CHECK(output.is_equal("IP6 truncated header, length 1\n"));
322
323 ip6_hdr ip6Hdr2{};
324 ip6Hdr2.ip6_vfc = 10 << 4;
325
326 EncodingBuffer pkt2;
327 this->receiveIp6(pkt2, &ip6Hdr2);
328 BOOST_CHECK(output.is_equal("IP6 bad version 10\n"));
329
330 ip6_hdr ip6Hdr3{};
331 ip6Hdr3.ip6_vfc = 6 << 4;
332 ip6Hdr3.ip6_plen = 1400;
333 endian::native_to_big_inplace(ip6Hdr3.ip6_plen);
334
335 EncodingBuffer pkt3;
336 this->receiveIp6(pkt3, &ip6Hdr3);
337 BOOST_CHECK(output.is_equal("IP6 truncated payload, 1400 bytes missing\n"));
338}
339
Davide Pesaventof9126532018-08-04 18:31:06 -0400340BOOST_AUTO_TEST_CASE(UnsupportedIpProto)
341{
342 dump.wantTimestamp = false;
343
344 ip ipHdr{};
345 ipHdr.ip_v = 4;
346 ipHdr.ip_hl = 5;
347 ipHdr.ip_len = sizeof(ipHdr);
348 endian::native_to_big_inplace(ipHdr.ip_len);
349 ipHdr.ip_p = IPPROTO_SCTP;
350
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400351 EncodingBuffer pkt1;
352 this->receiveIp4(pkt1, &ipHdr);
Davide Pesaventof9126532018-08-04 18:31:06 -0400353 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 -0400354
355 ip6_hdr ip6Hdr{};
356 ip6Hdr.ip6_vfc = 6 << 4;
357 ip6Hdr.ip6_nxt = IPPROTO_NONE;
358
359 EncodingBuffer pkt2;
360 this->receiveIp6(pkt2, &ip6Hdr);
361 BOOST_CHECK(output.is_equal("IP6 :: > ::, [No next header]\n"));
Davide Pesaventof9126532018-08-04 18:31:06 -0400362}
363
364BOOST_AUTO_TEST_CASE(MalformedTcpHeader)
365{
366 dump.wantTimestamp = false;
367
368 tcphdr tcpHdr1{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500369 tcpHdr1.TH_OFF = 0x2;
Davide Pesaventof9126532018-08-04 18:31:06 -0400370
371 EncodingBuffer pkt1;
372 this->receiveTcp4(pkt1, &tcpHdr1);
373 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, TCP bad header length 8\n"));
374
375 tcphdr tcpHdr2{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500376 tcpHdr2.TH_OFF = 0xf;
Davide Pesaventof9126532018-08-04 18:31:06 -0400377
378 EncodingBuffer pkt2;
379 this->receiveTcp4(pkt2, &tcpHdr2);
380 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, TCP truncated header, 40 bytes missing\n"));
381}
382
383BOOST_AUTO_TEST_CASE(MalformedUdpHeader)
384{
385 dump.wantTimestamp = false;
386
387 udphdr udpHdr1{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500388 udpHdr1.UH_LEN = 3;
389 endian::native_to_big_inplace(udpHdr1.UH_LEN);
Davide Pesaventof9126532018-08-04 18:31:06 -0400390
391 EncodingBuffer pkt1;
392 this->receiveUdp4(pkt1, &udpHdr1);
393 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, UDP bad length 3\n"));
394
395 udphdr udpHdr2{};
Davide Pesavento7b9837b2019-02-23 19:07:50 -0500396 udpHdr2.UH_LEN = 1000;
397 endian::native_to_big_inplace(udpHdr2.UH_LEN);
Davide Pesaventof9126532018-08-04 18:31:06 -0400398
399 EncodingBuffer pkt2;
400 this->receiveUdp4(pkt2, &udpHdr2);
401 BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, UDP truncated packet, 992 bytes missing\n"));
402}
403
404BOOST_AUTO_TEST_CASE(InvalidTlvLength)
405{
406 dump.wantTimestamp = false;
407 this->readFile("tests/dump/invalid-tlv-length.pcap");
408
409 const std::string expected =
410 "IP 128.196.203.36 > 128.187.81.12, TCP, length 147, NDNLPv2 invalid packet: "
411 "TLV-LENGTH of sub-element of type 5 exceeds TLV-VALUE boundary of parent block\n";
412 BOOST_CHECK(output.is_equal(expected));
413}
414
415BOOST_AUTO_TEST_CASE(UnrecognizedLpField)
416{
417 dump.wantTimestamp = false;
418 this->readFile("tests/dump/unrecognized-lp-field.pcap");
419
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400420 const std::string expected =
421 "IP 128.196.203.36 > 128.187.81.12, TCP, length 800, "
422 "NDNLPv2 invalid packet: unrecognized field 4 cannot be ignored\n";
Davide Pesaventoecd44802018-07-23 23:48:10 -0400423 BOOST_CHECK(output.is_equal(expected));
Vince Lehman277ecf02016-02-10 16:37:48 -0600424}
425
Davide Pesaventob5b8f952018-07-26 14:19:16 -0400426BOOST_AUTO_TEST_CASE(NoTimestamp)
427{
428 dump.wantTimestamp = false;
429
430 lp::Packet lpPacket;
431 this->receive(lpPacket);
432
Davide Pesaventof9126532018-08-04 18:31:06 -0400433 BOOST_CHECK(output.is_equal("Ethernet, NDNLPv2 idle\n"));
Davide Pesaventob5b8f952018-07-26 14:19:16 -0400434}
435
Davide Pesaventof9126532018-08-04 18:31:06 -0400436BOOST_AUTO_TEST_CASE(FromFile)
Vince Lehman277ecf02016-02-10 16:37:48 -0600437{
Davide Pesaventoecd44802018-07-23 23:48:10 -0400438 dump.pcapFilter = "";
Davide Pesaventof9126532018-08-04 18:31:06 -0400439 this->readFile("tests/dump/nack.pcap");
Vince Lehman277ecf02016-02-10 16:37:48 -0600440
Davide Pesaventoecd44802018-07-23 23:48:10 -0400441 const std::string expected =
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400442 "1571091605.129263 IP 127.0.0.1 > 127.0.0.1, TCP, length 36, "
443 "INTEREST: /producer/nack/no-route?Nonce=3301604226\n"
444 "1571091605.129702 IP 127.0.0.1 > 127.0.0.1, TCP, length 49, "
445 "NDNLPv2, NACK (NoRoute): /producer/nack/no-route?Nonce=3301604226\n";
Davide Pesaventoecd44802018-07-23 23:48:10 -0400446 BOOST_CHECK(output.is_equal(expected));
Vince Lehman277ecf02016-02-10 16:37:48 -0600447}
448
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400449BOOST_AUTO_TEST_CASE(LinuxSllTcp4)
450{
451 dump.wantTimestamp = false;
452 this->readFile("tests/dump/linux-sll-tcp4.pcap");
453
454 const std::string expected =
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400455 "IP 162.211.64.84 > 131.179.196.46, TCP, length 41, INTEREST: /ndn/edu/arizona/ping/8202?Nonce=1059849935\n"
456 "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 -0400457 BOOST_CHECK(output.is_equal(expected));
458}
459
460BOOST_AUTO_TEST_CASE(LinuxSllUdp4)
461{
462 dump.wantTimestamp = false;
463 this->readFile("tests/dump/linux-sll-udp4.pcap");
464
465 const std::string expected =
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400466 "IP 162.211.64.84 > 131.179.196.46, UDP, length 42, INTEREST: /ndn/edu/arizona/ping/31044?Nonce=3171630323\n"
467 "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 -0400468 BOOST_CHECK(output.is_equal(expected));
469}
470
471BOOST_AUTO_TEST_CASE(LinuxSllTcp6)
472{
473 dump.wantTimestamp = false;
474 this->readFile("tests/dump/linux-sll-tcp6.pcap");
475
476 const std::string expected =
477 "IP6 2602:fff6:d:b317::39f8 > 2001:660:3302:282c:160::163, TCP, length 42, "
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400478 "INTEREST: /ndn/edu/arizona/ping/19573?Nonce=777756283\n"
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400479 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, TCP, length 404, "
480 "DATA: /ndn/edu/arizona/ping/19573\n"
481 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, TCP, length 56, "
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400482 "invalid network packet: Unrecognized element of critical type 9\n";
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400483 BOOST_CHECK(output.is_equal(expected));
484}
485
486BOOST_AUTO_TEST_CASE(LinuxSllUdp6)
487{
488 dump.wantTimestamp = false;
489 this->readFile("tests/dump/linux-sll-udp6.pcap");
490
491 const std::string expected =
492 "IP6 2602:fff6:d:b317::39f8 > 2001:660:3302:282c:160::163, UDP, length 39, "
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400493 "INTEREST: /ndn/edu/arizona/ping/18?Nonce=571618686\n"
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400494 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, UDP, length 401, "
495 "DATA: /ndn/edu/arizona/ping/18\n"
496 "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, UDP, length 56, "
Davide Pesavento327fb4b2019-10-14 19:01:27 -0400497 "invalid network packet: Unrecognized element of critical type 9\n";
Davide Pesavento0ca7e692018-08-05 02:21:06 -0400498 BOOST_CHECK(output.is_equal(expected));
499}
500
Davide Pesaventoecd44802018-07-23 23:48:10 -0400501BOOST_AUTO_TEST_SUITE_END() // TestNdnDump
502BOOST_AUTO_TEST_SUITE_END() // Dump
Vince Lehman277ecf02016-02-10 16:37:48 -0600503
504} // namespace tests
505} // namespace dump
506} // namespace ndn