refactored MPESection (deleted DSMCCSection & DatagramSection); crc calculation doesn...
tho [Fri, 7 Dec 2007 14:43:26 +0000 (14:43 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@547 270642c3-0616-0410-b53a-bc976706d245

Packets/DefaultBundle/SConscript
Packets/MPEGDVBBundle/DSMCCSection.cc [deleted file]
Packets/MPEGDVBBundle/DSMCCSection.hh [deleted file]
Packets/MPEGDVBBundle/DatagramSection.cc [deleted file]
Packets/MPEGDVBBundle/DatagramSection.hh [deleted file]
Packets/MPEGDVBBundle/MPESection.cc [new file with mode: 0644]
Packets/MPEGDVBBundle/MPESection.hh [new file with mode: 0644]
Packets/MPEGDVBBundle/MPESection.test.cc [new file with mode: 0644]
Packets/MPEGDVBBundle/SConscript

index 0514a40..4d765df 100644 (file)
@@ -9,9 +9,14 @@ sources = SENFSCons.GlobSources()
 
 SENFSCons.StandardTargets(env)
 
-SENFSCons.Object(env, target = 'DefaultBundle', sources=sources,
-                 LIBS = ['Packets', 'Socket', 'Utils'])
-SENFSCons.Lib(env, library = 'Packets_DefaultBundle', sources = sources[0],
-              LIBS = ['Packets', 'Socket', 'Utils'], no_includes = 1)
+SENFSCons.Object(env, 
+    target = 'DefaultBundle', 
+    sources=sources,
+    LIBS = ['Packets', 'Socket', 'Utils'])
+
+SENFSCons.Lib(env, 
+    library = 'Packets_DefaultBundle',
+    sources = sources[0],
+    no_includes = 1)
                  
 SENFSCons.Doxygen(env)
diff --git a/Packets/MPEGDVBBundle/DSMCCSection.cc b/Packets/MPEGDVBBundle/DSMCCSection.cc
deleted file mode 100644 (file)
index d0c8b34..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-// $Id$
-//
-// Copyright (C) 2007
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Thorsten Horstmann <thorsten.horstmann@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 DSMCCSection non-inline non-template implementation */
-
-#include "DSMCCSection.hh"
-//#include "DSMCCSection.ih"
-
-// Custom includes
-#include <iomanip>
-
-#define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
-
-//namespace {
-//    senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::EthVLanPacketType>
-//        registerEthVLanPacket(0x8100);
-//}
-
-
-prefix_ void senf::DSMCCSectionType::dump(packet p, std::ostream & os)
-{
-    os << "DSMCC Section:\n"
-       << std::hex
-       << "  table_id: 0x" << unsigned(p->table_id()) << "\n"
-       << "  section_syntax_indicator: " << p->ssi() << "\n"
-       << "  private_indicator: " << p->private_indicator() << "\n"
-       << std::dec
-       << "  section_length: " << p->sec_length() << "\n"
-       << std::hex 
-       << "  table_id_extension: " << p->table_id_extension() << "\n"
-       << "  version_number: " << p->version_num() << "\n"
-       << "  current_next_indicator: " << p->curr_next_indicator() << "\n"
-       << "  section_number: " << unsigned(p->sec_num()) << "\n"
-       << "  last_section_number: " << unsigned(p->last_sec_num()) << "\n"
-       << std::dec
-       << "  CRC: " << unsigned(p->crc()) << "\n";
-}
-
-prefix_ senf::PacketParserBase::size_type senf::DSMCCSectionType::initSize()
-{
-    return parser::fixed_bytes + 32/8;
-}
-
-prefix_ senf::PacketParserBase::size_type senf::DSMCCSectionType::initHeadSize()
-{
-    return parser::fixed_bytes;
-}
-
-///////////////////////////////cc.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:
diff --git a/Packets/MPEGDVBBundle/DSMCCSection.hh b/Packets/MPEGDVBBundle/DSMCCSection.hh
deleted file mode 100644 (file)
index e6c2cef..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-// $Id:DSMCCSection.hh 327 2007-07-20 10:03:44Z tho $
-//
-// Copyright (C) 2007
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Thorsten Horstmann <thorsten.horstmann@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 DSMCCSection public header */
-
-#ifndef HH_DSMCCSection_
-#define HH_DSMCCSection_ 1
-
-// Custom includes
-#include <algorithm>
-#include "../../Packets/Packets.hh"
-
-//#include "DSMCCSection.mpp"
-///////////////////////////////hh.p////////////////////////////////////////
-
-namespace senf {
-
-    /** \brief Parse a DSMCC Section
-    
-        Parser implementing the header of a DSMCC Section
-        
-        \see DSMCCSectionType
-     */
-    struct Parse_DSMCCSection : public PacketParserBase
-    {
-#       include SENF_FIXED_PARSER()
-
-        SENF_PARSER_FIELD    ( table_id            , Parse_UInt8   );
-        
-        SENF_PARSER_BITFIELD ( ssi                 ,  1 , bool     );
-        SENF_PARSER_BITFIELD ( private_indicator   ,  1 , bool     );
-        SENF_PARSER_SKIP_BITS( 2 );
-        SENF_PARSER_BITFIELD ( sec_length          , 12 , unsigned );
-        
-        SENF_PARSER_FIELD    ( table_id_extension  , Parse_UInt16  );
-        
-        SENF_PARSER_SKIP_BITS( 2 );
-        SENF_PARSER_BITFIELD ( version_num         ,  5 , unsigned );
-        SENF_PARSER_BITFIELD ( curr_next_indicator ,  1 , bool     );
-
-        SENF_PARSER_FIELD    ( sec_num             , Parse_UInt8   );
-        SENF_PARSER_FIELD    ( last_sec_num        , Parse_UInt8   );
-
-        SENF_PARSER_FINALIZE( Parse_DSMCCSection );
-
-        Parse_UInt32 crc() const { return parse<Parse_UInt32>( data().size()-4 ); }
-    };
-    
-    /** \brief DSMCC Section
-        
-        \par Packet type (typedef):
-            \ref DSMCCSection
-
-        \par Fields:
-            \ref Parse_DSMCCSection
-
-        \ingroup protocolbundle_mpegdvb
-     */
-    struct DSMCCSectionType
-        : public PacketTypeBase,
-          public PacketTypeMixin<DSMCCSectionType>
-    {
-        typedef PacketTypeMixin<DSMCCSectionType> mixin;
-        typedef ConcretePacket<DSMCCSectionType> packet;
-        typedef Parse_DSMCCSection parser;
-
-        using mixin::nextPacketRange;
-//          using mixin::nextPacketType;
-        using mixin::init;
-        
-        static void dump(packet p, std::ostream & os);
-        
-        static PacketParserBase::size_type initSize();
-        static PacketParserBase::size_type initHeadSize();
-    };
-        
-    typedef DSMCCSectionType::packet DSMCCSection;
-}
-
-
-///////////////////////////////hh.e////////////////////////////////////////
-//#include "DSMCCSection.cci"
-//#include "DSMCCSection.ct"
-//#include "DSMCCSection.cti"
-#endif
-
-\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:
diff --git a/Packets/MPEGDVBBundle/DatagramSection.cc b/Packets/MPEGDVBBundle/DatagramSection.cc
deleted file mode 100644 (file)
index e34c3c3..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-// $Id$
-//
-// Copyright (C) 2007
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Thorsten Horstmann <thorsten.horstmann@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 DatagramSection non-inline non-template implementation */
-
-#include "DatagramSection.hh"
-//#include "DatagramSection.ih"
-
-// Custom includes
-#include <iomanip>
-
-#define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
-
-//namespace {
-//    senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::EthVLanPacketType>
-//        registerEthVLanPacket(0x8100);
-//}
-
-
-prefix_ void senf::DatagramSectionType::dump(packet p, std::ostream & os)
-{
-    os << "Datagram Section (MPE):\n"
-       << std::hex
-       << "  table_id: 0x" << unsigned(p->table_id()) << "\n"
-       << "  section_syntax_indicator: " << p->ssi() << "\n"
-       << "  private_indicator: " << p->private_indicator() << "\n"
-       << std::dec
-       << "  section_length: " << p->sec_length() << "\n"
-       << std::hex 
-       << "  MAC_address_6: " << unsigned(p->mac_addr_6()) << "\n"
-       << "  MAC_address_5: " << unsigned(p->mac_addr_5()) << "\n"
-       << "  payload_scrambling_control: " << p->payload_scrmbl_ctrl() << "\n"
-       << "  address_scrambling_control: " << p-> addr_scrmbl_ctrl()  << "\n"
-       << "  LLC_SNAP_flag: " << p->llc_snap_flag() << "\n"
-       << "  current_next_indicator: " << p->curr_next_indicator() << "\n"
-       << "  section_number: " << unsigned(p->sec_num()) << "\n"
-       << "  last_section_number: " << unsigned(p->last_sec_num()) << "\n"
-       << "  MAC_address_4: " << unsigned(p->mac_addr_4()) << "\n"
-       << "  MAC_address_3: " << unsigned(p->mac_addr_3()) << "\n"
-       << "  MAC_address_2: " << unsigned(p->mac_addr_2()) << "\n"
-       << "  MAC_address_1: " << unsigned(p->mac_addr_1()) << "\n"
-       << std::dec
-       << "  CRC: " << unsigned(p->crc()) << "\n";
-}
-
-prefix_ senf::PacketParserBase::size_type senf::DatagramSectionType::initSize()
-{
-    return parser::fixed_bytes + 32/8;
-}
-
-prefix_ senf::PacketParserBase::size_type senf::DatagramSectionType::initHeadSize()
-{
-    return parser::fixed_bytes;
-}
-
-///////////////////////////////cc.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:
diff --git a/Packets/MPEGDVBBundle/DatagramSection.hh b/Packets/MPEGDVBBundle/DatagramSection.hh
deleted file mode 100644 (file)
index bf5d87a..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-// $Id:DatagramSection.hh 327 2007-07-20 10:03:44Z tho $
-//
-// Copyright (C) 2007
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Thorsten Horstmann <thorsten.horstmann@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.
-
-/** \brief
-    \file DatagramSection public header */
-
-#ifndef HH_DatagramSection_
-#define HH_DatagramSection_ 1
-
-// Custom includes
-#include <algorithm>
-#include "../../Packets/Packets.hh"
-#include "DSMCCSection.hh"
-
-
-//#include "DatagramSection.mpp"
-///////////////////////////////hh.p////////////////////////////////////////
-
-namespace senf {
-
-    /** \brief Parse a Datagram Section
-    
-        Parser implementing the Datagram Section.
-    
-        \see DatagramSectionType
-     */
-    struct Parse_DatagramSection : public Parse_DSMCCSection
-    {
-#       include SENF_FIXED_PARSER()
-
-        SENF_PARSER_INHERIT( Parse_DSMCCSection );
-
-        SENF_PARSER_FIELD    ( mac_addr_4          , Parse_UInt8  );
-        SENF_PARSER_FIELD    ( mac_addr_3          , Parse_UInt8  );
-        SENF_PARSER_FIELD    ( mac_addr_2          , Parse_UInt8  );
-        SENF_PARSER_FIELD    ( mac_addr_1          , Parse_UInt8  );
-
-        SENF_PARSER_FINALIZE( Parse_DatagramSection );
-
-        // Parse table_id_extension as two bytes
-        SENF_PARSER_GOTO( table_id_extension );
-        SENF_PARSER_FIELD    ( mac_addr_6          , Parse_UInt8  );
-        SENF_PARSER_FIELD    ( mac_addr_5          , Parse_UInt8  );
-
-        // Divide 5 bit version_num field into several subfields.
-        SENF_PARSER_SKIP_BITS( 2 );
-        SENF_PARSER_BITFIELD ( payload_scrmbl_ctrl ,  2, unsigned );
-        SENF_PARSER_BITFIELD ( addr_scrmbl_ctrl    ,  2, unsigned );
-        SENF_PARSER_BITFIELD ( llc_snap_flag       ,  1, bool     );
-    };
-
-    /** \brief Datagram Section
-        
-        \par Packet type (typedef):
-            \ref DatagramSection
-
-        \par Fields:
-            \ref Parse_DatagramSection
-
-        \ingroup protocolbundle_mpegdvb
-     */
-    struct DatagramSectionType
-        : public DSMCCSectionType,
-          public PacketTypeMixin<DatagramSectionType>
-    {
-        typedef PacketTypeMixin<DatagramSectionType> mixin;
-        typedef ConcretePacket<DatagramSectionType> packet;
-        typedef Parse_DatagramSection parser;
-
-        using mixin::nextPacketRange;
-        using mixin::init;
-        
-        static void dump(packet p, std::ostream & os);
-        
-        static PacketParserBase::size_type initSize();
-        static PacketParserBase::size_type initHeadSize();
-    };
-        
-    typedef DatagramSectionType::packet DatagramSection;
-}
-
-
-///////////////////////////////hh.e////////////////////////////////////////
-//#include "DatagramSection.cci"
-//#include "DatagramSection.ct"
-//#include "DatagramSection.cti"
-#endif
-
-\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:
diff --git a/Packets/MPEGDVBBundle/MPESection.cc b/Packets/MPEGDVBBundle/MPESection.cc
new file mode 100644 (file)
index 0000000..d6b2d5e
--- /dev/null
@@ -0,0 +1,119 @@
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
+// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+//     Thorsten Horstmann <thorsten.horstmann@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 MPESection non-inline non-template implementation */
+
+#include "MPESection.hh"
+//#include "MPESection.ih"
+
+// Custom includes
+#include <iomanip>
+#include <boost/io/ios_state.hpp>
+#include "../../Packets/DefaultBundle/LlcSnapPacket.hh"
+#include "../../Packets/DefaultBundle/IPv4Packet.hh"
+#include "../../Packets/DefaultBundle/IPv6Packet.hh"
+
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+//prefix_ boost::uint32_t senf::Parse_MPESection::calcCrc()
+//    const
+//{
+//    return std::for_each(
+//            data().begin(), 
+//            boost::prior(data().end(), 4), 
+//            crc32_t() ).checksum();
+//}
+
+
+prefix_ void senf::MPESectionType::dump(packet p, std::ostream & os)
+{
+    boost::io::ios_all_saver ias(os);
+    os << "MPE Section:\n"
+       << std::hex
+       << "  table_id: 0x" << unsigned(p->table_id()) << "\n"
+       << "  section_syntax_indicator: " << p->section_syntax_indicator() << "\n"
+       << "  private_indicator: " << p->private_indicator() << "\n"
+       << std::dec
+       << "  section_length: " << p->section_length() << "\n"
+       << std::hex 
+       << "  MAC_address_6: 0x" << unsigned(p->mac_addr_6()) << "\n"
+       << "  MAC_address_5: 0x" << unsigned(p->mac_addr_5()) << "\n"
+       << "  payload_scrambling_control: 0x" << p->payload_scrmbl_ctrl() << "\n"
+       << "  address_scrambling_control: 0x" << p-> addr_scrmbl_ctrl()  << "\n"
+       << "  LLC_SNAP_flag: 0x" << p->llc_snap_flag() << "\n"
+       << "  current_next_indicator: 0x" << p->curr_next_indicator() << "\n"
+       << "  section_number: 0x" << unsigned(p->section_num()) << "\n"
+       << "  last_section_number: 0x" << unsigned(p->last_section_num()) << "\n"
+       << "  real_time_parameters: \n"
+       << "    delta_t: 0x" << unsigned(p->real_time_parameters().delta_t()) << "\n"
+       << "    table_boundary: 0x" << unsigned(p->real_time_parameters().table_boundary()) << "\n"
+       << "    frame_boundary: 0x" << unsigned(p->real_time_parameters().frame_boundary()) << "\n"
+       << "    address: 0x" << unsigned(p->real_time_parameters().address()) << "\n"
+       << std::dec
+       << "  CRC: " << unsigned(p->crc()) << "\n";
+}
+
+prefix_ senf::PacketParserBase::size_type senf::MPESectionType::initSize()
+{
+    return parser::fixed_bytes + 32/8;
+}
+
+prefix_ senf::PacketParserBase::size_type senf::MPESectionType::initHeadSize()
+{
+    return parser::fixed_bytes;
+}
+
+prefix_ senf::PacketInterpreterBase::factory_t senf::MPESectionType::nextPacketType(packet p)
+{
+    if (p.data().size() > initSize()+1) {
+        if (p->llc_snap_flag())
+            return LlcSnapPacket::factory();
+        if (p->ip_datagram_version().value() == 4)
+            return IPv4Packet::factory();
+        if (p->ip_datagram_version().value() == 6)
+            return IPv4Packet::factory();
+    }
+    return no_factory();
+}
+
+prefix_ void senf::MPESectionType::finalize(packet p)
+{
+    p->llc_snap_flag() = p.next().is<LlcSnapPacket>() ? 1 : 0;
+    p->section_length() = p.data().size() - 3;
+//    p->crc() = p->calcCrc();
+}
+
+///////////////////////////////cc.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:
diff --git a/Packets/MPEGDVBBundle/MPESection.hh b/Packets/MPEGDVBBundle/MPESection.hh
new file mode 100644 (file)
index 0000000..0bf928b
--- /dev/null
@@ -0,0 +1,154 @@
+// $Id:DSMCCSection.hh 327 2007-07-20 10:03:44Z tho $
+//
+// Copyright (C) 2007
+// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
+// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+//     Thorsten Horstmann <thorsten.horstmann@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 MPESection public header */
+
+#ifndef HH_MPESection_
+#define HH_MPESection_ 1
+
+// Custom includes
+#include <boost/crc.hpp>
+#include <algorithm>
+#include "../../Packets/Packets.hh"
+
+//#include "MPESection.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace senf {
+
+    struct Parse_MPERealTimeParameters : public PacketParserBase
+    {
+#       include SENF_FIXED_PARSER()
+
+        SENF_PARSER_BITFIELD ( delta_t,                  12, unsigned );
+        SENF_PARSER_BITFIELD ( table_boundary,           1,  bool     );
+        SENF_PARSER_BITFIELD ( frame_boundary,           1,  bool     );
+        SENF_PARSER_BITFIELD ( address,                  18, unsigned );
+        
+        SENF_PARSER_FINALIZE( Parse_MPERealTimeParameters );
+    };
+    
+
+    /** \brief Parse a MPE Section
+    
+        Parser implementing the header of a MPE Section
+        
+        \see MPESectionType
+     */
+    struct Parse_MPESection : public PacketParserBase
+    {
+#       include SENF_FIXED_PARSER()
+
+        SENF_PARSER_FIELD( table_id, Parse_UInt8 );
+        
+        SENF_PARSER_BITFIELD        ( section_syntax_indicator, 1,  bool     );
+        SENF_PARSER_BITFIELD        ( private_indicator,        1,  bool     );
+        SENF_PARSER_PRIVATE_BITFIELD( reserved_1,               2,  unsigned );
+        SENF_PARSER_BITFIELD        ( section_length,           12, unsigned );
+        
+        SENF_PARSER_FIELD( mac_addr_6, Parse_UInt8 );
+        SENF_PARSER_FIELD( mac_addr_5, Parse_UInt8 );
+        
+        SENF_PARSER_PRIVATE_BITFIELD( reserved_2,          2, unsigned );
+        SENF_PARSER_BITFIELD        ( payload_scrmbl_ctrl, 2, unsigned );
+        SENF_PARSER_BITFIELD        ( addr_scrmbl_ctrl,    2, unsigned );
+        SENF_PARSER_BITFIELD        ( llc_snap_flag,       1, bool     );
+        SENF_PARSER_BITFIELD        ( curr_next_indicator, 1, bool     );
+
+        SENF_PARSER_FIELD( section_num,      Parse_UInt8 );
+        SENF_PARSER_FIELD( last_section_num, Parse_UInt8 );
+
+        SENF_PARSER_FIELD( real_time_parameters, Parse_MPERealTimeParameters );
+        
+        SENF_PARSER_FINALIZE( Parse_MPESection );
+        
+        SENF_PARSER_PRIVATE_BITFIELD( ip_datagram_version, 4, unsigned );
+        
+        SENF_PARSER_INIT() {
+            table_id() = 0x3e;
+            section_syntax_indicator() = 1;
+            private_indicator() = 0;
+            reserved_1() = 3;
+            reserved_2() = 3;
+            payload_scrmbl_ctrl() = 0;
+            addr_scrmbl_ctrl() = 0;
+            curr_next_indicator() = 1;
+        }
+        
+        Parse_UInt32 crc() const { return parse<Parse_UInt32>( data().size()-4 ); }
+        
+//        typedef boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0, false, false> crc32_t;
+//        boost::uint32_t calcCrc() const;
+        
+        friend class MPESectionType;
+    };
+    
+    
+    /** \brief MPE Section
+        
+        \par Packet type (typedef):
+            \ref MPESection
+
+        \par Fields:
+            \ref Parse_MPESection
+
+        \ingroup protocolbundle_mpegdvb
+     */
+    struct MPESectionType
+        : public PacketTypeBase,
+          public PacketTypeMixin<MPESectionType>
+    {
+        typedef PacketTypeMixin<MPESectionType> mixin;
+        typedef ConcretePacket<MPESectionType> packet;
+        typedef Parse_MPESection parser;
+
+        using mixin::nextPacketRange;
+        using mixin::init;
+        
+        static void dump(packet p, std::ostream & os);
+        static void finalize(packet p);
+        static factory_t nextPacketType(packet p);
+        static PacketParserBase::size_type initSize();
+        static PacketParserBase::size_type initHeadSize();
+    };
+        
+    typedef ConcretePacket<MPESectionType> MPESection;
+}
+
+
+///////////////////////////////hh.e////////////////////////////////////////
+//#include "MPESection.cci"
+//#include "MPESection.ct"
+//#include "MPESection.cti"
+#endif
+
+\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:
diff --git a/Packets/MPEGDVBBundle/MPESection.test.cc b/Packets/MPEGDVBBundle/MPESection.test.cc
new file mode 100644 (file)
index 0000000..f639241
--- /dev/null
@@ -0,0 +1,176 @@
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
+// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+//     Thorsten Horstmann <thorsten.horstmann@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.
+
+// Unit tests
+
+//#include "MPESection.test.hh"
+//#include "MPESection.test.ih"
+
+// Custom includes
+#include "MPESection.hh"
+
+#include "../../Utils/auto_unit_test.hh"
+#include "../../Packets/DefaultBundle/LlcSnapPacket.hh"
+#include "../../Packets/DefaultBundle/EthernetPacket.hh"
+#include "../../Packets/DefaultBundle/IPv4Packet.hh"
+#include <boost/test/test_tools.hpp>
+#include <senf/Utils/hexdump.hh>
+
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+using namespace senf;
+
+BOOST_AUTO_UNIT_TEST(MPESection_parse_chain)
+{
+    // MPE section captured with dvbsnoop
+    unsigned char data[] = { 
+            // MPE Header
+            0x3e, 0xb0, 0x77, 0x00, 0x00, 0xc3, 0x00, 0x00,
+            0x04, 0xd8, 0x12, 0x0c,
+            // LLC/SNAP Header
+            0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x00, 0x62,
+            // Ethernet Header
+            0x01, 0x00, 0x5e, 0x01, 0x02, 0x03, 0x12, 0xb0,
+            0x43, 0x61, 0x5d, 0x99, 0x08, 0x00, 
+            // IPv4 Header
+            0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
+            0x01, 0x01, 0xc6, 0xfb, 0xc0, 0xa8, 0x01, 0x01,
+            0xef, 0x01, 0x02, 0x03, 
+            // Payload (ICMP)
+            0x08, 0x00, 0x0e, 0xa3, 0xf2, 0x72, 0x55, 0xea, 
+            0xa2, 0xae, 0x56, 0x47, 0xbb, 0x06, 0x02, 0x00, 
+            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+            0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
+            0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 
+            0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 
+            0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 
+            0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+            // MPE Trailer (crc)
+            0xb5, 0x77, 0x4c, 0x3c
+    };
+            
+    senf::MPESection sec (senf::MPESection::create(data));
+    
+    BOOST_CHECK_EQUAL(   sec->table_id(),                0x3eu       );
+    BOOST_CHECK(         sec->section_syntax_indicator()             );
+    BOOST_CHECK(       ! sec->private_indicator()                    );
+    BOOST_CHECK_EQUAL(   sec->section_length(),          0x77u       );
+    BOOST_CHECK_EQUAL(   sec->mac_addr_6(),              0x0u        );
+    BOOST_CHECK_EQUAL(   sec->mac_addr_5(),              0x0u        );
+    BOOST_CHECK_EQUAL(   sec->payload_scrmbl_ctrl(),     0x0u        );
+    BOOST_CHECK_EQUAL(   sec->addr_scrmbl_ctrl(),        0x0u        );
+    BOOST_CHECK      (   sec->llc_snap_flag()                        );
+    BOOST_CHECK      (   sec->curr_next_indicator()                  );
+    BOOST_CHECK_EQUAL(   sec->section_num(),             0x0u        );
+    BOOST_CHECK_EQUAL(   sec->last_section_num(),        0x0u        );
+    BOOST_CHECK_EQUAL(   sec->real_time_parameters().delta_t(),        0x4du   );
+    BOOST_CHECK_EQUAL(   sec->real_time_parameters().table_boundary(), 1       );
+    BOOST_CHECK_EQUAL(   sec->real_time_parameters().frame_boundary(), 0       );
+    BOOST_CHECK_EQUAL(   sec->real_time_parameters().address(),        0x120cu );
+    BOOST_CHECK_EQUAL(   sec->crc(), 3044494396u                     );
+    
+    BOOST_REQUIRE( sec.next().is<senf::LlcSnapPacket>() );
+    senf::LlcSnapPacket llcsnap (sec.next().as<senf::LlcSnapPacket>());
+
+    BOOST_CHECK_EQUAL( llcsnap->dsap(), 0xaau        );
+    BOOST_CHECK_EQUAL( llcsnap->ssap(), 0xaau        );
+    BOOST_CHECK_EQUAL( llcsnap->ctrl(), 0x3u         );
+    BOOST_CHECK_EQUAL( llcsnap->protocolId(), 0u     );
+    BOOST_CHECK_EQUAL( llcsnap->type_length(), 0x62u );
+
+    BOOST_REQUIRE( llcsnap.next().is<senf::EthernetPacket>() );
+    senf::EthernetPacket eth (llcsnap.next().as<senf::EthernetPacket>());
+    
+    BOOST_CHECK_EQUAL( eth->destination().value(), senf::MACAddress::from_string("01:00:5e:01:02:03") );
+    BOOST_CHECK_EQUAL( eth->source().value(),      senf::MACAddress::from_string("12:b0:43:61:5d:99") );
+    BOOST_CHECK_EQUAL( eth->type_length(),         0x800u                                             );
+
+    BOOST_REQUIRE( eth.next().is<senf::IPv4Packet>() );
+    senf::IPv4Packet ip (eth.next().as<senf::IPv4Packet>());
+    
+    BOOST_CHECK_EQUAL( ip->version(),    0x4u   );
+    BOOST_CHECK_EQUAL( ip->ihl(),        0x5u   );
+    BOOST_CHECK_EQUAL( ip->tos(),        0x0u   );
+    BOOST_CHECK_EQUAL( ip->length(),     0x54u  );
+    BOOST_CHECK_EQUAL( ip->identifier(), 0x0u   );
+    BOOST_CHECK_EQUAL( ip->df(),         1      );
+    BOOST_CHECK_EQUAL( ip->mf(),         0      );
+    BOOST_CHECK_EQUAL( ip->frag(),       0x0u   );
+    BOOST_CHECK_EQUAL( ip->ttl(),        1      );
+    BOOST_CHECK_EQUAL( ip->protocol(),   1      );
+    BOOST_CHECK_EQUAL( ip->checksum(),   0xc6fb );
+    BOOST_CHECK_EQUAL( ip->source().value(),      senf::INet4Address::from_string("192.168.1.1") );
+    BOOST_CHECK_EQUAL( ip->destination().value(), senf::INet4Address::from_string("239.1.2.3")   );
+}
+
+
+BOOST_AUTO_UNIT_TEST(MPESection_create)
+{
+    senf::MPESection sec (senf::MPESection::create());
+    sec->real_time_parameters().delta_t()        = 0x4du;
+    sec->real_time_parameters().table_boundary() = 1;
+    sec->real_time_parameters().frame_boundary() = 0;
+    sec->real_time_parameters().address()        = 0x120cu;
+    
+    senf::LlcSnapPacket llcsnap (senf::LlcSnapPacket::createAfter(sec));
+    
+    senf::EthernetPacket eth (senf::EthernetPacket::createAfter(llcsnap));
+    eth->destination() = senf::MACAddress::from_string("01:00:5e:01:02:03");
+    eth->source()      = senf::MACAddress::from_string("12:b0:43:61:5d:99");
+    
+    senf::IPv4Packet ip (senf::IPv4Packet::createAfter(eth));
+    ip->df()          = 1;
+    ip->ttl()         = 1;
+    ip->protocol()    = 1;
+    ip->source()      = senf::INet4Address::from_string("192.168.1.1");
+    ip->destination() = senf::INet4Address::from_string("239.1.2.3");
+    
+    unsigned char payload_data[] = { 
+            // Payload (ICMP)
+            0x08, 0x00, 0x0e, 0xa3, 0xf2, 0x72, 0x55, 0xea, 
+            0xa2, 0xae, 0x56, 0x47, 0xbb, 0x06, 0x02, 0x00, 
+            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+            0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
+            0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 
+            0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 
+            0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 
+            0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
+    };
+    senf::DataPacket payload (senf::DataPacket::createAfter(ip, payload_data));
+    
+    sec.finalize();
+}
+
+///////////////////////////////cc.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 8529e7b..c219242 100644 (file)
@@ -9,10 +9,15 @@ sources = SENFSCons.GlobSources()
 
 SENFSCons.StandardTargets(env)
 
-SENFSCons.Object(env, target = 'MPEGDVBBundle', sources=sources,
-                 LIBS = ['Packets', 'Socket', 'Utils'])
-SENFSCons.Lib(env, library = 'Packets_MPEGDVBBundle', sources = sources[0],
-              LIBS = ['Packets', 'Socket', 'Utils'], no_includes = 1)
+SENFSCons.Object(env, 
+    target = 'MPEGDVBBundle', 
+    sources = sources,
+    LIBS = ['Packets_DefaultBundle', 'Packets', 'Socket', 'Utils'])
+
+SENFSCons.Lib(env, 
+    library = 'Packets_MPEGDVBBundle', 
+    sources = sources[0],
+    no_includes = 1)
 
 SENFSCons.Doxygen(env, extra_sources = [
     env.Dia2Png("TLV.dia")