2b5914c6d77480be344f3d9e027427bf416b58c7
[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     senf::dumpPacketRegistries(std::cout);
38
39     unsigned char data[] = {
40             0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3a, 0xff, //IPv6
41             0x20, 0x01, 0x08, 0x90, 0x06, 0x00, 0xff, 0xff,
42             0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01,
43             0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44             0x00, 0x00, 0x00, 0x01, 0xff, 0x03, 0x00, 0x02,
45             0x87, 0x00, 0xaf, 0x30,                         //ICMPv6
46             0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x08, 0x90, //Neighbor Solicitation
47             0x60, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
48             0x00, 0x03, 0x00, 0x02,
49             0x01, 0x01, 0x00, 0x0d,                         //Source Option
50             0x88, 0x70, 0xe4, 0xc0,
51     };
52
53     senf::IPv6Packet ip (senf::IPv6Packet::create(data));
54     senf::ICMPv6Packet icmp (ip.find<senf::ICMPv6Packet>());
55
56     BOOST_CHECK_EQUAL(icmp->type(), 0x87 );
57     BOOST_CHECK( icmp.next() );
58     BOOST_CHECK( icmp.next().is<senf::NDPNeighborSolicitationMessage>() );
59     senf::NDPNeighborSolicitationMessage rnadm (icmp.next().as<senf::NDPNeighborSolicitationMessage>());
60     BOOST_CHECK_EQUAL(rnadm.size(),28);
61
62     senf::NDPNeighborSolicitationMessage::Parser::options_t::container roptC(rnadm->options() );
63     senf::NDPNeighborSolicitationMessage::Parser::options_t::container::const_iterator listIter (roptC.begin());
64     BOOST_CHECK( listIter->is<senf::NDPSourceLLAddressTLVParser>() );
65     BOOST_CHECK_EQUAL( listIter->type(), 1u );
66     BOOST_CHECK_EQUAL( listIter->length(), 1u );
67     senf::NDPSourceLLAddressTLVParser llopt (listIter->as<senf::NDPSourceLLAddressTLVParser>());
68 }
69
70 ///////////////////////////////cc.e////////////////////////////////////////
71
72
73 // Local Variables:
74 // mode: c++
75 // fill-column: 100
76 // c-file-style: "senf"
77 // indent-tabs-mode: nil
78 // ispell-local-dictionary: "american"
79 // compile-command: "scons -u test"
80 // comment-column: 40
81 // End: