switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / DefaultBundle / IPv6Extensions.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27 //   Philipp Batroff <pug@berlios.de>
28 /** \file
29     \brief IPv6Extensions public header */
30
31 #ifndef HH_SENF_Packets_DefaultBundle_IPv6Extensions_
32 #define HH_SENF_Packets_DefaultBundle_IPv6Extensions_ 1
33
34 // Custom includes
35 #include "IPv6ExtOptions.hh"
36 #include "ListOptionTypeParser.hh"
37 #include "IPv6Packet.hh"
38
39 //#include "IPv6Extensions.mpp"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41
42 namespace senf {
43
44     /** \brief Parse in IPv6 fragment extension header
45
46         Parser implementing the IPv6 fragment extension. The fields implemented are:
47         \image html IPv6FragmentPacket.png
48
49         \see IPv6ExtensionType_Fragment \n
50             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
51      */
52     struct IPv6FragmentPacketParser : public PacketParserBase
53     {
54 #       include SENF_FIXED_PARSER()
55
56         SENF_PARSER_FIELD            ( nextHeader     , UInt8Parser  );
57         SENF_PARSER_PRIVATE_FIELD    ( reserved1      , UInt8Parser  );
58         SENF_PARSER_BITFIELD         ( fragmentOffset , 13, unsigned );
59         SENF_PARSER_PRIVATE_BITFIELD ( reserved2      ,  2, unsigned );
60         SENF_PARSER_BITFIELD         ( moreFragments  ,  1, bool     );
61         SENF_PARSER_FIELD            ( id             , UInt32Parser );
62
63         SENF_PARSER_FINALIZE(IPv6FragmentPacketParser);
64     };
65
66     /** \brief IPv6 fragment extension
67
68         \par Packet type (typedef):
69             \ref IPv6FragmentPacket
70
71         \par Fields:
72             \ref IPv6FragmentPacketParser
73
74         \par Associated registries:
75             \ref IpTypes
76
77         \par Finalize action:
78             Set \a nextHeader from type of next packet if found in \ref IpTypes
79
80         \ingroup protocolbundle_default
81      */
82     struct IPv6FragmentPacketType
83         : public PacketTypeBase,
84           public PacketTypeMixin<IPv6FragmentPacketType, IpTypes>
85     {
86 #ifndef DOXYGEN
87         typedef PacketTypeMixin<IPv6FragmentPacketType, IpTypes> mixin;
88 #endif
89         /** \brief IPv6 fragment extension packet typedef */
90         typedef ConcretePacket<IPv6FragmentPacketType> packet;
91         /** \brief typedef to the parser of IPv6 fragment extension packet */
92         typedef IPv6FragmentPacketParser parser;
93
94         using mixin::nextPacketRange;
95         using mixin::nextPacketType;
96         using mixin::initSize;
97         using mixin::init;
98
99         static key_t nextPacketKey(packet p)
100             { return p->nextHeader(); }
101
102         /** \brief Dump given IPv6FragmentPacket in readable form to given output stream */
103         static void dump(packet p, std::ostream & os);
104
105         static void finalize(packet p);
106     };
107
108     /** \brief IPv6 fragment extension packet typedef
109         \ingroup protocolbundle_default
110      */
111     typedef ConcretePacket<IPv6FragmentPacketType> IPv6FragmentPacket;
112
113 // =====================================================================================================
114
115     /** \brief Parse in IPv6 routing extension header
116
117         Parser implementing the IPv6 routing Header extension (type 0 only).
118         The fields implemented are:
119         \image html IPv6RoutingPacket.png
120
121         \see IPv6ExtensionType_Routing \n
122             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
123      */
124     struct IPv6RoutingPacketParser : public PacketParserBase
125     {
126         /*
127         The Type 0 Routing header has the following format: (RFC 2460)
128
129         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
130         |  Next Header  |  Hdr Ext Len  | Routing Type=0| Segments Left |
131         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
132         |                            Reserved                           |
133         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
134         |                                                               |
135         +
136         |                                                               |
137         +                           Address[1]
138         |                                                               |
139         +
140         |                                                               |
141         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142         .                               .                               .
143         .                               .                               .
144         .                               .                               .
145         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
146         |                                                               |
147         +
148         |                                                               |
149         +                           Address[n]
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 ( IPv6RoutingPacketParser );
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 IPv6RoutingPacket
177
178         \par Fields:
179             \ref IPv6RoutingPacketParser
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     struct IPv6RoutingPacketType
190     :   public PacketTypeBase,
191         public PacketTypeMixin<IPv6RoutingPacketType, IpTypes>
192     {
193 #ifndef DOXYGEN
194         typedef PacketTypeMixin<IPv6RoutingPacketType, IpTypes> mixin;
195 #endif
196         /** \brief IPv6 routing extension packet typedef */
197         typedef ConcretePacket<IPv6RoutingPacketType> packet;
198         /** \brief typedef to the parser of IPv6 routing extension packet */
199         typedef IPv6RoutingPacketParser parser;
200
201         using mixin::nextPacketRange;
202         using mixin::nextPacketType;
203         using mixin::init;
204         using mixin::initSize;
205
206         static key_t nextPacketKey(packet p)
207             { return p->nextHeader(); }
208
209         /** \brief Dump given IPv6RoutingPacket in readable form to given output stream */
210         static void dump(packet p, std::ostream & os);
211
212         static void finalize(packet p);
213     };
214
215     /** \brief IPv6 routing extension packet typedef
216         \ingroup protocolbundle_default
217      */
218     typedef ConcretePacket<IPv6RoutingPacketType> IPv6RoutingPacket;
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 IPv6HopByHopOptionsPacket.png
227
228         \see IPv6ExtensionType_HopByHop \n
229             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
230     */
231     struct IPv6HopByHopOptionsPacketParser : public PacketParserBase
232     {
233 #       include SENF_PARSER()
234
235         SENF_PARSER_FIELD    ( nextHeader, UInt8Parser   );
236         SENF_PARSER_FIELD_RO ( headerLength, UInt8Parser );
237
238         typedef detail::FixedAuxParserPolicy<UInt8Parser, 1u> ListOptionTypeAuxPolicy;
239         typedef detail::ListOptionTypeParser_Policy<
240             IPv6GenericOptionParser, ListOptionTypeAuxPolicy> ListOptionTypePolicy;
241         typedef ListParser<ListOptionTypePolicy> ListOptionTypeParser;
242
243         SENF_PARSER_FIELD  ( options, ListOptionTypeParser);
244
245         SENF_PARSER_FINALIZE ( IPv6HopByHopOptionsPacketParser );
246     };
247
248     /** \brief IPv6 Hop-By-Hop extension
249
250         \par Packet type (typedef):
251             \ref IPv6HopByHopOptionsPacket
252
253         \par Fields:
254             \ref IPv6HopByHopOptionsPacketParser
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     struct IPv6HopByHopOptionsPacketType
265     :   public PacketTypeBase,
266         public PacketTypeMixin<IPv6HopByHopOptionsPacketType, IpTypes>
267     {
268 #ifndef DOXYGEN
269         typedef PacketTypeMixin<IPv6HopByHopOptionsPacketType, IpTypes> mixin;
270 #endif
271         /** \brief IPv6 Hop-By-Hop extension packet typedef */
272         typedef ConcretePacket<IPv6HopByHopOptionsPacketType> packet;
273         /** \brief typedef to the parser of IPv6 Hop-By-Hop extension packet */
274         typedef IPv6HopByHopOptionsPacketParser parser;
275
276         using mixin::nextPacketRange;
277         using mixin::nextPacketType;
278         using mixin::init;
279         using mixin::initSize;
280
281         static key_t nextPacketKey(packet p) {
282             return p->nextHeader(); }
283
284         /** \brief Dump given IPv6HopByHopOptionsPacket in readable form to given output stream */
285         static void dump(packet p, std::ostream & os);
286
287         static void finalize(packet p);
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_RO ( headerLength, UInt8Parser );
311         typedef detail::FixedAuxParserPolicy<UInt8Parser, 1u> ListOptionTypeAuxPolicy;
312         typedef detail::ListOptionTypeParser_Policy<
313             IPv6GenericOptionParser, ListOptionTypeAuxPolicy> ListOptionTypePolicy;
314         typedef ListParser<ListOptionTypePolicy> ListOptionTypeParser;
315
316         SENF_PARSER_FIELD  ( options, ListOptionTypeParser);
317
318         SENF_PARSER_FINALIZE ( IPv6DestinationOptionsPacketParser );
319     };
320
321     /** \brief IPv6 Destination Options extension
322
323         \par Packet type (typedef):
324             \ref IPv6DestinationOptionsPacket
325
326         \par Fields:
327             \ref IPv6DestinationOptionsPacketParser
328
329         \par Associated registries:
330             \ref IpTypes
331
332         \par Finalize action:
333             Set \a nextHeader from type of next packet if found in \ref IpTypes
334
335         \ingroup protocolbundle_default
336      */
337     struct IPv6DestinationOptionsPacketType
338     :   public PacketTypeBase,
339         public PacketTypeMixin<IPv6DestinationOptionsPacketType, IpTypes>
340     {
341 #ifndef DOXYGEN
342         typedef PacketTypeMixin<IPv6DestinationOptionsPacketType, IpTypes> mixin;
343 #endif
344         /** \brief IPv6 Destination Options extension packet typedef */
345         typedef ConcretePacket<IPv6DestinationOptionsPacketType> packet;
346         /** \brief typedef to the parser of IPv6 Destination Options extension packet */
347         typedef IPv6DestinationOptionsPacketParser parser;
348
349         using mixin::nextPacketRange;
350         using mixin::nextPacketType;
351         using mixin::init;
352         using mixin::initSize;
353
354         static key_t nextPacketKey(packet p)
355         { return p->nextHeader(); }
356         /** \brief Dump given IPv6DestinationOptionsPacket in readable form to given output stream */
357         static void dump(packet p, std::ostream & os);
358
359         static void finalize(packet p);
360     };
361
362     /** \brief IPv6 routing Destination Options packet typedef
363         \ingroup protocolbundle_default
364      */
365     typedef ConcretePacket<IPv6DestinationOptionsPacketType> IPv6DestinationOptionsPacket;
366
367 }
368
369 //-/////////////////////////////////////////////////////////////////////////////////////////////////
370 //#include "IPv6Extensions.cci"
371 //#include "IPv6Extensions.ct"
372 //#include "IPv6Extensions.cti"
373 #endif
374
375 \f
376 // Local Variables:
377 // mode: c++
378 // fill-column: 100
379 // c-file-style: "senf"
380 // indent-tabs-mode: nil
381 // ispell-local-dictionary: "american"
382 // compile-command: "scons -u test"
383 // comment-column: 40
384 // End: