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 // Stefan Bund <stefan.bund@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 typedef Parse_UInt16 Parse_Type;
75 SENF_PACKET_PARSER_INIT(Parse_Ethernet);
77 SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
78 ((Field)( destination, Parse_MAC ))
79 ((Field)( source, Parse_MAC ))
80 ((Field)( type, Parse_Type )) );
84 Parse_MAC destination();
91 /** \brief EtherType registry
93 This registry registers packet types with their EtherType number.
95 \see <a href="http://www.iana.org/assignments/ethernet-numbers">Ethernet numbers</a> \n
100 typedef boost::uint16_t key_t;
103 /** \brief Ethernet packet
105 \par Packet type (typedef):
111 \par Associated registries:
114 \ingroup protocolbundle_default
116 struct EthernetPacketType
117 : public PacketTypeBase,
118 public PacketTypeMixin<EthernetPacketType, EtherTypes>
120 typedef PacketTypeMixin<EthernetPacketType, EtherTypes> mixin;
121 typedef ConcretePacket<EthernetPacketType> packet;
122 typedef Parse_Ethernet parser;
124 using mixin::nextPacketRange;
125 using mixin::nextPacketType;
126 using mixin::initSize;
129 /** \todo Add LLC/SNAP support -> only use the registry
130 for type() values >=1536, otherwise expect an LLC header */
131 static registry_key_t nextPacketKey(packet p)
132 { return p->type(); }
134 static void dump(packet p, std::ostream & os);
135 static void finalize(packet p);
138 /** \brief Ethernet packet typedef */
139 typedef EthernetPacketType::packet EthernetPacket;
141 /** \brief Parse an ethernet VLAN tag
143 Parser interpreting the ethernet VLAN tag. Fields are
145 \see EthVLanPacketType
147 struct Parse_EthVLan : public PacketParserBase
149 typedef Parse_UIntField < 0, 3 > Parse_Priority;
150 typedef Parse_Flag < 3 > Parse_CFI;
151 typedef Parse_UIntField < 4, 16 > Parse_VLanId;
152 typedef Parse_UInt16 Parse_Type;
156 SENF_PACKET_PARSER_INIT(Parse_EthVLan);
158 SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
159 ((OverlayField)( priority, Parse_Priority ))
160 ((OverlayField)( cfi, Parse_CFI ))
161 ((Field )( vlanId, Parse_VLanId ))
162 ((Field )( type, Parse_Type )) );
166 Parse_Priority priority();
168 Parse_VLanId vlanId();
174 /** \brief Ethernet VLAN tag
176 \par Packet type (typedef):
182 \par Associated registries:
185 \ingroup protocolbundle_default
187 struct EthVLanPacketType
188 : public PacketTypeBase,
189 public PacketTypeMixin<EthVLanPacketType, EtherTypes>
191 typedef PacketTypeMixin<EthVLanPacketType, EtherTypes> mixin;
192 typedef ConcretePacket<EthVLanPacketType> packet;
193 typedef Parse_EthVLan parser;
195 using mixin::nextPacketRange;
196 using mixin::nextPacketType;
197 using mixin::initSize;
200 /** \todo Add LLC/SNAP support -> only use the registry
201 for type() values >=1536, otherwise expect an LLC header */
202 static registry_key_t nextPacketKey(packet p)
203 { return p->type(); }
205 static void dump(packet p, std::ostream & os);
206 static void finalize(packet p);
209 /** \brief Ethernet VLAN tag typedef */
210 typedef EthVLanPacketType::packet EthVLanPacket;
214 ///////////////////////////////hh.e////////////////////////////////////////
216 #ifndef SENF_PACKETS_DECL_ONLY
217 //#include "EthernetPacket.cci"
218 //#include "EthernetPacket.ct"
219 //#include "EthernetPacket.cti"
226 // c-file-style: "senf"
227 // indent-tabs-mode: nil
228 // ispell-local-dictionary: "american"
229 // compile-command: "scons -u test"
230 // comment-column: 40