446ef03d07b6d331ec3f00ad300a2a219eb1ede3
[senf.git] / Packets / MPEGDVBBundle / GREPacket.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 //     Joachim Kaeber <jkaeber@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 GREPacket public header */
25
26 #ifndef HH_GREPacket
27 #define HH_GREPacket 1
28
29 // Custom includes
30 #include <algorithm>
31 #include "../../Packets/Packets.hh"
32 #include "../DefaultBundle/EthernetPacket.hh"
33
34 //#include "GREPacket.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf {
38
39     /** \brief Parse a GRE packet
40
41         Parser implementing the header of a General Routing Encapsulation (GRE, RFC 2784) Packet
42         
43         \see GREPacketType
44      */
45     struct GREChecksumParser : public PacketParserBase {
46 #       include SENF_PARSER()        
47         SENF_PARSER_FIELD ( checksum1_, UInt16Parser );
48         SENF_PARSER_PRIVATE_FIELD ( reserved1_, UInt16Parser );
49         SENF_PARSER_FINALIZE(GREChecksumParser);
50     };
51
52     struct GREPacketParser : public PacketParserBase
53     {
54 #       include SENF_PARSER()
55
56         SENF_PARSER_BITFIELD         ( checksum_present,  1, bool );
57         SENF_PARSER_PRIVATE_BITFIELD ( reserved0_,       12, unsigned ); // TODO: SKIP !!
58         SENF_PARSER_BITFIELD         ( version_number,    3, unsigned ); // TODO: Always Zero !!
59         SENF_PARSER_FIELD            ( protocol_type,    UInt16Parser );
60         SENF_PARSER_PRIVATE_VARIANT  ( checksum_,  checksum_present,
61                                                    (VoidPacketParser) (GREChecksumParser) );
62  
63         SENF_PARSER_FINALIZE( GREPacketParser );
64
65       private: 
66         UInt16Parser checksum() const /// only defined if checksum_present() == \c true
67              { return checksum_().get<1>().checksum1_(); }
68     };
69     
70     /** \brief GRE packet
71         
72         \par Packet type (typedef):
73             \ref GREPacket
74
75         \par Fields:
76             \ref GREPacketParser
77
78         \ingroup protocolbundle_mpegdvb
79      */
80     struct GREPacketType
81         : public PacketTypeBase,
82           public PacketTypeMixin<GREPacketType, EtherTypes>
83     {
84         typedef PacketTypeMixin<GREPacketType, EtherTypes> mixin;
85         typedef ConcretePacket<GREPacketType> packet;
86         typedef GREPacketParser parser;
87     
88         using mixin::nextPacketRange;
89         using mixin::nextPacketType;
90         using mixin::init;
91         using mixin::initSize;
92         
93         static void dump(packet p, std::ostream & os);
94         static EtherTypes::key_t nextPacketKey(packet p) {
95           return p->protocol_type();
96         }
97         static void finalize(packet p) {
98           p->protocol_type() << key(p.next(nothrow));
99           p->version_number() = 0; // as per RFC2784, 2.3.1
100
101           if (p->checksum_present()) { 
102             // compute checksum
103           } else {
104             // ???
105           }
106         }
107     };
108     
109     /** \brief GRE packet typedef */
110     typedef GREPacketType::packet GREPacket;
111     
112   
113 }
114
115
116 ///////////////////////////////hh.e////////////////////////////////////////
117 //#include "TransportPacket.cci"
118 //#include "TransportPacket.ct"
119 //#include "TransportPacket.cti"
120 #endif
121
122 \f
123 // Local Variables:
124 // mode: c++
125 // fill-column: 100
126 // c-file-style: "senf"
127 // indent-tabs-mode: nil
128 // ispell-local-dictionary: "american"
129 // compile-command: "scons -u test"
130 // comment-column: 40
131 // End: