d8633c75c1d38fd4298eff3f836e094b08958565
[senf.git] / senf / Packets / MPEGDVBBundle / SNDUPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.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_SENF_Packets_MPEGDVBBundle_SNDUPacket_
27 #define HH_SENF_Packets_MPEGDVBBundle_SNDUPacket_ 1
28
29 // Custom includes
30 #include <algorithm>
31 #include <boost/crc.hpp>
32 #include <senf/Packets/Packets.hh>
33 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
34
35 //#include "SNDUPacket.mpp"
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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 SNDUPacketParser : public PacketParserBase
47     {
48 #       include SENF_PARSER()
49
50         /* We first define the fields as they appear in the field. Some of the fields are declared
51            private. We provide custom accessors for those fields further down. */
52
53         SENF_PARSER_PRIVATE_BITFIELD ( d_bit_       ,  1 , unsigned );
54         SENF_PARSER_BITFIELD         ( length       , 15 , unsigned );
55         SENF_PARSER_FIELD            ( type         , UInt16Parser  );
56         SENF_PARSER_PRIVATE_VARIANT  ( destination_ , d_bit_        ,
57                                                       (MACAddressParser) (VoidPacketParser) );
58
59         SENF_PARSER_FINALIZE( SNDUPacketParser );
60
61         MACAddressParser destination()  ///< Only defined if d_bit() == \c false
62             { return destination_().get<0>(); }
63
64         bool d_bit()                    ///< Destination absent bit
65             { return d_bit_(); }
66
67         void withDestination()          ///< Clear destination absent bit
68             { destination_().init<0>(); }
69
70         void withoutDestination()       ///< Set destination absent bit
71             { destination_().init<1>(); }
72
73         UInt32Parser crc()
74             { return parse<UInt32Parser>( data().size() - 4 ); }
75
76         boost::uint32_t calcCrc() const;
77     };
78
79
80     struct ULEExtHeaderTypes {
81         typedef boost::uint16_t key_t;
82     };
83
84     /** \brief ULE SNDU Packet
85
86         \par Packet type (typedef):
87             \ref SNDUPacket
88
89         \par Fields:
90             \ref SNDUPacketParser
91             \image html SNDUPacket.png
92
93         \ingroup protocolbundle_mpegdvb
94      */
95     struct SNDUPacketType
96         : public PacketTypeBase
97 //          public PacketTypeMixin<SNDUPacketType, ULEExtHeaderTypes>
98     {
99 //        typedef PacketTypeMixin<SNDUPacketType, ULEExtHeaderType> mixin;
100         typedef ConcretePacket<SNDUPacketType> packet;
101         typedef SNDUPacketParser parser;
102
103 //        using mixin::nextPacketRange;
104 //        using mixin::nextPacketType;
105 //        using mixin::init;
106
107 //        static key_t nextPacketKey(packet p);
108
109         static void init(packet p);
110
111         static factory_t nextPacketType(packet p);
112
113         static optional_range nextPacketRange(packet p);
114
115         static void dump(packet p, std::ostream & os);
116
117         static PacketParserBase::size_type initSize();
118
119         static PacketParserBase::size_type initHeadSize();
120     };
121
122     typedef SNDUPacketType::packet SNDUPacket;
123
124     typedef boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0, false, false> ule_crc32;
125
126
127     /*!
128      \def ULE_END_INDICATOR
129          ULE End Indicator; indicates to the receiver that there are no
130          further SNDUs present within the current TS packet.
131     */
132 #   define ULE_END_INDICATOR 0xffff
133 }
134
135
136 //-/////////////////////////////////////////////////////////////////////////////////////////////////
137 //#include "SNDUPacket.cci"
138 //#include "SNDUPacket.ct"
139 //#include "SNDUPacket.cti"
140 #endif
141
142 \f
143 // Local Variables:
144 // mode: c++
145 // fill-column: 100
146 // c-file-style: "senf"
147 // indent-tabs-mode: nil
148 // ispell-local-dictionary: "american"
149 // compile-command: "scons -u test"
150 // comment-column: 40
151 // End: