X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FDefaultBundle%2FIPv6Extensions.test.cc;h=beb8c79be0b6badd0f3c972547f174e68c30fc42;hb=bd9f9d3fd6fbcff0112a7bf48ab9284da9576b11;hp=fa36831cb904867416afb6bc052983ea977d409b;hpb=f73fa16ed5abdce272ac77f8b8b9ef2b9922c266;p=senf.git diff --git a/Packets/DefaultBundle/IPv6Extensions.test.cc b/Packets/DefaultBundle/IPv6Extensions.test.cc index fa36831..beb8c79 100644 --- a/Packets/DefaultBundle/IPv6Extensions.test.cc +++ b/Packets/DefaultBundle/IPv6Extensions.test.cc @@ -1,10 +1,10 @@ // $Id$ // // Copyright (C) 2007 -// Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// 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 @@ -21,7 +21,7 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief IPv6Extensions.test unit tests */ + \brief IPv6Extensions unit tests */ //#include "IPv6Extensions.test.hh" //#include "IPv6Extensions.test.ih" @@ -30,7 +30,7 @@ #include "IPv6Extensions.hh" #include "IPv6Packet.hh" #include "UDPPacket.hh" -#include "../../Socket/Protocols/INet/INetAddressing.hh" +#include "ICMPv6Packet.hh" #include "../../Utils/auto_unit_test.hh" #include @@ -38,11 +38,11 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -BOOST_AUTO_UNIT_TEST(ipv6Extension_Fragment_packet) +BOOST_AUTO_UNIT_TEST(ipv6Extensions) { // Just for the fun of it, we test a nice chain: A fragment of a fragmented UDP packet - unsigned char data[] = { + unsigned char Fragment_packetData[] = { // IP header 0x60, 0x00, 0x00, 0x00, // IP Version, class, flow label 0, 20, // payload length @@ -66,39 +66,96 @@ BOOST_AUTO_UNIT_TEST(ipv6Extension_Fragment_packet) 0x11, 0x12, 0x13, 0x14 }; - senf::IPv6Packet p (senf::IPv6Packet::create(data)); + senf::IPv6Packet pFragment_packet (senf::IPv6Packet::create(Fragment_packetData)); - BOOST_CHECK_EQUAL( p->version(), 6u ); - BOOST_CHECK_EQUAL( p->length(), 20u ); - BOOST_CHECK_EQUAL( p->nextHeader(), 44u ); - BOOST_CHECK_EQUAL( p->source().value(), senf::INet6Address::from_string("2001::1") ); - BOOST_CHECK_EQUAL( p->destination().value(), senf::INet6Address::from_string("2001::2") ); - BOOST_CHECK( p.next().is() ); + 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") ); - senf::IPv6Extension_Fragment f (p.next().as()); + std::ostringstream oss (std::ostringstream::out); + SENF_CHECK_NO_THROW( pFragment_packet.dump( oss)); - BOOST_CHECK_EQUAL( f->nextHeader(), 17u ); - BOOST_CHECK_EQUAL( f->fragmentOffset(), 160u ); - BOOST_CHECK_EQUAL( f->id(), 0x01020304u ); - BOOST_CHECK( f.next().is() ); + BOOST_CHECK( pFragment_packet.next().is() ); - senf::UDPPacket u (f.next().as()); + senf::IPv6Extension_Fragment fFragment_packet (pFragment_packet.next().as()); - BOOST_CHECK_EQUAL( u->source(), 0x1000u ); - BOOST_CHECK_EQUAL( u->destination(), 0x2000u ); - BOOST_CHECK_EQUAL( u->length(), 12u ); - BOOST_CHECK( u.next().is() ); + BOOST_CHECK_EQUAL( fFragment_packet->nextHeader(), 17u ); + BOOST_CHECK_EQUAL( fFragment_packet->fragmentOffset(), 160u ); + BOOST_CHECK_EQUAL( fFragment_packet->id(), 0x01020304u ); + BOOST_CHECK( fFragment_packet.next().is() ); - senf::DataPacket d (u.next().as()); - senf::PacketData::iterator i (u.next().data().begin()); - BOOST_CHECK_EQUAL( d.size(), 4u ); - BOOST_CHECK_EQUAL( d.data()[0], 0x11 ); -} + senf::UDPPacket uFragment_packet (fFragment_packet.next().as()); + + BOOST_CHECK_EQUAL( uFragment_packet->source(), 0x1000u ); + BOOST_CHECK_EQUAL( uFragment_packet->destination(), 0x2000u ); + BOOST_CHECK_EQUAL( uFragment_packet->length(), 12u ); + BOOST_CHECK( uFragment_packet.next().is() ); + + senf::DataPacket dFragment_packet (uFragment_packet.next().as()); + senf::PacketData::iterator i (uFragment_packet.next().data().begin()); + BOOST_CHECK_EQUAL( dFragment_packet.size(), 4u ); + BOOST_CHECK_EQUAL( dFragment_packet.data()[0], 0x11 ); + //============================================================================================== + + 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, 0x00, 0x00, 0x00 + }; + + senf::IPv6Packet pRouting_packet (senf::IPv6Packet::create(Routing_packetData)); + + 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")); + SENF_CHECK_NO_THROW( pRouting_packet.dump( oss)); + + BOOST_REQUIRE( pRouting_packet.next().is() ); + + senf::IPv6Extension_Routing pRouting_extension (pRouting_packet.next().as()); + + BOOST_CHECK_EQUAL( pRouting_extension->nextHeader(), 58u ); + BOOST_CHECK_EQUAL( pRouting_extension->headerLength(), 0x00 ); + BOOST_CHECK_EQUAL( pRouting_extension->routingType(), 0x00 ); + BOOST_CHECK_EQUAL( pRouting_extension->segmentsLeft(), 0x00); + + BOOST_CHECK_EQUAL( pRouting_extension->reserved(), 0u); + + BOOST_REQUIRE( pRouting_extension.next().is() ); + senf::ICMPv6Packet pICMPv6 (pRouting_extension.next().as()); + BOOST_CHECK_EQUAL( pICMPv6->type(), 1u); + 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. + */ ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ - + // Local Variables: // mode: c++ // fill-column: 100