switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / MPEGDVBBundle / GREPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Joachim Kaeber <jkaeber@berlios.de>
27 /** \file
28     \brief GREPacket public header */
29
30 #ifndef HH_SENF_Packets_MPEGDVBBundle_GREPacket_
31 #define HH_SENF_Packets_MPEGDVBBundle_GREPacket_ 1
32
33 // Custom includes
34 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
35
36 //#include "GREPacket.mpp"
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38
39 namespace senf {
40
41     /** \brief Parse a GRE packet
42
43         Parser implementing the header of a General Routing Encapsulation (GRE, RFC 2784) Packet
44
45         \see GREPacketType
46      */
47     struct GREChecksumParser : public PacketParserBase {
48 #       include SENF_PARSER()
49         SENF_PARSER_FIELD ( checksum1_, UInt16Parser );
50         SENF_PARSER_PRIVATE_FIELD ( reserved1_, UInt16Parser );
51         SENF_PARSER_FINALIZE(GREChecksumParser);
52     };
53
54     struct GREPacketParser : public PacketParserBase
55     {
56 #       include SENF_PARSER()
57
58         SENF_PARSER_BITFIELD         ( checksum_present,  1, bool );
59         SENF_PARSER_PRIVATE_BITFIELD ( reserved0_,       12, unsigned ); // TODO: SKIP !!
60         SENF_PARSER_BITFIELD         ( version_number,    3, unsigned ); // TODO: Always Zero !!
61         SENF_PARSER_FIELD            ( protocol_type,    UInt16Parser );
62         SENF_PARSER_PRIVATE_VARIANT  ( checksum_,  checksum_present,
63                                                    (VoidPacketParser) (GREChecksumParser) );
64
65         SENF_PARSER_FINALIZE( GREPacketParser );
66
67       private:
68         UInt16Parser checksum() const /// only defined if checksum_present() == \c true
69              { return checksum_().get<1>().checksum1_(); }
70     };
71
72     /** \brief GRE packet
73
74         \par Packet type (typedef):
75             \ref GREPacket
76
77         \par Fields:
78             \ref GREPacketParser
79             \image html GREPacket.png
80
81         \ingroup protocolbundle_mpegdvb
82      */
83     struct GREPacketType
84         : public PacketTypeBase,
85           public PacketTypeMixin<GREPacketType, EtherTypes>
86     {
87         typedef PacketTypeMixin<GREPacketType, EtherTypes> mixin;
88         typedef ConcretePacket<GREPacketType> packet;
89         typedef GREPacketParser parser;
90
91         using mixin::nextPacketRange;
92         using mixin::nextPacketType;
93         using mixin::init;
94         using mixin::initSize;
95
96         static void dump(packet p, std::ostream & os);
97         static EtherTypes::key_t nextPacketKey(packet p) {
98           return p->protocol_type();
99         }
100         static void finalize(packet p) {
101           p->protocol_type() << key(p.next(nothrow));
102           p->version_number() = 0; // as per RFC2784, 2.3.1
103
104           if (p->checksum_present()) {
105             // compute checksum
106           } else {
107             // ???
108           }
109         }
110     };
111
112     /** \brief GRE packet typedef */
113     typedef GREPacketType::packet GREPacket;
114
115
116 }
117
118
119 //-/////////////////////////////////////////////////////////////////////////////////////////////////
120 //#include "TransportPacket.cci"
121 //#include "TransportPacket.ct"
122 //#include "TransportPacket.cti"
123 #endif
124
125 \f
126 // Local Variables:
127 // mode: c++
128 // fill-column: 100
129 // c-file-style: "senf"
130 // indent-tabs-mode: nil
131 // ispell-local-dictionary: "american"
132 // compile-command: "scons -u test"
133 // comment-column: 40
134 // End: