Fix Build-Depends in debian/control
[senf.git] / Packets / DefaultBundle / IPv6Extensions.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 IPv6Extensions unit tests */
25
26 //#include "IPv6Extensions.test.hh"
27 //#include "IPv6Extensions.test.ih"
28
29 // Custom includes
30 #include "IPv6Extensions.hh"
31 #include "IPv6Packet.hh"
32 #include "UDPPacket.hh"
33
34 #include "../../Utils/auto_unit_test.hh"
35 #include <boost/test/test_tools.hpp>
36
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 BOOST_AUTO_UNIT_TEST(ipv6Extension_Fragment_packet)
41 {
42     // Just for the fun of it, we test a nice chain: A fragment of a fragmented UDP packet
43
44     unsigned char data[] = {
45         // IP header
46         0x60, 0x00, 0x00, 0x00,         // IP Version, class, flow label
47         0, 20,                          // payload length
48         44,                             // next header (IPv6 Fragment)
49         32,                             // hop limit
50         0x20, 0x01, 0, 0, 0, 0, 0, 0,   // source ip = 2001::1
51            0, 0, 0, 0, 0, 0, 0, 0x01,
52         0x20, 0x01, 0, 0, 0, 0, 0, 0,   // destination ip = 2001::2
53            0, 0, 0, 0, 0, 0, 0, 0x02,
54         // IPv6 Fragment header
55         17,                             // next header (UDP)
56         0,                              // reserved
57         0x05, 0x00,                     // fragment offset, last fragment
58         0x01, 0x02, 0x03, 0x04,         // id
59         // UDP header
60         0x10, 0x00,                     // source port
61         0x20, 0x00,                     // destination port
62         0, 12,                          // length
63         0x00, 0x00,                     // CRC (no, I won't calculate this one ...)
64         // Payload data
65         0x11, 0x12, 0x13, 0x14
66     };
67
68     senf::IPv6Packet p (senf::IPv6Packet::create(data));
69
70     BOOST_CHECK_EQUAL( p->version(), 6u );
71     BOOST_CHECK_EQUAL( p->length(), 20u );
72     BOOST_CHECK_EQUAL( p->nextHeader(), 44u );
73     BOOST_CHECK_EQUAL( p->source().value(), senf::INet6Address::from_string("2001::1") );
74     BOOST_CHECK_EQUAL( p->destination().value(), senf::INet6Address::from_string("2001::2") );
75
76     std::ostringstream oss (std::ostringstream::out);
77     SENF_CHECK_NO_THROW( p.dump( oss));
78
79     BOOST_CHECK( p.next().is<senf::IPv6Extension_Fragment>() );
80
81     senf::IPv6Extension_Fragment f (p.next().as<senf::IPv6Extension_Fragment>());
82
83     BOOST_CHECK_EQUAL( f->nextHeader(), 17u );
84     BOOST_CHECK_EQUAL( f->fragmentOffset(), 160u );
85     BOOST_CHECK_EQUAL( f->id(), 0x01020304u );
86     BOOST_CHECK( f.next().is<senf::UDPPacket>() );
87
88     senf::UDPPacket u (f.next().as<senf::UDPPacket>());
89
90     BOOST_CHECK_EQUAL( u->source(), 0x1000u );
91     BOOST_CHECK_EQUAL( u->destination(), 0x2000u );
92     BOOST_CHECK_EQUAL( u->length(), 12u );
93     BOOST_CHECK( u.next().is<senf::DataPacket>() );
94
95     senf::DataPacket d (u.next().as<senf::DataPacket>());
96     senf::PacketData::iterator i (u.next().data().begin());
97     BOOST_CHECK_EQUAL( d.size(), 4u );
98     BOOST_CHECK_EQUAL( d.data()[0], 0x11 );
99 }
100
101 ///////////////////////////////cc.e////////////////////////////////////////
102 #undef prefix_
103
104
105 // Local Variables:
106 // mode: c++
107 // fill-column: 100
108 // c-file-style: "senf"
109 // indent-tabs-mode: nil
110 // ispell-local-dictionary: "american"
111 // compile-command: "scons -u test"
112 // comment-column: 40
113 // End: