added FormFeed character for emacs to end of files
[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     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 IPv6PRoutingPacketParser
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     typedef ConcretePacket<IPv6RoutingPacketType> IPv6RoutingPacket;
214
215     
216 // =====================================================================================================
217     
218     /** \brief Parse in IPv6 Hop-By-Hop extension header
219
220         Parser implementing the IPv6 routing Header extension. The fields implemented are:
221         \image html IPv6HopByHopOptionsPacket.png
222
223         \see IPv6ExtensionType_HopByHop \n
224             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
225     */
226     struct IPv6HopByHopOptionsPacketParser : public PacketParserBase 
227     {
228 #       include SENF_PARSER()
229       
230         SENF_PARSER_FIELD ( nextHeader, UInt8Parser   );
231         SENF_PARSER_FIELD ( headerLength, UInt8Parser );
232
233         typedef detail::FixedAuxParserPolicy<UInt8Parser, 1u> ListOptionTypeAuxPolicy;
234         typedef detail::ListOptionTypeParser_Policy<
235             IPv6GenericOptionTLVParser, ListOptionTypeAuxPolicy> ListOptionTypePolicy;
236         typedef ListParser<ListOptionTypePolicy> ListOptionTypeParser;
237
238         SENF_PARSER_FIELD  ( options, ListOptionTypeParser);
239
240         SENF_PARSER_FINALIZE ( IPv6HopByHopOptionsPacketParser );
241     };
242     
243     /** \brief IPv6 Hop-By-Hop extension
244
245         \par Packet type (typedef):
246             \ref IPv6HopByHopOptionsPacket
247
248         \par Fields:
249             \ref IPv6HopByHopOptionsPacketParser
250         
251         \par Associated registries:
252             \ref IpTypes
253         
254         \par Finalize action:
255             Set \a nextHeader from type of next packet if found in \ref IpTypes
256
257         \ingroup protocolbundle_default
258     */
259     struct IPv6HopByHopOptionsPacketType
260     :   public PacketTypeBase,
261         public PacketTypeMixin<IPv6HopByHopOptionsPacketType, IpTypes>
262     {
263 #ifndef DOXYGEN
264         typedef PacketTypeMixin<IPv6HopByHopOptionsPacketType, IpTypes> mixin;
265 #endif
266         /** \brief IPv6 Hop-By-Hop extension packet typedef */
267         typedef ConcretePacket<IPv6HopByHopOptionsPacketType> packet;
268         /** \brief typedef to the parser of IPv6 Hop-By-Hop extension packet */
269         typedef IPv6HopByHopOptionsPacketParser parser;
270         
271         using mixin::nextPacketRange;
272         using mixin::nextPacketType;
273         using mixin::init;
274         using mixin::initSize;
275         
276         static key_t nextPacketKey(packet p) 
277         { return p->nextHeader(); }
278         
279         /** \brief Dump given IPv6HopByHopOptionsPacket in readable form to given output stream */
280         static void dump(packet p, std::ostream & os); 
281         
282         static void finalize(packet p) { 
283             p->nextHeader() << key(p.next(nothrow)); }
284     };
285     
286     /** \brief IPv6 routing Hop-By-Hop packet typedef */
287     typedef ConcretePacket<IPv6HopByHopOptionsPacketType> IPv6HopByHopOptionsPacket;
288     
289 // =====================================================================================================
290     
291     /** \brief Parse in IPv6 Destination Options extension header
292
293         Parser implementing the IPv6 Destination Options Header extension. 
294         The fields implemented are:
295         \image html IPv6DestinationOptionsPacket.png
296
297         \see IPv6ExtensionType_Destination \n
298             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
299      */    
300     struct IPv6DestinationOptionsPacketParser : public PacketParserBase 
301     {
302 #       include SENF_PARSER()
303         SENF_PARSER_FIELD ( nextHeader, UInt8Parser   );
304         SENF_PARSER_FIELD ( headerLength, UInt8Parser );
305         
306         SENF_PARSER_FINALIZE ( IPv6DestinationOptionsPacketParser );
307     };
308     
309     /** \brief IPv6 Destination Options extension
310
311         \par Packet type (typedef):
312             \ref IPv6DestinationOptionsPacket
313
314         \par Fields:
315             \ref IPv6DestinationOptionsPacketParser
316         
317         \par Associated registries:
318             \ref IpTypes
319         
320         \par Finalize action:
321             Set \a nextHeader from type of next packet if found in \ref IpTypes
322
323         \ingroup protocolbundle_default
324      */
325     struct IPv6DestinationOptionsPacketType
326     :   public PacketTypeBase,
327         public PacketTypeMixin<IPv6DestinationOptionsPacketType, IpTypes>
328     {
329 #ifndef DOXYGEN
330         typedef PacketTypeMixin<IPv6DestinationOptionsPacketType, IpTypes> mixin;
331 #endif
332         /** \brief IPv6 Destination Options extension packet typedef */
333         typedef ConcretePacket<IPv6DestinationOptionsPacketType> packet;
334         /** \brief typedef to the parser of IPv6 Destination Options extension packet */
335         typedef IPv6DestinationOptionsPacketParser parser;
336         
337         using mixin::nextPacketRange;
338         using mixin::nextPacketType;
339         using mixin::init;
340         using mixin::initSize;
341         
342         static key_t nextPacketKey(packet p) 
343         { return p->nextHeader(); }
344         /** \brief Dump given IPv6DestinationOptionsPacket in readable form to given output stream */
345         static void dump(packet p, std::ostream & os); 
346         
347         static void finalize(packet p) { 
348             p->nextHeader() << key(p.next(nothrow)); }
349     };
350     
351     /** \brief IPv6 routing Destination Options packet typedef */
352     typedef ConcretePacket<IPv6DestinationOptionsPacketType> IPv6DestinationOptionsPacket;
353     
354 }
355
356 ///////////////////////////////hh.e////////////////////////////////////////
357 //#include "IPv6Extensions.cci"
358 //#include "IPv6Extensions.ct"
359 //#include "IPv6Extensions.cti"
360 #endif
361
362 \f
363 // Local Variables:
364 // mode: c++
365 // fill-column: 100
366 // c-file-style: "senf"
367 // indent-tabs-mode: nil
368 // ispell-local-dictionary: "american"
369 // compile-command: "scons -u test"
370 // comment-column: 40
371 // End: