4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
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
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.
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.
19 // The Original Code is Fraunhofer FOKUS code.
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.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief IPv6Packet unit tests */
31 //#include "IPv6Packet.test.hh"
32 //#include "IPv6Packet.test.ih"
35 #include "IPv6Packet.hh"
36 #include <senf/Socket/Protocols/INet/INetAddressing.hh>
37 #include <senf/Packets/DataPacket.hh>
39 #include <senf/Utils/auto_unit_test.hh>
40 #include <boost/test/test_tools.hpp>
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45 SENF_AUTO_UNIT_TEST(ipV6Packet_parse)
47 unsigned char data[] = {
48 0x60, 0x12, 0x20, 0x30,
49 0x00, 0x01, 0x03, 0x04,
50 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
51 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
52 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
53 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
57 senf::IPv6Packet p (senf::IPv6Packet::create(data));
59 BOOST_CHECK_EQUAL( p->version(), 0x06u );
60 BOOST_CHECK_EQUAL( p->trafficClass(), 0x01u );
61 BOOST_CHECK_EQUAL( p->flowLabel(), 0x22030u );
62 BOOST_CHECK_EQUAL( p->length(), 0x0001u );
63 BOOST_CHECK_EQUAL( p->nextHeader(), 0x03u );
64 BOOST_CHECK_EQUAL( p->hopLimit(), 0x04u );
65 BOOST_CHECK_EQUAL( p->source().value(),
66 senf::INet6Address::from_string("1011:1213:1415:1617:1819:1a1b:1c1d:1e1f") );
67 BOOST_CHECK_EQUAL( p->destination().value(),
68 senf::INet6Address::from_string("2021:2223:2425:2627:2829:2a2b:2c2d:2e2f") );
70 BOOST_CHECK( p.next() );
71 BOOST_CHECK( p.next().is<senf::DataPacket>() );
72 BOOST_CHECK_EQUAL( p.next().size(), 1u );
74 std::ostringstream oss (std::ostringstream::out);
75 SENF_CHECK_NO_THROW( p.dump( oss));
78 SENF_AUTO_UNIT_TEST(ipV6Packet_create)
80 senf::IPv6Packet ip (senf::IPv6Packet::create());
82 ip->trafficClass() = 0x01u;
83 ip->flowLabel() = 0x22030u;
84 ip->hopLimit() = 0x04u;
85 ip->source() = senf::INet6Address::from_string("1011:1213:1415:1617:1819:1a1b:1c1d:1e1f");
86 ip->destination() = senf::INet6Address::from_string("2021:2223:2425:2627:2829:2a2b:2c2d:2e2f");
90 unsigned char data[] = {
91 0x60, 0x12, 0x20, 0x30,
92 0x00, 0x00, 0x3b, 0x04,
93 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
94 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
95 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
96 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
98 BOOST_CHECK_EQUAL_COLLECTIONS(
99 data, data+sizeof(data), ip.data().begin(), ip.data().end() );
102 //-/////////////////////////////////////////////////////////////////////////////////////////////////
109 // c-file-style: "senf"
110 // indent-tabs-mode: nil
111 // ispell-local-dictionary: "american"
112 // compile-command: "scons -u test"
113 // comment-column: 40