Packets/DefaultBundle/MPSPacket: updated finalize method, enhanced unit test
cni [Wed, 1 Jul 2009 09:38:41 +0000 (09:38 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1252 270642c3-0616-0410-b53a-bc976706d245

Packets/DefaultBundle/MPLSPacket.cc
Packets/DefaultBundle/MPLSPacket.hh
Packets/DefaultBundle/MPLSPacket.test.cc

index d191e5b..543d709 100644 (file)
@@ -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<MPLSPacket>()) //not the last label on the MPLS stack
+        p->s_() << false;
+    else
+        p->s_() << true;
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////
index 5413f3b..9b1d2ab 100644 (file)
@@ -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
 
-\f
+
 // Local Variables:
 // mode: c++
 // fill-column: 100
index a5254f7..a81d35f 100644 (file)
@@ -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<senf::MPLSPacket>() );
+    BOOST_REQUIRE( p.next().is<senf::MPLSPacket>() );
+    BOOST_CHECK( p->s());
+    BOOST_CHECK( !p2->s());
 
 }