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