From: tho Date: Wed, 5 Dec 2007 10:29:26 +0000 (+0000) Subject: moved LLC/SNAP out of EthernetPacket to support Ethernet in LLC/SNAP in MPE X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=15aafcdbb483b75f1b03c45af47d01a2d019c903;p=senf.git moved LLC/SNAP out of EthernetPacket to support Ethernet in LLC/SNAP in MPE git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@541 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/DefaultBundle/EthernetPacket.cc b/Packets/DefaultBundle/EthernetPacket.cc index 5551342..04cac5b 100644 --- a/Packets/DefaultBundle/EthernetPacket.cc +++ b/Packets/DefaultBundle/EthernetPacket.cc @@ -27,6 +27,7 @@ //#include "EthernetPacket.ih" // Custom includes +#include "LlcSnapPacket.hh" #include #include @@ -65,7 +66,7 @@ prefix_ senf::PacketInterpreterBase::factory_t senf::EthernetPacketType::nextPac return e ? e->factory() : no_factory(); } if (p->type_length() <= 1500) - return EthLlcSnapPacket::factory(); + return LlcSnapPacket::factory(); return no_factory(); } @@ -75,7 +76,7 @@ prefix_ void senf::EthernetPacketType::finalize(packet p) if (k) p->type_length() << k; else - if (p.next().is()) + if (p.next().is()) p->type_length() << p.next().data().size(); else p->type_length() << 0; @@ -97,25 +98,6 @@ prefix_ void senf::EthVLanPacketType::finalize(packet p) p->type() << key(p.next()); } -prefix_ void senf::EthLlcSnapPacketType::dump(packet p, std::ostream & os) -{ - boost::io::ios_all_saver ias(os); - os << "Ethernet LLC/SNAP\n" - << std::hex << std::setfill('0') - << " LLC\n" - << " DSAP: 0x" << unsigned(p->dsap()) << "\n" - << " SSAP: 0x" << unsigned(p->ssap()) << "\n" - << " controlId: 0x" << unsigned(p->ctrl()) << "\n" - << " SNAP\n" - << " ProtocolId: 0x" << std::setw(6) << unsigned(p->protocolId()) << "\n" - << " type : 0x" << std::setw(4) << unsigned(p->type()) << "\n"; -} - -prefix_ void senf::EthLlcSnapPacketType::finalize(packet p) -{ - p->type() << key(p.next()); -} - ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ diff --git a/Packets/DefaultBundle/EthernetPacket.hh b/Packets/DefaultBundle/EthernetPacket.hh index 5b0856d..635f43b 100644 --- a/Packets/DefaultBundle/EthernetPacket.hh +++ b/Packets/DefaultBundle/EthernetPacket.hh @@ -3,7 +3,7 @@ // Copyright (C) 2006 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) // Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// Thorsten Horstmann // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -115,7 +115,6 @@ namespace senf { typedef Parse_Ethernet parser; #endif using mixin::nextPacketRange; - // using mixin::nextPacketType; using mixin::initSize; using mixin::init; @@ -188,78 +187,8 @@ namespace senf { /** \brief Ethernet VLAN tag typedef */ typedef ConcretePacket EthVLanPacket; - - /** \brief Parse an ethernet LLC/SNAP header - - \todo document me - - \see EthVLanPacketType - */ - struct Parse_EthLlcSnapPacket : public PacketParserBase - { -# include SENF_FIXED_PARSER() - - SENF_PARSER_FIELD( dsap, Parse_UInt8 ); - SENF_PARSER_FIELD( ssap, Parse_UInt8 ); - SENF_PARSER_FIELD( ctrl, Parse_UInt8 ); - - SENF_PARSER_FIELD( protocolId, Parse_UInt24 ); - SENF_PARSER_FIELD( type, Parse_UInt16 ); - - SENF_PARSER_FINALIZE(Parse_EthLlcSnapPacket); - - SENF_PARSER_INIT() { - dsap() = 0xaa; - ssap() = 0xaa; - ctrl() = 0x03; - protocolId() = 0x000000; - } - }; - - /** \brief Ethernet LLC/SNAP header - - \todo document me - - \par Packet type (typedef): - \ref EthLlcSnapPacketType - - \par Fields: - \ref Parse_EthLlcSnapPacket - - \par Associated registries: - \ref EtherTypes - - \par Finalize action: - XXXX - - \ingroup protocolbundle_default - */ - struct EthLlcSnapPacketType - : public PacketTypeBase, - public PacketTypeMixin - { -#ifndef DOXYGEN - typedef PacketTypeMixin mixin; - typedef ConcretePacket packet; - typedef Parse_EthLlcSnapPacket parser; -#endif - using mixin::nextPacketRange; - using mixin::nextPacketType; - using mixin::initSize; - using mixin::init; - - static registry_key_t nextPacketKey(packet p) - { return p->type(); } - - static void dump(packet p, std::ostream & os); - static void finalize(packet p); - }; - - /** \brief Ethernet VLAN tag typedef */ - typedef ConcretePacket EthLlcSnapPacket; } - ///////////////////////////////hh.e//////////////////////////////////////// #endif #ifndef SENF_PACKETS_DECL_ONLY diff --git a/Packets/DefaultBundle/EthernetPacket.test.cc b/Packets/DefaultBundle/EthernetPacket.test.cc index 176eef3..17ac1ce 100644 --- a/Packets/DefaultBundle/EthernetPacket.test.cc +++ b/Packets/DefaultBundle/EthernetPacket.test.cc @@ -27,6 +27,7 @@ // Custom includes #include "EthernetPacket.hh" +#include "LlcSnapPacket.hh" #include "IPv4Packet.hh" #include "../../Utils/auto_unit_test.hh" @@ -91,31 +92,13 @@ BOOST_AUTO_UNIT_TEST(ethernetPacket_create) BOOST_CHECK_EQUAL(vlan->type(), 0x0800u); } -BOOST_AUTO_UNIT_TEST(llcsnap_parse) -{ - senf::PacketData::byte data[] = { - 0xaa, // DSAP - 0xaa, // SSAP - 0x03, // ctrl - 0x00, 0x00, 0x00, // Protocol Identification Field - 0x10, 0x11 // EtherType - }; - senf::EthLlcSnapPacket p (senf::EthLlcSnapPacket::create(data)); - - BOOST_CHECK_EQUAL( p->dsap(), 0xaa ); - BOOST_CHECK_EQUAL( p->ssap(), 0xaa ); - BOOST_CHECK_EQUAL( p->ctrl(), 0x03 ); - BOOST_CHECK_EQUAL( p->protocolId(), 0x000000u ); - BOOST_CHECK_EQUAL( p->type(), 0x1011 ); -} - -BOOST_AUTO_UNIT_TEST(llcsnap_create) +BOOST_AUTO_UNIT_TEST(ethernetPacket_llcsnap) { senf::EthernetPacket eth (senf::EthernetPacket::create()); eth->source() = senf::MACAddress::from_string("01:02:03:04:05:06"); eth->destination() = senf::MACAddress::from_string("07:08:09:0a:0b:0c"); - senf::EthLlcSnapPacket llcsnap (senf::EthLlcSnapPacket::createAfter(eth)); + senf::LlcSnapPacket llcsnap (senf::LlcSnapPacket::createAfter(eth)); senf::DataPacket payload (senf::DataPacket::createAfter( llcsnap, std::string("Hello, world!"))); eth.finalize(); @@ -125,11 +108,11 @@ BOOST_AUTO_UNIT_TEST(llcsnap_create) BOOST_CHECK_EQUAL( llcsnap->ssap(), 0xaa ); BOOST_CHECK_EQUAL( llcsnap->ctrl(), 0x03 ); BOOST_CHECK_EQUAL( llcsnap->protocolId(), 0x000000u ); - BOOST_CHECK_EQUAL( llcsnap->type(), 0u); + BOOST_CHECK_EQUAL( llcsnap->type_length(), 0u); senf::IPv4Packet ip (senf::IPv4Packet::createAfter(llcsnap)); eth.finalize(); - BOOST_CHECK_EQUAL(llcsnap->type(), 0x0800u); + BOOST_CHECK_EQUAL(llcsnap->type_length(), 0x0800u); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Packets/DefaultBundle/LlcSnapPacket.cc b/Packets/DefaultBundle/LlcSnapPacket.cc new file mode 100644 index 0000000..77378cd --- /dev/null +++ b/Packets/DefaultBundle/LlcSnapPacket.cc @@ -0,0 +1,87 @@ +// $Id: EthernetPacket.cc 523 2007-11-16 10:34:57Z tho $ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief LlcSnapPacket non-inline non-template implementation */ + +#include "LlcSnapPacket.hh" +//#include "LlcSnapPacket.ih" + +// Custom includes +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +prefix_ void senf::LlcSnapPacketType::dump(packet p, std::ostream & os) +{ + boost::io::ios_all_saver ias(os); + os << "LLC/SNAP\n" + << std::hex << std::setfill('0') + << " LLC\n" + << " DSAP: 0x" << unsigned(p->dsap()) << "\n" + << " SSAP: 0x" << unsigned(p->ssap()) << "\n" + << " controlId: 0x" << unsigned(p->ctrl()) << "\n" + << " SNAP\n" + << " ProtocolId: 0x" << std::setw(6) << unsigned(p->protocolId()) << "\n" + << " type_length: 0x" << std::setw(4) << unsigned(p->type_length()) << "\n"; +} + +prefix_ senf::PacketInterpreterBase::factory_t senf::LlcSnapPacketType::nextPacketType(packet p) +{ + if (p->type_length() >= 1536) { + PkReg_Entry const * e; + e = PacketRegistry::lookup( p->type_length(), nothrow ); + return e ? e->factory() : no_factory(); + } + if (p->type_length() <= 1500) + return EthernetPacket::factory(); + return no_factory(); +} + +prefix_ void senf::LlcSnapPacketType::finalize(packet p) +{ + optional_registry_key_t k = key(p.next()); + if (k) + p->type_length() << k; + else + if (p.next().is()) + p->type_length() << p.next().data().size(); + else + p->type_length() << 0; +} + + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 +// End: diff --git a/Packets/DefaultBundle/LlcSnapPacket.hh b/Packets/DefaultBundle/LlcSnapPacket.hh new file mode 100644 index 0000000..c021c9f --- /dev/null +++ b/Packets/DefaultBundle/LlcSnapPacket.hh @@ -0,0 +1,121 @@ +// $id: EthernetPacket.hh 299 2007-07-10 21:23:49Z g0dil $ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Thorsten Horstmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief LLC/SNAP public header */ + +#ifndef HH_LlcSnapPacket_ +#define HH_LlcSnapPacket_ 1 + +// Custom includes +#include +#include "EthernetPacket.hh" +#include "../../Packets/Packets.hh" + +//#include "LlcSnapPacket.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { + + /** \brief Parse a LLC/SNAP header + + \todo document me + */ + struct Parse_LlcSnapPacket : public PacketParserBase + { +# include SENF_FIXED_PARSER() + + SENF_PARSER_FIELD( dsap, Parse_UInt8 ); + SENF_PARSER_FIELD( ssap, Parse_UInt8 ); + SENF_PARSER_FIELD( ctrl, Parse_UInt8 ); + + SENF_PARSER_FIELD( protocolId, Parse_UInt24 ); + SENF_PARSER_FIELD( type_length, Parse_UInt16 ); + + SENF_PARSER_FINALIZE(Parse_LlcSnapPacket); + + SENF_PARSER_INIT() { + dsap() = 0xaa; + ssap() = 0xaa; + ctrl() = 0x03; + protocolId() = 0x000000; + } + }; + + /** \brief LLC/SNAP header + + \todo document me + + \par Packet type (typedef): + \ref LlcSnapPacketType + + \par Fields: + \ref Parse_LlcSnapPacket + + \par Associated registries: + \ref EtherTypes + + \par Finalize action: + XXXX + + \ingroup protocolbundle_default + */ + struct LlcSnapPacketType + : public PacketTypeBase, + public PacketTypeMixin + { +#ifndef DOXYGEN + typedef PacketTypeMixin mixin; + typedef ConcretePacket packet; + typedef Parse_LlcSnapPacket parser; +#endif + using mixin::nextPacketRange; + using mixin::initSize; + using mixin::init; + + static factory_t nextPacketType(packet p); + static void dump(packet p, std::ostream & os); + static void finalize(packet p); + }; + + typedef ConcretePacket LlcSnapPacket; +} + + +///////////////////////////////hh.e//////////////////////////////////////// +#endif +#ifndef SENF_PACKETS_DECL_ONLY +//#include "LlcSnapPacket.cci" +//#include "LlcSnapPacket.ct" +//#include "LlcSnapPacket.cti" +#endif + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 +// End: diff --git a/Packets/DefaultBundle/LlcSnapPacket.test.cc b/Packets/DefaultBundle/LlcSnapPacket.test.cc new file mode 100644 index 0000000..eee2296 --- /dev/null +++ b/Packets/DefaultBundle/LlcSnapPacket.test.cc @@ -0,0 +1,84 @@ +// $Id: EthernetPacket.test.cc 530 2007-11-23 12:47:50Z g0dil $ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Thorsten Horstmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +// Unit tests + +//#include "LlcSnapPacket.test.hh" +//#include "LlcSnapPacket.test.ih" + +// Custom includes +#include "LlcSnapPacket.hh" +#include "EthernetPacket.hh" + +#include "../../Utils/auto_unit_test.hh" +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(llcsnap_parse) +{ + senf::PacketData::byte data[] = { + 0xaa, // DSAP + 0xaa, // SSAP + 0x03, // ctrl + 0x00, 0x00, 0x00, // Protocol Identification Field + 0x10, 0x11 // EtherType / Length + }; + senf::LlcSnapPacket p (senf::LlcSnapPacket::create(data)); + + BOOST_CHECK_EQUAL( p->dsap(), 0xaa ); + BOOST_CHECK_EQUAL( p->ssap(), 0xaa ); + BOOST_CHECK_EQUAL( p->ctrl(), 0x03 ); + BOOST_CHECK_EQUAL( p->protocolId(), 0x000000u ); + BOOST_CHECK_EQUAL( p->type_length(), 0x1011 ); +} + +BOOST_AUTO_UNIT_TEST(llcSnapPacket_ethernet) +{ + senf::LlcSnapPacket llcsnap (senf::LlcSnapPacket::create()); + senf::EthernetPacket eth (senf::EthernetPacket::createAfter(llcsnap)); + senf::DataPacket payload (senf::DataPacket::createAfter( + eth, std::string("Hello, world!"))); + llcsnap.finalize(); + + BOOST_CHECK_EQUAL( llcsnap->dsap(), 0xaa ); + BOOST_CHECK_EQUAL( llcsnap->ssap(), 0xaa ); + BOOST_CHECK_EQUAL( llcsnap->ctrl(), 0x03 ); + BOOST_CHECK_EQUAL( llcsnap->protocolId(), 0x000000u ); + BOOST_CHECK_EQUAL( llcsnap->type_length(), 14 + 13); +} + + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 +// End: