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