switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / DefaultBundle / IPv6Packet.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief IPv6Packet public header */
30
31 #ifndef HH_SENF_Packets_DefaultBundle_IPv6Packet_
32 #define HH_SENF_Packets_DefaultBundle_IPv6Packet_ 1
33
34 // Custom includes
35 #include <senf/Socket/Protocols/INet/INet6Address.hh>
36 #include <senf/Packets/Packets.hh>
37 #include "IPv4Packet.hh"
38
39 //#include "IPv6Packet.mpp"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41
42 namespace senf {
43
44     /** \brief Parse an IPv6 address
45
46         \see INet6Address
47      */
48     struct INet6AddressParser
49         : public ValueParserBase<INet6AddressParser, INet6Address, 16u>
50     {
51         INet6AddressParser(data_iterator i, state_type s) : Base(i,s) {}
52
53         value_type value() const { return value_type::from_data(i()); }
54         void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
55
56         using Base::operator=;
57     };
58
59     /** \brief Parse an IPv6 packet
60
61         \image html IPv6Packet.png
62         \see IPv6PacketType \n
63             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
64      */
65     struct IPv6PacketParser : public PacketParserBase
66     {
67 #       include SENF_FIXED_PARSER()
68
69         SENF_PARSER_BITFIELD( version,       4, unsigned );
70         SENF_PARSER_BITFIELD( trafficClass,  8, unsigned );
71         SENF_PARSER_BITFIELD( flowLabel,    20, unsigned );
72
73         SENF_PARSER_FIELD( length,       UInt16Parser       );
74         SENF_PARSER_FIELD( nextHeader,   UInt8Parser        );
75         SENF_PARSER_FIELD( hopLimit,     UInt8Parser        );
76         SENF_PARSER_FIELD( source,       INet6AddressParser );
77         SENF_PARSER_FIELD( destination,  INet6AddressParser );
78
79         SENF_PARSER_INIT() {
80             version() = 6;
81         }
82
83         SENF_PARSER_FINALIZE(IPv6PacketParser);
84     };
85
86     /** \brief IPv6 packet
87
88         \par Packet type (typedef):
89             \ref IPv6Packet
90
91         \par Fields:
92             \ref IPv6PacketParser
93
94         <table class="packet" cellpadding="5" cellspacing="1" border="1">
95           <tr>
96             <th width="12.5%">0</th>  <th width="12.5%">4</th> <th width="12.5%">8</th>
97             <th width="12.5%">12</th> <th width="12.5%">16</th> <th width="12.5%">20</th>
98             <th width="12.5%">24</th> <th width="6.5%">28</th>
99             <th style="text-align:right" width="6%">31</th>
100           </tr><tr>
101             <td>\ref IPv6PacketParser::version() "Version"</td>
102             <td colspan="2">\ref IPv6PacketParser::trafficClass() "Traffic Class"</td>
103             <td colspan="6">\ref IPv6PacketParser::flowLabel() "Flow Label"</td>
104           </tr><tr>
105             <td colspan="4">\ref IPv6PacketParser::length() "Payload Length"</td>
106             <td colspan="2">\ref IPv6PacketParser::nextHeader() "Next Header"</td>
107             <td colspan="3">\ref IPv6PacketParser::hopLimit() "Hop Limit"</td>
108           </tr><tr>
109             <td colspan="9" style="height:8em">
110               \ref IPv6PacketParser::source() "Source Address"</td>
111           </tr><tr>
112             <td colspan="9" style="height:8em">
113               \ref IPv6PacketParser::destination()  "Destination Address"</td>
114           </tr>
115         </table>
116
117         \par Associated registries:
118             \ref IpTypes
119
120         \par Finalize action:
121             \copydetails finalize()
122
123         \ingroup protocolbundle_default
124      */
125     struct IPv6PacketType
126         : public PacketTypeBase,
127           public PacketTypeMixin<IPv6PacketType, IpTypes>
128     {
129 #ifndef DOXYGEN
130         typedef PacketTypeMixin<IPv6PacketType, IpTypes> mixin;
131 #endif
132         typedef ConcretePacket<IPv6PacketType> packet; ///< IPv6 packet typedef
133         typedef IPv6PacketParser parser;               ///< typedef to the parser of IPv6 packet
134
135         using mixin::nextPacketRange;
136         using mixin::nextPacketType;
137         using mixin::initSize;
138         using mixin::init;
139
140         static key_t nextPacketKey(packet p)
141             { return p->nextHeader(); }
142
143         /** \brief Dump given IPv6Packet in readable form to given output stream */
144         static void dump(packet p, std::ostream & os);
145
146         static void finalize(packet p); ///< Finalize packet.
147                                         /**< \li set \ref IPv6PacketParser::length() "length"
148                                                from payload size
149                                              \li set \ref IPv6PacketParser::nextHeader()
150                                                "nextHeader" from type of next packet if found
151                                                in \ref IpTypes */
152     };
153
154     /** \brief IPv6 packet typedef
155         \ingroup protocolbundle_default
156      */
157     typedef ConcretePacket<IPv6PacketType> IPv6Packet;
158 }
159
160 //-/////////////////////////////////////////////////////////////////////////////////////////////////
161 //#include "IPv6Packet.cci"
162 //#include "IPv6Packet.ct"
163 //#include "IPv6Packet.cti"
164 #endif
165
166 \f
167 // Local Variables:
168 // mode: c++
169 // fill-column: 100
170 // c-file-style: "senf"
171 // indent-tabs-mode: nil
172 // ispell-local-dictionary: "american"
173 // compile-command: "scons -u test"
174 // comment-column: 40
175 // End: