457597b70f03be8b041e8da15829e160268241cf
[senf.git] / Packets / DefaultBundle / IpV6Extensions.test.cc
1 // Copyright (C) 2007
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief IpV6Extensions.test unit tests */
23
24 //#include "IpV6Extensions.test.hh"
25 //#include "IpV6Extensions.test.ih"
26
27 // Custom includes
28 #include "IpV6Extensions.hh"
29 #include "IpV6Packet.hh"
30 #include "UDPPacket.hh"
31 #include "Socket/Protocols/INet/INetAddressing.hh"
32
33 #include <boost/test/auto_unit_test.hpp>
34 #include <boost/test/test_tools.hpp>
35
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 BOOST_AUTO_UNIT_TEST(ipv6Extension_Fragment_packet)
40 {
41     // Just for the fun of it, we test a nice chain: A fragment of a fragmented UDP packet
42
43     unsigned char data[] = {
44         // IP header
45         0x60, 0x00, 0x00, 0x00,         // IP Version, class, flow label
46         0, 20,                          // payload length
47         44,                             // next header (IPv6 Fragment)
48         32,                             // hop limit
49         0x20, 0x01, 0, 0, 0, 0, 0, 0,   // source ip = 2001::1
50            0, 0, 0, 0, 0, 0, 0, 0x01,
51         0x20, 0x01, 0, 0, 0, 0, 0, 0,   // destination ip = 2001::2
52            0, 0, 0, 0, 0, 0, 0, 0x02,
53         // IPv6 Fragment header
54         17,                             // next header (UDP)
55         0,                              // reserved
56         0x05, 0x00,                     // fragment offset, last fragment
57         0x01, 0x02, 0x03, 0x04,         // id
58         // UDP header
59         0x10, 0x00,                     // source port
60         0x20, 0x00,                     // destination port
61         0, 12,                          // length
62         0x00, 0x00,                     // CRC (no, I won't calculate this one ...)
63         // Payload data
64         0x11, 0x12, 0x13, 0x14
65     };
66
67     senf::IpV6Packet p (senf::IpV6Packet::create(data));
68
69     BOOST_CHECK_EQUAL( p->version(), 6u );
70     BOOST_CHECK_EQUAL( p->length(), 20u );
71     BOOST_CHECK_EQUAL( p->nextHeader(), 44u );
72     BOOST_CHECK_EQUAL( senf::INet6Address::from_data(p->source().i()), 
73                        senf::INet6Address::from_string("2001::1") );
74     BOOST_CHECK_EQUAL( senf::INet6Address::from_data(p->destination().i()),
75                        senf::INet6Address::from_string("2001::2") );
76     BOOST_CHECK( p.next().is<senf::IpV6Extension_Fragment>() );
77
78     senf::IpV6Extension_Fragment f (p.next().as<senf::IpV6Extension_Fragment>());
79
80     BOOST_CHECK_EQUAL( f->nextHeader(), 17u );
81     BOOST_CHECK_EQUAL( f->fragmentOffset(), 160u );
82     BOOST_CHECK_EQUAL( f->id(), 0x01020304u );
83     BOOST_CHECK( f.next().is<senf::UDPPacket>() );
84
85     senf::UDPPacket u (f.next().as<senf::UDPPacket>());
86
87     BOOST_CHECK_EQUAL( u->source(), 0x1000u );
88     BOOST_CHECK_EQUAL( u->destination(), 0x2000u );
89     BOOST_CHECK_EQUAL( u->length(), 12u );
90     BOOST_CHECK( u.next().is<senf::DataPacket>() );
91
92     senf::DataPacket d (u.next().as<senf::DataPacket>());
93     senf::PacketData::iterator i (u.next().data().begin());
94     BOOST_CHECK_EQUAL( d.size(), 4u );
95     BOOST_CHECK_EQUAL( d.data()[0], 0x11 );
96 }
97
98 ///////////////////////////////cc.e////////////////////////////////////////
99 #undef prefix_
100
101 \f
102 // Local Variables:
103 // mode: c++
104 // fill-column: 100
105 // c-file-style: "senf"
106 // indent-tabs-mode: nil
107 // ispell-local-dictionary: "american"
108 // compile-command: "scons -u test"
109 // comment-column: 40
110 // End: