Packets/DefaultBundle: Documentation
[senf.git] / Packets / DefaultBundle / IpV4Packet.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@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 #ifndef HH_IpV4Packet_
24 #define HH_IpV4Packet_ 1
25
26 // Custom includes
27 #include "Packets/Packets.hh"
28
29 //#include "IpV4Packet.mpp"
30 ///////////////////////////////hh.p////////////////////////////////////////
31
32 namespace senf {
33
34     /** \brief Parse an IpV4 packet
35
36         Parser implementing the IpV4 header. The fields implemented are:
37
38         <table class="senf">
39             <tr><th>Field name</th><th>Parser type</th></tr>
40             <tr><td>version</td><td>\ref Parse_Version</td></tr>
41             <tr><td>ihl</td><td>\ref Parse_IHL</td></tr>
42             <tr><td>tos</td><td>\ref Parse_8bit</td></tr>
43             <tr><td>length</td><td>\ref Parse_16bit</td></tr>
44             <tr><td>identifier</td><td>\ref Parse_16bit</td></tr>
45             <tr><td>reserved</td><td>\ref Parse_R</td></tr>
46             <tr><td>df</td><td>\ref Parse_DF</td></tr>
47             <tr><td>mf</td><td>\ref Parse_MF</td></tr>
48             <tr><td>frag</td><td>\ref Parse_Frag</td></tr>
49             <tr><td>ttl</td><td>\ref Parse_8bit</td></tr>
50             <tr><td>protocol</td><td>\ref Parse_8bit</td></tr>
51             <tr><td>crc</td><td>\ref Parse_16bit</td></tr>
52             <tr><td>source</td><td>\ref Parse_32bit</td></tr>
53             <tr><td>destination</td><td>\ref Parse_32bit</td></tr>
54         </table>
55
56         \see IpV4PacketType \n
57             <a href="http://tools.ietf.org/html/rfc791">RFC 791</a>
58
59         \todo Implement options
60      */
61     struct Parse_IpV4 : public PacketParserBase
62     {
63         SENF_PACKET_PARSER_NO_INIT(Parse_IpV4);
64
65         ///////////////////////////////////////////////////////////////////////////
66
67         typedef Parse_UIntField <  0,  4 > Parse_Version;
68         typedef Parse_UIntField <  4,  8 > Parse_IHL;
69         typedef Parse_UInt8                Parse_8bit;
70         typedef Parse_UInt16               Parse_16bit;
71         typedef Parse_Flag      <  0     > Parse_R;
72         typedef Parse_Flag      <  1     > Parse_DF;
73         typedef Parse_Flag      <  2     > Parse_MF;
74         typedef Parse_UIntField <  3, 16 > Parse_Frag;
75         typedef Parse_UInt32               Parse_32bit;
76
77         SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
78             ((OverlayField)( version,     Parse_Version ))
79             ((Field       )( ihl,         Parse_IHL     ))
80             ((Field       )( tos,         Parse_8bit    ))
81             ((Field       )( length,      Parse_16bit   ))
82             ((Field       )( identifier,  Parse_16bit   ))
83             ((OverlayField)( reserved,    Parse_R       ))
84             ((OverlayField)( df,          Parse_DF      ))
85             ((OverlayField)( mf,          Parse_MF      ))
86             ((Field       )( frag,        Parse_Frag    ))
87             ((Field       )( ttl,         Parse_8bit    ))
88             ((Field       )( protocol,    Parse_8bit    ))
89             ((Field       )( crc,         Parse_16bit   ))
90             ((Field       )( source,      Parse_32bit   ))
91             ((Field       )( destination, Parse_32bit   )) );
92
93         void init() {
94             version() = 4;
95         }
96     };
97
98     /** \brief IP protocol number registry
99
100         This registeres packets with their IP protocol number.
101
102         \see <a href="http://www.iana.org/assignments/protocol-numbers">Protocol numbers</a>
103             PacketRegistry
104      */
105     struct IpTypes {
106         typedef boost::uint16_t key_t;
107     };
108
109     /** \brief IpV4 packet
110         
111         \par Packet type (typedef):
112             \ref IpV4Packet
113
114         \par Fields:
115             \ref Parse_IpV4
116
117         \par Associated registries:
118             \ref IpTypes
119
120         \ingroup protocolbundle_default
121      */
122     struct IpV4PacketType
123         : public PacketTypeBase,
124           public PacketTypeMixin<IpV4PacketType, IpTypes>
125     {
126         typedef PacketTypeMixin<IpV4PacketType, IpTypes> mixin;
127         typedef ConcretePacket<IpV4PacketType> packet;
128         typedef Parse_IpV4 parser;
129
130         using mixin::nextPacketRange;
131         using mixin::nextPacketType;
132         using mixin::initSize;
133         using mixin::init;
134
135         static registry_key_t nextPacketKey(packet p) 
136             { return p->protocol(); }
137
138         static void dump(packet p, std::ostream & os);
139     };
140         
141     /** \brief IpV4 packet typedef */
142     typedef IpV4PacketType::packet IpV4Packet;
143 }
144
145
146 ///////////////////////////////hh.e////////////////////////////////////////
147 #endif
148 #ifndef SENF_PACKETS_DECL_ONLY
149 //#include IpV4Packet.cci"
150 //#include "IpV4Packet.ct"
151 //#include "IpV4Packet.cti"
152 #endif
153
154 \f
155 // Local Variables:
156 // mode: c++
157 // fill-column: 100
158 // c-file-style: "senf"
159 // indent-tabs-mode: nil
160 // ispell-local-dictionary: "american"
161 // compile-command: "scons -u test"
162 // comment-column: 40
163 // End: