13f2d526913b834d00bdc4a69a06129ba9d1fa19
[senf.git] / senf / Packets / DefaultBundle / IPv6Packet.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@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 IPv6Packet unit tests */
25
26 //#include "IPv6Packet.test.hh"
27 //#include "IPv6Packet.test.ih"
28
29 // Custom includes
30 #include "IPv6Packet.hh"
31 #include <senf/Socket/Protocols/INet/INetAddressing.hh>
32 #include <senf/Packets/DataPacket.hh>
33
34 #include <senf/Utils/auto_unit_test.hh>
35 #include <boost/test/test_tools.hpp>
36
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 SENF_AUTO_UNIT_TEST(ipV6Packet_parse)
41 {
42     unsigned char data[] = {
43             0x60, 0x12, 0x20, 0x30,
44             0x00, 0x01, 0x03, 0x04,
45             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
46             0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
47             0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
48             0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
49             0xff
50     };
51
52     senf::IPv6Packet p (senf::IPv6Packet::create(data));
53
54     BOOST_CHECK_EQUAL( p->version(),       0x06u      );
55     BOOST_CHECK_EQUAL( p->trafficClass(),  0x01u      );
56     BOOST_CHECK_EQUAL( p->flowLabel(),     0x22030u   );
57     BOOST_CHECK_EQUAL( p->length(),        0x0001u    );
58     BOOST_CHECK_EQUAL( p->nextHeader(),    0x03u      );
59     BOOST_CHECK_EQUAL( p->hopLimit(),      0x04u      );
60     BOOST_CHECK_EQUAL( p->source().value(),
61                        senf::INet6Address::from_string("1011:1213:1415:1617:1819:1a1b:1c1d:1e1f") );
62     BOOST_CHECK_EQUAL( p->destination().value(),
63                        senf::INet6Address::from_string("2021:2223:2425:2627:2829:2a2b:2c2d:2e2f") );
64
65     BOOST_CHECK( p.next() );
66     BOOST_CHECK( p.next().is<senf::DataPacket>() );
67     BOOST_CHECK_EQUAL( p.next().size(), 1u );
68
69     std::ostringstream oss (std::ostringstream::out);
70     SENF_CHECK_NO_THROW( p.dump( oss));
71 }
72
73 SENF_AUTO_UNIT_TEST(ipV6Packet_create)
74 {
75     senf::IPv6Packet ip (senf::IPv6Packet::create());
76
77     ip->trafficClass() = 0x01u;
78     ip->flowLabel() = 0x22030u;
79     ip->hopLimit() = 0x04u;
80     ip->source() = senf::INet6Address::from_string("1011:1213:1415:1617:1819:1a1b:1c1d:1e1f");
81     ip->destination() = senf::INet6Address::from_string("2021:2223:2425:2627:2829:2a2b:2c2d:2e2f");
82
83     ip.finalizeAll();
84
85     unsigned char data[] = {
86             0x60, 0x12, 0x20, 0x30,
87             0x00, 0x00, 0x3b, 0x04,
88             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
89             0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
90             0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
91             0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
92     };
93     BOOST_CHECK_EQUAL_COLLECTIONS(
94             data, data+sizeof(data), ip.data().begin(), ip.data().end() );
95 }
96
97 ///////////////////////////////cc.e////////////////////////////////////////
98 #undef prefix_
99
100 \f
101 // Local Variables:
102 // mode: c++
103 // fill-column: 100
104 // c-file-style: "senf"
105 // indent-tabs-mode: nil
106 // ispell-local-dictionary: "american"
107 // compile-command: "scons -u test"
108 // comment-column: 40
109 // End: