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