Packets/DefaultBundle: use new generic TLV base class for IPv6Options
tho [Thu, 8 Oct 2009 16:30:35 +0000 (16:30 +0000)]
Packets: Documentation: added ConcretePacket typedefs into bundle groups

git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1481 270642c3-0616-0410-b53a-bc976706d245

18 files changed:
senf/Packets/80211Bundle/WLANPacket.cc
senf/Packets/80211Bundle/WLANPacket.hh
senf/Packets/80221Bundle/TLVPacket.hh
senf/Packets/DefaultBundle/EthernetPacket.hh
senf/Packets/DefaultBundle/ICMPv6Packet.hh
senf/Packets/DefaultBundle/IPv4Packet.hh
senf/Packets/DefaultBundle/IPv6ExtOptionType.cc [deleted file]
senf/Packets/DefaultBundle/IPv6ExtOptionType.ct [deleted file]
senf/Packets/DefaultBundle/IPv6ExtOptionType.hh
senf/Packets/DefaultBundle/IPv6Extensions.cc
senf/Packets/DefaultBundle/IPv6Extensions.hh
senf/Packets/DefaultBundle/IPv6Extensions.test.cc
senf/Packets/DefaultBundle/IPv6Packet.hh
senf/Packets/DefaultBundle/ListOptionTypeParser.test.cc
senf/Packets/DefaultBundle/LlcSnapPacket.hh
senf/Packets/DefaultBundle/TCPPacket.hh
senf/Packets/DefaultBundle/UDPPacket.hh
senf/Packets/Packets.hh

index ba4fafe..013f645 100644 (file)
 
 // Definition of non-inline non-template functions
 
-// Custom includes
 #include "WLANPacket.hh"
+//#include "WLANPacket.ih"
+
+// Custom includes
 #include <senf/Packets/Packets.hh>
 #include <boost/io/ios_state.hpp>
 
 #define prefix_
+///////////////////////////////cc.p///////////////////////////////////////
 
 namespace {
-    
     void dumpBase(senf::WLANPacketParser const & p, std::ostream & os)
     {
         os << "  version                 : " << unsigned(p.version()) <<"\n"
@@ -81,32 +83,37 @@ prefix_ senf::MACAddressParser senf::WLANPacket_DataFrameParser::destinationAddr
 {
     switch (dsBits()) {
     case 0 :
-    case 2 : return addr1();
-    default: return addr3();
+    case 2 : 
+        return addr1();
+    default: 
+        return addr3();
     }
 }
 
 prefix_ senf::MACAddressParser senf::WLANPacket_DataFrameParser::sourceAddress()
     const
 {
-    switch (dsBits())
-    {
+    switch (dsBits()) {
     case 0 :
-    case 1 : return addr2();
+    case 1 :
+        return addr2();
     // TODO wds frames
     // case 3 : return addr4();
-    default: return addr3();
+    default: 
+        return addr3();
     }
 }
 
 prefix_ senf::MACAddressParser senf::WLANPacket_DataFrameParser::bssid()
     const
 {
-    switch (dsBits())
-    {
-    case 0 : return addr3();
-    case 1 : return addr1();
-    default: return addr2();
+    switch (dsBits()) {
+    case 0 :
+        return addr3();
+    case 1 :
+        return addr1();
+    default:
+        return addr2();
     }
 }
 
@@ -131,6 +138,7 @@ prefix_ void senf::WLANPacket_DataFrameType::dump(packet p, std::ostream &os)
         os << senf::fieldName("QOS data")              << p->qosField() << "\n";
 }
 
+///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 
 \f
index b406a94..b0539d6 100644 (file)
@@ -30,6 +30,8 @@
 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
 #include <senf/Packets/DefaultBundle/LlcSnapPacket.hh>
 
+///////////////////////////////hh.p////////////////////////////////////////
+
 namespace senf
 {
 
@@ -134,7 +136,7 @@ namespace senf
 
         SENF_PARSER_INHERIT(WLANPacketParser);
 
-        SENF_PARSER_FIELD            ( receiverAddress, MACAddressParser );
+        SENF_PARSER_FIELD   ( receiverAddress, MACAddressParser );
 
         //only RTS frame contains a source address field
         //variant is also needed to set correct subtype value
@@ -267,7 +269,11 @@ namespace senf
     typedef WLANPacket_DataFrameType::packet WLANPacket_DataFrame;
 }
 
-#endif /* HH_SENF_Packets_80211Bundle_WLANPacket_ */
+///////////////////////////////hh.e////////////////////////////////////////
+//#include "WLANPacket.cci"
+//#include "WLANPacket.ct"
+//#include "WLANPacket.cti"
+#endif
 
 \f
 // Local Variables:
index c0f6413..f0e6e9c 100644 (file)
@@ -194,7 +194,9 @@ namespace senf {
         
     };
     
-    /** \brief GenericTLV packet typedef */
+    /** \brief GenericTLV packet typedef
+        \ingroup protocolbundle_80221
+     */
     typedef ConcretePacket<GenericTLVPacketType> GenericTLVPacket;
 }
 
index 70c769d..bade575 100644 (file)
@@ -189,7 +189,9 @@ namespace senf {
         static void finalize(packet p);
     };
 
-    /** \brief Ethernet VLAN tag typedef */
+    /** \brief Ethernet VLAN tag typedef
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<EthVLanPacketType> EthVLanPacket;
 
 }
index 1165701..c5c2694 100644 (file)
@@ -89,6 +89,9 @@ namespace senf
         }
     };
     
+    /** \brief ICMPv6 packet typedef
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<ICMPv6PacketType> ICMPv6Packet;
 }
 
index 0122084..898620b 100644 (file)
@@ -195,7 +195,9 @@ namespace senf {
                                                \ref IPv4PacketParser::checksum() "checksum" */
     };
 
-    /** \brief IPv4 packet typedef */
+    /** \brief IPv4 packet typedef
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<IPv4PacketType> IPv4Packet;
 }
 
diff --git a/senf/Packets/DefaultBundle/IPv6ExtOptionType.cc b/senf/Packets/DefaultBundle/IPv6ExtOptionType.cc
deleted file mode 100644 (file)
index 549026d..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-// $Id: IPv6ExtOptionType.cc 869 2008-06-09 13:57:27Z pug $
-//
-// Copyright (C) 2009
-// Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-//     Philipp.Batroff@fokus.fraunhofer.de
-//
-// 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
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-/** \file
-    \brief IPv6Extension-Options non-inline non-template implementation */
-
-#include "IPv6ExtOptionType.hh"
-// Custom includes
-
-#define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
-
-prefix_  senf::PacketInterpreterBase::range senf::IPv6GenericOptionTLVParser::value() 
-    const 
-{
-    senf::PacketData::iterator begin (boost::next(i(), 2 ));
-    return PacketInterpreterBase::range(begin, boost::next( begin, optionLength()) );
-}
-
-///////////////////////////////cc.e////////////////////////////////////////
-#undef prefix_
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// comment-column: 40
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// End:
diff --git a/senf/Packets/DefaultBundle/IPv6ExtOptionType.ct b/senf/Packets/DefaultBundle/IPv6ExtOptionType.ct
deleted file mode 100644 (file)
index ca43a48..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-// $Id: IPv6ExtOptionType.ct 869 2008-06-09 13:57:27Z pug $
-//
-// Copyright (C) 2009
-// Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-//     Philipp.Batroff@fokus.fraunhofer.de
-//
-// 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
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-/** \file
-    \brief IPv6Extension-Options non-inline template implementation  */
-
-//#include "IPv6ExtOptionType.ih"
-
-// Custom includes
-
-#define prefix_
-///////////////////////////////ct.p////////////////////////////////////////
-
-template <class ForwardReadableRange>
-prefix_ void senf::IPv6GenericOptionTLVParser::value(ForwardReadableRange const &range)
-{
-    unsigned int rangeSize = boost::size(range);
-    
-    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() ));
-    unsigned int val = *(boost::begin(range));
-    unsigned int mask = 192u;
-    altAction() = (val & mask) >> 6;
-    mask = 32u;
-    changeFlag() = (val & mask) >> 5;
-    mask = 31u;
-    optionType() = (val & mask);
-    optionLength() = *(boost::next( boost::begin(range), 1));
-}
-
-template <class ForwardReadableRange>
-prefix_ void senf::IPv6GenericOptionTLVParser::setPayload(ForwardReadableRange const &range)
-{
-    unsigned int rangeSize = boost::size(range);
-    if ( rangeSize != optionLength() )
-        resize( (optionLength() + 2), (rangeSize + 2) );
-    std::copy( boost::begin(range), boost::end(range), boost::next( i(), 2));
-    optionLength() = rangeSize;
-}
-
-template <class Parser>
-prefix_ Parser senf::IPv6GenericOptionTLVParser::init()
-{  
-    size_type oldSize (bytes() );
-    size_type newParserSize ( senf::init_bytes<Parser>::value );
-    resize(  oldSize, newParserSize);
-    std::fill(i(),boost::next(i(), newParserSize), 0u);
-    Parser concreteParser = Parser(i(), state() );
-    concreteParser.init();
-    concreteParser.optionLength() = (newParserSize-2);
-    return concreteParser;
-}
-
-template <class Parser>
-prefix_ Parser senf::IPv6GenericOptionTLVParser::as()
-{
-    return Parser(i(), state() );
-}
-
-
-///////////////////////////////ct.e////////////////////////////////////////
-#undef prefix_
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// comment-column: 40
-// End:
index e992efd..db7468a 100644 (file)
@@ -37,44 +37,23 @@ namespace senf {
     {
     public:
 #       include SENF_PARSER()
-        SENF_PARSER_BITFIELD (altAction,  2, unsigned);
-        SENF_PARSER_BITFIELD (changeFlag, 1, unsigned);
-        SENF_PARSER_BITFIELD (optionType, 5, unsigned);
-        SENF_PARSER_FIELD (optionLength, UInt8Parser);
-        SENF_PARSER_FINALIZE (IPv6OptionTLVParser);
+        SENF_PARSER_FIELD ( type, UInt8Parser );
+        SENF_PARSER_GOTO ( type );
+        SENF_PARSER_BITFIELD ( altAction,  2, unsigned );
+        SENF_PARSER_BITFIELD ( changeFlag, 1, unsigned );
+        SENF_PARSER_BITFIELD ( optionType, 5, unsigned );
+        SENF_PARSER_FIELD (length, UInt8Parser );
+        SENF_PARSER_FINALIZE (IPv6OptionTLVParser );
     };
 
-    
-    struct IPv6GenericOptionTLVParser : public IPv6OptionTLVParser
-    {
-#       include SENF_PARSER()
-        SENF_PARSER_INHERIT ( IPv6OptionTLVParser );
-        SENF_PARSER_SKIP ( optionLength(), 0 );
-        SENF_PARSER_FINALIZE ( IPv6GenericOptionTLVParser );
-
-        senf::PacketInterpreterBase::range value() const;
-
-        template <class Parser>
-        Parser init();
-
-        template <class Parser>
-        Parser as();
-
-        static const unsigned int typeCode = 7u;
-
-        template<class ForwardReadableRange>
-        void value(ForwardReadableRange const &range);
-
-        template<class ForwardReadableRange>
-        void setPayload(ForwardReadableRange const &range);
-    };
+    typedef GenericTLVParserBase<IPv6OptionTLVParser> IPv6GenericOptionTLVParser;
 
 }
 
 
 ///////////////////////////////hh.e////////////////////////////////////////
 //#include "IPv6ExtOptionType.cci"
