1 // $id: EthernetPacket.hh 299 2007-07-10 21:23:49Z g0dil $
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Thorsten Horstmann <thorsten.horstmann@fokus.fraunhofer.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_EthernetPacket_
27 #define HH_EthernetPacket_ 1
31 #include "../../Socket/Protocols/Raw/MACAddress.hh"
32 #include "../../Packets/Packets.hh"
34 //#include "EthernetPacket.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
39 /** \brief Parse an Ethernet MAC address
41 The ethernet MAC is returned by value as a 6-byte sequence
46 struct Parse_MAC : public PacketParserBase
48 Parse_MAC(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
50 ///////////////////////////////////////////////////////////////////////////
52 typedef MACAddress value_type;
53 static const size_type fixed_bytes = 6u;
55 value_type value() const { return MACAddress::from_data(i()); }
56 void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
57 operator value_type () { return value(); }
58 byte & operator[](size_type index) { return *boost::next(i(),index); }
60 Parse_MAC const & operator= (value_type const & other) { value(other); return *this; }
63 /** \brief Parse an Ethernet packet
65 Parser implementing an ethernet header.
67 \see EthernetPacketType
69 struct Parse_Ethernet : public PacketParserBase
71 # include SENF_FIXED_PARSER()
73 SENF_PARSER_FIELD( destination, Parse_MAC );
74 SENF_PARSER_FIELD( source, Parse_MAC );
75 SENF_PARSER_FIELD( type_length, Parse_UInt16 );
77 SENF_PARSER_FINALIZE(Parse_Ethernet);
80 /** \brief EtherType registry
82 This registry registers packet types with their EtherType number.
84 \see <a href="http://www.iana.org/assignments/ethernet-numbers">Ethernet numbers</a> \n
89 typedef boost::uint16_t key_t;
92 /** \brief Ethernet packet
94 \par Packet type (typedef):
100 \par Associated registries:
103 \par Finalize action:
104 Set \a type from type of next packet if found in \ref EtherTypes
106 \ingroup protocolbundle_default
108 struct EthernetPacketType
109 : public PacketTypeBase,
110 public PacketTypeMixin<EthernetPacketType, EtherTypes>
113 typedef PacketTypeMixin<EthernetPacketType, EtherTypes> mixin;
114 typedef ConcretePacket<EthernetPacketType> packet;
115 typedef Parse_Ethernet parser;
117 using mixin::nextPacketRange;
118 using mixin::initSize;
121 static factory_t nextPacketType(packet p);
122 static void dump(packet p, std::ostream & os);
123 static void finalize(packet p);
126 /** \brief Ethernet packet typedef */
127 typedef ConcretePacket<EthernetPacketType> EthernetPacket;
129 /** \brief Parse an ethernet VLAN tag
131 Parser interpreting the ethernet VLAN tag. Fields are
133 \see EthVLanPacketType
135 struct Parse_EthVLan : public PacketParserBase
137 # include SENF_FIXED_PARSER()
139 SENF_PARSER_BITFIELD( priority, 3, unsigned );
140 SENF_PARSER_BITFIELD( cfi, 1, bool );
141 SENF_PARSER_BITFIELD( vlanId, 12, unsigned );
143 SENF_PARSER_FIELD( type, Parse_UInt16 );
145 SENF_PARSER_FINALIZE(Parse_EthVLan);
148 /** \brief Ethernet VLAN tag
150 \par Packet type (typedef):
156 \par Associated registries:
159 \par Finalize action:
160 Set \a type from type of next packet if found in \ref EtherTypes
162 \ingroup protocolbundle_default
164 struct EthVLanPacketType
165 : public PacketTypeBase,
166 public PacketTypeMixin<EthVLanPacketType, EtherTypes>
169 typedef PacketTypeMixin<EthVLanPacketType, EtherTypes> mixin;
170 typedef ConcretePacket<EthVLanPacketType> packet;
171 typedef Parse_EthVLan 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 registry_key_t nextPacketKey(packet p)
181 { return p->type(); }
183 static void dump(packet p, std::ostream & os);
184 static void finalize(packet p);
187 /** \brief Ethernet VLAN tag typedef */
188 typedef ConcretePacket<EthVLanPacketType> EthVLanPacket;
192 ///////////////////////////////hh.e////////////////////////////////////////
194 #ifndef SENF_PACKETS_DECL_ONLY
195 //#include "EthernetPacket.cci"
196 //#include "EthernetPacket.ct"
197 //#include "EthernetPacket.cti"
204 // c-file-style: "senf"
205 // indent-tabs-mode: nil
206 // ispell-local-dictionary: "american"
207 // compile-command: "scons -u test"
208 // comment-column: 40