From: tho Date: Mon, 28 Sep 2009 10:58:10 +0000 (+0000) Subject: moved IPv6Option example to unit test X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=51eaceeb2936c1e6a8fe8cc3c2dfdf28013b68f9;p=senf.git moved IPv6Option example to unit test git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1451 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/DefaultBundle/IPv6ExtOptionType.hh b/senf/Packets/DefaultBundle/IPv6ExtOptionType.hh index 29d2f59..9a88acb 100644 --- a/senf/Packets/DefaultBundle/IPv6ExtOptionType.hh +++ b/senf/Packets/DefaultBundle/IPv6ExtOptionType.hh @@ -33,7 +33,7 @@ ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { - class IPv6OptionTLVParser : public PacketParserBase + class IPv6OptionTLVParser : public PacketParserBase { public: # include SENF_PARSER() @@ -69,22 +69,6 @@ namespace senf { void setPayload(ForwardReadableRange const &range); }; - struct IPv6ChecksumOptionTLVParser : public IPv6OptionTLVParser - { -# include SENF_PARSER() - SENF_PARSER_INHERIT ( IPv6OptionTLVParser ); - SENF_PARSER_FIELD ( SlfNetType, UInt8Parser); - SENF_PARSER_FIELD ( checksum, UInt16Parser ); - - SENF_PARSER_INIT() { - optionType() = typeCode; - optionLength() = senf::init_bytes::value -senf::init_bytes::value; - SlfNetType() = SN_typeCode; - } - SENF_PARSER_FINALIZE ( IPv6ChecksumOptionTLVParser ); - static const unsigned int typeCode = 13u; - static const unsigned int SN_typeCode = 77u; - }; } diff --git a/senf/Packets/DefaultBundle/IPv6Extensions.hh b/senf/Packets/DefaultBundle/IPv6Extensions.hh index ee4e18e..879b87c 100644 --- a/senf/Packets/DefaultBundle/IPv6Extensions.hh +++ b/senf/Packets/DefaultBundle/IPv6Extensions.hh @@ -223,7 +223,8 @@ namespace senf { \see IPv6ExtensionType_HopByHop \n RFC 2460 */ - struct IPv6HopByHopOptionsPacketParser : public PacketParserBase { + struct IPv6HopByHopOptionsPacketParser : public PacketParserBase + { # include SENF_PARSER() SENF_PARSER_FIELD ( nextHeader, UInt8Parser ); diff --git a/senf/Packets/DefaultBundle/IPv6Extensions.test.cc b/senf/Packets/DefaultBundle/IPv6Extensions.test.cc index 404ebc6..08e3dec 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 @@ -310,24 +311,47 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create) eth.data().begin(), eth.data().end() ); } -//provisionary unittest, only creating extensino Header Packet type -BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create_SN) { - - unsigned char data[] = { 0x3a, 0x00, 0x0d, 0x03, 0x01, 0xab, 0xcd, 0x00 }; +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; + optionLength() = 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) { + 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() ); - p->nextHeader() = 58u; + p->nextHeader() = 0x3a; { senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optC(p->options() ); { - senf::IPv6ChecksumOptionTLVParser opt ( optC.push_back_space().init()); -// opt.altAction() = 0u; -// opt.changeFlag() = 0u; -// opt.optionType() = 5u; - SENF_CHECK_NO_THROW( opt.SlfNetType() = 1u) ; - opt.checksum() = 0xabcdu; + IPv6ChecksumOptionTLVParser opt ( + optC.push_back_space().init()); + SENF_CHECK_NO_THROW( opt.slfNetType() = 1u) ; + opt.checksum() = 0x01234567u; } } + SENF_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data), p.data().begin(), p.data().end() ); } diff --git a/senf/Packets/extra-tests/AllBundles.test.cc b/senf/Packets/extra-tests/AllBundles.test.cc index 27553a4..7398028 100644 --- a/senf/Packets/extra-tests/AllBundles.test.cc +++ b/senf/Packets/extra-tests/AllBundles.test.cc @@ -23,9 +23,6 @@ /** \file \brief AllBundles unit tests */ -//#include "PacketLink.test.hh" -//#include "PacketLink.test.ih" - // Custom includes #include #include