-#include "IPv6ExtOptionType.ct"
+//#include "IPv6ExtOptionType.ct"
 //#include "IPv6ExtOptionType.cti"
 #endif
 
index d033d44..d579277 100644 (file)
@@ -26,8 +26,9 @@
 
 #include "IPv6Extensions.hh"
 //#include "IPv6Extensions.ih"
-#include <senf/Utils/hexdump.hh>
+
 // Custom includes
+#include <senf/Utils/hexdump.hh>
 
 //#include "IPv6Extensions.mpp"
 #define prefix_
@@ -79,7 +80,7 @@ prefix_ void senf::IPv6HopByHopOptionsPacketType::dump(packet p, std::ostream &
         os << senf::fieldName("  AltAction")           << unsigned(optIter->altAction()) << "\n"
            << senf::fieldName("  ChangeFlag")          << unsigned(optIter->changeFlag()) << "\n"
            << senf::fieldName("  Option Type")         << unsigned(optIter->optionType()) << "\n"
-           << senf::fieldName("  OptionLength")        << unsigned(optIter->optionLength()) <<"\n";
+           << senf::fieldName("  length")              << unsigned(optIter->length()) <<"\n";
         senf::hexdump(boost::begin(optIter->value()) , boost::end(optIter->value()), os );
     }
 }
