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