Packets: Some more porting of old parsers to the new parse helpers
[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 //     Thorsten Horstmann <thorsten.horstmann@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/Packets.hh"
33 #include "../DefaultBundle/EthernetPacket.hh"
34
35 //#include "SNDUPacket.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 namespace senf {
39
40     /** \brief parse ULE SNDU Packet
41     
42         Parser implementing the header and trailer of a ULE SNDU Packet
43         
44         \see SNDUPacketType
45      */
46     struct Parse_SNDUPacket : public PacketParserBase
47     {
48 #       include SENF_PARSER()
49
50         SENF_PARSER_BITFIELD     ( d_bit       ,  1 , bool     );
51         SENF_PARSER_BITFIELD     ( length      , 15 , unsigned );
52
53         SENF_PARSER_FIELD        ( type        , Parse_UInt16  );
54
55         // This field only exists, if d_bit() is *not* set. New SNDUPackets are created with d_bit()
56         // set to 0, they have destination. We set the size of this field depending on the value of
57         // d_bit(), the init_bytes value is set to 6 bytes (the size of a MAC address)
58         SENF_PARSER_CUSTOM_FIELD ( destination , Parse_MAC     , d_bit() ? 0 : 6 , 6 ) {
59             BOOST_ASSERT( ! d_bit() );
60             return parse<destination_t>( destination_offset() );
61         }
62
63         // This field is placed at the end of the parser. It is therefore only considered for
64         // calculating init_bytes but not for calculating bytes()
65         SENF_PARSER_CUSTOM_FIELD ( crc         , Parse_UInt32  , 0 , 4 ) {
66             return parse<crc_t>( data().size() - 4 );
67         }
68
69         SENF_PARSER_FINALIZE( Parse_SNDUPacket );
70         
71         boost::uint32_t calcCrc() const;
72     };
73
74     
75     struct ULEExtHeaderTypes {
76         typedef boost::uint16_t key_t;
77     };
78     
79     /** \brief ULE SNDU Packet
80         
81         \par Packet type (typedef):
82             \ref SNDUPacket
83
84         \par Fields:
85             \ref Parse_SNDUPacket
86
87         \ingroup protocolbundle_mpegdvb
88      */
89     struct SNDUPacketType
90         : public PacketTypeBase
91 //          public PacketTypeMixin<SNDUPacketType, ULEExtHeaderTypes>
92     {
93 //        typedef PacketTypeMixin<SNDUPacketType, ULEExtHeaderType> mixin;
94         typedef ConcretePacket<SNDUPacketType> packet;
95         typedef Parse_SNDUPacket parser;
96
97 //        using mixin::nextPacketRange;
98 //        using mixin::nextPacketType;
99 //        using mixin::init;
100         
101 //        static registry_key_t nextPacketKey(packet p);
102         
103         static void init(packet p);
104
105         static factory_t nextPacketType(packet p);
106         
107         static optional_range nextPacketRange(packet p);
108         
109         static void dump(packet p, std::ostream & os);
110         
111         static PacketParserBase::size_type initSize();
112         
113         static PacketParserBase::size_type initHeadSize();
114     };
115         
116     typedef SNDUPacketType::packet SNDUPacket;
117     
118     typedef boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0, false, false> ule_crc32;
119
120
121     /*!
122      \def ULE_END_INDICATOR 
123          ULE End Indicator; indicates to the receiver that there are no 
124          further SNDUs present within the current TS packet.
125     */
126 #   define ULE_END_INDICATOR 0xffff
127 }
128
129
130 ///////////////////////////////hh.e////////////////////////////////////////
131 //#include "SNDUPacket.cci"
132 //#include "SNDUPacket.ct"
133 //#include "SNDUPacket.cti"
134 #endif
135
136 \f
137 // Local Variables:
138 // mode: c++
139 // fill-column: 100
140 // c-file-style: "senf"
141 // indent-tabs-mode: nil
142 // ispell-local-dictionary: "american"
143 // compile-command: "scons -u test"
144 // comment-column: 40
145 // End: