Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

DefaultBundle/EthernetPacket.hh

Go to the documentation of this file.
00001 // $Id: EthernetPacket.hh 1754 2010-12-09 15:45:42Z tho $
00002 //
00003 // Copyright (C) 2006
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Thorsten Horstmann <tho@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Packets_DefaultBundle_EthernetPacket_
00027 #define HH_SENF_Packets_DefaultBundle_EthernetPacket_ 1
00028 
00029 // Custom includes
00030 #include <senf/Socket/Protocols/Raw/MACAddress.hh>
00031 #include <senf/Packets/Packets.hh>
00032 
00033 //#include "EthernetPacket.mpp"
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 
00036 namespace senf {
00037 
00045     struct MACAddressParser
00046         : public ValueParserBase<MACAddressParser, MACAddress, 6u>
00047     {
00048         MACAddressParser(data_iterator i, state_type s) : Base(i,s) {}
00049 
00050         value_type value() const { return MACAddress::from_data(i()); }
00051         void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
00052 
00053         using Base::operator=;
00054     };
00055 
00062     struct EthernetPacketParser : public PacketParserBase
00063     {
00064 #       include SENF_FIXED_PARSER()
00065 
00066         SENF_PARSER_FIELD( destination, MACAddressParser    );
00067         SENF_PARSER_FIELD( source,      MACAddressParser    );
00068         SENF_PARSER_FIELD( type_length, UInt16Parser );
00069 
00070         SENF_PARSER_FINALIZE(EthernetPacketParser);
00071     };
00072 
00080     struct EtherTypes {
00081         typedef boost::uint16_t key_t;
00082     };
00083 
00101     struct EthernetPacketType
00102         : public PacketTypeBase,
00103           public PacketTypeMixin<EthernetPacketType, EtherTypes>
00104     {
00105 #ifndef DOXYGEN
00106         typedef PacketTypeMixin<EthernetPacketType, EtherTypes> mixin;
00107 #endif
00108         typedef ConcretePacket<EthernetPacketType> packet;
00109         typedef EthernetPacketParser parser;
00110 
00111         using mixin::nextPacketRange;
00112         using mixin::initSize;
00113         using mixin::init;
00114 
00115         static factory_t nextPacketType(packet p);
00117         static void dump(packet p, std::ostream & os);
00118         static void finalize(packet p);
00119     };
00120 
00124     typedef ConcretePacket<EthernetPacketType> EthernetPacket;
00125 
00126 
00133     struct EthVLanPacketParser : public PacketParserBase
00134     {
00135 #       include SENF_FIXED_PARSER()
00136 
00137         SENF_PARSER_BITFIELD( priority,  3, unsigned );
00138         SENF_PARSER_BITFIELD( cfi,       1, bool     );
00139         SENF_PARSER_BITFIELD( vlanId,   12, unsigned );
00140 
00141         SENF_PARSER_FIELD( type, UInt16Parser );
00142 
00143         SENF_PARSER_FINALIZE(EthVLanPacketParser);
00144     };
00145 
00163     struct EthVLanPacketType
00164         : public PacketTypeBase,
00165           public PacketTypeMixin<EthVLanPacketType, EtherTypes>
00166     {
00167 #ifndef DOXYGEN
00168         typedef PacketTypeMixin<EthVLanPacketType, EtherTypes> mixin;
00169 #endif
00170         typedef ConcretePacket<EthVLanPacketType> packet;
00171         typedef EthVLanPacketParser parser;
00172 
00173         using mixin::nextPacketRange;
00174         using mixin::nextPacketType;
00175         using mixin::initSize;
00176         using mixin::init;
00177 
00180         static key_t nextPacketKey(packet p)
00181             { return p->type(); }
00182 
00184         static void dump(packet p, std::ostream & os);
00185         static void finalize(packet p);
00186     };
00187 
00191     typedef ConcretePacket<EthVLanPacketType> EthVLanPacket;
00192 
00193 }
00194 
00195 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00196 //#include "EthernetPacket.cci"
00197 //#include "EthernetPacket.ct"
00198 //#include "EthernetPacket.cti"
00199 #endif
00200 
00201 
00202 // Local Variables:
00203 // mode: c++
00204 // fill-column: 100
00205 // c-file-style: "senf"
00206 // indent-tabs-mode: nil
00207 // ispell-local-dictionary: "american"
00208 // compile-command: "scons -u test"
00209 // comment-column: 40
00210 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research