Added ICMPv6 Packet Parser and Unittests for different ICMP Packages.
[senf.git] / Packets / DefaultBundle / ICMPv6Packet.hh
1 // Copyright (C) 2008
2 // Fraunhofer Institute for Open Communication Systems (FOKUS)
3 // Competence Center NETwork research (NET), St. Augustin, GERMANY
4 //     Philipp Batroff <Philipp.Batroff@fokus.fraunhofer.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 #ifndef HH_ICMPV6Packet
22 #define HH_ICMPV6Packet
23
24 // Custom includes
25 #include "../../Packets/Packets.hh"
26 #include "../../Packets/DefaultBundle/IPv6Packet.hh"
27
28 namespace senf{
29     struct ICMPV6PacketParser : public senf::PacketParserBase
30     {
31     #       include SENF_FIXED_PARSER()
32             SENF_PARSER_FIELD    ( type, senf::UInt8Parser );
33             SENF_PARSER_FIELD    ( code, senf::UInt8Parser );
34             SENF_PARSER_PRIVATE_FIELD ( checksum, senf::UInt16Parser);
35     
36             SENF_PARSER_FINALIZE ( ICMPV6PacketParser );
37     
38             void calcChecksum() const;
39             boost::uint16_t checksumOutput() const
40                 { return this->checksum();}
41     };
42     
43         struct ICMPTypes {
44             // ICMP type registry
45             typedef boost::uint16_t key_t;
46         };
47     
48     struct ICMPV6PacketType 
49             : public senf::PacketTypeBase,
50             public senf::PacketTypeMixin<ICMPV6PacketType, ICMPTypes>
51     {
52         typedef senf::PacketTypeMixin<ICMPV6PacketType, ICMPTypes> mixin;
53         typedef senf::ConcretePacket<ICMPV6PacketType> packet;
54         typedef ICMPV6PacketParser parser;
55         
56         using mixin::nextPacketRange;
57         using mixin::nextPacketType;
58         using mixin::init;
59         using mixin::initSize;
60         
61         static void dump(packet p, std::ostream & os);
62         static senf::IpTypes::key_t nextPacketKey(packet p) { 
63             return p->type();
64         }
65         static void finalize(packet p) {
66             p->calcChecksum();
67             p->type() << key(p.next(senf::nothrow));
68         }
69     };
70     
71     typedef ICMPV6PacketType::packet ICMPv6Packet;
72 }
73 #endif