From: cni Date: Mon, 29 Jun 2009 13:39:59 +0000 (+0000) Subject: Packets/DefaultBundle: added MPLS header X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=5a5aac2396efc10548b2c5e9fc90c97961bfc31f;p=senf.git Packets/DefaultBundle: added MPLS header git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1245 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/DefaultBundle/MPLSPacket.cc b/Packets/DefaultBundle/MPLSPacket.cc new file mode 100644 index 0000000..86b3d7c --- /dev/null +++ b/Packets/DefaultBundle/MPLSPacket.cc @@ -0,0 +1,71 @@ +// $Id$ +// +// Copyright (C) 2006 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Christian Niephaus +// +// 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 MPLSPacket non-inline non-template implementation */ + +#include "MPLSPacket.hh" +//#include "MPLSPacket.ih" + +// Custom includes +#include +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// +// senf::MPLSPacketType + +prefix_ void senf::MPLSPacketType::dump(packet p, std::ostream & os) +{ + boost::io::ios_all_saver ias(os); + os << "MPLS Header: \n" + << " label : " << p->label() << "\n" + << " traffic class : " << p->tc() << "\n" + << " bottom of stack : " << p->s() << "\n" + << " Time-to-live : " << p->ttl() << "\n"; +} + +prefix_ senf::PacketInterpreterBase::factory_t senf::MPLSPacketType::nextPacketType(packet p) +{ + if (p->s()) //last MPLS header + return no_factory(); + else + return MPLSPacket::factory(); +} + +prefix_ void senf::MPLSPacketType::finalize(packet p) +{ +} + +///////////////////////////////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/MPLSPacket.hh b/Packets/DefaultBundle/MPLSPacket.hh new file mode 100644 index 0000000..8ee0a1c --- /dev/null +++ b/Packets/DefaultBundle/MPLSPacket.hh @@ -0,0 +1,110 @@ +// $Id$ +// +// Copyright (C) 2006 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Christian Niephaus +// +// 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 MPLSPacket public header */ + +#ifndef HH_SENF_Packets_DefaultBundle_MPLSPacket_ +#define HH_SENF_Packets_DefaultBundle_MPLSPacket_ 1 + +// Custom includes + +#include "../../Packets/Packets.hh" + +//#include "MPLSPacket.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { + + /** \brief Parse an MPLS packet + + Parser implementing an MPLS header. + + \see MPLSPacketType + */ + struct MPLSPacketParser : public PacketParserBase + { +# include SENF_FIXED_PARSER() + + SENF_PARSER_BITFIELD( label, 20, unsigned); + SENF_PARSER_BITFIELD( tc, 3, unsigned); + SENF_PARSER_BITFIELD( s, 1, bool); + SENF_PARSER_FIELD( ttl, UInt8Parser); + + SENF_PARSER_FINALIZE(MPLSPacketParser); + }; + + /** \brief MPLS packet + + \par Packet type (typedef): + \ref MPLSPacket + + \par Fields: + \ref MPLSPacketParser + + + \ingroup protocolbundle_default + */ + struct MPLSPacketType + : public PacketTypeBase, + public PacketTypeMixin + { +#ifndef DOXYGEN + typedef PacketTypeMixin mixin; +#endif + typedef ConcretePacket packet; + typedef MPLSPacketParser parser; + + using mixin::nextPacketRange; + using mixin::initSize; + using mixin::init; + + static factory_t nextPacketType(packet p); + /// Dump given MPLSPacket in readable form to given output stream + static void dump(packet p, std::ostream & os); + static void finalize(packet p); + }; + + /** \brief MPLS packet typedef */ + typedef ConcretePacket MPLSPacket; + + +} + +///////////////////////////////hh.e//////////////////////////////////////// +#endif +#ifndef SENF_PACKETS_DECL_ONLY +//#include "MPLSPacket.cci" +//#include "MPLSPacket.ct" +//#include "MPLSPacket.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/MPLSPacket.test.cc b/Packets/DefaultBundle/MPLSPacket.test.cc new file mode 100644 index 0000000..a5254f7 --- /dev/null +++ b/Packets/DefaultBundle/MPLSPacket.test.cc @@ -0,0 +1,98 @@ +// $Id$ +// +// Copyright (C) 2006 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Christian Niephaus +// +// 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 MPLSPacket unit tests */ + +//#include "MPLSPacket.test.hh" +//#include "MPLSPacket.test.ih" + +// Custom includes +#include "MPLSPacket.hh" + + +#include "../../Utils/auto_unit_test.hh" +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(mplsPacket_parse) +{ + senf::PacketData::byte data[] = { + 0x00, 0x3e, 0x90, 0x80, //1st mpls header + 0x00, 0x3e, 0xb1, 0x80, // last mpls header + 0x00 //data + }; + senf::MPLSPacket p (senf::MPLSPacket::create(data)); + + BOOST_CHECK_EQUAL( p->label(), 1001u); + BOOST_CHECK_EQUAL( p->tc(), 0u ); + BOOST_CHECK( !p->s()); + BOOST_CHECK_EQUAL( p->ttl(), 128u ); + + std::ostringstream oss (std::ostringstream::out); + SENF_CHECK_NO_THROW( p.dump( oss)); +} + +BOOST_AUTO_UNIT_TEST(mplsPacket_parse_chain) +{ + senf::PacketData::byte data[] = { + 0x00, 0x3e, 0x90, 0x80, //1st mpls header + 0x00, 0x3e, 0xb1, 0x80, // last mpls header + 0x00 //data + }; + + senf::MPLSPacket p (senf::MPLSPacket::create(data)); + + BOOST_REQUIRE( p.next().is() ); + senf::MPLSPacket p2 (p.next().as()); + BOOST_CHECK( p2->s()); + BOOST_REQUIRE( p2.next().is() ); +} + +BOOST_AUTO_UNIT_TEST(mplsPacket_create) +{ + senf::MPLSPacket p (senf::MPLSPacket::create()); + p->label()=4444u; + p->ttl()=10u; + p->s()=true; + p->tc()=0x0u; + + SENF_CHECK_NO_THROW(p.finalizeThis()); + +} + + +///////////////////////////////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: