Merged revisions 262,264-265,267-282,284-298,300-311 via svnmerge from
[senf.git] / Packets / DefaultBundle / IpV6Packet.hh
1 // Copyright (C) 2007
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.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 /** \file
22     \brief IpV6Packet public header */
23
24 #ifndef HH_IpV6Packet_
25 #define HH_IpV6Packet_ 1
26
27 // Custom includes
28 #include "Packets/PacketType.hh"
29 #include "Packets/ParseInt.hh"
30 #include "Packets/PacketRegistry.hh"
31 #include "Packets/PacketParser.hh"
32 #include "Packets/ParseArray.hh"
33 #include "IpV4Packet.hh"
34
35 //#include "IpV6Packet.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 namespace senf {
39
40     // See RFC2460
41     struct Parse_IpV6 : public PacketParserBase
42     {
43         SENF_PACKET_PARSER_NO_INIT(Parse_IpV6);
44
45         ///////////////////////////////////////////////////////////////////////////
46
47         typedef Parse_UIntField <  0,  4 > Parse_Version;
48         typedef Parse_UIntField <  4, 12 > Parse_Class;
49         typedef Parse_UIntField < 12, 32 > Parse_FlowLabel;
50         typedef Parse_UInt8                Parse_8bit;
51         typedef Parse_UInt16               Parse_16bit;
52
53         typedef Parse_Array < 16, Parse_8bit > Parse_Addr;
54
55         SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
56             ((OverlayField)( version,      Parse_Version   ))
57             ((OverlayField)( trafficClass, Parse_Class     ))
58             ((Field       )( flowLabel,    Parse_FlowLabel ))
59             ((Field       )( length,       Parse_16bit     ))
60             ((Field       )( nextHeader,   Parse_8bit      ))
61             ((Field       )( hopLimit,     Parse_8bit      ))
62             ((Field       )( source,       Parse_Addr      ))
63             ((Field       )( destination,  Parse_Addr      )) );
64
65         void init() {
66             version() = 6;
67         }
68     };
69
70     struct IpV6PacketType
71         : public PacketTypeBase,
72           public PacketTypeMixin<IpV6PacketType, IpTypes>
73     {
74         typedef PacketTypeMixin<IpV6PacketType, IpTypes> mixin;
75         typedef ConcretePacket<IpV6PacketType> packet;
76         typedef Parse_IpV6 parser;
77
78         using mixin::nextPacketRange;
79         using mixin::nextPacketType;
80         using mixin::initSize;
81         using mixin::init;
82
83         static registry_key_t nextPacketKey(packet p) 
84             { return p->nextHeader(); }
85         
86         static void dump(packet p, std::ostream & os);
87     };
88
89     typedef IpV6PacketType::packet IpV6Packet;
90
91 }
92
93 ///////////////////////////////hh.e////////////////////////////////////////
94 //#include "IpV6Packet.cci"
95 //#include "IpV6Packet.ct"
96 //#include "IpV6Packet.cti"
97 #endif
98
99 \f
100 // Local Variables:
101 // mode: c++
102 // fill-column: 100
103 // c-file-style: "senf"
104 // indent-tabs-mode: nil
105 // ispell-local-dictionary: "american"
106 // compile-command: "scons -u test"
107 // comment-column: 40
108 // End: