4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
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
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.
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.
19 // The Original Code is Fraunhofer FOKUS code.
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.
26 // Thorsten Horstmann <tho@berlios.de>
29 \brief EthernetPacket public header */
31 #ifndef HH_SENF_Packets_DefaultBundle_EthernetPacket_
32 #define HH_SENF_Packets_DefaultBundle_EthernetPacket_ 1
35 #include <senf/Socket/Protocols/Raw/MACAddress.hh>
36 #include <senf/Packets/Packets.hh>
38 //#include "EthernetPacket.mpp"
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43 /** \brief Parse an Ethernet MAC address
45 The ethernet MAC is returned by value as a 6-byte sequence
50 struct MACAddressParser
51 : public ValueParserBase<MACAddressParser, MACAddress, 6u>
53 MACAddressParser(data_iterator i, state_type s) : Base(i,s) {}
55 value_type value() const { return MACAddress::from_data(i()); }
56 void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
58 using Base::operator=;
61 /** \brief Parse an Ethernet packet
63 Parser implementing an ethernet header.
65 \see EthernetPacketType
67 struct EthernetPacketParser : public PacketParserBase
69 # include SENF_FIXED_PARSER()
71 SENF_PARSER_FIELD( destination, MACAddressParser );
72 SENF_PARSER_FIELD( source, MACAddressParser );
73 SENF_PARSER_FIELD( type_length, UInt16Parser );
75 SENF_PARSER_FINALIZE(EthernetPacketParser);
78 /** \brief EtherType registry
80 This registry registers packet types with their EtherType number.
82 \see <a href="http://www.iana.org/assignments/ethernet-numbers">Ethernet numbers</a> \n
86 typedef boost::uint16_t key_t;
89 /** \brief Ethernet packet
91 \par Packet type (typedef):
95 \ref EthernetPacketParser
96 \image html EthernetPacket.png
98 \par Associated registries:
101 \par Finalize action:
102 Set \a type from type of next packet if found in \ref EtherTypes
104 \ingroup protocolbundle_default
106 struct EthernetPacketType
107 : public PacketTypeBase,
108 public PacketTypeMixin<EthernetPacketType, EtherTypes>
111 typedef PacketTypeMixin<EthernetPacketType, EtherTypes> mixin;
113 typedef ConcretePacket<EthernetPacketType> packet;
114 typedef EthernetPacketParser parser;
116 using mixin::nextPacketRange;
117 using mixin::initSize;
120 static factory_t nextPacketType(packet p);
121 /// Dump given EthernetPacket in readable form to given output stream
122 static void dump(packet p, std::ostream & os);
123 static void finalize(packet p);
126 /** \brief Ethernet packet typedef
127 \ingroup protocolbundle_default
129 typedef ConcretePacket<EthernetPacketType> EthernetPacket;
132 /** \brief Parse an ethernet VLAN tag
134 Parser interpreting the ethernet VLAN tag. Fields are
136 \see EthVLanPacketType
138 struct EthVLanPacketParser : public PacketParserBase
140 # include SENF_FIXED_PARSER()
142 SENF_PARSER_BITFIELD( priority, 3, unsigned );
143 SENF_PARSER_BITFIELD( cfi, 1, bool );
144 SENF_PARSER_BITFIELD( vlanId, 12, unsigned );
146 SENF_PARSER_FIELD( type, UInt16Parser );
148 SENF_PARSER_FINALIZE(EthVLanPacketParser);
151 /** \brief Ethernet VLAN tag
153 \par Packet type (typedef):
157 \ref EthVLanPacketParser
158 \image html EthVLanPacket.png
160 \par Associated registries:
163 \par Finalize action:
164 Set \a type from type of next packet if found in \ref EtherTypes
166 \ingroup protocolbundle_default
168 struct EthVLanPacketType
169 : public PacketTypeBase,
170 public PacketTypeMixin<EthVLanPacketType, EtherTypes>
173 typedef PacketTypeMixin<EthVLanPacketType, EtherTypes> mixin;
175 typedef ConcretePacket<EthVLanPacketType> packet;
176 typedef EthVLanPacketParser parser;
178 using mixin::nextPacketRange;
179 using mixin::nextPacketType;
180 using mixin::initSize;
183 /** \todo Add LLC/SNAP support -> only use the registry
184 for type() values >=1536, otherwise expect an LLC header */
185 static key_t nextPacketKey(packet p)
186 { return p->type(); }
188 /// Dump given EthVLanPacket in readable form to given output stream
189 static void dump(packet p, std::ostream & os);
190 static void finalize(packet p);
193 /** \brief Ethernet VLAN tag typedef
194 \ingroup protocolbundle_default
196 typedef ConcretePacket<EthVLanPacketType> EthVLanPacket;
200 //-/////////////////////////////////////////////////////////////////////////////////////////////////
201 //#include "EthernetPacket.cci"
202 //#include "EthernetPacket.ct"
203 //#include "EthernetPacket.cti"
210 // c-file-style: "senf"
211 // indent-tabs-mode: nil
212 // ispell-local-dictionary: "american"
213 // compile-command: "scons -u test"
214 // comment-column: 40