X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FDefaultBundle%2FICMPv6Packet.test.cc;h=3502a61a429fc14f5ee268a62b59a61470cee57b;hb=209950ee5f6898978cd68614ef339ae3531c5c53;hp=3fa5002dc3b8041e8b338568b60ea220fb394383;hpb=ec7f715d7eef5bb915c7ca39587a99fb41d8d3be;p=senf.git diff --git a/senf/Packets/DefaultBundle/ICMPv6Packet.test.cc b/senf/Packets/DefaultBundle/ICMPv6Packet.test.cc index 3fa5002..3502a61 100644 --- a/senf/Packets/DefaultBundle/ICMPv6Packet.test.cc +++ b/senf/Packets/DefaultBundle/ICMPv6Packet.test.cc @@ -27,12 +27,14 @@ #include #include "ICMPv6Packet.hh" #include "ICMPv6TypePacket.hh" +#include "NDPOptions.hh" #include #include +///////////////////////////////cc.p//////////////////////////////////////// -BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet) +SENF_AUTO_UNIT_TEST(ICMPv6Packet_packet) { unsigned char dataListenerReport[] = { 0x8f, 0x00, 0x8d, 0x54, 0x00, 0x00, 0x00, 0x01, @@ -156,9 +158,109 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet) SENF_CHECK_NO_THROW( pErrParamProblem.dump( oss)); + unsigned char dataRouterSolicitation[] = { + 0x85, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x05, 0x01, 0x00, 0x00, + 0x12, 0x34, 0x56, 0x78 + }; + + senf::ICMPv6Packet pRouterSolicitation ( senf::ICMPv6Packet::create(dataRouterSolicitation) ); + BOOST_CHECK_EQUAL( pRouterSolicitation->type(), 0x85 ); + BOOST_CHECK_EQUAL( pRouterSolicitation->code(), 0x00 ); + BOOST_CHECK_EQUAL( pRouterSolicitation->checksum(), 0x0000 ); + BOOST_CHECK( pRouterSolicitation.next() ); + BOOST_CHECK( pRouterSolicitation.next().is() ); + BOOST_CHECK_EQUAL( pRouterSolicitation.next().size(), 12u ); + + senf::NDPRouterSolicitationMessage pOption(pRouterSolicitation.next().as()); + senf::NDPRouterSolicitationMessage::Parser::options_t::container optC(pOption->options() ); + senf::NDPRouterSolicitationMessage::Parser::options_t::container::iterator listIter (optC.begin()); + BOOST_CHECK_EQUAL(listIter->type(),5u); + BOOST_CHECK_EQUAL(listIter->length(),1u); + + SENF_CHECK_NO_THROW( pRouterSolicitation.dump( oss)); + + unsigned char dataRouterAdvertisement[] = { + 0x86, 0x00, 0x00, 0x00, + 0xFF, 0x00, 0x23, 0x28, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + }; + + senf::ICMPv6Packet pRouterAdvertisement ( senf::ICMPv6Packet::create(dataRouterAdvertisement) ); + BOOST_CHECK_EQUAL( pRouterAdvertisement->type(), 0x86 ); + BOOST_CHECK_EQUAL( pRouterAdvertisement->code(), 0x00 ); + BOOST_CHECK_EQUAL( pRouterAdvertisement->checksum(), 0x0000 ); + BOOST_CHECK( pRouterAdvertisement.next() ); + BOOST_CHECK( pRouterAdvertisement.next().is() ); + BOOST_CHECK_EQUAL( pRouterAdvertisement.next().size(), 12u ); + + SENF_CHECK_NO_THROW( pRouterAdvertisement.dump( oss)); + + unsigned char dataNeighborSolicitation[] = { + 0x87, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + }; + + senf::ICMPv6Packet pNeighborSolicitation ( senf::ICMPv6Packet::create(dataNeighborSolicitation) ); + BOOST_CHECK_EQUAL( pNeighborSolicitation->type(), 0x87 ); + BOOST_CHECK_EQUAL( pNeighborSolicitation->code(), 0x00 ); + BOOST_CHECK_EQUAL( pNeighborSolicitation->checksum(), 0x0000 ); + BOOST_CHECK( pNeighborSolicitation.next() ); + BOOST_CHECK( pNeighborSolicitation.next().is() ); + BOOST_CHECK_EQUAL( pNeighborSolicitation.next().size(), 20u ); + + SENF_CHECK_NO_THROW( pNeighborSolicitation.dump( oss)); + + unsigned char dataNeighborAdvertisement[] = { + 0x88, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + }; + + senf::ICMPv6Packet pNeighborAdvertisement ( senf::ICMPv6Packet::create(dataNeighborAdvertisement) ); + BOOST_CHECK_EQUAL( pNeighborAdvertisement->type(), 0x88 ); + BOOST_CHECK_EQUAL( pNeighborAdvertisement->code(), 0x00 ); + BOOST_CHECK_EQUAL( pNeighborAdvertisement->checksum(), 0x0000 ); + BOOST_CHECK( pNeighborAdvertisement.next() ); + BOOST_CHECK( pNeighborAdvertisement.next().is() ); + BOOST_CHECK_EQUAL( pNeighborAdvertisement.next().size(), 20u ); + + SENF_CHECK_NO_THROW( pNeighborAdvertisement.dump( oss)); + + unsigned char dataRedirect[] = { + 0x89, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + }; + + senf::ICMPv6Packet pRedirect ( senf::ICMPv6Packet::create(dataRedirect) ); + BOOST_CHECK_EQUAL( pRedirect->type(), 0x89 ); + BOOST_CHECK_EQUAL( pRedirect->code(), 0x00 ); + BOOST_CHECK_EQUAL( pRedirect->checksum(), 0x0000 ); + BOOST_CHECK( pRedirect.next() ); + BOOST_CHECK( pRedirect.next().is() ); + BOOST_CHECK_EQUAL( pRedirect.next().size(), 36u ); + + SENF_CHECK_NO_THROW( pRedirect.dump( oss)); } -BOOST_AUTO_UNIT_TEST(ICMPv6Packet_create) +SENF_AUTO_UNIT_TEST(ICMPv6Packet_create) { std::ostringstream oss (std::ostringstream::out); @@ -195,46 +297,49 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_create) ip.finalizeAll(); -// std::string dump ( -// "Internet protocol Version 6:\n" -// " version : 6\n" -// " traffic class : 0x00\n" -// " flow label : 0x00000\n" -// " payload length : 64\n" -// " next header : 58\n" -// " hop limit : 64\n" -// " source : ::1\n" -// " destination : ::1\n" -// "ICMPv6 protocol:\n" -// " type : 128\n" -// " code : 0\n" -// " checksum : 0xdae0\n" -// "ICMPv6 Echo Request:\n" -// " identifier : 40830\n" -// " sequence nr. : 9\n" -// "Payload data (56 bytes)\n" -// ); - -// { -// std::stringstream ss; -// ip.dump(ss); -// BOOST_CHECK_EQUAL( ss.str(), dump ); -// } - SENF_CHECK_NO_THROW (ip.dump( oss )); + std::string dump ( + "Internet protocol Version 6:\n" + " version : 6\n" + " traffic class : 0x00\n" + " flow label : 0x00000\n" + " payload length : 64\n" + " next header : 58\n" + " hop limit : 64\n" + " source : ::1\n" + " destination : ::1\n" + "ICMPv6 protocol:\n" + " type : 128\n" + " code : 0\n" + " checksum : 0xdae0\n" + "ICMPv6 Echo Request:\n" + " Identifier : 40830\n" + " SequenceNumber : 9\n" + "Payload data (56 bytes)\n" + ); + + { + std::stringstream ss; + ip.dump(ss); + BOOST_CHECK_EQUAL( ss.str(), dump ); + } + SENF_CHECK_EQUAL_COLLECTIONS( ip.data().begin(), ip.data().end(), ping, ping+sizeof(ping) ); -// senf::IPv6Packet orig (senf::IPv6Packet::create(ping)); -// -// { -// std::stringstream ss; -// orig.dump(ss); -// BOOST_CHECK_EQUAL( ss.str(), dump ); -// } + senf::IPv6Packet orig (senf::IPv6Packet::create(ping)); + + { + std::stringstream ss; + orig.dump(ss); + BOOST_CHECK_EQUAL( ss.str(), dump ); + } } +///////////////////////////////cc.e//////////////////////////////////////// + + // Local Variables: // mode: c++ // fill-column: 100