Packets/DefaultBundle: added MPLS header
cni [Mon, 29 Jun 2009 13:39:59 +0000 (13:39 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1245 270642c3-0616-0410-b53a-bc976706d245

Packets/DefaultBundle/MPLSPacket.cc [new file with mode: 0644]
Packets/DefaultBundle/MPLSPacket.hh [new file with mode: 0644]
Packets/DefaultBundle/MPLSPacket.test.cc [new file with mode: 0644]

diff --git a/Packets/DefaultBundle/MPLSPacket.cc b/Packets/DefaultBundle/MPLSPacket.cc
new file mode 100644 (file)
index 0000000..86b3d7c
--- /dev/null
@@ -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 <cni@berlios.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 MPLSPacket non-inline non-template implementation */
+
+#include "MPLSPacket.hh"
+//#include "MPLSPacket.ih"
+
+// Custom includes
+#include <iomanip>
+#include <boost/io/ios_state.hpp>
+
+#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 (file)
index 0000000..8ee0a1c
--- /dev/null
@@ -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 <cni@berlios.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 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<MPLSPacketType>
+    {
+#ifndef DOXYGEN
+        typedef PacketTypeMixin<MPLSPacketType> mixin;
+#endif
+        typedef ConcretePacket<MPLSPacketType> 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<MPLSPacketType> MPLSPacket;
+
+
+}
+
+///////////////////////////////hh.e////////////////////////////////////////
+#endif
+#ifndef SENF_PACKETS_DECL_ONLY
+//#include "MPLSPacket.cci"
+//#include "MPLSPacket.ct"
+//#include "MPLSPacket.cti"
+#endif
+
+\f
+// 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 (file)
index 0000000..a5254f7
--- /dev/null
@@ -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 <cni@berlios.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 MPLSPacket unit tests */
+
+//#include "MPLSPacket.test.hh"
+//#include "MPLSPacket.test.ih"
+
+// Custom includes
+#include "MPLSPacket.hh"
+
+
+#include "../../Utils/auto_unit_test.hh"
+#include <boost/test/test_tools.hpp>
+
+#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>() );
+    senf::MPLSPacket p2 (p.next().as<senf::MPLSPacket>());
+    BOOST_CHECK( p2->s());
+    BOOST_REQUIRE( p2.next().is<senf::DataPacket>() );
+}
+
+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: