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.
23 #ifndef HH_EthernetPacket_
24 #define HH_EthernetPacket_ 1
28 #include <boost/array.hpp>
29 #include "Packets/Packets.hh"
31 //#include "EthernetPacket.mpp"
32 ///////////////////////////////hh.p////////////////////////////////////////
36 ///\addtogroup protocolbundle_default
40 : boost::array<PacketParserBase::byte,6>
42 MACAddress(std::string addr);
43 template <class InputIterator>
44 MACAddress(InputIterator i);
46 struct SyntaxException : public std::exception
47 { virtual char const * what() const throw() { return "invalid mac address syntax"; } };
50 struct Parse_MAC : public PacketParserBase
52 Parse_MAC(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
54 ///////////////////////////////////////////////////////////////////////////
56 typedef MACAddress value_type;
57 static const size_type fixed_bytes = 6u;
59 value_type value() const { return MACAddress(i()); }
60 void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
61 operator value_type () { return value(); }
62 byte & operator[](size_type index) { return *boost::next(i(),index); }
64 Parse_MAC const & operator= (value_type const & other) { value(other); return *this; }
67 struct Parse_Ethernet : public PacketParserBase
69 SENF_PACKET_PARSER_INIT(Parse_Ethernet);
71 ///////////////////////////////////////////////////////////////////////////
73 typedef Parse_UInt16 Parse_Type;
75 SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
76 ((Field)( destination, Parse_MAC ))
77 ((Field)( source, Parse_MAC ))
78 ((Field)( type, Parse_Type )) );
82 // See http://www.iana.org/assignments/ethernet-numbers
83 typedef boost::uint16_t key_t;
86 struct EthernetPacketType
87 : public PacketTypeBase,
88 public PacketTypeMixin<EthernetPacketType, EtherTypes>
90 typedef PacketTypeMixin<EthernetPacketType, EtherTypes> mixin;
91 typedef ConcretePacket<EthernetPacketType> packet;
92 typedef Parse_Ethernet parser;
94 using mixin::nextPacketRange;
95 using mixin::nextPacketType;
96 using mixin::initSize;
99 /** \todo Add LLC/SNAP support -> only use the registry
100 for type() values >=1536, otherwise expect an LLC header */
101 static registry_key_t nextPacketKey(packet p)
102 { return p->type(); }
104 static void dump(packet p, std::ostream & os);
107 typedef EthernetPacketType::packet EthernetPacket;
109 struct Parse_EthVLan : public PacketParserBase
111 SENF_PACKET_PARSER_INIT(Parse_EthVLan);
113 ///////////////////////////////////////////////////////////////////////////
115 typedef Parse_UIntField < 0, 3 > Parse_Priority;
116 typedef Parse_Flag < 3 > Parse_CFI;
117 typedef Parse_UIntField < 4, 16 > Parse_VLanId;
118 typedef Parse_UInt16 Parse_Type;
120 SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
121 ((OverlayField)( priority, Parse_Priority ))
122 ((OverlayField)( cfi, Parse_CFI ))
123 ((Field )( vlanId, Parse_VLanId ))
124 ((Field )( type, Parse_Type )) );
127 struct EthVLanPacketType
128 : public PacketTypeBase,
129 public PacketTypeMixin<EthVLanPacketType, EtherTypes>
131 typedef PacketTypeMixin<EthVLanPacketType, EtherTypes> mixin;
132 typedef ConcretePacket<EthVLanPacketType> packet;
133 typedef Parse_EthVLan parser;
135 using mixin::nextPacketRange;
136 using mixin::nextPacketType;
137 using mixin::initSize;
140 /** \todo Add LLC/SNAP support -> only use the registry
141 for type() values >=1536, otherwise expect an LLC header */
142 static registry_key_t nextPacketKey(packet p)
143 { return p->type(); }
145 static void dump(packet p, std::ostream & os);
148 typedef EthVLanPacketType::packet EthVLanPacket;
154 ///////////////////////////////hh.e////////////////////////////////////////
156 #ifndef SENF_PACKETS_DECL_ONLY
157 //#include "EthernetPacket.cci"
158 #include "EthernetPacket.ct"
159 //#include "EthernetPacket.cti"
166 // c-file-style: "senf"
167 // indent-tabs-mode: nil
168 // ispell-local-dictionary: "american"
169 // compile-command: "scons -u test"
170 // comment-column: 40