switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / DefaultBundle / ICMPv6Packet.test.cc
index 9424438..85e0472 100644 (file)
@@ -2,23 +2,28 @@
 //
 // Copyright (C) 2008
 // Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-//     Philipp Batroff <pug@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.
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at 
+// http://senf.berlios.de/license.html
 //
-// 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.
+// The Fraunhofer FOKUS Public License Version 1.0 is based on, 
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
 //
-// 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.
+// Software distributed under the License is distributed on an "AS IS" basis, 
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+//   Philipp Batroff <pug@berlios.de>
 
 /** \file
     \brief ICMPv6Packet unit tests */
 #include <sstream>
 #include "ICMPv6Packet.hh"
 #include "ICMPv6TypePacket.hh"
+#include "NDPOptions.hh"
 
 #include <senf/Utils/auto_unit_test.hh>
 #include <boost/test/test_tools.hpp>
 
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 
-BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
+SENF_AUTO_UNIT_TEST(ICMPv6Packet_packet)
 {
     unsigned char dataListenerReport[] = {
             0x8f, 0x00, 0x8d, 0x54, 0x00, 0x00, 0x00, 0x01,
@@ -54,7 +61,7 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
     SENF_CHECK_NO_THROW( pListenerReport.dump( oss));
 
     unsigned char dataListenerQuery[] = {
-        0x82, 0x00, 0xf7, 0xd6, 0x27, 0x10, 0x00, 0x00, 
+        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
@@ -68,7 +75,7 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
     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
     };
@@ -81,11 +88,11 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
     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   );
@@ -95,12 +102,12 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
     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 
+        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   );
@@ -110,12 +117,12 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
     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 
+        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   );
@@ -125,12 +132,12 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
     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   );
@@ -140,12 +147,12 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
     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   );
@@ -155,20 +162,120 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_packet)
     BOOST_CHECK_EQUAL( pErrParamProblem.next().size(), 4u );
 
     SENF_CHECK_NO_THROW( pErrParamProblem.dump( oss));
-    
+
+    unsigned char dataRouterSolicitation[] = {
+        0x85, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x05, 0x01, 0x00, 0x00,
+        0x12, 0x34, 0x56, 0x78
+    };
+
+    senf::ICMPv6Packet pRouterSolicitation ( senf::ICMPv6Packet::create(dataRouterSolicitation) );
+    BOOST_CHECK_EQUAL( pRouterSolicitation->type(),     0x85   );
+    BOOST_CHECK_EQUAL( pRouterSolicitation->code(),     0x00   );
+    BOOST_CHECK_EQUAL( pRouterSolicitation->checksum(), 0x0000 );
+    BOOST_CHECK( pRouterSolicitation.next() );
+    BOOST_CHECK( pRouterSolicitation.next().is<senf::NDPRouterSolicitationMessage>() );
+    BOOST_CHECK_EQUAL( pRouterSolicitation.next().size(), 12u );
+
+    senf::NDPRouterSolicitationMessage pOption(pRouterSolicitation.next().as<senf::NDPRouterSolicitationMessage>());
+    senf::NDPRouterSolicitationMessage::Parser::options_t::container optC(pOption->options() );
+    senf::NDPRouterSolicitationMessage::Parser::options_t::container::iterator listIter (optC.begin());
+    BOOST_CHECK_EQUAL(listIter->type(),5u);
+    BOOST_CHECK_EQUAL(listIter->length(),1u);
+
+    SENF_CHECK_NO_THROW( pRouterSolicitation.dump( oss));
+
+    unsigned char dataRouterAdvertisement[] = {
+        0x86, 0x00, 0x00, 0x00,
+        0xFF, 0x00, 0x23, 0x28,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+    };
+
+    senf::ICMPv6Packet pRouterAdvertisement ( senf::ICMPv6Packet::create(dataRouterAdvertisement) );
+    BOOST_CHECK_EQUAL( pRouterAdvertisement->type(),     0x86   );
+    BOOST_CHECK_EQUAL( pRouterAdvertisement->code(),     0x00   );
+    BOOST_CHECK_EQUAL( pRouterAdvertisement->checksum(), 0x0000 );
+    BOOST_CHECK( pRouterAdvertisement.next() );
+    BOOST_CHECK( pRouterAdvertisement.next().is<senf::NDPRouterAdvertisementMessage>() );
+    BOOST_CHECK_EQUAL( pRouterAdvertisement.next().size(), 12u );
+
+    SENF_CHECK_NO_THROW( pRouterAdvertisement.dump( oss));
+
+    unsigned char dataNeighborSolicitation[] = {
+        0x87, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00
+    };
+
+    senf::ICMPv6Packet pNeighborSolicitation ( senf::ICMPv6Packet::create(dataNeighborSolicitation) );
+    BOOST_CHECK_EQUAL( pNeighborSolicitation->type(),     0x87   );
+    BOOST_CHECK_EQUAL( pNeighborSolicitation->code(),     0x00   );
+    BOOST_CHECK_EQUAL( pNeighborSolicitation->checksum(), 0x0000 );
+    BOOST_CHECK( pNeighborSolicitation.next() );
+    BOOST_CHECK( pNeighborSolicitation.next().is<senf::NDPNeighborSolicitationMessage>() );
+    BOOST_CHECK_EQUAL( pNeighborSolicitation.next().size(), 20u );
+
+    SENF_CHECK_NO_THROW( pNeighborSolicitation.dump( oss));
+
+    unsigned char dataNeighborAdvertisement[] = {
+        0x88, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00
+    };
+
+    senf::ICMPv6Packet pNeighborAdvertisement ( senf::ICMPv6Packet::create(dataNeighborAdvertisement) );
+    BOOST_CHECK_EQUAL( pNeighborAdvertisement->type(),     0x88   );
+    BOOST_CHECK_EQUAL( pNeighborAdvertisement->code(),     0x00   );
+    BOOST_CHECK_EQUAL( pNeighborAdvertisement->checksum(), 0x0000 );
+    BOOST_CHECK( pNeighborAdvertisement.next() );
+    BOOST_CHECK( pNeighborAdvertisement.next().is<senf::NDPNeighborAdvertisementMessage>() );
+    BOOST_CHECK_EQUAL( pNeighborAdvertisement.next().size(), 20u );
+
+    SENF_CHECK_NO_THROW( pNeighborAdvertisement.dump( oss));
+
+    unsigned char dataRedirect[] = {
+        0x89, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00
+    };
+
+    senf::ICMPv6Packet pRedirect ( senf::ICMPv6Packet::create(dataRedirect) );
+    BOOST_CHECK_EQUAL( pRedirect->type(),     0x89   );
+    BOOST_CHECK_EQUAL( pRedirect->code(),     0x00   );
+    BOOST_CHECK_EQUAL( pRedirect->checksum(), 0x0000 );
+    BOOST_CHECK( pRedirect.next() );
+    BOOST_CHECK( pRedirect.next().is<senf::NDPRedirectMessage>() );
+    BOOST_CHECK_EQUAL( pRedirect.next().size(), 36u );
+
+    SENF_CHECK_NO_THROW( pRedirect.dump( oss));
 }
 
-BOOST_AUTO_UNIT_TEST(ICMPv6Packet_create)
+SENF_AUTO_UNIT_TEST(ICMPv6Packet_create)
 {
     std::ostringstream oss (std::ostringstream::out);
-    
+
     unsigned char ping[] = { 0x60, 0x00, 0x00, 0x00, 0x00, 0x40, 0x3a, 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,
                              0x80, 0x00, 0xda, 0xe0, 0x9f, 0x7e, 0x00, 0x09,
-                             
+
                              0xb7, 0x3c, 0xbb, 0x4a, 0x9d, 0x90, 0x0a, 0x00, //payload
                              0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
                              0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@@ -185,7 +292,7 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_create)
 
     senf::ICMPv6Packet icmp (senf::ICMPv6Packet::createAfter(ip));
     icmp->code() = 0;
-    
+
     senf::ICMPv6EchoRequest ereq (senf::ICMPv6EchoRequest::createAfter(icmp));
     ereq->identifier() = 0x9f7e;
     ereq->seqNr() = 9;
@@ -194,7 +301,7 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_create)
         senf::DataPacket::createAfter(ereq, std::make_pair(ping+48, ping+sizeof(ping))));
 
     ip.finalizeAll();
-    
+
     SENF_CHECK_NO_THROW (ip.dump( oss ));
 
     std::string dump (
@@ -235,6 +342,9 @@ BOOST_AUTO_UNIT_TEST(ICMPv6Packet_create)
     }
 }
 
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+
+\f
 // Local Variables:
 // mode: c++
 // fill-column: 100