Packets/DefaultBundle/UDPPacket: added unit test for udp in ipv6
tho [Mon, 9 Mar 2009 13:15:20 +0000 (13:15 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1148 270642c3-0616-0410-b53a-bc976706d245

Packets/DefaultBundle/UDPPacket.test.cc

index dd39540..d9b4eee 100644 (file)
@@ -28,6 +28,7 @@
 // Custom includes
 #include "UDPPacket.hh"
 #include "IPv4Packet.hh"
+#include "IPv6Packet.hh"
 
 #include "../../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
-BOOST_AUTO_UNIT_TEST(udpPacket_packet)
+BOOST_AUTO_UNIT_TEST(udpPacket_parse)
 {
 
-    unsigned char data[] = { 0x01, 0x02, 0x03, 0x04,
-                             0x05, 0x06, 0x07, 0x08
-                           };
+    unsigned char data[] = { 
+            0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
+    };
 
     senf::UDPPacket p (senf::UDPPacket::create(data));
 
@@ -53,13 +54,15 @@ BOOST_AUTO_UNIT_TEST(udpPacket_packet)
     SENF_CHECK_NO_THROW( p.dump( oss));
 }
 
-BOOST_AUTO_UNIT_TEST(udpPacket_create)
+BOOST_AUTO_UNIT_TEST(udpPacket_in_ipv6_create)
 {
-    unsigned char data[] = { 0x45, 0x00, 0x00, 0x26, 0x00, 0x00, 0x40, 0x00,
-                             0x40, 0x11, 0x3c, 0xc5, 0x7f, 0x00, 0x00, 0x01,
-                             0x7f, 0x00, 0x00, 0x01, 0x5b, 0xa0, 0x30, 0x39,
-                             0x00, 0x12, 0xfa, 0x6e, 0x54, 0x45, 0x53, 0x54,
-                             0x2d, 0x57, 0x52, 0x49, 0x54, 0x45 };
+    unsigned char data[] = { 
+            0x45, 0x00, 0x00, 0x26, 0x00, 0x00, 0x40, 0x00,
+            0x40, 0x11, 0x3c, 0xc5, 0x7f, 0x00, 0x00, 0x01,
+            0x7f, 0x00, 0x00, 0x01, 0x5b, 0xa0, 0x30, 0x39,
+            0x00, 0x12, 0xfa, 0x6e, 0x54, 0x45, 0x53, 0x54,
+            0x2d, 0x57, 0x52, 0x49, 0x54, 0x45 
+    };
 
     senf::IPv4Packet ip (senf::IPv4Packet::create());
     ip->source() = senf::INet4Address::Loopback;
@@ -71,7 +74,7 @@ BOOST_AUTO_UNIT_TEST(udpPacket_create)
     udp->source() = 23456;
     udp->destination() = 12345;
 
-    senf::DataPacket::createAfter(udp,std::string("TEST-WRITE"));
+    senf::DataPacket::createAfter(udp, std::string("TEST-WRITE"));
 
     // validates, since the checksum is 0 and thus ignored !
     BOOST_CHECK( udp->validateChecksum() );
@@ -82,6 +85,47 @@ BOOST_AUTO_UNIT_TEST(udpPacket_create)
     BOOST_CHECK( udp->validateChecksum() );
 }
 
+BOOST_AUTO_UNIT_TEST(udpPacket_in_ipv6_parse)
+{
+    // captured udp packet generated with mgen send over ipv6
+    unsigned char data[] = { 
+            // IPv6 Packet
+            0x60, 0x00, 0x00, 0x00, 0x00, 0x32, 0x11, 0x40,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+            // UDP Packet
+            0x13, 0x89, 0x13, 0x88, 0x00, 0x32, 0x11, 0x23,
+            // mgen payload
+            0x00, 0x2a, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01,
+            0x00, 0x00, 0x00, 0x0b, 0x49, 0xb5, 0x0a, 0x90,
+            0x00, 0x09, 0x5b, 0x37, 0x13, 0x88, 0x02, 0x10,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+            0x00, 0x00    
+    };
+
+    senf::IPv6Packet ip (senf::IPv6Packet::create(data));
+    BOOST_CHECK_EQUAL( ip->length(),     50u  );
+    BOOST_CHECK_EQUAL( ip->nextHeader(), 0x11 );
+    BOOST_CHECK_EQUAL( ip->hopLimit(),   64u  );
+    BOOST_CHECK_EQUAL( ip->source().value(),      senf::INet6Address::Loopback );
+    BOOST_CHECK_EQUAL( ip->destination().value(), senf::INet6Address::Loopback );
+    
+    std::ostringstream oss (std::ostringstream::out);
+    SENF_CHECK_NO_THROW( ip.dump( oss));
+    
+    BOOST_REQUIRE( ip.next().is<senf::UDPPacket>() );
+    senf::UDPPacket udp (ip.next().as<senf::UDPPacket>());
+    
+    BOOST_CHECK_EQUAL( udp->source(),      5001u  );
+    BOOST_CHECK_EQUAL( udp->destination(), 5000u  );
+    BOOST_CHECK_EQUAL( udp->length(),      50u    );
+    BOOST_CHECK_EQUAL( udp->checksum(),    0x1123 );
+    
+    BOOST_CHECK( udp->validateChecksum() );
+}
 
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_