X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FDefaultBundle%2FIPv6Extensions.test.cc;h=a473d8526fed4b5504aac80f6f92c473d6aaeaac;hb=f723d7852a8195072eee387ea9ca77156b58438b;hp=1834bd87b608a717875e12823baf185a6ad79529;hpb=7fa56b4683159c364b49fe297db5b8dd6fdaefb0;p=senf.git diff --git a/senf/Packets/DefaultBundle/IPv6Extensions.test.cc b/senf/Packets/DefaultBundle/IPv6Extensions.test.cc index 1834bd8..a473d85 100644 --- a/senf/Packets/DefaultBundle/IPv6Extensions.test.cc +++ b/senf/Packets/DefaultBundle/IPv6Extensions.test.cc @@ -5,6 +5,7 @@ // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // Philipp Batroff +// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or @@ -33,7 +34,6 @@ #include "ICMPv6Packet.hh" #include "ICMPv6TypePacket.hh" #include "EthernetPacket.hh" -#include #include #include @@ -44,7 +44,6 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_fragment) { // Just for the fun of it, we test a nice chain: A fragment of a fragmented UDP packet - unsigned char Fragment_packetData[] = { // IP header 0x60, 0x00, 0x00, 0x00, // IP Version, class, flow label @@ -210,12 +209,12 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_parse) BOOST_CHECK_EQUAL( listIter->altAction(), 0u); BOOST_CHECK_EQUAL( listIter->changeFlag(), 0u); BOOST_CHECK_EQUAL( listIter->optionType(), 5u); - BOOST_CHECK_EQUAL( listIter->optionLength(), 2u); + BOOST_CHECK_EQUAL( listIter->length(), 2u); ++listIter; BOOST_CHECK_EQUAL( listIter->altAction(), 0u); BOOST_CHECK_EQUAL( listIter->changeFlag(), 0u); BOOST_CHECK_EQUAL( listIter->optionType(), 2u); - BOOST_CHECK_EQUAL( listIter->optionLength(), 0); + BOOST_CHECK_EQUAL( listIter->length(), 0); BOOST_REQUIRE( pHop_extension.next().is() ); senf::ICMPv6Packet pICMPv6 (pHop_extension.next().as()); @@ -224,46 +223,43 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_parse) BOOST_CHECK_EQUAL( pICMPv6->checksum(), 0x50cc); } -BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create) -{ - try{ - std::ostringstream oss (std::ostringstream::out); + +BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create) +{ + std::ostringstream oss (std::ostringstream::out); unsigned char HopByHop_packetData[] = { - //Ethernet - 0x33 ,0x33 ,0x00 ,0x00 ,0x00 ,0x16 , //destination MAC - 0x00 ,0x19 ,0xb9 ,0xeb ,0xb2 ,0x26 , //source MAC - 0x86 ,0xdd, //type (IPv6) - //IPv6 - 0x60, 0x00, 0x00, 0x00, //IP version, class, flow label - 0x00, 0x24, //payload length - 0x00, //next header: IPv6 hop-by-hop option (0) - 0x01, //hop limit (1) - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //IPv6 Source address (fe80::219:b9ff:feeb:b226) - 0x02, 0x19, 0xb9, 0xff, 0xfe, 0xeb, 0xb2, 0x26, - - 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //IPv6 Destination address ff02::16 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - //HopByHop option - 0x3a, //next Header (ICMPv6) - 0x00, //Length (0 = 8Bytes) - - //option Header - 0x05, //option type - 0x02, //option Length (= 2 byte) - 0x00, 0x00, //data (zero data here ...) - 0x01, 0x00, //padding - //ICMPv6 - 0x8f, //type 143 - 0x00, //code 0, should always be 0 - 0x50 ,0xcc , //checksum - - //MLDv2 - 0x00 ,0x00 , //reserved, zero by default - 0x00 ,0x01 , //nr of McAddressRecords - 0x04 , //recordType - 0x00 , //auxiliarydatalength - 0x00 ,0x00 , // number of sources - 0xff ,0x02 ,0x00 ,0x00, 0x00 ,0x00 ,0x00 ,0x00 , //ipv6McAddress ff02::1:ffeb:b226 + // Ethernet + 0x33 ,0x33 ,0x00 ,0x00 ,0x00 ,0x16 , // destination MAC + 0x00 ,0x19 ,0xb9 ,0xeb ,0xb2 ,0x26 , // source MAC + 0x86 ,0xdd, // type (IPv6) + // IPv6 + 0x60, 0x00, 0x00, 0x00, // IP version, class, flow label + 0x00, 0x24, // payload length + 0x00, // next header: IPv6 hop-by-hop option (0) + 0x01, // hop limit (1) + 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // IPv6 Source address + 0x02, 0x19, 0xb9, 0xff, 0xfe, 0xeb, 0xb2, 0x26, // (fe80::219:b9ff:feeb:b226) + 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // IPv6 Destination address + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, // (ff02::16) + // HopByHop option + 0x3a, // next Header (ICMPv6) + 0x00, // Length (0 = 8Bytes) + // option Header + 0x05, // option type + 0x02, // option Length (= 2 byte) + 0x00, 0x00, // data (zero data here ...) + 0x01, 0x00, // padding + // ICMPv6 + 0x8f, // type 143 + 0x00, // code 0, should always be 0 + 0x50 ,0xcc , // checksum + // MLDv2 + 0x00 ,0x00 , // reserved, zero by default + 0x00 ,0x01 , // nr of McAddressRecords + 0x04 , // recordType + 0x00 , // auxiliarydatalength + 0x00 ,0x00 , // number of sources + 0xff ,0x02 ,0x00 ,0x00, 0x00 ,0x00 ,0x00 ,0x00 , // ipv6McAddress ff02::1:ffeb:b226 0x00 ,0x00 ,0x00 ,0x01 ,0xff ,0xeb ,0xb2 ,0x26 }; senf::EthernetPacket eth (senf::EthernetPacket::create() ); @@ -290,14 +286,12 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create) opt.changeFlag() = 0u; opt.optionType() = 5u; unsigned char val[] = {0x00, 0x00}; - opt.setPayload(val); + opt.value(val); } } senf::ICMPv6Packet icmp (senf::ICMPv6Packet::createAfter (pext)); - icmp->type() = 0x8f; icmp->code() = 0u; - icmp->checksum() = 0u; senf::MLDv2ListenerReport mld ( senf::MLDv2ListenerReport::createAfter(icmp) ); { senf::MLDv2ListenerReport::Parser::mcastAddrRecords_t::container c (mld->mcastAddrRecords() ); @@ -307,25 +301,87 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create) c.back().mcAddress() = addr; } eth.finalizeAll(); - SENF_CHECK_NO_THROW( ip.dump(oss) ); + SENF_CHECK_NO_THROW( eth.dump(oss) ); SENF_CHECK_EQUAL_COLLECTIONS( HopByHop_packetData, HopByHop_packetData+sizeof(HopByHop_packetData), eth.data().begin(), eth.data().end() ); - eth.dump(std::cout); - senf::hexdump(eth.data().begin(), eth.data().end(), std::cout); - std::cout << "\n\n" << std::endl; - senf::hexdump(boost::begin(HopByHop_packetData), boost::end(HopByHop_packetData), std::cout); - } - catch (std::exception & e) +} + + +namespace { + struct IPv6ChecksumOptionTLVParser : public senf::IPv6OptionTLVParser + { + # include SENF_PARSER() + SENF_PARSER_INHERIT ( IPv6OptionTLVParser ); + SENF_PARSER_FIELD ( slfNetType, senf::UInt8Parser ); + SENF_PARSER_FIELD ( checksum, senf::UInt32Parser ); + + SENF_PARSER_INIT() { + optionType() = typeCode; + length() = senf::init_bytes::value -senf::init_bytes::value; + slfNetType() = SN_typeCode; + } + SENF_PARSER_FINALIZE ( IPv6ChecksumOptionTLVParser ); + static const boost::uint8_t typeCode = 0x0d; + static const boost::uint8_t SN_typeCode = 0x4d; + }; +} + +BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create_SN) +{ + senf::IPv6HopByHopOptionsPacket p ( senf::IPv6HopByHopOptionsPacket::create() ); + p->nextHeader() = 0x3a; { - std::cerr << e.what() << std::endl; throw; + senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optC (p->options() ); + { + IPv6ChecksumOptionTLVParser opt ( + optC.push_back_space().init()); + SENF_CHECK_NO_THROW( opt.slfNetType() = 1u) ; + opt.checksum() = 0x01234567u; + } } + + unsigned char data[] = { + 0x3a, 0x01, // Hop-By-Hop Header (nextHeader, length) + 0x0d, 0x05, // option type, length + // option value: slfNetType, checksum + 0x01, 0x01, 0x23, 0x45, 0x67, + // padding (PadN option: type, length, 0-padding) + 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + SENF_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data), + p.data().begin(), p.data().end() ); +} + + +BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_parse_SN) +{ + unsigned char data[] = { + 0x3a, 0x01, // Hop-By-Hop Header (nextHeader, length) + 0x0d, 0x05, // option type, length + // option value: slfNetType, checksum + 0x01, 0x01, 0x23, 0x45, 0x67, + // padding (PadN option: type, length, 0-padding) + 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + senf::IPv6HopByHopOptionsPacket p ( senf::IPv6HopByHopOptionsPacket::create(data) ); + BOOST_CHECK_EQUAL( p->nextHeader(), 0x3a); + + typedef senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optContainer_t; + optContainer_t optC (p->options() ); + optContainer_t::iterator listIter (optC.begin()); + + BOOST_CHECK_EQUAL( listIter->optionType(), 0x0d); + IPv6ChecksumOptionTLVParser opt ( listIter->as()); + BOOST_CHECK_EQUAL( opt.slfNetType(), 0x01); + BOOST_CHECK_EQUAL( opt.checksum(), 0x01234567); } ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ - + // Local Variables: // mode: c++ // fill-column: 100