- Added Unittests for all ICMPv6 - MLDv2 Packet Types
pug [Tue, 10 Mar 2009 13:04:21 +0000 (13:04 +0000)]
- Fixed Reverse Lookup in PacketParser for MLDv2 Packets

git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1150 270642c3-0616-0410-b53a-bc976706d245

Packets/DefaultBundle/ICMPv6Packet.test.cc
Packets/DefaultBundle/ICMPv6TypePacket.hh
Packets/DefaultBundle/Mldv2Packet.test.cc

index a116e2b..497d2dc 100644 (file)
@@ -22,6 +22,9 @@
 
 // Definition of non-inline non-template functions
 
+/** \file
+    \brief ICMPv6Packet unit tests */
+
 // Custom includes
 
 #include "../../Utils/auto_unit_test.hh"
 
 BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
 {
-    unsigned char data[] = {
+    unsigned char dataListenerReport[] = {
             0x8f, 0x00, 0x8d, 0x54, 0x00, 0x00, 0x00, 0x01,
             0x04, 0x00, 0x00, 0x00, 0xff, 0x15, 0x00, 0x00,
             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             0x00, 0x00, 0x00, 0x16
     };
 
-    senf::ICMPv6Packet p ( senf::ICMPv6Packet::create(data) );
+    senf::ICMPv6Packet pListenerReport ( senf::ICMPv6Packet::create(dataListenerReport) );
 
-    BOOST_CHECK_EQUAL( p->type(),     0x8f   );
-    BOOST_CHECK_EQUAL( p->code(),     0x00   );
-    BOOST_CHECK_EQUAL( p->checksum(), 0x8d54 );
-    BOOST_CHECK( p.next() );
-    BOOST_CHECK( p.next().is<senf::MLDv2ListenerReport>() );
-    BOOST_CHECK_EQUAL( p.next().size(), 24u );
+    BOOST_CHECK_EQUAL( pListenerReport->type(),     0x8f   );
+    BOOST_CHECK_EQUAL( pListenerReport->code(),     0x00   );
+    BOOST_CHECK_EQUAL( pListenerReport->checksum(), 0x8d54 );
+    BOOST_CHECK( pListenerReport.next() );
+    BOOST_CHECK( pListenerReport.next().is<senf::MLDv2ListenerReport>() );
+    BOOST_CHECK_EQUAL( pListenerReport.next().size(), 24u );
 
     std::ostringstream oss (std::ostringstream::out);
-    SENF_CHECK_NO_THROW( p.dump( oss));
+    SENF_CHECK_NO_THROW( pListenerReport.dump( oss));
+
+    unsigned char dataListenerQuery[] = {
+        0x82, 0x00, 0xf7, 0xd6, 0x27, 0x10, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x02, 0x7d, 0x00, 0x00
+    };
+    senf::ICMPv6Packet pListenerQuery ( senf::ICMPv6Packet::create(dataListenerQuery) );
+    BOOST_CHECK_EQUAL( pListenerQuery->type(),     0x82   );
+    BOOST_CHECK_EQUAL( pListenerQuery->code(),     0x00   );
+    BOOST_CHECK_EQUAL( pListenerQuery->checksum(), 0xf7d6 );
+    BOOST_CHECK( pListenerQuery.next() );
+    BOOST_CHECK( pListenerQuery.next().is<senf::MLDv2ListenerQuery>() );
+    BOOST_CHECK_EQUAL( pListenerQuery.next().size(), 24u );
+
+    SENF_CHECK_NO_THROW( pListenerQuery.dump( oss));
+    
+    unsigned char dataEchoRequest[] = {
+        0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07
+    };
+    senf::ICMPv6Packet pEchoRequest ( senf::ICMPv6Packet::create(dataEchoRequest) );
+    BOOST_CHECK_EQUAL( pEchoRequest->type(),     0x80   );
+    BOOST_CHECK_EQUAL( pEchoRequest->code(),     0x00   );
+    BOOST_CHECK_EQUAL( pEchoRequest->checksum(), 0x0000 );
+    BOOST_CHECK( pEchoRequest.next() );
+    BOOST_CHECK( pEchoRequest.next().is<senf::ICMPv6EchoRequest>() );
+    BOOST_CHECK_EQUAL( pEchoRequest.next().size(), 4u );
+
+    SENF_CHECK_NO_THROW( pEchoRequest.dump( oss));
+    
+    unsigned char dataEchoReply[] = {
+        0x81, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x4d
+    };
+    
+    senf::ICMPv6Packet pEchoReply ( senf::ICMPv6Packet::create(dataEchoReply) );
+    BOOST_CHECK_EQUAL( pEchoReply->type(),     0x81   );
+    BOOST_CHECK_EQUAL( pEchoReply->code(),     0x00   );
+    BOOST_CHECK_EQUAL( pEchoReply->checksum(), 0x0000 );
+    BOOST_CHECK( pEchoReply.next() );
+    BOOST_CHECK( pEchoReply.next().is<senf::ICMPv6EchoReply>() );
+    BOOST_CHECK_EQUAL( pEchoReply.next().size(), 4u );
+
+    SENF_CHECK_NO_THROW( pEchoReply.dump( oss));
+    
+    
+    unsigned char dataErrDestUnreachable[] = {
+        0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
+    };
+    
+    senf::ICMPv6Packet pErrDestUnreachable ( senf::ICMPv6Packet::create(dataErrDestUnreachable) );
+    BOOST_CHECK_EQUAL( pErrDestUnreachable->type(),     0x01   );
+    BOOST_CHECK_EQUAL( pErrDestUnreachable->code(),     0x00   );
+    BOOST_CHECK_EQUAL( pErrDestUnreachable->checksum(), 0x0000 );
+    BOOST_CHECK( pErrDestUnreachable.next() );
+    BOOST_CHECK( pErrDestUnreachable.next().is<senf::ICMPv6ErrDestUnreachable>() );
+    BOOST_CHECK_EQUAL( pErrDestUnreachable.next().size(), 4u );
+
+    SENF_CHECK_NO_THROW( pErrDestUnreachable.dump( oss));
+    
+    
+    unsigned char dataErrTooBig[] = {
+        0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0xd8 
+    };
+    
+    senf::ICMPv6Packet pErrTooBig ( senf::ICMPv6Packet::create(dataErrTooBig) );
+    BOOST_CHECK_EQUAL( pErrTooBig->type(),     0x02   );
+    BOOST_CHECK_EQUAL( pErrTooBig->code(),     0x00   );
+    BOOST_CHECK_EQUAL( pErrTooBig->checksum(), 0x0000 );
+    BOOST_CHECK( pErrTooBig.next() );
+    BOOST_CHECK( pErrTooBig.next().is<senf::ICMPv6ErrTooBig>() );
+    BOOST_CHECK_EQUAL( pErrTooBig.next().size(), 4u );
+
+    SENF_CHECK_NO_THROW( pErrTooBig.dump( oss));
+    
+    
+    unsigned char dataErrTimeExceeded[] = {
+        0x03, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+    };
+    
+    senf::ICMPv6Packet pErrTimeExceeded ( senf::ICMPv6Packet::create(dataErrTimeExceeded) );
+    BOOST_CHECK_EQUAL( pErrTimeExceeded->type(),     0x03   );
+    BOOST_CHECK_EQUAL( pErrTimeExceeded->code(),     0x63   );
+    BOOST_CHECK_EQUAL( pErrTimeExceeded->checksum(), 0x0000 );
+    BOOST_CHECK( pErrTimeExceeded.next() );
+    BOOST_CHECK( pErrTimeExceeded.next().is<senf::ICMPv6ErrTimeExceeded>() );
+    BOOST_CHECK_EQUAL( pErrTimeExceeded.next().size(), 4u );
+
+    SENF_CHECK_NO_THROW( pErrTimeExceeded.dump( oss));
+    
+    
+    unsigned char dataErrParamProblem[] = {
+        0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+    };
+    
+    senf::ICMPv6Packet pErrParamProblem ( senf::ICMPv6Packet::create(dataErrParamProblem) );
+    BOOST_CHECK_EQUAL( pErrParamProblem->type(),     0x04   );
+    BOOST_CHECK_EQUAL( pErrParamProblem->code(),     0x01   );
+    BOOST_CHECK_EQUAL( pErrParamProblem->checksum(), 0x0000 );
+    BOOST_CHECK( pErrParamProblem.next() );
+    BOOST_CHECK( pErrParamProblem.next().is<senf::ICMPv6ErrParamProblem>() );
+    BOOST_CHECK_EQUAL( pErrParamProblem.next().size(), 4u );
+
+    SENF_CHECK_NO_THROW( pErrParamProblem.dump( oss));
+    
 }
+
+// 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:
index 475b11f..7196f4f 100644 (file)
@@ -172,7 +172,7 @@ namespace senf {
     
         /*   Code     static set to 0       */
     //     SENF_PARSER_INIT() {
-    //         ICMPv6Packet icmpv6 (senf::Packet().rfind<ICMPv6Packet>(senf::nothrow));
+    //         ICMPv6Packet icmpv6 (packet().rfind<ICMPv6Packet>(senf::nothrow));
     //         icmpv6->code() = 0;
     //     }
         
@@ -216,7 +216,7 @@ namespace senf {
         /*  Code    0 - Hop limit exceeded in transit
                     1 - Fragment reassembly time exceeded   */
         void setErrCode(int code){
-            ICMPv6Packet icmpv6 (senf::Packet().rfind<ICMPv6Packet>(senf::nothrow));
+            ICMPv6Packet icmpv6 (packet().rfind<ICMPv6Packet>(senf::nothrow));
             icmpv6->code() = code;
         }
         
@@ -261,7 +261,7 @@ namespace senf {
                     2 - Unrecognized IPv6 option encountered          */
         
         void setErrCode(int code){
-            ICMPv6Packet icmpv6 (senf::Packet().rfind<ICMPv6Packet>(senf::nothrow));
+            ICMPv6Packet icmpv6 (packet().rfind<ICMPv6Packet>(senf::nothrow));
             icmpv6->code() = code;
         }
         SENF_PARSER_FINALIZE ( ICMPv6ErrParamProblemParser );
index b26eabe..a6c072a 100644 (file)
 
 BOOST_AUTO_UNIT_TEST(ICMPv6_MLDv2_Packet_packet)
 {
-    unsigned char data[] = {0x00 ,0x00 ,0x00 ,0x01 ,0x04 ,0x00 ,0x00 ,0x00 ,0xff ,0x15 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x16};
+    unsigned char data[] = {
+        0x00 ,0x00 ,0x00 ,0x01 ,0x04 ,0x00 ,0x00 ,0x00 ,
+        0xff ,0x15 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
+        0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x16
+    };
 
 
     senf::MLDv2ListenerReport p ( senf::MLDv2ListenerReport::create(data) );