From: cni Date: Wed, 1 Jul 2009 09:38:41 +0000 (+0000) Subject: Packets/DefaultBundle/MPSPacket: updated finalize method, enhanced unit test X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=1f18b34d44aef4554ad8b226b5e2815286d16e8c;p=senf.git Packets/DefaultBundle/MPSPacket: updated finalize method, enhanced unit test git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1252 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/DefaultBundle/MPLSPacket.cc b/Packets/DefaultBundle/MPLSPacket.cc index d191e5b..543d709 100644 --- a/Packets/DefaultBundle/MPLSPacket.cc +++ b/Packets/DefaultBundle/MPLSPacket.cc @@ -63,6 +63,10 @@ prefix_ senf::PacketInterpreterBase::factory_t senf::MPLSPacketType::nextPacketT prefix_ void senf::MPLSPacketType::finalize(packet p) { + if (p.prev(senf::nothrow).is()) //not the last label on the MPLS stack + p->s_() << false; + else + p->s_() << true; } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Packets/DefaultBundle/MPLSPacket.hh b/Packets/DefaultBundle/MPLSPacket.hh index 5413f3b..9b1d2ab 100644 --- a/Packets/DefaultBundle/MPLSPacket.hh +++ b/Packets/DefaultBundle/MPLSPacket.hh @@ -49,10 +49,12 @@ namespace senf { SENF_PARSER_BITFIELD( label, 20, unsigned); SENF_PARSER_BITFIELD( tc, 3, unsigned); - SENF_PARSER_BITFIELD( s, 1, bool); + SENF_PARSER_BITFIELD_RO( s, 1, bool); SENF_PARSER_FIELD( ttl, UInt8Parser); SENF_PARSER_FINALIZE(MPLSPacketParser); + + friend class MPLSPacketType; }; /** \brief MPLS packet @@ -62,7 +64,7 @@ namespace senf { \par Fields: \ref MPLSPacketParser - + \ingroup protocolbundle_default */ @@ -82,7 +84,7 @@ namespace senf { 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 dump(packet p, std::ostream & os); static void finalize(packet p); }; @@ -100,7 +102,7 @@ namespace senf { //#include "MPLSPacket.cti" #endif - + // Local Variables: // mode: c++ // fill-column: 100 diff --git a/Packets/DefaultBundle/MPLSPacket.test.cc b/Packets/DefaultBundle/MPLSPacket.test.cc index a5254f7..a81d35f 100644 --- a/Packets/DefaultBundle/MPLSPacket.test.cc +++ b/Packets/DefaultBundle/MPLSPacket.test.cc @@ -28,6 +28,7 @@ // Custom includes #include "MPLSPacket.hh" +#include "EthernetPacket.hh" #include "../../Utils/auto_unit_test.hh" @@ -72,13 +73,26 @@ BOOST_AUTO_UNIT_TEST(mplsPacket_parse_chain) BOOST_AUTO_UNIT_TEST(mplsPacket_create) { - senf::MPLSPacket p (senf::MPLSPacket::create()); + 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::MPLSPacket p (senf::MPLSPacket::createAfter(eth)); p->label()=4444u; p->ttl()=10u; - p->s()=true; p->tc()=0x0u; - SENF_CHECK_NO_THROW(p.finalizeThis()); + senf::MPLSPacket p2 (senf::MPLSPacket::createAfter(p)); + p->label()=5555u; + p->ttl()=10u; + p->tc()=0x0u; + + SENF_CHECK_NO_THROW(eth.finalizeAll()); + + BOOST_REQUIRE( eth.next().is() ); + BOOST_REQUIRE( p.next().is() ); + BOOST_CHECK( p->s()); + BOOST_CHECK( !p2->s()); }