Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 60f8cc1 | 2018-05-10 22:05:21 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 7b9837b | 2019-02-23 19:07:50 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, University of Memphis, |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 4 | * University Pierre & Marie Curie, Sorbonne University. |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 5 | * |
| 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 Pesavento | 60f8cc1 | 2018-05-10 22:05:21 -0400 | [diff] [blame] | 23 | #include "tests/identity-management-fixture.hpp" |
| 24 | #include "tests/test-common.hpp" |
| 25 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 26 | #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> |
| 33 | |
| 34 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 35 | #include <ndn-cxx/lp/packet.hpp> |
Junxiao Shi | c9575a6 | 2017-07-01 06:16:02 +0000 | [diff] [blame] | 36 | #include <ndn-cxx/net/ethernet.hpp> |
Junxiao Shi | 20b2297 | 2017-05-24 21:04:16 +0000 | [diff] [blame] | 37 | |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 38 | namespace ndn { |
| 39 | namespace dump { |
| 40 | namespace tests { |
| 41 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 42 | namespace endian = boost::endian; |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 43 | using namespace ndn::tests; |
| 44 | |
| 45 | class StdCoutRedirector |
| 46 | { |
| 47 | public: |
| 48 | StdCoutRedirector(std::ostream& os) |
| 49 | { |
| 50 | // Redirect std::cout to the specified output stream |
| 51 | originalBuffer = std::cout.rdbuf(os.rdbuf()); |
| 52 | } |
| 53 | |
| 54 | ~StdCoutRedirector() |
| 55 | { |
| 56 | // Revert state for std::cout |
| 57 | std::cout.rdbuf(originalBuffer); |
| 58 | } |
| 59 | |
| 60 | private: |
| 61 | std::streambuf* originalBuffer; |
| 62 | }; |
| 63 | |
Junxiao Shi | 20b2297 | 2017-05-24 21:04:16 +0000 | [diff] [blame] | 64 | class NdnDumpFixture : public IdentityManagementFixture |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 65 | { |
| 66 | protected: |
| 67 | NdnDumpFixture() |
| 68 | { |
| 69 | dump.m_dataLinkType = DLT_EN10MB; |
| 70 | } |
| 71 | |
Junxiao Shi | 20b2297 | 2017-05-24 21:04:16 +0000 | [diff] [blame] | 72 | template<typename Packet> |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 73 | void |
| 74 | receive(const Packet& packet) |
| 75 | { |
Junxiao Shi | 20b2297 | 2017-05-24 21:04:16 +0000 | [diff] [blame] | 76 | EncodingBuffer buffer(packet.wireEncode()); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 77 | receiveEthernet(buffer); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 81 | receiveEthernet(EncodingBuffer& buffer, uint16_t ethertype = s_ethertypeNdn) |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 82 | { |
Junxiao Shi | c9575a6 | 2017-07-01 06:16:02 +0000 | [diff] [blame] | 83 | ethernet::Address host; |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 84 | |
| 85 | // Ethernet header |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 86 | buffer.prependByteArray(reinterpret_cast<const uint8_t*>(ðertype), ethernet::TYPE_LEN); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 87 | buffer.prependByteArray(host.data(), host.size()); |
| 88 | buffer.prependByteArray(host.data(), host.size()); |
| 89 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 90 | // pcap header |
Davide Pesavento | ecd4480 | 2018-07-23 23:48:10 -0400 | [diff] [blame] | 91 | pcap_pkthdr pkthdr{}; |
| 92 | pkthdr.caplen = pkthdr.len = buffer.size(); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 93 | |
| 94 | { |
| 95 | StdCoutRedirector redirect(output); |
Davide Pesavento | ecd4480 | 2018-07-23 23:48:10 -0400 | [diff] [blame] | 96 | dump.printPacket(&pkthdr, buffer.buf()); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 100 | void |
| 101 | receiveIp4(EncodingBuffer& buffer, const ip* ipHeader) |
| 102 | { |
| 103 | buffer.prependByteArray(reinterpret_cast<const uint8_t*>(ipHeader), sizeof(ip)); |
| 104 | receiveEthernet(buffer, s_ethertypeIp4); |
| 105 | } |
| 106 | |
| 107 | void |
| 108 | receiveIp6(EncodingBuffer& buffer, const ip6_hdr* ip6Header) |
| 109 | { |
| 110 | buffer.prependByteArray(reinterpret_cast<const uint8_t*>(ip6Header), sizeof(ip6_hdr)); |
| 111 | receiveEthernet(buffer, s_ethertypeIp6); |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | receiveTcp4(EncodingBuffer& buffer, const tcphdr* tcpHeader) |
| 116 | { |
| 117 | buffer.prependByteArray(reinterpret_cast<const uint8_t*>(tcpHeader), sizeof(tcphdr)); |
| 118 | |
| 119 | ip ipHeader{}; |
| 120 | ipHeader.ip_v = 4; |
| 121 | ipHeader.ip_hl = 5; |
| 122 | ipHeader.ip_len = endian::native_to_big(static_cast<uint16_t>(buffer.size() + sizeof(ipHeader))); |
| 123 | ipHeader.ip_ttl = 1; |
| 124 | ipHeader.ip_p = IPPROTO_TCP; |
| 125 | |
| 126 | receiveIp4(buffer, &ipHeader); |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | receiveUdp4(EncodingBuffer& buffer, const udphdr* udpHeader) |
| 131 | { |
| 132 | buffer.prependByteArray(reinterpret_cast<const uint8_t*>(udpHeader), sizeof(udphdr)); |
| 133 | |
| 134 | ip ipHeader{}; |
| 135 | ipHeader.ip_v = 4; |
| 136 | ipHeader.ip_hl = 5; |
| 137 | ipHeader.ip_len = endian::native_to_big(static_cast<uint16_t>(buffer.size() + sizeof(ipHeader))); |
| 138 | ipHeader.ip_ttl = 1; |
| 139 | ipHeader.ip_p = IPPROTO_UDP; |
| 140 | |
| 141 | receiveIp4(buffer, &ipHeader); |
| 142 | } |
| 143 | |
| 144 | void |
| 145 | readFile(const std::string& filename) |
| 146 | { |
| 147 | StdCoutRedirector redirect(output); |
| 148 | dump.inputFile = filename; |
| 149 | dump.run(); |
| 150 | } |
| 151 | |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 152 | protected: |
Davide Pesavento | ecd4480 | 2018-07-23 23:48:10 -0400 | [diff] [blame] | 153 | NdnDump dump; |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 154 | boost::test_tools::output_test_stream output; |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 155 | |
| 156 | static const uint16_t s_ethertypeNdn; |
| 157 | static const uint16_t s_ethertypeIp4; |
| 158 | static const uint16_t s_ethertypeIp6; |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 159 | }; |
| 160 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 161 | const uint16_t NdnDumpFixture::s_ethertypeNdn = endian::native_to_big(ethernet::ETHERTYPE_NDN); |
| 162 | const uint16_t NdnDumpFixture::s_ethertypeIp4 = endian::native_to_big(uint16_t(ETHERTYPE_IP)); |
| 163 | const uint16_t NdnDumpFixture::s_ethertypeIp6 = endian::native_to_big(uint16_t(ETHERTYPE_IPV6)); |
| 164 | |
Davide Pesavento | ecd4480 | 2018-07-23 23:48:10 -0400 | [diff] [blame] | 165 | BOOST_AUTO_TEST_SUITE(Dump) |
| 166 | BOOST_FIXTURE_TEST_SUITE(TestNdnDump, NdnDumpFixture) |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 167 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 168 | BOOST_AUTO_TEST_CASE(Interest) |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 169 | { |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 170 | auto interest = makeInterest("/test", false, DEFAULT_INTEREST_LIFETIME, 1); |
| 171 | this->receive(*interest); |
| 172 | BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?Nonce=1\n")); |
| 173 | this->receive(interest->setCanBePrefix(true)); |
| 174 | BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?CanBePrefix&Nonce=1\n")); |
| 175 | this->receive(interest->setInterestLifetime(50_ms)); |
| 176 | BOOST_CHECK(output.is_equal("0.000000 Ethernet, INTEREST: /test?CanBePrefix&Nonce=1&Lifetime=50\n")); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 177 | } |
| 178 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 179 | BOOST_AUTO_TEST_CASE(Data) |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 180 | { |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 181 | auto data = makeData("/test"); |
| 182 | this->receive(*data); |
| 183 | BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n")); |
| 184 | this->receive(data->setContentType(tlv::ContentType_Key)); |
| 185 | BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n")); |
| 186 | this->receive(data->setFreshnessPeriod(42_h)); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 187 | BOOST_CHECK(output.is_equal("0.000000 Ethernet, DATA: /test\n")); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 188 | } |
| 189 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 190 | BOOST_AUTO_TEST_CASE(Nack) |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 191 | { |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 192 | auto interest = makeInterest("/test", false, DEFAULT_INTEREST_LIFETIME, 1); |
Junxiao Shi | 20d5a0b | 2018-08-14 09:26:11 -0600 | [diff] [blame] | 193 | auto nack = makeNack(*interest, lp::NackReason::DUPLICATE); |
| 194 | lp::Packet lpPacket(interest->wireEncode()); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 195 | lpPacket.add<lp::NackField>(nack.getHeader()); |
| 196 | |
| 197 | this->receive(lpPacket); |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 198 | BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2, NACK (Duplicate): /test?Nonce=1\n")); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 199 | } |
| 200 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 201 | BOOST_AUTO_TEST_CASE(LpFragment) |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 202 | { |
| 203 | const uint8_t data[10] = { |
| 204 | 0x06, 0x08, // Data packet |
| 205 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 206 | }; |
| 207 | |
Junxiao Shi | 20b2297 | 2017-05-24 21:04:16 +0000 | [diff] [blame] | 208 | Buffer buffer(data, 4); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 209 | lp::Packet lpPacket; |
| 210 | lpPacket.add<lp::FragmentField>(std::make_pair(buffer.begin(), buffer.end())); |
| 211 | lpPacket.add<lp::FragIndexField>(0); |
| 212 | lpPacket.add<lp::FragCountField>(2); |
| 213 | lpPacket.add<lp::SequenceField>(1000); |
| 214 | |
| 215 | this->receive(lpPacket); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 216 | BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 fragment\n")); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 217 | } |
| 218 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 219 | BOOST_AUTO_TEST_CASE(LpIdle) |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 220 | { |
| 221 | lp::Packet lpPacket; |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 222 | this->receive(lpPacket); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 223 | BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDNLPv2 idle\n")); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 224 | } |
| 225 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 226 | BOOST_AUTO_TEST_CASE(IncompleteNdnPacket) |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 227 | { |
| 228 | const uint8_t interest[] = { |
| 229 | 0x05, 0x0E, // Interest |
| 230 | 0x07, 0x06, // Name |
| 231 | 0x08, 0x04, // NameComponent |
| 232 | 0x74, 0x65, 0x73, 0x74, |
| 233 | 0x0a, 0x04, // Nonce |
| 234 | 0x00, 0x00, 0x00, 0x01 |
| 235 | }; |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 236 | EncodingBuffer buffer; |
| 237 | buffer.prependByteArray(interest, 4); |
| 238 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 239 | this->receiveEthernet(buffer); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 240 | BOOST_CHECK(output.is_equal("0.000000 Ethernet, NDN truncated packet, length 4\n")); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 241 | } |
| 242 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 243 | BOOST_AUTO_TEST_CASE(UnsupportedNdnPacket) |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 244 | { |
Junxiao Shi | 20b2297 | 2017-05-24 21:04:16 +0000 | [diff] [blame] | 245 | EncodingBuffer buffer(encoding::makeEmptyBlock(tlv::Name)); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 246 | this->receiveEthernet(buffer); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 247 | BOOST_CHECK(output.is_equal("0.000000 Ethernet, [Unsupported NDN packet type 7]\n")); |
| 248 | } |
| 249 | |
| 250 | BOOST_AUTO_TEST_CASE(UnsupportedEtherType) |
| 251 | { |
| 252 | EncodingBuffer pkt; |
| 253 | uint16_t type = ETHERTYPE_ARP; |
| 254 | endian::native_to_big_inplace(type); |
| 255 | |
| 256 | this->receiveEthernet(pkt, type); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 257 | BOOST_CHECK(output.is_equal("0.000000 [Unsupported ethertype 0x806]\n")); |
| 258 | } |
| 259 | |
| 260 | BOOST_AUTO_TEST_CASE(MalformedIpv4Header) |
| 261 | { |
| 262 | dump.wantTimestamp = false; |
| 263 | |
| 264 | uint8_t theAnswer = 42; |
| 265 | |
| 266 | EncodingBuffer pkt1; |
| 267 | pkt1.prependByte(theAnswer); |
| 268 | this->receiveEthernet(pkt1, s_ethertypeIp4); |
| 269 | BOOST_CHECK(output.is_equal("IP truncated header, length 1\n")); |
| 270 | |
| 271 | ip ipHdr2{}; |
| 272 | ipHdr2.ip_v = 7; |
| 273 | |
| 274 | EncodingBuffer pkt2; |
| 275 | this->receiveIp4(pkt2, &ipHdr2); |
| 276 | BOOST_CHECK(output.is_equal("IP bad version 7\n")); |
| 277 | |
| 278 | ip ipHdr3{}; |
| 279 | ipHdr3.ip_v = 4; |
| 280 | ipHdr3.ip_hl = 2; |
| 281 | |
| 282 | EncodingBuffer pkt3; |
| 283 | this->receiveIp4(pkt3, &ipHdr3); |
| 284 | BOOST_CHECK(output.is_equal("IP bad header length 8\n")); |
| 285 | |
| 286 | ip ipHdr4{}; |
| 287 | ipHdr4.ip_v = 4; |
| 288 | ipHdr4.ip_hl = 5; |
| 289 | ipHdr4.ip_len = 10; |
| 290 | endian::native_to_big_inplace(ipHdr4.ip_len); |
| 291 | |
| 292 | EncodingBuffer pkt4; |
| 293 | this->receiveIp4(pkt4, &ipHdr4); |
| 294 | BOOST_CHECK(output.is_equal("IP bad length 10\n")); |
| 295 | |
| 296 | ip ipHdr5{}; |
| 297 | ipHdr5.ip_v = 4; |
| 298 | ipHdr5.ip_hl = 5; |
| 299 | ipHdr5.ip_len = 1000; |
| 300 | endian::native_to_big_inplace(ipHdr5.ip_len); |
| 301 | |
| 302 | EncodingBuffer pkt5; |
| 303 | this->receiveIp4(pkt5, &ipHdr5); |
| 304 | BOOST_CHECK(output.is_equal("IP truncated packet, 980 bytes missing\n")); |
| 305 | } |
| 306 | |
Davide Pesavento | 0ca7e69 | 2018-08-05 02:21:06 -0400 | [diff] [blame] | 307 | BOOST_AUTO_TEST_CASE(MalformedIpv6Header) |
| 308 | { |
| 309 | dump.wantTimestamp = false; |
| 310 | |
| 311 | uint8_t theAnswer = 42; |
| 312 | |
| 313 | EncodingBuffer pkt1; |
| 314 | pkt1.prependByte(theAnswer); |
| 315 | this->receiveEthernet(pkt1, s_ethertypeIp6); |
| 316 | BOOST_CHECK(output.is_equal("IP6 truncated header, length 1\n")); |
| 317 | |
| 318 | ip6_hdr ip6Hdr2{}; |
| 319 | ip6Hdr2.ip6_vfc = 10 << 4; |
| 320 | |
| 321 | EncodingBuffer pkt2; |
| 322 | this->receiveIp6(pkt2, &ip6Hdr2); |
| 323 | BOOST_CHECK(output.is_equal("IP6 bad version 10\n")); |
| 324 | |
| 325 | ip6_hdr ip6Hdr3{}; |
| 326 | ip6Hdr3.ip6_vfc = 6 << 4; |
| 327 | ip6Hdr3.ip6_plen = 1400; |
| 328 | endian::native_to_big_inplace(ip6Hdr3.ip6_plen); |
| 329 | |
| 330 | EncodingBuffer pkt3; |
| 331 | this->receiveIp6(pkt3, &ip6Hdr3); |
| 332 | BOOST_CHECK(output.is_equal("IP6 truncated payload, 1400 bytes missing\n")); |
| 333 | } |
| 334 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 335 | BOOST_AUTO_TEST_CASE(UnsupportedIpProto) |
| 336 | { |
| 337 | dump.wantTimestamp = false; |
| 338 | |
| 339 | ip ipHdr{}; |
| 340 | ipHdr.ip_v = 4; |
| 341 | ipHdr.ip_hl = 5; |
| 342 | ipHdr.ip_len = sizeof(ipHdr); |
| 343 | endian::native_to_big_inplace(ipHdr.ip_len); |
| 344 | ipHdr.ip_p = IPPROTO_SCTP; |
| 345 | |
Davide Pesavento | 0ca7e69 | 2018-08-05 02:21:06 -0400 | [diff] [blame] | 346 | EncodingBuffer pkt1; |
| 347 | this->receiveIp4(pkt1, &ipHdr); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 348 | BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, [Unsupported IP proto 132]\n")); |
Davide Pesavento | 0ca7e69 | 2018-08-05 02:21:06 -0400 | [diff] [blame] | 349 | |
| 350 | ip6_hdr ip6Hdr{}; |
| 351 | ip6Hdr.ip6_vfc = 6 << 4; |
| 352 | ip6Hdr.ip6_nxt = IPPROTO_NONE; |
| 353 | |
| 354 | EncodingBuffer pkt2; |
| 355 | this->receiveIp6(pkt2, &ip6Hdr); |
| 356 | BOOST_CHECK(output.is_equal("IP6 :: > ::, [No next header]\n")); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | BOOST_AUTO_TEST_CASE(MalformedTcpHeader) |
| 360 | { |
| 361 | dump.wantTimestamp = false; |
| 362 | |
| 363 | tcphdr tcpHdr1{}; |
Davide Pesavento | 7b9837b | 2019-02-23 19:07:50 -0500 | [diff] [blame] | 364 | tcpHdr1.TH_OFF = 0x2; |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 365 | |
| 366 | EncodingBuffer pkt1; |
| 367 | this->receiveTcp4(pkt1, &tcpHdr1); |
| 368 | BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, TCP bad header length 8\n")); |
| 369 | |
| 370 | tcphdr tcpHdr2{}; |
Davide Pesavento | 7b9837b | 2019-02-23 19:07:50 -0500 | [diff] [blame] | 371 | tcpHdr2.TH_OFF = 0xf; |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 372 | |
| 373 | EncodingBuffer pkt2; |
| 374 | this->receiveTcp4(pkt2, &tcpHdr2); |
| 375 | BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, TCP truncated header, 40 bytes missing\n")); |
| 376 | } |
| 377 | |
| 378 | BOOST_AUTO_TEST_CASE(MalformedUdpHeader) |
| 379 | { |
| 380 | dump.wantTimestamp = false; |
| 381 | |
| 382 | udphdr udpHdr1{}; |
Davide Pesavento | 7b9837b | 2019-02-23 19:07:50 -0500 | [diff] [blame] | 383 | udpHdr1.UH_LEN = 3; |
| 384 | endian::native_to_big_inplace(udpHdr1.UH_LEN); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 385 | |
| 386 | EncodingBuffer pkt1; |
| 387 | this->receiveUdp4(pkt1, &udpHdr1); |
| 388 | BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, UDP bad length 3\n")); |
| 389 | |
| 390 | udphdr udpHdr2{}; |
Davide Pesavento | 7b9837b | 2019-02-23 19:07:50 -0500 | [diff] [blame] | 391 | udpHdr2.UH_LEN = 1000; |
| 392 | endian::native_to_big_inplace(udpHdr2.UH_LEN); |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 393 | |
| 394 | EncodingBuffer pkt2; |
| 395 | this->receiveUdp4(pkt2, &udpHdr2); |
| 396 | BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, UDP truncated packet, 992 bytes missing\n")); |
| 397 | } |
| 398 | |
| 399 | BOOST_AUTO_TEST_CASE(InvalidTlvLength) |
| 400 | { |
| 401 | dump.wantTimestamp = false; |
| 402 | this->readFile("tests/dump/invalid-tlv-length.pcap"); |
| 403 | |
| 404 | const std::string expected = |
| 405 | "IP 128.196.203.36 > 128.187.81.12, TCP, length 147, NDNLPv2 invalid packet: " |
| 406 | "TLV-LENGTH of sub-element of type 5 exceeds TLV-VALUE boundary of parent block\n"; |
| 407 | BOOST_CHECK(output.is_equal(expected)); |
| 408 | } |
| 409 | |
| 410 | BOOST_AUTO_TEST_CASE(UnrecognizedLpField) |
| 411 | { |
| 412 | dump.wantTimestamp = false; |
| 413 | this->readFile("tests/dump/unrecognized-lp-field.pcap"); |
| 414 | |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 415 | const std::string expected = |
| 416 | "IP 128.196.203.36 > 128.187.81.12, TCP, length 800, " |
| 417 | "NDNLPv2 invalid packet: unrecognized field 4 cannot be ignored\n"; |
Davide Pesavento | ecd4480 | 2018-07-23 23:48:10 -0400 | [diff] [blame] | 418 | BOOST_CHECK(output.is_equal(expected)); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 419 | } |
| 420 | |
Davide Pesavento | b5b8f95 | 2018-07-26 14:19:16 -0400 | [diff] [blame] | 421 | BOOST_AUTO_TEST_CASE(NoTimestamp) |
| 422 | { |
| 423 | dump.wantTimestamp = false; |
| 424 | |
| 425 | lp::Packet lpPacket; |
| 426 | this->receive(lpPacket); |
| 427 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 428 | BOOST_CHECK(output.is_equal("Ethernet, NDNLPv2 idle\n")); |
Davide Pesavento | b5b8f95 | 2018-07-26 14:19:16 -0400 | [diff] [blame] | 429 | } |
| 430 | |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 431 | BOOST_AUTO_TEST_CASE(FromFile) |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 432 | { |
Davide Pesavento | ecd4480 | 2018-07-23 23:48:10 -0400 | [diff] [blame] | 433 | dump.pcapFilter = ""; |
Davide Pesavento | f912653 | 2018-08-04 18:31:06 -0400 | [diff] [blame] | 434 | this->readFile("tests/dump/nack.pcap"); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 435 | |
Davide Pesavento | ecd4480 | 2018-07-23 23:48:10 -0400 | [diff] [blame] | 436 | const std::string expected = |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 437 | "1571091605.129263 IP 127.0.0.1 > 127.0.0.1, TCP, length 36, " |
| 438 | "INTEREST: /producer/nack/no-route?Nonce=3301604226\n" |
| 439 | "1571091605.129702 IP 127.0.0.1 > 127.0.0.1, TCP, length 49, " |
| 440 | "NDNLPv2, NACK (NoRoute): /producer/nack/no-route?Nonce=3301604226\n"; |
Davide Pesavento | ecd4480 | 2018-07-23 23:48:10 -0400 | [diff] [blame] | 441 | BOOST_CHECK(output.is_equal(expected)); |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 442 | } |
| 443 | |
Davide Pesavento | 0ca7e69 | 2018-08-05 02:21:06 -0400 | [diff] [blame] | 444 | BOOST_AUTO_TEST_CASE(LinuxSllTcp4) |
| 445 | { |
| 446 | dump.wantTimestamp = false; |
| 447 | this->readFile("tests/dump/linux-sll-tcp4.pcap"); |
| 448 | |
| 449 | const std::string expected = |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 450 | "IP 162.211.64.84 > 131.179.196.46, TCP, length 41, INTEREST: /ndn/edu/arizona/ping/8202?Nonce=1059849935\n" |
| 451 | "IP 131.179.196.46 > 162.211.64.84, TCP, length 403, DATA: /ndn/edu/arizona/ping/8202\n"; |
Davide Pesavento | 0ca7e69 | 2018-08-05 02:21:06 -0400 | [diff] [blame] | 452 | BOOST_CHECK(output.is_equal(expected)); |
| 453 | } |
| 454 | |
| 455 | BOOST_AUTO_TEST_CASE(LinuxSllUdp4) |
| 456 | { |
| 457 | dump.wantTimestamp = false; |
| 458 | this->readFile("tests/dump/linux-sll-udp4.pcap"); |
| 459 | |
| 460 | const std::string expected = |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 461 | "IP 162.211.64.84 > 131.179.196.46, UDP, length 42, INTEREST: /ndn/edu/arizona/ping/31044?Nonce=3171630323\n" |
| 462 | "IP 131.179.196.46 > 162.211.64.84, UDP, length 404, DATA: /ndn/edu/arizona/ping/31044\n"; |
Davide Pesavento | 0ca7e69 | 2018-08-05 02:21:06 -0400 | [diff] [blame] | 463 | BOOST_CHECK(output.is_equal(expected)); |
| 464 | } |
| 465 | |
| 466 | BOOST_AUTO_TEST_CASE(LinuxSllTcp6) |
| 467 | { |
| 468 | dump.wantTimestamp = false; |
| 469 | this->readFile("tests/dump/linux-sll-tcp6.pcap"); |
| 470 | |
| 471 | const std::string expected = |
| 472 | "IP6 2602:fff6:d:b317::39f8 > 2001:660:3302:282c:160::163, TCP, length 42, " |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 473 | "INTEREST: /ndn/edu/arizona/ping/19573?Nonce=777756283\n" |
Davide Pesavento | 0ca7e69 | 2018-08-05 02:21:06 -0400 | [diff] [blame] | 474 | "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, TCP, length 404, " |
| 475 | "DATA: /ndn/edu/arizona/ping/19573\n" |
| 476 | "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, TCP, length 56, " |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 477 | "invalid network packet: Unrecognized element of critical type 9\n"; |
Davide Pesavento | 0ca7e69 | 2018-08-05 02:21:06 -0400 | [diff] [blame] | 478 | BOOST_CHECK(output.is_equal(expected)); |
| 479 | } |
| 480 | |
| 481 | BOOST_AUTO_TEST_CASE(LinuxSllUdp6) |
| 482 | { |
| 483 | dump.wantTimestamp = false; |
| 484 | this->readFile("tests/dump/linux-sll-udp6.pcap"); |
| 485 | |
| 486 | const std::string expected = |
| 487 | "IP6 2602:fff6:d:b317::39f8 > 2001:660:3302:282c:160::163, UDP, length 39, " |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 488 | "INTEREST: /ndn/edu/arizona/ping/18?Nonce=571618686\n" |
Davide Pesavento | 0ca7e69 | 2018-08-05 02:21:06 -0400 | [diff] [blame] | 489 | "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, UDP, length 401, " |
| 490 | "DATA: /ndn/edu/arizona/ping/18\n" |
| 491 | "IP6 2001:660:3302:282c:160::163 > 2602:fff6:d:b317::39f8, UDP, length 56, " |
Davide Pesavento | 327fb4b | 2019-10-14 19:01:27 -0400 | [diff] [blame^] | 492 | "invalid network packet: Unrecognized element of critical type 9\n"; |
Davide Pesavento | 0ca7e69 | 2018-08-05 02:21:06 -0400 | [diff] [blame] | 493 | BOOST_CHECK(output.is_equal(expected)); |
| 494 | } |
| 495 | |
Davide Pesavento | ecd4480 | 2018-07-23 23:48:10 -0400 | [diff] [blame] | 496 | BOOST_AUTO_TEST_SUITE_END() // TestNdnDump |
| 497 | BOOST_AUTO_TEST_SUITE_END() // Dump |
Vince Lehman | 277ecf0 | 2016-02-10 16:37:48 -0600 | [diff] [blame] | 498 | |
| 499 | } // namespace tests |
| 500 | } // namespace dump |
| 501 | } // namespace ndn |