Added dump information for NDP options to appropriate ICMPv6 types
[senf.git] / senf / Packets / DefaultBundle / NDPMessage.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2010
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Sauer <ssauer@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief NDPMessage unit tests */
25
26 // Custom includes
27 #include "ICMPv6Packet.hh"
28 #include "ICMPv6TypePacket.hh"
29 #include "NDPOptions.hh"
30
31 #include <senf/Utils/auto_unit_test.hh>
32 #include <boost/test/test_tools.hpp>
33
34 ///////////////////////////////cc.p////////////////////////////////////////
35 SENF_AUTO_UNIT_TEST(NDPMessage_create)
36 {
37     unsigned char data[] = {
38             0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3a, 0xff, //IPv6
39             0x20, 0x01, 0x08, 0x90, 0x06, 0x00, 0xff, 0xff,
40             0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01,
41             0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42             0x00, 0x00, 0x00, 0x01, 0xff, 0x03, 0x00, 0x02,
43             0x87, 0x00, 0xaf, 0x30,                         //ICMPv6
44             0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x08, 0x90, //Neighbor Solicitation
45             0x60, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
46             0x00, 0x03, 0x00, 0x02,
47             0x01, 0x01, 0x00, 0x0d,                         //Source Option
48             0x88, 0x70, 0xe4, 0xc0,
49     };
50
51     senf::IPv6Packet ip (senf::IPv6Packet::create(data));
52     senf::ICMPv6Packet icmp (ip.find<senf::ICMPv6Packet>());
53
54     BOOST_CHECK_EQUAL(icmp->type(), 0x87 );
55     BOOST_CHECK( icmp.next() );
56     BOOST_CHECK( icmp.next().is<senf::NDPNeighborSolicitationMessage>() );
57     senf::NDPNeighborSolicitationMessage rnadm (icmp.next().as<senf::NDPNeighborSolicitationMessage>());
58     BOOST_CHECK_EQUAL(rnadm.size(),28);
59
60     senf::NDPNeighborSolicitationMessage::Parser::options_t::container roptC(rnadm->options() );
61     senf::NDPNeighborSolicitationMessage::Parser::options_t::container::const_iterator listIter (roptC.begin());
62     BOOST_CHECK( listIter->is<senf::NDPSourceLLAddressTLVParser>() );
63     BOOST_CHECK_EQUAL( listIter->type(), 1u );
64     BOOST_CHECK_EQUAL( listIter->length(), 1u );
65     senf::NDPSourceLLAddressTLVParser llopt (listIter->as<senf::NDPSourceLLAddressTLVParser>());
66 }
67
68 ///////////////////////////////cc.e////////////////////////////////////////
69
70
71 // Local Variables:
72 // mode: c++
73 // fill-column: 100
74 // c-file-style: "senf"
75 // indent-tabs-mode: nil
76 // ispell-local-dictionary: "american"
77 // compile-command: "scons -u test"
78 // comment-column: 40
79 // End: