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