872a39e44509c1564663b46afd3771acfc10e455
[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         Parse_SNDUPacket(data_iterator i, state_type s) : PacketParserBase(i,s) {}
49         
50         typedef Parse_Flag      <     0 > Parse_daaf;  // Destination Address Absent Field
51         typedef Parse_UIntField < 1, 16 > Parse_length;
52                 
53         Parse_daaf d_bit() const {
54             return parse<Parse_daaf>( 0 );
55         }
56         Parse_length length() const {
57             return parse<Parse_length>( 0 );
58         }
59         Parse_UInt16 type() const {
60             return parse<Parse_UInt16>( 2 );
61         }
62         Parse_MAC destination() const {
63             BOOST_ASSERT( ! d_bit() );
64             return parse<Parse_MAC>( 4 );
65         }
66         Parse_UInt32 crc() const { 
67             return parse<Parse_UInt32>( data().size()-4 ); 
68         }
69         
70         void init() const {
71             defaultInit();
72             d_bit() = false;
73         }
74         
75         PacketParserBase::size_type bytes() const;
76         
77         static const size_type init_bytes = 2+2+4; // D-Bit + 15 bits length + 16 bits type field + 32 bits crc
78
79         boost::uint32_t calcCrc() const;
80     };
81
82     
83     struct ULEExtHeaderTypes {
84         typedef boost::uint16_t key_t;
85     };
86     
87     /** \brief ULE SNDU Packet
88         
89         \par Packet type (typedef):
90             \ref SNDUPacket
91
92         \par Fields:
93             \ref Parse_SNDUPacket
94
95         \ingroup protocolbundle_mpegdvb
96      */
97     struct SNDUPacketType
98         : public PacketTypeBase
99 //          public PacketTypeMixin<SNDUPacketType, ULEExtHeaderTypes>
100     {
101 //        typedef PacketTypeMixin<SNDUPacketType, ULEExtHeaderType> mixin;
102         typedef ConcretePacket<SNDUPacketType> packet;
103         typedef Parse_SNDUPacket parser;
104
105 //        using mixin::nextPacketRange;
106 //        using mixin::nextPacketType;
107 //        using mixin::init;
108         
109 //        static registry_key_t nextPacketKey(packet p);
110         
111         static void init(packet p);
112
113         static factory_t nextPacketType(packet p);
114         
115         static optional_range nextPacketRange(packet p);
116         
117         static void dump(packet p, std::ostream & os);
118         
119         static PacketParserBase::size_type initSize();
120         
121         static PacketParserBase::size_type initHeadSize();
122     };
123         
124     typedef SNDUPacketType::packet SNDUPacket;
125     
126     typedef boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0, false, false> ule_crc32;
127
128
129     /*!
130      \def ULE_END_INDICATOR 
131          ULE End Indicator; indicates to the receiver that there are no 
132          further SNDUs present within the current TS packet.
133     */
134 #   define ULE_END_INDICATOR 0xffff
135 }
136
137
138 ///////////////////////////////hh.e////////////////////////////////////////
139 //#include "SNDUPacket.cci"
140 //#include "SNDUPacket.ct"
141 //#include "SNDUPacket.cti"
142 #endif
143
144 \f
145 // Local Variables:
146 // mode: c++
147 // fill-column: 100
148 // c-file-style: "senf"
149 // indent-tabs-mode: nil
150 // ispell-local-dictionary: "american"
151 // compile-command: "scons -u test"
152 // comment-column: 40
153 // End: