switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / DefaultBundle / NDPMessage.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2010
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Sauer <ssauer@berlios.de>
27
28 /** \file
29     \brief NDPMessage unit tests */
30
31 // Custom includes
32 #include "ICMPv6Packet.hh"
33 #include "ICMPv6TypePacket.hh"
34 #include "NDPOptions.hh"
35
36 #include <senf/Utils/auto_unit_test.hh>
37 #include <boost/test/test_tools.hpp>
38
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 SENF_AUTO_UNIT_TEST(NDPMessage_create)
41 {
42     senf::dumpPacketRegistries(std::cout);
43
44     unsigned char data[] = {
45             0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3a, 0xff, //IPv6
46             0x20, 0x01, 0x08, 0x90, 0x06, 0x00, 0xff, 0xff,
47             0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01,
48             0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49             0x00, 0x00, 0x00, 0x01, 0xff, 0x03, 0x00, 0x02,
50             0x87, 0x00, 0xaf, 0x30,                         //ICMPv6
51             0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x08, 0x90, //Neighbor Solicitation
52             0x60, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
53             0x00, 0x03, 0x00, 0x02,
54             0x01, 0x01, 0x00, 0x0d,                         //Source Option
55             0x88, 0x70, 0xe4, 0xc0,
56     };
57
58     senf::IPv6Packet ip (senf::IPv6Packet::create(data));
59     senf::ICMPv6Packet icmp (ip.find<senf::ICMPv6Packet>());
60
61     BOOST_CHECK_EQUAL(icmp->type(), 0x87 );
62     BOOST_CHECK( icmp.next() );
63     BOOST_CHECK( icmp.next().is<senf::NDPNeighborSolicitationMessage>() );
64     senf::NDPNeighborSolicitationMessage rnadm (icmp.next().as<senf::NDPNeighborSolicitationMessage>());
65     BOOST_CHECK_EQUAL(rnadm.size(),28);
66
67     senf::NDPNeighborSolicitationMessage::Parser::options_t::container roptC(rnadm->options() );
68     senf::NDPNeighborSolicitationMessage::Parser::options_t::container::const_iterator listIter (roptC.begin());
69     BOOST_CHECK( listIter->is<senf::NDPSourceLLAddressTLVParser>() );
70     BOOST_CHECK_EQUAL( listIter->type(), 1u );
71     BOOST_CHECK_EQUAL( listIter->length(), 1u );
72     senf::NDPSourceLLAddressTLVParser llopt (listIter->as<senf::NDPSourceLLAddressTLVParser>());
73 }
74
75 //-/////////////////////////////////////////////////////////////////////////////////////////////////
76
77
78 // Local Variables:
79 // mode: c++
80 // fill-column: 100
81 // c-file-style: "senf"
82 // indent-tabs-mode: nil
83 // ispell-local-dictionary: "american"
84 // compile-command: "scons -u test"
85 // comment-column: 40
86 // End: