From: tho Date: Thu, 1 Oct 2009 09:29:27 +0000 (+0000) Subject: Packets/DefaultBundle: added as<>() member to IPv6GenericOptionTLVParser X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=5367b304d03eba5b7738b46b86532b0141b60d95;p=senf.git Packets/DefaultBundle: added as<>() member to IPv6GenericOptionTLVParser git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1472 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/DefaultBundle/IPv6ExtOptionType.ct b/senf/Packets/DefaultBundle/IPv6ExtOptionType.ct index c6fc9d2..ca43a48 100644 --- a/senf/Packets/DefaultBundle/IPv6ExtOptionType.ct +++ b/senf/Packets/DefaultBundle/IPv6ExtOptionType.ct @@ -26,7 +26,6 @@ //#include "IPv6ExtOptionType.ih" // Custom includes -#include #define prefix_ ///////////////////////////////ct.p//////////////////////////////////////// @@ -38,7 +37,8 @@ prefix_ void senf::IPv6GenericOptionTLVParser::value(ForwardReadableRange const if ( (rangeSize-2) != optionLength() ) resize(optionLength()+2, rangeSize); - std::copy(boost::next(boost::begin(range), 2), boost::next(boost::end(range)), boost::next(i(), 2 + optionLength() )); + std::copy(boost::next(boost::begin(range), 2), boost::next(boost::end(range)), + boost::next(i(), 2 + optionLength() )); unsigned int val = *(boost::begin(range)); unsigned int mask = 192u; altAction() = (val & mask) >> 6; @@ -59,7 +59,6 @@ prefix_ void senf::IPv6GenericOptionTLVParser::setPayload(ForwardReadableRange c optionLength() = rangeSize; } - template prefix_ Parser senf::IPv6GenericOptionTLVParser::init() { @@ -73,13 +72,11 @@ prefix_ Parser senf::IPv6GenericOptionTLVParser::init() return concreteParser; } - -// template -// prefix_ Parser& senf::GenericOptTypeTLVParser::get() -// { -// SENF_ASSERT (optionType() == typeCode); -// return *(this); -// } +template +prefix_ Parser senf::IPv6GenericOptionTLVParser::as() +{ + return Parser(i(), state() ); +} ///////////////////////////////ct.e//////////////////////////////////////// diff --git a/senf/Packets/DefaultBundle/IPv6ExtOptionType.hh b/senf/Packets/DefaultBundle/IPv6ExtOptionType.hh index b9b4a46..e992efd 100644 --- a/senf/Packets/DefaultBundle/IPv6ExtOptionType.hh +++ b/senf/Packets/DefaultBundle/IPv6ExtOptionType.hh @@ -57,8 +57,8 @@ namespace senf { template Parser init(); - // template - // Parser& get(); + template + Parser as(); static const unsigned int typeCode = 7u; diff --git a/senf/Packets/DefaultBundle/IPv6Extensions.test.cc b/senf/Packets/DefaultBundle/IPv6Extensions.test.cc index 635fba2..a51d254 100644 --- a/senf/Packets/DefaultBundle/IPv6Extensions.test.cc +++ b/senf/Packets/DefaultBundle/IPv6Extensions.test.cc @@ -223,6 +223,7 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_parse) BOOST_CHECK_EQUAL( pICMPv6->checksum(), 0x50cc); } + BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create) { std::ostringstream oss (std::ostringstream::out); @@ -306,6 +307,7 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create) eth.data().begin(), eth.data().end() ); } + namespace { struct IPv6ChecksumOptionTLVParser : public senf::IPv6OptionTLVParser { @@ -325,20 +327,12 @@ namespace { }; } -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 - }; - +BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create_SN) +{ senf::IPv6HopByHopOptionsPacket p ( senf::IPv6HopByHopOptionsPacket::create() ); p->nextHeader() = 0x3a; { - senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optC(p->options() ); + senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optC (p->options() ); { IPv6ChecksumOptionTLVParser opt ( optC.push_back_space().init()); @@ -347,10 +341,43 @@ 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_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_ diff --git a/senf/Packets/MPEGDVBBundle/SNDUPacket.cc b/senf/Packets/MPEGDVBBundle/SNDUPacket.cc index c9e40ab..e6761b3 100644 --- a/senf/Packets/MPEGDVBBundle/SNDUPacket.cc +++ b/senf/Packets/MPEGDVBBundle/SNDUPacket.cc @@ -28,7 +28,6 @@ // Custom includes #include -#include #include @@ -84,12 +83,12 @@ prefix_ void senf::SNDUPacketType::dump(packet p, std::ostream & os) { os << "SNDUPacket:\n" << std::dec - << senf::fieldName("d_bit") << p->d_bit() << "\n" - << senf::fieldName("length") << unsigned(p->length()) << "\n" + << senf::fieldName("d_bit") << p->d_bit() << "\n" + << senf::fieldName("length") << unsigned(p->length()) << "\n" << std::hex - << senf::fieldName("type") << "0x" << unsigned(p->type()) << "\n" + << senf::fieldName("type") << "0x" << unsigned(p->type()) << "\n" << std::dec - << senf::fieldName("crc") << unsigned(p->crc()) << "\n"; + << senf::fieldName("crc") << unsigned(p->crc()) << "\n"; } prefix_ senf::PacketParserBase::size_type senf::SNDUPacketType::initSize()