Packets: Add packet diagrams
[senf.git] / Packets / DefaultBundle / ICMPv6Packet.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 #ifndef HH_SENF_Packets_DefaultBundle_ICMPv6Packet_
24 #define HH_SENF_Packets_DefaultBundle_ICMPv6Packet_ 1
25
26 // Custom includes
27 #include "../../Packets/Packets.hh"
28 #include "../../Packets/DefaultBundle/IPv6Packet.hh"
29
30 namespace senf 
31 {
32
33     struct ICMPv6PacketParser : public PacketParserBase
34     {
35 #       include SENF_FIXED_PARSER()
36         SENF_PARSER_FIELD ( type,     UInt8Parser  );
37         SENF_PARSER_FIELD ( code,     UInt8Parser  );
38         SENF_PARSER_FIELD ( checksum, UInt16Parser );
39     
40         SENF_PARSER_FINALIZE ( ICMPv6PacketParser );
41         
42         boost::uint16_t calcChecksum() const;
43     };
44     
45     struct ICMPTypes {
46         // ICMP type registry
47         typedef boost::uint16_t key_t;
48     };
49
50     /** \brief ICMP Packet for IPv6
51
52         \par Packet type (typedef):
53             \ref ICMPv6Packet
54
55         \par Fields:
56             \ref ICMPv6PacketParser
57             \image html ICMPv6Packet.png
58         
59         \par Associated registries:
60             \ref ICMPTypes
61
62         \ingroup protocolbundle_default
63      */
64     struct ICMPv6PacketType 
65         : public PacketTypeBase,
66           public PacketTypeMixin<ICMPv6PacketType, ICMPTypes>
67     {
68         typedef PacketTypeMixin<ICMPv6PacketType, ICMPTypes> mixin;
69         typedef ConcretePacket<ICMPv6PacketType> packet;
70         typedef ICMPv6PacketParser parser;
71         
72         using mixin::nextPacketRange;
73         using mixin::nextPacketType;
74         using mixin::init;
75         using mixin::initSize;
76         
77         static void dump(packet p, std::ostream & os);
78         
79         static IpTypes::key_t nextPacketKey(packet p) { 
80             return p->type();
81         }
82         
83         static void finalize(packet p) {
84             p->checksum() << p->calcChecksum();
85             p->type() << key(p.next(senf::nothrow));
86         }
87     };
88     
89     typedef ConcretePacket<ICMPv6PacketType> ICMPv6Packet;
90 }
91
92 #endif
93
94 \f
95 // Local Variables:
96 // mode: c++
97 // fill-column: 100
98 // c-file-style: "senf"
99 // indent-tabs-mode: nil
100 // ispell-local-dictionary: "american"
101 // compile-command: "scons -u test"
102 // comment-column: 40
103 // End:
104 ss