index 6ad1af8..b506914 100644 (file)
@@ -104,7 +104,9 @@ namespace senf {
             p->nextHeader() << key(p.next(nothrow)); }
     };
 
-    /** \brief IPv6 fragment extension packet typedef */
+    /** \brief IPv6 fragment extension packet typedef 
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<IPv6FragmentPacketType> IPv6FragmentPacket;
 
 // =====================================================================================================
@@ -209,7 +211,9 @@ namespace senf {
             p->nextHeader() << key(p.next(nothrow)); }
     };
     
-    /** \brief IPv6 routing extension packet typedef */
+    /** \brief IPv6 routing extension packet typedef
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<IPv6RoutingPacketType> IPv6RoutingPacket;
 
     
@@ -283,7 +287,9 @@ namespace senf {
             p->nextHeader() << key(p.next(nothrow)); }
     };
     
-    /** \brief IPv6 routing Hop-By-Hop packet typedef */
+    /** \brief IPv6 routing Hop-By-Hop packet typedef
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<IPv6HopByHopOptionsPacketType> IPv6HopByHopOptionsPacket;
     
 // =====================================================================================================
@@ -348,7 +354,9 @@ namespace senf {
             p->nextHeader() << key(p.next(nothrow)); }
     };
     
-    /** \brief IPv6 routing Destination Options packet typedef */
+    /** \brief IPv6 routing Destination Options packet typedef
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<IPv6DestinationOptionsPacketType> IPv6DestinationOptionsPacket;
     
 }
index a51d254..a473d85 100644 (file)
@@ -209,12 +209,12 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_parse)
     BOOST_CHECK_EQUAL( listIter->altAction(), 0u);
     BOOST_CHECK_EQUAL( listIter->changeFlag(), 0u);
     BOOST_CHECK_EQUAL( listIter->optionType(), 5u);
-    BOOST_CHECK_EQUAL( listIter->optionLength(), 2u);
+    BOOST_CHECK_EQUAL( listIter->length(), 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_CHECK_EQUAL( listIter->length(), 0);
 
     BOOST_REQUIRE( pHop_extension.next().is<senf::ICMPv6Packet>() );
     senf::ICMPv6Packet pICMPv6  (pHop_extension.next().as<senf::ICMPv6Packet>());
@@ -286,7 +286,7 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_create)
             opt.changeFlag() = 0u;
             opt.optionType() = 5u;
             unsigned char val[] = {0x00, 0x00};
-            opt.setPayload(val);
+            opt.value(val);
         }
     }
 
@@ -318,7 +318,7 @@ namespace {
         
         SENF_PARSER_INIT() {
             optionType() = typeCode;
-            optionLength() = senf::init_bytes<IPv6ChecksumOptionTLVParser>::value -senf::init_bytes<IPv6OptionTLVParser>::value;
+            length() = senf::init_bytes<IPv6ChecksumOptionTLVParser>::value -senf::init_bytes<IPv6OptionTLVParser>::value;
             slfNetType() = SN_typeCode;     
         }
         SENF_PARSER_FINALIZE ( IPv6ChecksumOptionTLVParser );
index 7fecab5..4986d3e 100644 (file)
@@ -152,10 +152,10 @@ namespace senf {
                                                in \ref IpTypes */
     };
 
-    /** \brief IPv6 packet typedef */
+    /** \brief IPv6 packet typedef
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<IPv6PacketType> IPv6Packet;
-
-    ///@}
 }
 
 ///////////////////////////////hh.e////////////////////////////////////////
index 34fca75..75977f8 100644 (file)
@@ -89,19 +89,19 @@ BOOST_AUTO_UNIT_TEST(ListOptionTypeParser_container)
         BOOST_CHECK_EQUAL( c.bytes(), 0u ); // padding bytes wont be in here, added/removed automatically in destructor
         BOOST_CHECK( c.begin() == c.end() );
 
-        unsigned char d[]  = {0x65, 0x02, 0x40, 0x34};
-        unsigned char d1[] = {0x03, 0x01, 0x77};
-        unsigned char d2[] = {0x07, 0x01, 0x13};
+        std::vector<unsigned char> d (2, 0xab);
+        std::vector<unsigned char> d1 (1, 0x77);
+        std::vector<unsigned char> d2 (1, 0x13);
 
-        SENF_CHECK_NO_THROW( c.push_back( d ) );
+        SENF_CHECK_NO_THROW( c.push_back( std::make_pair(0x65, d) ));
         BOOST_CHECK_EQUAL( c.bytes(), 4u );
         BOOST_CHECK_EQUAL( c.size(), 1u );
 
-        SENF_CHECK_NO_THROW( c.push_back( d1 ) );
+        SENF_CHECK_NO_THROW( c.push_back( std::make_pair(0x03, d1) ));
         BOOST_CHECK_EQUAL( c.bytes(), 7u );
         BOOST_CHECK_EQUAL( c.size(), 2u );
 
-        SENF_CHECK_NO_THROW( c.push_back( d2 ) );
+        SENF_CHECK_NO_THROW( c.push_back( std::make_pair(0x07, d2) ));
         BOOST_CHECK_EQUAL( c.bytes(), 10u );
         BOOST_CHECK_EQUAL( c.size(), 3u );
 
@@ -109,16 +109,16 @@ BOOST_AUTO_UNIT_TEST(ListOptionTypeParser_container)
         BOOST_CHECK_EQUAL( cIter->altAction(), 1u);
         BOOST_CHECK_EQUAL( cIter->changeFlag(), 1u);
         BOOST_CHECK_EQUAL( cIter->optionType(), 5u);
-        BOOST_CHECK_EQUAL( cIter->optionLength(), 2u);
-        BOOST_CHECK_EQUAL( *(boost::begin(cIter->value()) ), 0x40);
-        BOOST_CHECK_EQUAL( *(boost::next(boost::begin(cIter->value()) )), 0x34);
+        BOOST_CHECK_EQUAL( cIter->length(), 2u);
+        BOOST_CHECK_EQUAL( *(boost::begin(cIter->value()) ), 0xab);
+        BOOST_CHECK_EQUAL( *(boost::next(boost::begin(cIter->value()) )), 0xab);
         cIter++;
         BOOST_CHECK_EQUAL( cIter->optionType(), 3u);
-        BOOST_CHECK_EQUAL( cIter->optionLength(), 1u);
+        BOOST_CHECK_EQUAL( cIter->length(), 1u);
         BOOST_CHECK_EQUAL( *(boost::begin(cIter->value() )), 0x77);
         cIter++;
         BOOST_CHECK_EQUAL( cIter->optionType(), 7u);
-        BOOST_CHECK_EQUAL( cIter->optionLength(), 1u);
+        BOOST_CHECK_EQUAL( cIter->length(), 1u);
         BOOST_CHECK_EQUAL( *(boost::begin(cIter->value())), 0x13);
 
         //deletes first element
index 115a4a2..9f0993d 100644 (file)
@@ -100,7 +100,9 @@ namespace senf {
         static void finalize(packet p);
     };
 
-    /** \brief LLC/SNAP packet typedef */
+    /** \brief LLC/SNAP packet typedef
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<LlcSnapPacketType> LlcSnapPacket;
 }
 
index 57f9cde..3376343 100644 (file)
@@ -163,7 +163,9 @@ namespace senf {
                                                "checksum" */
     };
 
-    /** \brief TCP packet typedef */
+    /** \brief TCP packet typedef 
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<TCPPacketType> TCPPacket;
 }
 
index e03408f..2914a48 100644 (file)
@@ -113,7 +113,9 @@ namespace senf {
                                                "checksum" */
     };
 
-    /** \brief UDP packet typedef */
+    /** \brief UDP packet typedef 
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<UDPPacketType> UDPPacket;
 }
 
index 7b466bc..fce26cb 100644 (file)
@@ -47,6 +47,7 @@
 #include "ParseHelpers.hh"
 #include "DataPacket.hh"
 #include "DumpFormat.hh"
+#include "GenericTLV.hh"
 
 #undef HH_SENF_Packets_Packets__decls_
 
@@ -71,6 +72,7 @@
 #include "ParseHelpers.hh"
 #include "DataPacket.hh"
 #include "DumpFormat.hh"
+#include "GenericTLV.hh"
 
 #endif