X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FDefaultBundle%2FIPv6Extensions.test.cc;h=380b696e09cc657f3013aef8892ddaf9febfb8bf;hb=328a72eb2f360d08f2d618ef6aae2ac6b42d76ab;hp=beb8c79be0b6badd0f3c972547f174e68c30fc42;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Packets/DefaultBundle/IPv6Extensions.test.cc b/senf/Packets/DefaultBundle/IPv6Extensions.test.cc index beb8c79..380b696 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 @@ -31,14 +32,15 @@ #include "IPv6Packet.hh" #include "UDPPacket.hh" #include "ICMPv6Packet.hh" +#include -#include "../../Utils/auto_unit_test.hh" +#include #include #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -BOOST_AUTO_UNIT_TEST(ipv6Extensions) +BOOST_AUTO_UNIT_TEST(ipv6Extensions_fragment) { // Just for the fun of it, we test a nice chain: A fragment of a fragmented UDP packet @@ -71,15 +73,17 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions) BOOST_CHECK_EQUAL( pFragment_packet->version(), 6u ); BOOST_CHECK_EQUAL( pFragment_packet->length(), 20u ); BOOST_CHECK_EQUAL( pFragment_packet->nextHeader(), 44u ); - BOOST_CHECK_EQUAL( pFragment_packet->source().value(), senf::INet6Address::from_string("2001::1") ); - BOOST_CHECK_EQUAL( pFragment_packet->destination().value(), senf::INet6Address::from_string("2001::2") ); + BOOST_CHECK_EQUAL( pFragment_packet->source().value(), + senf::INet6Address::from_string("2001::1") ); + BOOST_CHECK_EQUAL( pFragment_packet->destination().value(), + senf::INet6Address::from_string("2001::2") ); std::ostringstream oss (std::ostringstream::out); SENF_CHECK_NO_THROW( pFragment_packet.dump( oss)); - BOOST_CHECK( pFragment_packet.next().is() ); + BOOST_CHECK( pFragment_packet.next().is() ); - senf::IPv6Extension_Fragment fFragment_packet (pFragment_packet.next().as()); + senf::IPv6FragmentPacket fFragment_packet (pFragment_packet.next().as()); BOOST_CHECK_EQUAL( fFragment_packet->nextHeader(), 17u ); BOOST_CHECK_EQUAL( fFragment_packet->fragmentOffset(), 160u ); @@ -97,27 +101,31 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions) senf::PacketData::iterator i (uFragment_packet.next().data().begin()); BOOST_CHECK_EQUAL( dFragment_packet.size(), 4u ); BOOST_CHECK_EQUAL( dFragment_packet.data()[0], 0x11 ); +} - //============================================================================================== - + +BOOST_AUTO_UNIT_TEST(ipv6Extensions_routing) +{ unsigned char Routing_packetData[] = { // IP header 0x60, 0x30, 0x00, 0x00, - 0x00, 0x10, //payload Length - 0x2b, //next Header (43 = Routing Header) - 0xff, //Hop Limit - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x02, 0xff, 0xfe, 0x00, 0x02, 0x00, //Src Addr - 0x35, 0x55, 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, //Dest. Addr - //Routing Header - 0x3a, //nextHeader (58) - 0x00, //Length ( 0 ) - 0x00, //routing type ( 0 ) - 0x00, //Left Segments ( 0 ) - 0x00, 0x00, 0x00, 0x00, //reserved - //ICMPv6 - 0x01, //type: 1 (unreachable ) - 0x00, //code: 0 (route unreachable) - 0xa3, 0xd3, //checksum (incorrect in wireshark capture file, should be 0xa3c4) + 0x00, 0x10, // payload Length + 0x2b, // next Header (43 = Routing Header) + 0xff, // Hop Limit + 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x01, 0x02, 0xff, 0xfe, 0x00, 0x02, 0x00, // Src Addr + 0x35, 0x55, 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, + 0x77, 0x77, 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, // Dest. Addr + // Routing Header + 0x3a, // nextHeader (58) + 0x00, // length ( 0 ) + 0x00, // routing type ( 0 ) + 0x00, // Left Segments ( 0 ) + 0x00, 0x00, 0x00, 0x00, // reserved + // ICMPv6 + 0x01, // type: 1 (unreachable ) + 0x00, // code: 0 (route unreachable) + 0xa3, 0xd3, // checksum (incorrect in wireshark capture file, should be 0xa3c4) 0x00, 0x00, 0x00, 0x00 }; @@ -126,13 +134,17 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions) BOOST_CHECK_EQUAL( pRouting_packet->version(), 6u ); BOOST_CHECK_EQUAL( pRouting_packet->length(), 16u ); BOOST_CHECK_EQUAL( pRouting_packet->nextHeader(), 43u ); - BOOST_CHECK_EQUAL( pRouting_packet->source().value(), senf::INet6Address::from_string("fe80::201:2ff:fe00:200") ); - BOOST_CHECK_EQUAL( pRouting_packet->destination().value(), senf::INet6Address::from_string("3555:5555:6666:6666:7777:7777:8888:8888")); + BOOST_CHECK_EQUAL( pRouting_packet->source().value(), + senf::INet6Address::from_string("fe80::201:2ff:fe00:200") ); + BOOST_CHECK_EQUAL( pRouting_packet->destination().value(), + senf::INet6Address::from_string("3555:5555:6666:6666:7777:7777:8888:8888")); + + std::ostringstream oss (std::ostringstream::out); SENF_CHECK_NO_THROW( pRouting_packet.dump( oss)); - BOOST_REQUIRE( pRouting_packet.next().is() ); + BOOST_REQUIRE( pRouting_packet.next().is() ); - senf::IPv6Extension_Routing pRouting_extension (pRouting_packet.next().as()); + senf::IPv6RoutingPacket pRouting_extension (pRouting_packet.next().as()); BOOST_CHECK_EQUAL( pRouting_extension->nextHeader(), 58u ); BOOST_CHECK_EQUAL( pRouting_extension->headerLength(), 0x00 ); @@ -147,11 +159,138 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions) BOOST_CHECK_EQUAL( pICMPv6->code(), 0u); BOOST_CHECK_EQUAL( pICMPv6->checksum(), 0xa3d3); } - //============================================================================================== - - /* - no unittests for Hop by Hop - and Destination - Options extension Header yet. No real implementation there, only IPv6 extension skeleton implemented. - */ + + +BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_parse) +{ + unsigned char HopByHop_packetData[] = { + 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, + 0x02, 0x19, 0xb9, 0xff, 0xfe, 0xeb, 0xb2, 0x26, // IPv6 Source address + 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, // IPv6 Destination address 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 ...) + 0x02, //option type (2, set for testing purposes only) + 0x00, //option Type length (=0, no data field needed here) + // ICMPv6 + 0x8f, // type 143 + 0x00, // code 0, should always be 0 + 0x50, 0xcc, // checksum + }; + + senf::IPv6Packet pHop_packet (senf::IPv6Packet::create(HopByHop_packetData)); + BOOST_CHECK_EQUAL( pHop_packet->version(), 6u ); + BOOST_CHECK_EQUAL( pHop_packet->length(), 36u ); + BOOST_CHECK_EQUAL( pHop_packet->nextHeader(), 0u ); + BOOST_CHECK_EQUAL( pHop_packet->source().value(), + senf::INet6Address::from_string("fe80::219:b9ff:feeb:b226") ); + BOOST_CHECK_EQUAL( pHop_packet->destination().value(), senf::INet6Address::from_string("ff02::16") ); + + std::ostringstream oss (std::ostringstream::out); + SENF_CHECK_NO_THROW( pHop_packet.dump( oss )); + + BOOST_REQUIRE( pHop_packet.next().is() ); + senf::IPv6HopByHopOptionsPacket pHop_extension ( + pHop_packet.next().as()); + BOOST_CHECK_EQUAL( pHop_extension->nextHeader(), 58u ); + BOOST_CHECK_EQUAL( pHop_extension->headerLength(), 0x00 ); + + senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optC(pHop_extension->options() ); + senf::IPv6HopByHopOptionsPacket::Parser::options_t::container::iterator listIter (optC.begin()); + + BOOST_CHECK_EQUAL( listIter->altAction(), 0u); + BOOST_CHECK_EQUAL( listIter->changeFlag(), 0u); + BOOST_CHECK_EQUAL( listIter->optionType(), 5u); + BOOST_CHECK_EQUAL( listIter->optionLength(), 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_REQUIRE( pHop_extension.next().is() ); + senf::ICMPv6Packet pICMPv6 (pHop_extension.next().as()); + BOOST_CHECK_EQUAL( pICMPv6->type(), 0x8f); + BOOST_CHECK_EQUAL( pICMPv6->code(), 0u); + BOOST_CHECK_EQUAL( pICMPv6->checksum(), 0x50cc); +} + +BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create) +{ + std::ostringstream oss (std::ostringstream::out); + unsigned char HopByHop_packetData[] = { + 0x60, 0x00, 0x00, 0x00, //IP version, class, flow label + 0x00, 0x0c, //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 ...) + + 0x02, //option type (2, set for testing purposes only) + 0x00, //option Type length (=0, no data field needed here) + + //ICMPv6 + 0x8f, //type 143 + 0x00, //code 0, should always be 0 + 0xca, 0xdf, //checksum + }; + senf::IPv6Packet ip (senf::IPv6Packet::create()); + ip->version() = 6u; + ip->length() = 12u; + ip->nextHeader() = 0u; + ip->hopLimit() = 1u; + ip->source() = senf::INet6Address::from_string("fe80::219:b9ff:feeb:b226"); + ip->destination() = senf::INet6Address::from_string("ff02::16"); + senf::IPv6HopByHopOptionsPacket pext (senf::IPv6HopByHopOptionsPacket::createAfter(ip) ); + pext->nextHeader() = 58u; + pext->headerLength() = 0u; + { + senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optC(pext->options() ); + + optC.push_back_space(); + senf::IPv6GenericOptionTLVParser opt = optC.back().init(); + opt.altAction() = 0u; + opt.changeFlag() = 0u; + opt.optionType() = 5u; + unsigned char val[] = {0x00, 0x00}; + opt.setPayload(val); + + optC.push_back_space(); + opt = optC.back().init(); + opt.altAction() = 0u; + opt.changeFlag() = 0u; + opt.optionType() = 2u; + } + senf::ICMPv6Packet icmp (senf::ICMPv6Packet::createAfter (pext)); + icmp->type() = 0x8f; + icmp->code() = 0u; + ip.finalizeAll(); + SENF_CHECK_NO_THROW( ip.dump(oss) ); + BOOST_CHECK_EQUAL_COLLECTIONS( + HopByHop_packetData, HopByHop_packetData+sizeof(HopByHop_packetData), + ip.data().begin(), ip.data().end() ); +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_