Packets/DefaultBundle: Implement ICMPv6Packet::create unit test
[senf.git] / senf / Packets / DefaultBundle / ICMPv6TypePacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Philipp Batroff <pug@berlios.de>
7 //
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 // Definition of non-inline non-template functions
24
25 #ifndef HH_SENF_Packets_DefaultBundle_ICMPv6TypePacket_
26 #define HH_SENF_Packets_DefaultBundle_ICMPv6TypePacket_ 1
27
28 // Custom includes
29 #include <senf/Packets/Packets.hh>
30 #include "IPv6Packet.hh"
31 #include "ICMPv6Packet.hh"
32
33 namespace senf {
34
35     //#############################################################
36     //ICMPv6 Echo Request
37     //#############################################################
38     struct ICMPv6EchoRequestParser : public PacketParserBase
39     {
40 #       include SENF_FIXED_PARSER()
41         SENF_PARSER_FIELD ( identifier, UInt16Parser );
42         SENF_PARSER_FIELD ( seqNr,      UInt16Parser );
43         
44         SENF_PARSER_FINALIZE ( ICMPv6EchoRequestParser );
45     };
46     
47     /** \brief ICMPv6 Echo Request
48
49         \par Packet type (typedef):
50             \ref ICMPv6EchoRequest
51
52         \par Fields:
53             \ref ICMPv6EchoRequestParser
54             \image html ICMPv6EchoRequest.png
55
56         \ingroup protocolbundle_default
57      */
58     struct ICMPv6EchoRequestType
59         : public PacketTypeBase,
60           public PacketTypeMixin<ICMPv6EchoRequestType>
61     {
62         typedef PacketTypeMixin<ICMPv6EchoRequestType> mixin;
63         typedef ConcretePacket<ICMPv6EchoRequestType> packet;
64         typedef ICMPv6EchoRequestParser parser;
65         
66         using mixin::nextPacketRange;
67         using mixin::init;
68         using mixin::initSize;
69
70         static void dump(packet p, std::ostream & os);
71     };
72     
73     typedef ConcretePacket<ICMPv6EchoRequestType> ICMPv6EchoRequest;
74     
75     //#############################################################
76     //ICMPv6 Echo Reply
77     //#############################################################
78     struct ICMPv6EchoReplyParser : public PacketParserBase
79     {
80 #       include SENF_FIXED_PARSER()
81         SENF_PARSER_FIELD ( identifier, UInt16Parser );
82         SENF_PARSER_FIELD ( seqNr,      UInt16Parser );
83         
84         SENF_PARSER_FINALIZE ( ICMPv6EchoReplyParser );
85     };
86     
87     /** \brief ICMPv6 Echo Reply
88
89         \par Packet type (typedef):
90             \ref ICMPv6EchoReply
91
92         \par Fields:
93             \ref ICMPv6EchoReplyParser
94             \image html ICMPv6EchoReply.png
95
96         \ingroup protocolbundle_default
97      */
98     struct ICMPv6EchoReplyType
99         : public PacketTypeBase,
100           public PacketTypeMixin<ICMPv6EchoReplyType>
101     {
102         typedef PacketTypeMixin<ICMPv6EchoReplyType> mixin;
103         typedef ConcretePacket<ICMPv6EchoReplyType> packet;
104         typedef ICMPv6EchoReplyParser parser;
105         
106         using mixin::nextPacketRange;
107         using mixin::init;
108         using mixin::initSize;
109     };
110         
111     typedef ConcretePacket<ICMPv6EchoReplyType> ICMPv6EchoReply;
112     
113     //#############################################################
114     //ICMPv6 Error Destination Unreachable Message
115     //#############################################################
116     struct ICMPv6ErrDestUnreachableParser : public PacketParserBase
117     {
118 #       include SENF_FIXED_PARSER()
119         
120         //should be set static 0 by sender and ignored by receiver
121         SENF_PARSER_PRIVATE_FIELD ( unused, UInt32Parser );
122         
123         SENF_PARSER_INIT() { 
124             unused() = 0; 
125         }
126         /*   Code     0 - No route to destination
127                     1 - Communication with destination
128                             administratively prohibited
129                     2 - Beyond scope of source address
130                     3 - Address unreachable
131                     4 - Port unreachable
132                     5 - Source address failed ingress/egress policy
133                     6 - Reject route to destination   */
134         void setErrCode(int code) {
135             ICMPv6Packet icmpv6 (senf::Packet().rfind<ICMPv6Packet>(senf::nothrow));
136             icmpv6->code() = code;
137         }
138         
139         SENF_PARSER_FINALIZE ( ICMPv6ErrDestUnreachableParser );
140     };
141     
142     /** \brief ICMPv6 Destination unreachable
143
144         \par Packet type (typedef):
145             \ref ICMPv6ErrDestUnreachable
146
147         \par Fields:
148             \ref ICMPv6ErrDestUnreachableParser
149             \image html ICMPv6ErrDestUnreachable.png
150  
151         \ingroup protocolbundle_default
152     */
153     struct ICMPv6ErrDestUnreachableType
154         : public PacketTypeBase,
155           public PacketTypeMixin<ICMPv6ErrDestUnreachableType>
156     {
157         typedef PacketTypeMixin<ICMPv6ErrDestUnreachableType> mixin;
158         typedef ConcretePacket<ICMPv6ErrDestUnreachableType> packet;
159         typedef ICMPv6ErrDestUnreachableParser parser;
160         
161         using mixin::nextPacketRange;
162         using mixin::init;
163         using mixin::initSize;
164     };
165         
166     typedef ConcretePacket<ICMPv6ErrDestUnreachableType> ICMPv6ErrDestUnreachable;
167     
168     //#############################################################
169     //ICMPv6 Error Packet Too Big Message
170     //#############################################################
171     struct ICMPv6ErrTooBigParser : public PacketParserBase
172     {
173 #       include SENF_FIXED_PARSER()
174         SENF_PARSER_FIELD ( mtu, UInt32Parser );
175     
176         /*   Code     static set to 0       */
177     //     SENF_PARSER_INIT() {
178     //         ICMPv6Packet icmpv6 (packet().rfind<ICMPv6Packet>(senf::nothrow));
179     //         icmpv6->code() = 0;
180     //     }
181         
182         SENF_PARSER_FINALIZE ( ICMPv6ErrTooBigParser );
183     };
184     
185     /** \brief ICMPv6 Packet to big
186
187         \par Packet type (typedef):
188             \ref ICMPv6ErrTooBig
189
190         \par Fields:
191             \ref ICMPv6ErrTooBigParser
192             \image html ICMPv6ErrTooBig.png
193
194         \ingroup protocolbundle_default
195      */
196     struct ICMPv6ErrTooBigType
197         : public PacketTypeBase,
198           public PacketTypeMixin<ICMPv6ErrTooBigType>
199     {
200         typedef PacketTypeMixin<ICMPv6ErrTooBigType> mixin;
201         typedef ConcretePacket<ICMPv6ErrTooBigType> packet;
202         typedef ICMPv6ErrTooBigParser parser;
203         
204         using mixin::nextPacketRange;
205         using mixin::init;
206         using mixin::initSize;
207     };
208
209     typedef ConcretePacket<ICMPv6ErrTooBigType> ICMPv6ErrTooBig;
210     
211     //#############################################################
212     //ICMPv6 Error Time Exceeded Message
213     //#############################################################
214     struct ICMPv6ErrTimeExceededParser : public PacketParserBase
215     {
216 #       include SENF_FIXED_PARSER()
217         //should be set static 0 by sender and ignored by receiver
218         SENF_PARSER_FIELD    ( unused, UInt32Parser );
219         /*  Code    0 - Hop limit exceeded in transit
220                     1 - Fragment reassembly time exceeded   */
221         void setErrCode(int code){
222             ICMPv6Packet icmpv6 (packet().rfind<ICMPv6Packet>(senf::nothrow));
223             icmpv6->code() = code;
224         }
225         
226         SENF_PARSER_FINALIZE ( ICMPv6ErrTimeExceededParser );
227     };
228     
229     /** \brief ICMPv6 Time exceeded
230
231         \par Packet type (typedef):
232             \ref ICMPv6ErrTimeExceeded
233
234         \par Fields:
235             \ref ICMPv6ErrTimeExceededParser
236             \image html ICMPv6ErrTimeExceeded.png
237
238         \ingroup protocolbundle_default
239      */
240     struct ICMPv6ErrTimeExceededType
241         : public PacketTypeBase,
242           public PacketTypeMixin<ICMPv6ErrTimeExceededType>
243     {
244         typedef PacketTypeMixin<ICMPv6ErrTimeExceededType> mixin;
245         typedef ConcretePacket<ICMPv6ErrTimeExceededType> packet;
246         typedef ICMPv6ErrTimeExceededParser parser;
247         
248         using mixin::nextPacketRange;
249         using mixin::init;
250         using mixin::initSize;
251     };
252     typedef ConcretePacket<ICMPv6ErrTimeExceededType> ICMPv6ErrTimeExceeded;
253     
254     //#############################################################
255     //ICMPv6 Error Parameter Problem Message
256     //#############################################################
257     struct ICMPv6ErrParamProblemParser : public PacketParserBase
258     {
259 #       include SENF_FIXED_PARSER()
260         //should be set static 0 by sender and ignored by receiver
261         SENF_PARSER_FIELD ( pointer, UInt32Parser );
262         /*  Code      0 - Erroneous header field encountered
263                     1 - Unrecognized Next Header type encountered
264                     2 - Unrecognized IPv6 option encountered          */
265         
266         void setErrCode(int code){
267             ICMPv6Packet icmpv6 (packet().rfind<ICMPv6Packet>(senf::nothrow));
268             icmpv6->code() = code;
269         }
270         SENF_PARSER_FINALIZE ( ICMPv6ErrParamProblemParser );
271     };
272     
273     /** \brief ICMPv6 Parameter problem
274
275         \par Packet type (typedef):
276             \ref ICMPv6ErrParamProblem
277
278         \par Fields:
279             \ref ICMPv6ErrParamProblemParser
280             \image html ICMPv6ErrParamProblem.png
281
282         \ingroup protocolbundle_default
283      */
284     struct ICMPv6ErrParamProblemType
285         : public PacketTypeBase,
286           public PacketTypeMixin<ICMPv6ErrParamProblemType>
287     {
288         typedef PacketTypeMixin<ICMPv6ErrParamProblemType> mixin;
289         typedef ConcretePacket<ICMPv6ErrParamProblemType> packet;
290         typedef ICMPv6ErrParamProblemParser parser;
291         
292         using mixin::nextPacketRange;
293         using mixin::init;
294         using mixin::initSize;
295     };
296     typedef ConcretePacket<ICMPv6ErrParamProblemType> ICMPv6ErrParamProblem;
297     
298     //#############################################################
299     //ICMPv6 MLDv2 (RFC 3810) Multicast Listener Query
300     //#############################################################
301     struct MLDv2ListenerQueryParser : public PacketParserBase
302     {
303 #      include SENF_PARSER()
304         //need a variant here
305         // a.) maxResponseCode < 32768 =>Interger
306         // b.) maxResponseCode >=32768 => float (is there a float parser???)
307         /* 
308         float value as followed: 
309         0 1 2 3 4 5 6 7 8 9 A B C D E F
310         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
311         |1| exp |          mant         |
312         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */
313         
314         SENF_PARSER_FIELD ( maxResponseCode, UInt16Parser       );
315         SENF_PARSER_FIELD ( reserved,        UInt16Parser       ); // set to zero by default
316         SENF_PARSER_FIELD ( mcAddress,       INet6AddressParser );
317         SENF_PARSER_BITFIELD ( resv,  4, unsigned ); // set to zero by default
318         SENF_PARSER_BITFIELD ( sFlag, 1, unsigned );
319         SENF_PARSER_BITFIELD ( qrv,   3, unsigned );
320         SENF_PARSER_FIELD    ( qqic, UInt8Parser );
321         SENF_PARSER_PRIVATE_FIELD ( nrSources, UInt16Parser );
322         SENF_PARSER_VECTOR   (srcAddresses, nrSources, INet6AddressParser );
323         
324         SENF_PARSER_FINALIZE ( MLDv2ListenerQueryParser );
325         
326         SENF_PARSER_INIT() { 
327             reserved() = 0; 
328             resv() = 0;
329         }
330     };
331     
332     /** \brief MLDv2 Listener query
333
334         \par Packet type (typedef):
335             \ref MLDv2ListenerQuery
336
337         \par Fields:
338             \ref MLDv2ListenerQueryParser
339             \image html MLDv2ListenerQuery.png
340
341         \ingroup protocolbundle_default
342      */
343     struct MLDv2ListenerQueryType
344         : public PacketTypeBase,
345           public PacketTypeMixin<MLDv2ListenerQueryType>
346     {
347         typedef PacketTypeMixin<MLDv2ListenerQueryType> mixin;
348         typedef ConcretePacket<MLDv2ListenerQueryType> packet;
349         typedef MLDv2ListenerQueryParser parser;
350         
351         using mixin::nextPacketRange;
352         using mixin::init;
353         using mixin::initSize;
354     };
355         
356     typedef ConcretePacket<MLDv2ListenerQueryType> MLDv2ListenerQuery;
357     
358     //#############################################################
359     //ICMPv6 MLDv2 (RFC 3810) Multicast Listener Report Message
360     //#############################################################
361     //First: the Multicast Address Record Parser
362     struct MLDv2AddressRecordParser : public PacketParserBase
363     {
364 #       include SENF_PARSER()
365         
366         SENF_PARSER_FIELD   ( recordType, UInt8Parser );
367         SENF_PARSER_PRIVATE_FIELD   ( auxDataLen, UInt8Parser );
368         SENF_PARSER_PRIVATE_FIELD   ( nrOfSrcs, UInt16Parser );
369         SENF_PARSER_FIELD   ( mcAddress, INet6AddressParser);
370         SENF_PARSER_VECTOR  ( srcAddresses, nrOfSrcs, INet6AddressParser );
371         SENF_PARSER_VECTOR  ( auxData, auxDataLen, UInt32Parser );
372         
373         SENF_PARSER_FINALIZE ( MLDv2AddressRecordParser );
374     };
375     
376     struct MLDv2ListenerReportParser : public PacketParserBase
377     {
378 #       include SENF_PARSER()
379         
380         SENF_PARSER_FIELD   ( reserved, UInt16Parser );   //set to zero by default
381         SENF_PARSER_PRIVATE_FIELD   ( nrMcastAddrRecords_, UInt16Parser );
382         SENF_PARSER_LIST    ( mcastAddrRecords, nrMcastAddrRecords_, MLDv2AddressRecordParser );
383         
384         SENF_PARSER_FINALIZE ( MLDv2ListenerReportParser );
385         
386         SENF_PARSER_INIT() { 
387             reserved() = 0; 
388         }
389     };
390     
391     /** \brief MLDv2 Listener report
392
393         \par Packet type (typedef):
394             \ref MLDv2ListenerReport
395
396         \par Fields:
397             \ref MLDv2ListenerReportParser
398             \image html MLDv2ListenerReport.png
399             \image html MLDv2AddressRecord.png
400
401         \ingroup protocolbundle_default
402      */
403     struct MLDv2ListenerReportType
404         : public PacketTypeBase,
405           public PacketTypeMixin<MLDv2ListenerReportType>
406     {
407         typedef PacketTypeMixin<MLDv2ListenerReportType> mixin;
408         typedef ConcretePacket<MLDv2ListenerReportType> packet;
409         typedef MLDv2ListenerReportParser parser;
410         
411         using mixin::nextPacketRange;
412         using mixin::init;
413         using mixin::initSize;
414     };
415         
416     typedef ConcretePacket<MLDv2ListenerReportType> MLDv2ListenerReport;
417 }
418
419 #endif
420
421 \f
422 // Local Variables:
423 // mode: c++
424 // fill-column: 100
425 // c-file-style: "senf"
426 // indent-tabs-mode: nil
427 // ispell-local-dictionary: "american"
428 // compile-command: "scons -u test"
429 // comment-column: 40
430 // End: