Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Packets / DefaultBundle / EthernetPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@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 /** \file
24     \brief EthernetPacket public header */
25
26 #ifndef HH_SENF_Packets_DefaultBundle_EthernetPacket_
27 #define HH_SENF_Packets_DefaultBundle_EthernetPacket_ 1
28
29 // Custom includes
30 #include <algorithm>
31 #include <senf/Socket/Protocols/Raw/MACAddress.hh>
32 #include <senf/Packets/Packets.hh>
33
34 //#include "EthernetPacket.mpp"
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36
37 namespace senf {
38
39     /** \brief Parse an Ethernet MAC address
40
41         The ethernet MAC is returned by value as a 6-byte sequence
42
43         \see MACAddress \n
44             EthernetPacket
45      */
46     struct MACAddressParser
47         : public ValueParserBase<MACAddressParser, MACAddress, 6u>
48     {
49         MACAddressParser(data_iterator i, state_type s) : Base(i,s) {}
50
51         value_type value() const { return MACAddress::from_data(i()); }
52         void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
53
54         using Base::operator=;
55     };
56
57     /** \brief Parse an Ethernet packet
58
59         Parser implementing an ethernet header.
60
61         \see EthernetPacketType
62      */
63     struct EthernetPacketParser : public PacketParserBase
64     {
65 #       include SENF_FIXED_PARSER()
66
67         SENF_PARSER_FIELD( destination, MACAddressParser    );
68         SENF_PARSER_FIELD( source,      MACAddressParser    );
69         SENF_PARSER_FIELD( type_length, UInt16Parser );
70
71         SENF_PARSER_FINALIZE(EthernetPacketParser);
72     };
73
74     /** \brief EtherType registry
75
76         This registry registers packet types with their EtherType number.
77
78         \see <a href="http://www.iana.org/assignments/ethernet-numbers">Ethernet numbers</a> \n
79             \ref PacketRegistry
80      */
81     struct EtherTypes {
82         typedef boost::uint16_t key_t;
83     };
84
85     /** \brief Ethernet packet
86
87         \par Packet type (typedef):
88             \ref EthernetPacket
89
90         \par Fields:
91             \ref EthernetPacketParser
92             \image html EthernetPacket.png
93
94         \par Associated registries:
95             \ref EtherTypes
96
97         \par Finalize action:
98             Set \a type from type of next packet if found in \ref EtherTypes
99
100         \ingroup protocolbundle_default
101      */
102     struct EthernetPacketType
103         : public PacketTypeBase,
104           public PacketTypeMixin<EthernetPacketType, EtherTypes>
105     {
106 #ifndef DOXYGEN
107         typedef PacketTypeMixin<EthernetPacketType, EtherTypes> mixin;
108 #endif
109         typedef ConcretePacket<EthernetPacketType> packet;
110         typedef EthernetPacketParser parser;
111
112         using mixin::nextPacketRange;
113         using mixin::initSize;
114         using mixin::init;
115
116         static factory_t nextPacketType(packet p);
117         /// Dump given EthernetPacket in readable form to given output stream
118         static void dump(packet p, std::ostream & os);
119         static void finalize(packet p);
120     };
121
122     /** \brief Ethernet packet typedef
123         \ingroup protocolbundle_default
124      */
125     typedef ConcretePacket<EthernetPacketType> EthernetPacket;
126
127
128     /** \brief Parse an ethernet VLAN tag
129
130         Parser interpreting the ethernet VLAN tag. Fields are
131
132         \see EthVLanPacketType
133      */
134     struct EthVLanPacketParser : public PacketParserBase
135     {
136 #       include SENF_FIXED_PARSER()
137
138         SENF_PARSER_BITFIELD( priority,  3, unsigned );
139         SENF_PARSER_BITFIELD( cfi,       1, bool     );
140         SENF_PARSER_BITFIELD( vlanId,   12, unsigned );
141
142         SENF_PARSER_FIELD( type, UInt16Parser );
143
144         SENF_PARSER_FINALIZE(EthVLanPacketParser);
145     };
146
147     /** \brief Ethernet VLAN tag
148
149         \par Packet type (typedef):
150             \ref EthVLanPacket
151
152         \par Fields:
153             \ref EthVLanPacketParser
154             \image html EthVLanPacket.png
155
156         \par Associated registries:
157             \ref EtherTypes
158
159         \par Finalize action:
160             Set \a type from type of next packet if found in \ref EtherTypes
161
162         \ingroup protocolbundle_default
163      */
164     struct EthVLanPacketType
165         : public PacketTypeBase,
166           public PacketTypeMixin<EthVLanPacketType, EtherTypes>
167     {
168 #ifndef DOXYGEN
169         typedef PacketTypeMixin<EthVLanPacketType, EtherTypes> mixin;
170 #endif
171         typedef ConcretePacket<EthVLanPacketType> packet;
172         typedef EthVLanPacketParser parser;
173
174         using mixin::nextPacketRange;
175         using mixin::nextPacketType;
176         using mixin::initSize;
177         using mixin::init;
178
179         /** \todo Add LLC/SNAP support -> only use the registry
180             for type() values >=1536, otherwise expect an LLC header */
181         static key_t nextPacketKey(packet p)
182             { return p->type(); }
183
184         /// Dump given EthVLanPacket in readable form to given output stream
185         static void dump(packet p, std::ostream & os);
186         static void finalize(packet p);
187     };
188
189     /** \brief Ethernet VLAN tag typedef
190         \ingroup protocolbundle_default
191      */
192     typedef ConcretePacket<EthVLanPacketType> EthVLanPacket;
193
194 }
195
196 //-/////////////////////////////////////////////////////////////////////////////////////////////////
197 //#include "EthernetPacket.cci"
198 //#include "EthernetPacket.ct"
199 //#include "EthernetPacket.cti"
200 #endif
201
202 \f
203 // Local Variables:
204 // mode: c++
205 // fill-column: 100
206 // c-file-style: "senf"
207 // indent-tabs-mode: nil
208 // ispell-local-dictionary: "american"
209 // compile-command: "scons -u test"
210 // comment-column: 40
211 // End: