implemented nextPacketType/Range for SNDU (yeah!)
[senf.git] / Packets / MPEGDVBBundle / SNDUPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief SNDUPacket public header */
25
26 #ifndef HH_SNDUPacket_
27 #define HH_SNDUPacket_ 1
28
29 // Custom includes
30 #include <algorithm>
31 #include <boost/crc.hpp>
32 #include "Packets/PacketType.hh"
33 #include "Packets/ParseInt.hh"
34 #include "Packets/PacketRegistry.hh"
35 #include "Packets/PacketParser.hh"
36 #include "Packets/DefaultBundle/EthernetPacket.hh"
37
38 //#include "SNDUPacket.mpp"
39 ///////////////////////////////hh.p////////////////////////////////////////
40
41 namespace senf {
42
43     /** \brief parse ULE SNDU Packet
44     
45         Parser implementing the header and trailer of a ULE SNDU Packet
46         
47         \see SNDUPacketType
48      */
49     struct Parse_SNDUPacket : public PacketParserBase
50     {
51 #       ifndef DOXYGEN
52         
53         SENF_PACKET_PARSER_NO_INIT(Parse_SNDUPacket);
54
55 #       endif
56         
57         typedef Parse_Flag      <     0 > Parse_daaf;  // Destination Address Absent Field
58         typedef Parse_UIntField < 1, 16 > Parse_length;
59                 
60         Parse_daaf d_bit() const {
61             return parse<Parse_daaf>( 0 );
62         }
63         Parse_length length() const {
64             return parse<Parse_length>( 0 );
65         }
66         Parse_UInt16 type() const {
67             return parse<Parse_UInt16>( 2 );
68         }
69         Parse_MAC destination() const {
70             BOOST_ASSERT( ! d_bit() );
71             return parse<Parse_MAC>( 4 );
72         }
73         Parse_UInt32 crc() const { 
74             return parse<Parse_UInt32>( data().size()-4 ); 
75         }
76         
77         void init() const {
78             defaultInit();
79             d_bit() = false;
80         }
81         
82         PacketParserBase::size_type bytes() const;
83         
84         static const size_type init_bytes = 2+2+4; // D-Bit + 15 bits length + 16 bits type field + 32 bits crc
85
86         boost::uint32_t calcCrc() const;
87     };
88
89     
90     struct ULEExtHeaderTypes {
91         typedef boost::uint16_t key_t;
92     };
93     
94     /** \brief ULE SNDU Packet
95         
96         \par Packet type (typedef):
97             \ref SNDUPacket
98
99         \par Fields:
100             \ref Parse_SNDUPacket
101
102         \ingroup protocolbundle_mpegdvb
103      */
104     struct SNDUPacketType
105         : public PacketTypeBase
106 //          public PacketTypeMixin<SNDUPacketType, ULEExtHeaderTypes>
107     {
108 //        typedef PacketTypeMixin<SNDUPacketType, ULEExtHeaderType> mixin;
109         typedef ConcretePacket<SNDUPacketType> packet;
110         typedef Parse_SNDUPacket parser;
111
112 //        using mixin::nextPacketRange;
113 //        using mixin::nextPacketType;
114 //        using mixin::init;
115         
116 //        static registry_key_t nextPacketKey(packet p);
117         
118         static void init(packet p);
119
120         static factory_t nextPacketType(packet p);
121         
122         static optional_range nextPacketRange(packet p);
123         
124         static void dump(packet p, std::ostream & os);
125         
126         static PacketParserBase::size_type initSize();
127         
128         static PacketParserBase::size_type initHeadSize();
129     };
130         
131     typedef SNDUPacketType::packet SNDUPacket;
132     
133     typedef boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0, false, false> ule_crc32;
134
135
136     /*!
137      \def ULE_END_INDICATOR 
138          ULE End Indicator; indicates to the receiver that there are no 
139          further SNDUs present within the current TS packet.
140     */
141 #   define ULE_END_INDICATOR 0xffff
142 }
143
144
145 ///////////////////////////////hh.e////////////////////////////////////////
146 //#include "SNDUPacket.cci"
147 //#include "SNDUPacket.ct"
148 //#include "SNDUPacket.cti"
149 #endif
150
151 \f
152 // Local Variables:
153 // mode: c++
154 // fill-column: 100
155 // c-file-style: "senf"
156 // indent-tabs-mode: nil
157 // ispell-local-dictionary: "american"
158 // compile-command: "scons -u test"
159 // comment-column: 40
160 // End: