4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Thorsten Horstmann <tho@berlios.de>
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.
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.
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.
24 \brief EthernetPacket public header */
26 #ifndef HH_SENF_Packets_DefaultBundle_EthernetPacket_
27 #define HH_SENF_Packets_DefaultBundle_EthernetPacket_ 1
30 #include <senf/Socket/Protocols/Raw/MACAddress.hh>
31 #include <senf/Packets/Packets.hh>
33 //#include "EthernetPacket.mpp"
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38 /** \brief Parse an Ethernet MAC address
40 The ethernet MAC is returned by value as a 6-byte sequence
45 struct MACAddressParser
46 : public ValueParserBase<MACAddressParser, MACAddress, 6u>
48 MACAddressParser(data_iterator i, state_type s) : Base(i,s) {}
50 value_type value() const { return MACAddress::from_data(i()); }
51 void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
53 using Base::operator=;
56 /** \brief Parse an Ethernet packet
58 Parser implementing an ethernet header.
60 \see EthernetPacketType
62 struct EthernetPacketParser : public PacketParserBase
64 # include SENF_FIXED_PARSER()
66 SENF_PARSER_FIELD( destination, MACAddressParser );
67 SENF_PARSER_FIELD( source, MACAddressParser );
68 SENF_PARSER_FIELD( type_length, UInt16Parser );
70 SENF_PARSER_FINALIZE(EthernetPacketParser);
73 /** \brief EtherType registry
75 This registry registers packet types with their EtherType number.
77 \see <a href="http://www.iana.org/assignments/ethernet-numbers">Ethernet numbers</a> \n
81 typedef boost::uint16_t key_t;
84 /** \brief Ethernet packet
86 \par Packet type (typedef):
90 \ref EthernetPacketParser
91 \image html EthernetPacket.png
93 \par Associated registries:
97 Set \a type from type of next packet if found in \ref EtherTypes
99 \ingroup protocolbundle_default
101 struct EthernetPacketType
102 : public PacketTypeBase,
103 public PacketTypeMixin<EthernetPacketType, EtherTypes>
106 typedef PacketTypeMixin<EthernetPacketType, EtherTypes> mixin;
108 typedef ConcretePacket<EthernetPacketType> packet;
109 typedef EthernetPacketParser parser;
111 using mixin::nextPacketRange;
112 using mixin::initSize;
115 static factory_t nextPacketType(packet p);
116 /// Dump given EthernetPacket in readable form to given output stream
117 static void dump(packet p, std::ostream & os);
118 static void finalize(packet p);
121 /** \brief Ethernet packet typedef
122 \ingroup protocolbundle_default
124 typedef ConcretePacket<EthernetPacketType> EthernetPacket;
127 /** \brief Parse an ethernet VLAN tag
129 Parser interpreting the ethernet VLAN tag. Fields are
131 \see EthVLanPacketType
133 struct EthVLanPacketParser : public PacketParserBase
135 # include SENF_FIXED_PARSER()
137 SENF_PARSER_BITFIELD( priority, 3, unsigned );
138 SENF_PARSER_BITFIELD( cfi, 1, bool );
139 SENF_PARSER_BITFIELD( vlanId, 12, unsigned );
141 SENF_PARSER_FIELD( type, UInt16Parser );
143 SENF_PARSER_FINALIZE(EthVLanPacketParser);
146 /** \brief Ethernet VLAN tag
148 \par Packet type (typedef):
152 \ref EthVLanPacketParser
153 \image html EthVLanPacket.png
155 \par Associated registries:
158 \par Finalize action:
159 Set \a type from type of next packet if found in \ref EtherTypes
161 \ingroup protocolbundle_default
163 struct EthVLanPacketType
164 : public PacketTypeBase,
165 public PacketTypeMixin<EthVLanPacketType, EtherTypes>
168 typedef PacketTypeMixin<EthVLanPacketType, EtherTypes> mixin;
170 typedef ConcretePacket<EthVLanPacketType> packet;
171 typedef EthVLanPacketParser parser;
173 using mixin::nextPacketRange;
174 using mixin::nextPacketType;
175 using mixin::initSize;
178 /** \todo Add LLC/SNAP support -> only use the registry
179 for type() values >=1536, otherwise expect an LLC header */
180 static key_t nextPacketKey(packet p)
181 { return p->type(); }
183 /// Dump given EthVLanPacket in readable form to given output stream
184 static void dump(packet p, std::ostream & os);
185 static void finalize(packet p);
188 /** \brief Ethernet VLAN tag typedef
189 \ingroup protocolbundle_default
191 typedef ConcretePacket<EthVLanPacketType> EthVLanPacket;
195 //-/////////////////////////////////////////////////////////////////////////////////////////////////
196 //#include "EthernetPacket.cci"
197 //#include "EthernetPacket.ct"
198 //#include "EthernetPacket.cti"
205 // c-file-style: "senf"
206 // indent-tabs-mode: nil
207 // ispell-local-dictionary: "american"
208 // compile-command: "scons -u test"
209 // comment-column: 40