added IPv6 Option Type List Parser and generic packet parser with raw data access...
[senf.git] / senf / Packets / DefaultBundle / IPv6Extensions.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 //     Stefan Bund <g0dil@berlios.de>
7 //     Philipp Batroff <philipp.batroff@fokus.fraunhofer.de>
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 IPv6Extensions public header */
25
26 #ifndef HH_SENF_Packets_DefaultBundle_IPv6Extensions_
27 #define HH_SENF_Packets_DefaultBundle_IPv6Extensions_ 1
28
29 // Custom includes
30 #include <senf/Packets/Packets.hh>
31 #include <senf/Packets/AuxParser.hh>
32 #include <senf/Packets/ListOptionTypeParser.hh>
33 #include <senf/Packets/DefaultBundle/IPv6ExtOptionType.hh>
34
35 #include "IPv6Packet.hh"
36 //#include "IPv6Extensions.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 namespace senf {
40
41     /** \brief Parse in IPv6 fragment extension header
42         
43         Parser implementing the IPv6 fragment extension. The fields implemented are:
44         \image html IPv6Extensions_Fragment.png
45
46         \see IPv6ExtensionType_Fragment \n
47             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
48      */
49     struct IPv6PacketParserExtension_Fragment : public PacketParserBase
50     {
51 #       include SENF_FIXED_PARSER()
52
53         SENF_PARSER_FIELD            ( nextHeader     , UInt8Parser  );
54         SENF_PARSER_PRIVATE_FIELD    ( reserved1      , UInt8Parser  );
55
56         SENF_PARSER_BITFIELD         ( fragmentOffset , 13, unsigned );
57         SENF_PARSER_PRIVATE_BITFIELD ( reserved2      ,  2, unsigned );
58         SENF_PARSER_BITFIELD         ( moreFragments  ,  1, bool     );
59
60         SENF_PARSER_FIELD            ( id             , UInt32Parser );
61
62         SENF_PARSER_FINALIZE(IPv6PacketParserExtension_Fragment);
63     };
64
65     /** \brief IPv6 fragment extension
66
67         \par Packet type (typedef):
68             \ref IPv6Extension_Fragment
69
70         \par Fields:
71             \ref IPv6PacketParserExtension_Fragment
72         
73         \par Associated registries:
74             \ref IpTypes
75         
76         \par Finalize action:
77             Set \a nextHeader from type of next packet if found in \ref IpTypes
78
79         \ingroup protocolbundle_default
80      */
81     struct IPv6ExtensionType_Fragment
82         : public PacketTypeBase,
83           public PacketTypeMixin<IPv6ExtensionType_Fragment, IpTypes>
84     {
85 #ifndef DOXYGEN
86         typedef PacketTypeMixin<IPv6ExtensionType_Fragment, IpTypes> mixin;
87 #endif
88         /** \brief IPv6 fragment extension packet typedef */
89         typedef ConcretePacket<IPv6ExtensionType_Fragment> packet; 
90         /** \brief typedef to the parser of IPv6 fragment extension packet */
91         typedef IPv6PacketParserExtension_Fragment parser;
92
93         using mixin::nextPacketRange;
94         using mixin::nextPacketType;
95         using mixin::initSize;
96         using mixin::init;
97
98         static key_t nextPacketKey(packet p) 
99             { return p->nextHeader(); }
100         
101         /** \brief Dump given IPv6Extension_Fragment in readable form to given output stream */
102         static void dump(packet p, std::ostream & os); 
103
104         static void finalize(packet p) { 
105             p->nextHeader() << key(p.next(nothrow)); }
106     };
107
108     /** \brief IPv6 fragment extension packet typedef */
109     typedef ConcretePacket<IPv6ExtensionType_Fragment> IPv6Extension_Fragment;
110
111 // =====================================================================================================
112
113     /** \brief Parse in IPv6 routing extension header
114
115         Parser implementing the IPv6 routing Header extension. The fields implemented are:
116     \image html IPv6Extensions_Routing.png
117
118     \see IPv6ExtensionType_Routing \n
119     <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
120      */
121
122 //Routing Header Extension (type 0 only)
123     struct IPv6PacketParserExtension_Routing : public PacketParserBase
124     {
125 /*
126 The Type 0 Routing header has the following format: (RFC 2460)
127
128     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
129     |  Next Header  |  Hdr Ext Len  | Routing Type=0| Segments Left |
130     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
131     |                            Reserved                           |
132     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
133     |                                                               |
134     +                                                               +
135     |                                                               |
136     +                           Address[1]                          +
137     |                                                               |
138     +                                                               +
139     |                                                               |
140     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141     .                               .                               .
142     .                               .                               .
143     .                               .                               .
144     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145     |                                                               |
146     +                                                               +
147     |                                                               |
148     +                           Address[n]                          +
149     |                                                               |
150     +                                                               +
151     |                                                               |
152     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153
154 */
155 #       include SENF_PARSER()
156         
157         SENF_PARSER_FIELD ( nextHeader, UInt8Parser      );
158         SENF_PARSER_FIELD ( headerLength, UInt8Parser    );
159         SENF_PARSER_FIELD ( routingType, UInt8Parser     ); //set to Zero for minimal implementation
160         SENF_PARSER_FIELD_RO ( segmentsLeft, UInt8Parser );
161         SENF_PARSER_FIELD ( reserved, UInt32Parser       ); //set to zero by RFC
162         SENF_PARSER_VECTOR ( hopAddresses, segmentsLeft, INet6AddressParser );
163         
164         SENF_PARSER_FINALIZE ( IPv6PacketParserExtension_Routing );
165         
166         //provisionary, since only type 0 is implemented
167         SENF_PARSER_INIT() { 
168             routingType() = 0u;
169             reserved() = 0u; 
170         }
171     };
172     
173     /** \brief IPv6 routing extension
174
175         \par Packet type (typedef):
176     \ref IPv6Extension_Routing
177
178         \par Fields:
179     \ref IPv6PacketParserExtension_Routing
180         
181         \par Associated registries:
182     \ref IpTypes
183         
184         \par Finalize action:
185     Set \a nextHeader from type of next packet if found in \ref IpTypes
186
187     \ingroup protocolbundle_default
188          */
189     
190     struct IPv6ExtensionType_Routing
191     :   public PacketTypeBase,
192         public PacketTypeMixin<IPv6ExtensionType_Routing, IpTypes>
193
194     {
195 #ifndef DOXYGEN
196         typedef PacketTypeMixin<IPv6ExtensionType_Routing, IpTypes> mixin;
197 #endif
198         /** \brief IPv6 routing extension packet typedef */
199         typedef ConcretePacket<IPv6ExtensionType_Routing> packet;
200         /** \brief typedef to the parser of IPv6 routing extension packet */
201         typedef IPv6PacketParserExtension_Routing parser;
202         
203         using mixin::nextPacketRange;
204         using mixin::nextPacketType;
205         using mixin::init;
206         using mixin::initSize;
207         
208         static key_t nextPacketKey(packet p) 
209             { return p->nextHeader(); }
210         /** \brief Dump given IPv6Extension_Routing in readable form to given output stream */
211         static void dump(packet p, std::ostream & os); 
212         
213         static void finalize(packet p) { 
214             p->nextHeader() << key(p.next(nothrow)); }
215     };
216     
217     /** \brief IPv6 routing extension packet typedef */
218     typedef ConcretePacket<IPv6ExtensionType_Routing> IPv6Extension_Routing;
219
220     
221 // =====================================================================================================
222     
223     /** \brief Parse in IPv6 Hop-By-Hop extension header
224
225         Parser implementing the IPv6 routing Header extension. The fields implemented are:
226     \image html IPv6Extensions_HopByHop.png
227
228     \see IPv6ExtensionType_HopByHop \n
229     <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
230     */
231
232 // Hop-By-Hop Extension Header
233
234     struct IPv6PacketParserExtension_HopByHop : public PacketParserBase {
235 #       include SENF_PARSER()
236         SENF_PARSER_FIELD ( nextHeader, UInt8Parser   );
237         SENF_PARSER_FIELD ( headerLength, UInt8Parser );
238
239         typedef detail::FixedAuxParserPolicy<UInt8Parser, 1u> ListOptionTypeAuxPolicy;
240         typedef detail::ListOptionTypeParser_Policy<GenericOptTypeTLVPacketParser, ListOptionTypeAuxPolicy> ListOptionTypePolicy;
241         typedef ListParser<ListOptionTypePolicy> ListOptionTypeParser;
242
243         SENF_PARSER_FIELD  ( options, ListOptionTypeParser);
244
245         SENF_PARSER_FINALIZE ( IPv6PacketParserExtension_HopByHop );
246     };
247     
248     /** \brief IPv6 Hop-By-Hop extension
249
250         \par Packet type (typedef):
251     \ref IPv6Extension_HopByHop
252
253         \par Fields:
254     \ref IPv6PacketParserExtension_HopByHop
255         
256         \par Associated registries:
257     \ref IpTypes
258         
259         \par Finalize action:
260     Set \a nextHeader from type of next packet if found in \ref IpTypes
261
262     \ingroup protocolbundle_default
263     */
264     
265     struct IPv6ExtensionType_HopByHop
266     :   public PacketTypeBase,
267         public PacketTypeMixin<IPv6ExtensionType_HopByHop, IpTypes>
268     {
269 #ifndef DOXYGEN
270         typedef PacketTypeMixin<IPv6ExtensionType_HopByHop, IpTypes> mixin;
271 #endif
272         /** \brief IPv6 Hop-By-Hop extension packet typedef */
273         typedef ConcretePacket<IPv6ExtensionType_HopByHop> packet;
274         /** \brief typedef to the parser of IPv6 Hop-By-Hop extension packet */
275         typedef IPv6PacketParserExtension_HopByHop parser;
276         
277         using mixin::nextPacketRange;
278         using mixin::nextPacketType;
279         using mixin::init;
280         using mixin::initSize;
281         
282         static key_t nextPacketKey(packet p) 
283         { return p->nextHeader(); }
284         /** \brief Dump given IPv6Extension_HopByHop in readable form to given output stream */
285         static void dump(packet p, std::ostream & os); 
286         
287         static void finalize(packet p) { 
288             p->nextHeader() << key(p.next(nothrow)); }
289     };
290     
291     /** \brief IPv6 routing Hop-By-Hop packet typedef */
292     typedef ConcretePacket<IPv6ExtensionType_HopByHop> IPv6Extension_HopByHop;
293     
294 // =====================================================================================================
295     
296     /** \brief Parse in IPv6 Destination Options extension header
297
298         Parser implementing the IPv6 Destination Options Header extension. The fields implemented are:
299     \image html IPv6Extensions_Destination.png
300
301     \see IPv6ExtensionType_Destination \n
302     <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
303      */
304     
305     // Destination Options skeleton without TLV-Options
306
307     struct IPv6PacketParserExtension_Destination : public PacketParserBase {
308
309 #       include SENF_PARSER()
310         SENF_PARSER_FIELD ( nextHeader, UInt8Parser   );
311         SENF_PARSER_FIELD ( headerLength, UInt8Parser );
312         
313         SENF_PARSER_FINALIZE ( IPv6PacketParserExtension_Destination );
314     };
315     
316     /** \brief IPv6 Destination Options extension
317
318         \par Packet type (typedef):
319     \ref IPv6Extension_Destination
320
321         \par Fields:
322     \ref IPv6PacketParserExtension_Destination
323         
324         \par Associated registries:
325     \ref IpTypes
326         
327         \par Finalize action:
328     Set \a nextHeader from type of next packet if found in \ref IpTypes
329
330     \ingroup protocolbundle_default
331          */
332     
333     struct IPv6ExtensionType_Destination
334     :   public PacketTypeBase,
335         public PacketTypeMixin<IPv6ExtensionType_Destination, IpTypes>
336     {
337 #ifndef DOXYGEN
338         typedef PacketTypeMixin<IPv6ExtensionType_Destination, IpTypes> mixin;
339 #endif
340         /** \brief IPv6 Destination Options extension packet typedef */
341         typedef ConcretePacket<IPv6ExtensionType_Destination> packet;
342         /** \brief typedef to the parser of IPv6 Destination Options extension packet */
343         typedef IPv6PacketParserExtension_Destination parser;
344         
345         using mixin::nextPacketRange;
346         using mixin::nextPacketType;
347         using mixin::init;
348         using mixin::initSize;
349         
350         static key_t nextPacketKey(packet p) 
351         { return p->nextHeader(); }
352         /** \brief Dump given IPv6Extension_Destination in readable form to given output stream */
353         static void dump(packet p, std::ostream & os); 
354         
355         static void finalize(packet p) { 
356             p->nextHeader() << key(p.next(nothrow)); }
357     };
358     
359     /** \brief IPv6 routing Destination Options packet typedef */
360     typedef ConcretePacket<IPv6ExtensionType_Destination> IPv6Extension_Destination;
361
362     
363 } //namespace senf
364 ///////////////////////////////hh.e////////////////////////////////////////
365 //#include "IPv6Extensions.cci"
366 //#include "IPv6Extensions.ct"
367 //#include "IPv6Extensions.cti"
368 #endif
369
370 \f
371 // Local Variables:
372 // mode: c++
373 // fill-column: 100
374 // c-file-style: "senf"
375 // indent-tabs-mode: nil
376 // ispell-local-dictionary: "american"
377 // compile-command: "scons -u test"
378 // comment-column: 40
379 // End: