implemented nextPacketType/Range for SNDU (yeah!)
tho [Mon, 6 Aug 2007 14:54:43 +0000 (14:54 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@380 270642c3-0616-0410-b53a-bc976706d245

Examples/DVBAdapter/SConscript
Examples/DVBAdapter/ULEdec.cc
Packets/MPEGDVBBundle/SNDUPacket.cc
Packets/MPEGDVBBundle/SNDUPacket.hh
Packets/PacketType.hh

index c1618e3..c6de76e 100644 (file)
@@ -11,4 +11,5 @@ for f in glob.glob('*.cc'):
     
     SENFSCons.Binary(env, bin, f,
                  LIBS = [ 'Scheduler', 'Packets', 'Socket', 'Utils' ],
-                 OBJECTS = [ '#/Packets/MPEGDVBBundle/MPEGDVBBundle.o' ]);
+                 OBJECTS = [ '#/Packets/DefaultBundle/DefaultBundle.o',
+                             '#/Packets/MPEGDVBBundle/MPEGDVBBundle.o' ]);
index 786f07e..9eccad3 100644 (file)
@@ -178,8 +178,7 @@ ULEdec::iterator ULEdec::readContSNDUPacket(iterator i, iterator const i_end)
 ULEdec::iterator ULEdec::readNewSNDUPacket(iterator i, iterator const i_end)
 { 
     bool dbit = false;
-    senf::Packet::size_type sndu_length;
-    sndu_length = *i++ << 8 | *i++;
+    senf::Packet::size_type sndu_length = *i++ << 8 | *i++;
     if (sndu_length & 0x8000) {
         sndu_length &= 0x7FFF;
         dbit = true;
@@ -229,6 +228,12 @@ void ULEdec::handleSNDUPacket()
     if (this->snduPacket->crc() != this->snduPacket->calcCrc()) {
         throw ULEdecException("CRC Error");
     }
+//    senf::Packet nextPacket = this->snduPacket.next();
+//    senf::hexdump(
+//            nextPacket.data().begin(),
+//            nextPacket.data().end(),
+//            std::cout);
+    
 }
 
 
index 25ebb58..900b3db 100644 (file)
@@ -29,6 +29,7 @@
 // Custom includes
 #include <iomanip>
 #include "Utils/hexdump.hh"
+#include "Packets/DefaultBundle/EthernetPacket.hh"
 
 
 #define prefix_
@@ -58,11 +59,51 @@ prefix_ boost::uint32_t senf::Parse_SNDUPacket::calcCrc()
             ule_crc32() ).checksum();
 }
 
+//prefix_ senf::SNDUPacketType::registry_key_t senf::SNDUPacketType::nextPacketKey(packet p)
+//{
+//    return p->type(); 
+//}
+
+prefix_ void senf::SNDUPacketType::init(packet p)
+{
+    p->init();
+}
+
+prefix_ senf::PacketInterpreterBase::factory_t senf::SNDUPacketType::nextPacketType(packet p)
+{
+    if (p.data().size() < 8)
+        return no_factory();
+    PkReg_Entry const * e;
+    if (p->type() < 1536)
+        e = PacketRegistry<senf::ULEExtHeaderTypes>::lookup( p->type(), nothrow );
+    else
+        e = PacketRegistry<senf::EtherTypes>::lookup( 0x86dd, nothrow );
+    return e ? e->factory() : no_factory();
+}
+
+prefix_ senf::PacketInterpreterBase::optional_range 
+senf::SNDUPacketType::nextPacketRange(packet p) 
+{
+    if (p.data().size() < 8)
+        return no_range();
+    
+    size_type sz = 2 + 2;  // D-Bit + 15 bits length + 16 bits type field
+    if (! p->d_bit() )
+        sz += 6;  // + 6 Byte NPA destination address
+    return range(
+            boost::next(p.data().begin(), sz),
+            boost::prior(p.data().end(), 4));  // - 32 bits crc
+}
+
 prefix_ void senf::SNDUPacketType::dump(packet p, std::ostream & os)
 {
     os << "SNDUPacket:\n"
+       << std::dec
        << "  d_bit: " << p->d_bit() << "\n"
        << "  length: " << unsigned(p->length()) << "\n"
+       << std::hex
+       << "  type: 0x" << unsigned(p->type()) << "\n"
+       << std::dec
        << "  crc: " << unsigned(p->crc()) << "\n";
 }
 
index 4ab5824..d2a00fa 100644 (file)
@@ -86,6 +86,11 @@ namespace senf {
         boost::uint32_t calcCrc() const;
     };
 
+    
+    struct ULEExtHeaderTypes {
+        typedef boost::uint16_t key_t;
+    };
+    
     /** \brief ULE SNDU Packet
         
         \par Packet type (typedef):
@@ -97,20 +102,29 @@ namespace senf {
         \ingroup protocolbundle_mpegdvb
      */
     struct SNDUPacketType
-        : public PacketTypeBase,
-          public PacketTypeMixin<SNDUPacketType>
+        : public PacketTypeBase
+//          public PacketTypeMixin<SNDUPacketType, ULEExtHeaderTypes>
     {
-        typedef PacketTypeMixin<SNDUPacketType> mixin;
+//        typedef PacketTypeMixin<SNDUPacketType, ULEExtHeaderType> mixin;
         typedef ConcretePacket<SNDUPacketType> packet;
         typedef Parse_SNDUPacket parser;
 
-        using mixin::nextPacketRange;
-//          using mixin::nextPacketType;
-        using mixin::init;
+//        using mixin::nextPacketRange;
+//        using mixin::nextPacketType;
+//        using mixin::init;
+        
+//        static registry_key_t nextPacketKey(packet p);
+        
+        static void init(packet p);
+
+        static factory_t nextPacketType(packet p);
+        
+        static optional_range nextPacketRange(packet p);
         
         static void dump(packet p, std::ostream & os);
         
         static PacketParserBase::size_type initSize();
+        
         static PacketParserBase::size_type initHeadSize();
     };
         
index 02a11c3..863f966 100644 (file)
@@ -266,7 +266,7 @@ namespace senf {
                 // Return the key in the registry under which the next packet
                 // header is to be found. This member must be given if a Registry argument is
                 // passed to the PacketTypeMixin template.
-                return i.fields().typeField();
+                return p->typeField();
             }
 
             static void finalize(packet p)