Skip to content
Snippets Groups Projects
Commit ae6155a1 authored by tho's avatar tho
Browse files

moved LLC/SNAP out of EthernetPacket to support Ethernet in LLC/SNAP in MPE

parent 07c8f56c
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@
//#include "EthernetPacket.ih"
// Custom includes
#include "LlcSnapPacket.hh"
#include <iomanip>
#include <boost/io/ios_state.hpp>
......@@ -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<EthLlcSnapPacket>())
if (p.next().is<LlcSnapPacket>())
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_
......
......@@ -3,7 +3,7 @@
// Copyright (C) 2006
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
// Thorsten Horstmann <thorsten.horstmann@fokus.fraunhofer.de>
//
// 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<EthVLanPacketType> 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<EthLlcSnapPacketType, EtherTypes>
{
#ifndef DOXYGEN
typedef PacketTypeMixin<EthLlcSnapPacketType, EtherTypes> mixin;
typedef ConcretePacket<EthLlcSnapPacketType> 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<EthLlcSnapPacketType> EthLlcSnapPacket;
}
///////////////////////////////hh.e////////////////////////////////////////
#endif
#ifndef SENF_PACKETS_DECL_ONLY
......
......@@ -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////////////////////////////////////////
......
// $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 <stefan.bund@fokus.fraunhofer.de>
//
// 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 <iomanip>
#include <boost/io/ios_state.hpp>
#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<senf::EtherTypes>::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<EthernetPacket>())
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:
// $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 <thorsten.horstmann@fokus.fraunhofer.de>
//
// 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 <algorithm>
#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<LlcSnapPacketType, EtherTypes>
{
#ifndef DOXYGEN
typedef PacketTypeMixin<LlcSnapPacketType, EtherTypes> mixin;
typedef ConcretePacket<LlcSnapPacketType> 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<LlcSnapPacketType> 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:
// $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 <thorsten.horstmann@fokus.fraunhofer.de>
//
// 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 <boost/test/test_tools.hpp>
#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:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment