Added ICMPv6 types for IPv6 Neighbor Discovery
[senf.git] / senf / Packets / DefaultBundle / NDPMessage.test.cc
1 // $Id: ICMPv6Packet.test.cc 1550 2010-01-26 09:34:24Z tho $
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 ICMPv6Packet 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::ICMPv6Packet icmp (senf::ICMPv6Packet::create());
38     icmp->code() = 0;
39
40     senf::NDPNeighborAdvertisementMessage nadm (senf::NDPNeighborAdvertisementMessage::createAfter(icmp));
41     nadm->r() = true;
42     nadm->s() = true;
43     nadm->o() = false;
44     nadm->target() = senf::INet6Address::Loopback;
45
46     senf::NDPNeighborAdvertisementMessage::Parser::options_t::container optC(nadm->options());
47     senf::NDPMTUTLVParser opt(
48             optC.push_back_space().init<senf::NDPMTUTLVParser> ());
49     senf::NDPTargetLLAddressTLVParser opt2(
50             optC.push_back_space().init<senf::NDPTargetLLAddressTLVParser> ());
51     opt.mtu() = 1234u;
52     opt2.target() = senf::MACAddress::Broadcast;
53
54     icmp.finalizeAll();
55
56     BOOST_CHECK_EQUAL(icmp->type(), 0x88 );
57     BOOST_CHECK( icmp.next() );
58     BOOST_CHECK( icmp.next().is<senf::NDPNeighborAdvertisementMessage>() );
59     senf::NDPNeighborAdvertisementMessage rnadm (icmp.next().as<senf::NDPNeighborAdvertisementMessage>());
60
61     BOOST_CHECK_EQUAL( rnadm->r(), true  );
62     BOOST_CHECK_EQUAL( rnadm->s(), true  );
63     BOOST_CHECK_EQUAL( rnadm->o(), false );
64
65     senf::NDPNeighborAdvertisementMessage::Parser::options_t::container roptC(rnadm->options() );
66     senf::NDPNeighborAdvertisementMessage::Parser::options_t::container::iterator listIter (roptC.begin());
67     BOOST_CHECK( listIter->is<senf::NDPMTUTLVParser>() );
68     BOOST_CHECK_EQUAL( listIter->type(), 5u );
69     BOOST_CHECK_EQUAL( listIter->length(), 1u );
70     senf::NDPMTUTLVParser mtuopt (listIter->as<senf::NDPMTUTLVParser>());
71     BOOST_CHECK_EQUAL( mtuopt.mtu(), 1234u );
72     listIter++;
73     BOOST_CHECK( listIter->is<senf::NDPTargetLLAddressTLVParser>() );
74     BOOST_CHECK_EQUAL( listIter->type(), 2u );
75     BOOST_CHECK_EQUAL( listIter->length(), 1u );
76 }
77
78 ///////////////////////////////cc.e////////////////////////////////////////
79
80
81 // Local Variables:
82 // mode: c++
83 // fill-column: 100
84 // c-file-style: "senf"
85 // indent-tabs-mode: nil
86 // ispell-local-dictionary: "american"
87 // compile-command: "scons -u test"
88 // comment-column: 40
89 // End: