Packets/DefaultBundle: Document finalize() action
[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 "../../Socket/Protocols/INet/INet6Address.hh"
29 #include "../../Packets/Packets.hh"
30 #include "IpV4Packet.hh"
31
32 //#include "IpV6Packet.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36
37     /** \brief Parse an IpV6 address
38         
39         \see INet6Address
40      */
41     struct Parse_INet6Address : public PacketParserBase
42     {
43         Parse_INet6Address(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
44
45         ///////////////////////////////////////////////////////////////////////////
46
47         typedef INet6Address value_type;
48         static const size_type fixed_bytes = 16u;
49
50         value_type value() const { return value_type::from_data(i()); }
51         void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
52         operator value_type() { return value(); }
53         byte & operator[](size_type index) { return *boost::next(i(),index); }
54         Parse_INet6Address const & operator= (value_type const & other) 
55             { value(other); return *this; }
56     };
57
58     /** \brief Parse an IpV6 packet
59
60         \see IpV6PacketType \n
61             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
62      */
63     struct Parse_IpV6 : public PacketParserBase
64     {
65 #       include SENF_FIXED_PARSER()
66
67         SENF_PARSER_BITFIELD( version,       4, unsigned );
68         SENF_PARSER_BITFIELD( trafficClass,  8, unsigned );
69         SENF_PARSER_BITFIELD( flowLabel,    20, unsigned );
70
71         SENF_PARSER_FIELD( length,       Parse_UInt16       );
72         SENF_PARSER_FIELD( nextHeader,   Parse_UInt8        );
73         SENF_PARSER_FIELD( hopLimit,     Parse_UInt8        );
74         SENF_PARSER_FIELD( source,       Parse_INet6Address );
75         SENF_PARSER_FIELD( destination,  Parse_INet6Address );
76
77         SENF_PARSER_INIT() {
78             version() = 6;
79         }
80
81         SENF_PARSER_FINALIZE(Parse_IpV6);
82     };
83
84     /** \brief IpV6 packet
85
86         \par Packet type (typedef):
87             \ref IpV6Packet
88         
89         \par Fields:
90             \ref Parse_IpV6
91
92         \par Associated registries:
93             \ref IpTypes
94
95         \par Finalize action:
96             Set \a length from payload size\n
97             Set \a nextHeader from type of next packet if found in \ref IpTypes
98
99         \ingroup protocolbundle_default
100      */
101     struct IpV6PacketType
102         : public PacketTypeBase,
103           public PacketTypeMixin<IpV6PacketType, IpTypes>
104     {
105         typedef PacketTypeMixin<IpV6PacketType, IpTypes> mixin;
106         typedef ConcretePacket<IpV6PacketType> packet;
107         typedef Parse_IpV6 parser;
108
109         using mixin::nextPacketRange;
110         using mixin::nextPacketType;
111         using mixin::initSize;
112         using mixin::init;
113
114         static registry_key_t nextPacketKey(packet p) 
115             { return p->nextHeader(); }
116         
117         static void dump(packet p, std::ostream & os);
118
119         static void finalize(packet p);
120     };
121
122     /** \brief IpV6 packet typedef */
123     typedef IpV6PacketType::packet IpV6Packet;
124
125     ///@}
126 }
127
128 ///////////////////////////////hh.e////////////////////////////////////////
129 #endif
130 #ifndef SENF_PACKETS_DECL_ONLY
131 //#include "IpV6Packet.cci"
132 //#include "IpV6Packet.ct"
133 //#include "IpV6Packet.cti"
134 #endif
135
136 \f
137 // Local Variables:
138 // mode: c++
139 // fill-column: 100
140 // c-file-style: "senf"
141 // indent-tabs-mode: nil
142 // ispell-local-dictionary: "american"
143 // compile-command: "scons -u test"
144 // comment-column: 40
145 // End: