f2f3a47834cc596d4eb3bd42193223fc50109ae3
[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 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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     };
103
104     /** \brief IPv6 fragment extension packet typedef
105         \ingroup protocolbundle_default
106      */
107     typedef ConcretePacket<IPv6FragmentPacketType> IPv6FragmentPacket;
108
109 // =====================================================================================================
110
111     /** \brief Parse in IPv6 routing extension header
112
113         Parser implementing the IPv6 routing Header extension (type 0 only).
114         The fields implemented are:
115         \image html IPv6RoutingPacket.png
116
117         \see IPv6ExtensionType_Routing \n
118             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
119      */
120     struct IPv6RoutingPacketParser : public PacketParserBase
121     {
122         /*
123         The Type 0 Routing header has the following format: (RFC 2460)
124
125         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
126         |  Next Header  |  Hdr Ext Len  | Routing Type=0| Segments Left |
127         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128         |                            Reserved                           |
129         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
130         |                                                               |
131         +
132         |                                                               |
133         +                           Address[1]
134         |                                                               |
135         +
136         |                                                               |
137         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
138         .                               .                               .
139         .                               .                               .
140         .                               .                               .
141         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142         |                                                               |
143         +
144         |                                                               |
145         +                           Address[n]
146         |                                                               |
147         +
148         |                                                               |
149         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
150         */
151 #       include SENF_PARSER()
152
153         SENF_PARSER_FIELD ( nextHeader, UInt8Parser      );
154         SENF_PARSER_FIELD ( headerLength, UInt8Parser    );
155         SENF_PARSER_FIELD ( routingType, UInt8Parser     ); //set to Zero for minimal implementation
156         SENF_PARSER_FIELD_RO ( segmentsLeft, UInt8Parser );
157         SENF_PARSER_FIELD ( reserved, UInt32Parser       ); //set to zero by RFC
158         SENF_PARSER_VECTOR ( hopAddresses, segmentsLeft, INet6AddressParser );
159
160         SENF_PARSER_FINALIZE ( IPv6RoutingPacketParser );
161
162         //provisionary, since only type 0 is implemented
163         SENF_PARSER_INIT() {
164             routingType() = 0u;
165             reserved() = 0u;
166         }
167     };
168
169     /** \brief IPv6 routing extension
170
171         \par Packet type (typedef):
172             \ref IPv6RoutingPacket
173
174         \par Fields:
175             \ref IPv6RoutingPacketParser
176
177         \par Associated registries:
178             \ref IpTypes
179
180         \par Finalize action:
181             Set \a nextHeader from type of next packet if found in \ref IpTypes
182
183         \ingroup protocolbundle_default
184      */
185     struct IPv6RoutingPacketType
186     :   public PacketTypeBase,
187         public PacketTypeMixin<IPv6RoutingPacketType, IpTypes>
188     {
189 #ifndef DOXYGEN
190         typedef PacketTypeMixin<IPv6RoutingPacketType, IpTypes> mixin;
191 #endif
192         /** \brief IPv6 routing extension packet typedef */
193         typedef ConcretePacket<IPv6RoutingPacketType> packet;
194         /** \brief typedef to the parser of IPv6 routing extension packet */
195         typedef IPv6RoutingPacketParser parser;
196
197         using mixin::nextPacketRange;
198         using mixin::nextPacketType;
199         using mixin::init;
200         using mixin::initSize;
201
202         static key_t nextPacketKey(packet p)
203             { return p->nextHeader(); }
204
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     };
210
211     /** \brief IPv6 routing extension packet typedef
212         \ingroup protocolbundle_default
213      */
214     typedef ConcretePacket<IPv6RoutingPacketType> IPv6RoutingPacket;
215
216
217 // =====================================================================================================
218
219     /** \brief Parse in IPv6 Hop-By-Hop extension header
220
221         Parser implementing the IPv6 routing Header extension. The fields implemented are:
222         \image html IPv6HopByHopOptionsPacket.png
223
224         \see IPv6ExtensionType_HopByHop \n
225             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
226     */
227     struct IPv6HopByHopOptionsPacketParser : public PacketParserBase
228     {
229 #       include SENF_PARSER()
230
231         SENF_PARSER_FIELD    ( nextHeader, UInt8Parser   );
232         SENF_PARSER_FIELD_RO ( headerLength, UInt8Parser );
233
234         typedef detail::FixedAuxParserPolicy<UInt8Parser, 1u> ListOptionTypeAuxPolicy;
235         typedef detail::ListOptionTypeParser_Policy<
236             IPv6GenericOptionParser, ListOptionTypeAuxPolicy> ListOptionTypePolicy;
237         typedef ListParser<ListOptionTypePolicy> ListOptionTypeParser;
238
239         SENF_PARSER_FIELD  ( options, ListOptionTypeParser);
240
241         SENF_PARSER_FINALIZE ( IPv6HopByHopOptionsPacketParser );
242     };
243
244     /** \brief IPv6 Hop-By-Hop extension
245
246         \par Packet type (typedef):
247             \ref IPv6HopByHopOptionsPacket
248
249         \par Fields:
250             \ref IPv6HopByHopOptionsPacketParser
251
252         \par Associated registries:
253             \ref IpTypes
254
255         \par Finalize action:
256             Set \a nextHeader from type of next packet if found in \ref IpTypes
257
258         \ingroup protocolbundle_default
259     */
260     struct IPv6HopByHopOptionsPacketType
261     :   public PacketTypeBase,
262         public PacketTypeMixin<IPv6HopByHopOptionsPacketType, IpTypes>
263     {
264 #ifndef DOXYGEN
265         typedef PacketTypeMixin<IPv6HopByHopOptionsPacketType, IpTypes> mixin;
266 #endif
267         /** \brief IPv6 Hop-By-Hop extension packet typedef */
268         typedef ConcretePacket<IPv6HopByHopOptionsPacketType> packet;
269         /** \brief typedef to the parser of IPv6 Hop-By-Hop extension packet */
270         typedef IPv6HopByHopOptionsPacketParser parser;
271
272         using mixin::nextPacketRange;
273         using mixin::nextPacketType;
274         using mixin::init;
275         using mixin::initSize;
276
277         static key_t nextPacketKey(packet p) {
278             return p->nextHeader(); }
279
280         /** \brief Dump given IPv6HopByHopOptionsPacket in readable form to given output stream */
281         static void dump(packet p, std::ostream & os);
282
283         static void finalize(packet p);
284     };
285
286     /** \brief IPv6 routing Hop-By-Hop packet typedef
287         \ingroup protocolbundle_default
288      */
289     typedef ConcretePacket<IPv6HopByHopOptionsPacketType> IPv6HopByHopOptionsPacket;
290
291 // =====================================================================================================
292
293     /** \brief Parse in IPv6 Destination Options extension header
294
295         Parser implementing the IPv6 Destination Options Header extension.
296         The fields implemented are:
297         \image html IPv6DestinationOptionsPacket.png
298
299         \see IPv6ExtensionType_Destination \n
300             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
301      */
302     struct IPv6DestinationOptionsPacketParser : public PacketParserBase
303     {
304 #       include SENF_PARSER()
305         SENF_PARSER_FIELD ( nextHeader, UInt8Parser   );
306         SENF_PARSER_FIELD_RO ( headerLength, UInt8Parser );
307         typedef detail::FixedAuxParserPolicy<UInt8Parser, 1u> ListOptionTypeAuxPolicy;
308         typedef detail::ListOptionTypeParser_Policy<
309             IPv6GenericOptionParser, ListOptionTypeAuxPolicy> ListOptionTypePolicy;
310         typedef ListParser<ListOptionTypePolicy> ListOptionTypeParser;
311
312         SENF_PARSER_FIELD  ( options, ListOptionTypeParser);
313
314         SENF_PARSER_FINALIZE ( IPv6DestinationOptionsPacketParser );
315     };
316
317     /** \brief IPv6 Destination Options extension
318
319         \par Packet type (typedef):
320             \ref IPv6DestinationOptionsPacket
321
322         \par Fields:
323             \ref IPv6DestinationOptionsPacketParser
324
325         \par Associated registries:
326             \ref IpTypes
327
328         \par Finalize action:
329             Set \a nextHeader from type of next packet if found in \ref IpTypes
330
331         \ingroup protocolbundle_default
332      */
333     struct IPv6DestinationOptionsPacketType
334     :   public PacketTypeBase,
335         public PacketTypeMixin<IPv6DestinationOptionsPacketType, IpTypes>
336     {
337 #ifndef DOXYGEN
338         typedef PacketTypeMixin<IPv6DestinationOptionsPacketType, IpTypes> mixin;
339 #endif
340         /** \brief IPv6 Destination Options extension packet typedef */
341         typedef ConcretePacket<IPv6DestinationOptionsPacketType> packet;
342         /** \brief typedef to the parser of IPv6 Destination Options extension packet */
343         typedef IPv6DestinationOptionsPacketParser 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 IPv6DestinationOptionsPacket in readable form to given output stream */
353         static void dump(packet p, std::ostream & os);
354
355         static void finalize(packet p);
356     };
357
358     /** \brief IPv6 routing Destination Options packet typedef
359         \ingroup protocolbundle_default
360      */
361     typedef ConcretePacket<IPv6DestinationOptionsPacketType> IPv6DestinationOptionsPacket;
362
363 }
364
365 //-/////////////////////////////////////////////////////////////////////////////////////////////////
366 //#include "IPv6Extensions.cci"
367 //#include "IPv6Extensions.ct"
368 //#include "IPv6Extensions.cti"
369 #endif
370
371 \f
372 // Local Variables:
373 // mode: c++
374 // fill-column: 100
375 // c-file-style: "senf"
376 // indent-tabs-mode: nil
377 // ispell-local-dictionary: "american"
378 // compile-command: "scons -u test"
379 // comment-column: 40
380 // End: