Packets/DefaultBundle: use new generic TLV base class for IPv6Options
[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 <senf/Packets/Packets.hh>
32 #include <senf/Packets/AuxParser.hh>
33 #include "IPv6ExtOptionType.hh"
34 #include "ListOptionTypeParser.hh"
35 #include "IPv6Packet.hh"
36
37 //#include "IPv6Extensions.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
39
40 namespace senf {
41
42     /** \brief Parse in IPv6 fragment extension header
43         
44         Parser implementing the IPv6 fragment extension. The fields implemented are:
45         \image html IPv6FragmentPacket.png
46
47         \see IPv6ExtensionType_Fragment \n
48             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
49      */
50     struct IPv6FragmentPacketParser : public PacketParserBase
51     {
52 #       include SENF_FIXED_PARSER()
53
54         SENF_PARSER_FIELD            ( nextHeader     , UInt8Parser  );
55         SENF_PARSER_PRIVATE_FIELD    ( reserved1      , UInt8Parser  );
56         SENF_PARSER_BITFIELD         ( fragmentOffset , 13, unsigned );
57         SENF_PARSER_PRIVATE_BITFIELD ( reserved2      ,  2, unsigned );
58         SENF_PARSER_BITFIELD         ( moreFragments  ,  1, bool     );
59         SENF_PARSER_FIELD            ( id             , UInt32Parser );
60
61         SENF_PARSER_FINALIZE(IPv6FragmentPacketParser);
62     };
63
64     /** \brief IPv6 fragment extension
65
66         \par Packet type (typedef):
67             \ref IPv6FragmentPacket
68
69         \par Fields:
70             \ref IPv6FragmentPacketParser
71         
72         \par Associated registries:
73             \ref IpTypes
74         
75         \par Finalize action:
76             Set \a nextHeader from type of next packet if found in \ref IpTypes
77
78         \ingroup protocolbundle_default
79      */
80     struct IPv6FragmentPacketType
81         : public PacketTypeBase,
82           public PacketTypeMixin<IPv6FragmentPacketType, IpTypes>
83     {
84 #ifndef DOXYGEN
85         typedef PacketTypeMixin<IPv6FragmentPacketType, IpTypes> mixin;
86 #endif
87         /** \brief IPv6 fragment extension packet typedef */
88         typedef ConcretePacket<IPv6FragmentPacketType> packet;
89         /** \brief typedef to the parser of IPv6 fragment extension packet */
90         typedef IPv6FragmentPacketParser parser;
91
92         using mixin::nextPacketRange;
93         using mixin::nextPacketType;
94         using mixin::initSize;
95         using mixin::init;
96
97         static key_t nextPacketKey(packet p) 
98             { return p->nextHeader(); }
99         
100         /** \brief Dump given IPv6FragmentPacket in readable form to given output stream */
101         static void dump(packet p, std::ostream & os); 
102
103         static void finalize(packet p) { 
104             p->nextHeader() << key(p.next(nothrow)); }
105     };
106
107     /** \brief IPv6 fragment extension packet typedef 
108         \ingroup protocolbundle_default
109      */
110     typedef ConcretePacket<IPv6FragmentPacketType> IPv6FragmentPacket;
111
112 // =====================================================================================================
113
114     /** \brief Parse in IPv6 routing extension header
115
116         Parser implementing the IPv6 routing Header extension (type 0 only).
117         The fields implemented are:
118         \image html IPv6RoutingPacket.png
119
120         \see IPv6ExtensionType_Routing \n
121             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
122      */
123     struct IPv6RoutingPacketParser : 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 #       include SENF_PARSER()
155         
156         SENF_PARSER_FIELD ( nextHeader, UInt8Parser      );
157         SENF_PARSER_FIELD ( headerLength, UInt8Parser    );
158         SENF_PARSER_FIELD ( routingType, UInt8Parser     ); //set to Zero for minimal implementation
159         SENF_PARSER_FIELD_RO ( segmentsLeft, UInt8Parser );
160         SENF_PARSER_FIELD ( reserved, UInt32Parser       ); //set to zero by RFC
161         SENF_PARSER_VECTOR ( hopAddresses, segmentsLeft, INet6AddressParser );
162         
163         SENF_PARSER_FINALIZE ( IPv6RoutingPacketParser );
164         
165         //provisionary, since only type 0 is implemented
166         SENF_PARSER_INIT() { 
167             routingType() = 0u;
168             reserved() = 0u; 
169         }
170     };
171     
172     /** \brief IPv6 routing extension
173
174         \par Packet type (typedef):
175             \ref IPv6RoutingPacket
176
177         \par Fields:
178             \ref IPv6PRoutingPacketParser
179         
180         \par Associated registries:
181             \ref IpTypes
182         
183         \par Finalize action:
184             Set \a nextHeader from type of next packet if found in \ref IpTypes
185
186         \ingroup protocolbundle_default
187      */
188     struct IPv6RoutingPacketType
189     :   public PacketTypeBase,
190         public PacketTypeMixin<IPv6RoutingPacketType, IpTypes>
191     {
192 #ifndef DOXYGEN
193         typedef PacketTypeMixin<IPv6RoutingPacketType, IpTypes> mixin;
194 #endif
195         /** \brief IPv6 routing extension packet typedef */
196         typedef ConcretePacket<IPv6RoutingPacketType> packet;
197         /** \brief typedef to the parser of IPv6 routing extension packet */
198         typedef IPv6RoutingPacketParser parser;
199         
200         using mixin::nextPacketRange;
201         using mixin::nextPacketType;
202         using mixin::init;
203         using mixin::initSize;
204         
205         static key_t nextPacketKey(packet p) 
206             { return p->nextHeader(); }
207         /** \brief Dump given IPv6RoutingPacket in readable form to given output stream */
208         static void dump(packet p, std::ostream & os); 
209         
210         static void finalize(packet p) { 
211             p->nextHeader() << key(p.next(nothrow)); }
212     };
213     
214     /** \brief IPv6 routing extension packet typedef
215         \ingroup protocolbundle_default
216      */
217     typedef ConcretePacket<IPv6RoutingPacketType> IPv6RoutingPacket;
218
219     
220 // =====================================================================================================
221     
222     /** \brief Parse in IPv6 Hop-By-Hop extension header
223
224         Parser implementing the IPv6 routing Header extension. The fields implemented are:
225         \image html IPv6HopByHopOptionsPacket.png
226
227         \see IPv6ExtensionType_HopByHop \n
228             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
229     */
230     struct IPv6HopByHopOptionsPacketParser : public PacketParserBase 
231     {
232 #       include SENF_PARSER()
233       
234         SENF_PARSER_FIELD ( nextHeader, UInt8Parser   );
235         SENF_PARSER_FIELD ( headerLength, UInt8Parser );
236
237         typedef detail::FixedAuxParserPolicy<UInt8Parser, 1u> ListOptionTypeAuxPolicy;
238         typedef detail::ListOptionTypeParser_Policy<
239             IPv6GenericOptionTLVParser, ListOptionTypeAuxPolicy> ListOptionTypePolicy;
240         typedef ListParser<ListOptionTypePolicy> ListOptionTypeParser;
241
242         SENF_PARSER_FIELD  ( options, ListOptionTypeParser);
243
244         SENF_PARSER_FINALIZE ( IPv6HopByHopOptionsPacketParser );
245     };
246     
247     /** \brief IPv6 Hop-By-Hop extension
248
249         \par Packet type (typedef):
250             \ref IPv6HopByHopOptionsPacket
251
252         \par Fields:
253             \ref IPv6HopByHopOptionsPacketParser
254         
255         \par Associated registries:
256             \ref IpTypes
257         
258         \par Finalize action:
259             Set \a nextHeader from type of next packet if found in \ref IpTypes
260
261         \ingroup protocolbundle_default
262     */
263     struct IPv6HopByHopOptionsPacketType
264     :   public PacketTypeBase,
265         public PacketTypeMixin<IPv6HopByHopOptionsPacketType, IpTypes>
266     {
267 #ifndef DOXYGEN
268         typedef PacketTypeMixin<IPv6HopByHopOptionsPacketType, IpTypes> mixin;
269 #endif
270         /** \brief IPv6 Hop-By-Hop extension packet typedef */
271         typedef ConcretePacket<IPv6HopByHopOptionsPacketType> packet;
272         /** \brief typedef to the parser of IPv6 Hop-By-Hop extension packet */
273         typedef IPv6HopByHopOptionsPacketParser parser;
274         
275         using mixin::nextPacketRange;
276         using mixin::nextPacketType;
277         using mixin::init;
278         using mixin::initSize;
279         
280         static key_t nextPacketKey(packet p) 
281         { return p->nextHeader(); }
282         
283         /** \brief Dump given IPv6HopByHopOptionsPacket in readable form to given output stream */
284         static void dump(packet p, std::ostream & os); 
285         
286         static void finalize(packet p) { 
287             p->nextHeader() << key(p.next(nothrow)); }
288     };
289     
290     /** \brief IPv6 routing Hop-By-Hop packet typedef
291         \ingroup protocolbundle_default
292      */
293     typedef ConcretePacket<IPv6HopByHopOptionsPacketType> IPv6HopByHopOptionsPacket;
294     
295 // =====================================================================================================
296     
297     /** \brief Parse in IPv6 Destination Options extension header
298
299         Parser implementing the IPv6 Destination Options Header extension. 
300         The fields implemented are:
301         \image html IPv6DestinationOptionsPacket.png
302
303         \see IPv6ExtensionType_Destination \n
304             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
305      */    
306     struct IPv6DestinationOptionsPacketParser : public PacketParserBase 
307     {
308 #       include SENF_PARSER()
309         SENF_PARSER_FIELD ( nextHeader, UInt8Parser   );
310         SENF_PARSER_FIELD ( headerLength, UInt8Parser );
311         
312         SENF_PARSER_FINALIZE ( IPv6DestinationOptionsPacketParser );
313     };
314     
315     /** \brief IPv6 Destination Options extension
316
317         \par Packet type (typedef):
318             \ref IPv6DestinationOptionsPacket
319
320         \par Fields:
321             \ref IPv6DestinationOptionsPacketParser
322         
323         \par Associated registries:
324             \ref IpTypes
325         
326         \par Finalize action:
327             Set \a nextHeader from type of next packet if found in \ref IpTypes
328
329         \ingroup protocolbundle_default
330      */
331     struct IPv6DestinationOptionsPacketType
332     :   public PacketTypeBase,
333         public PacketTypeMixin<IPv6DestinationOptionsPacketType, IpTypes>
334     {
335 #ifndef DOXYGEN
336         typedef PacketTypeMixin<IPv6DestinationOptionsPacketType, IpTypes> mixin;
337 #endif
338         /** \brief IPv6 Destination Options extension packet typedef */
339         typedef ConcretePacket<IPv6DestinationOptionsPacketType> packet;
340         /** \brief typedef to the parser of IPv6 Destination Options extension packet */
341         typedef IPv6DestinationOptionsPacketParser parser;
342         
343         using mixin::nextPacketRange;
344         using mixin::nextPacketType;
345         using mixin::init;
346         using mixin::initSize;
347         
348         static key_t nextPacketKey(packet p) 
349         { return p->nextHeader(); }
350         /** \brief Dump given IPv6DestinationOptionsPacket in readable form to given output stream */
351         static void dump(packet p, std::ostream & os); 
352         
353         static void finalize(packet p) { 
354             p->nextHeader() << key(p.next(nothrow)); }
355     };
356     
357     /** \brief IPv6 routing Destination Options packet typedef
358         \ingroup protocolbundle_default
359      */
360     typedef ConcretePacket<IPv6DestinationOptionsPacketType> IPv6DestinationOptionsPacket;
361     
362 }
363
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: