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 IPv4Packet unit tests */
31 //#include "IPv4Packet.test.hh"
32 //#include "IPv4Packet.test.ih"
35 #include "IPv4Packet.hh"
36 #include "UDPPacket.hh"
38 #include <senf/Utils/auto_unit_test.hh>
39 #include <boost/test/test_tools.hpp>
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46 SENF_AUTO_UNIT_TEST(ipV4Packet_parse)
48 unsigned char data[] = {
49 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
50 0x09, 0x0A, 0x0B, 0x0C, 0x11, 0x12, 0x13, 0x14,
51 0x15, 0x16, 0x17, 0x18
54 senf::IPv4Packet p (senf::IPv4Packet::create(data));
56 BOOST_CHECK_EQUAL( p->version(), 0x00u );
57 BOOST_CHECK_EQUAL( p->ihl(), 0x01u );
58 BOOST_CHECK_EQUAL( p->tos(), 0x02u );
59 BOOST_CHECK_EQUAL( p->length(), 0x0304u );
60 BOOST_CHECK_EQUAL( p->identifier(), 0x0506u );
61 BOOST_CHECK_EQUAL( p->df(), 0 );
62 BOOST_CHECK_EQUAL( p->mf(), 0 );
63 BOOST_CHECK_EQUAL( p->frag(), 0x0708u );
64 BOOST_CHECK_EQUAL( p->ttl(), 0x09u );
65 BOOST_CHECK_EQUAL( p->protocol(), 0x0Au );
66 BOOST_CHECK_EQUAL( p->checksum(), 0x0B0Cu );
67 BOOST_CHECK_EQUAL( p->source().value(), senf::INet4Address(0x11121314u) );
68 BOOST_CHECK_EQUAL( p->destination().value(), senf::INet4Address(0x15161718u) );
70 std::ostringstream oss (std::ostringstream::out);
71 SENF_CHECK_NO_THROW( p.dump( oss));
74 SENF_AUTO_UNIT_TEST(ipV4Packet_create)
76 senf::IPv4Packet ip (senf::IPv4Packet::create());
78 BOOST_CHECK_EQUAL( ip->version(), 4u );
79 BOOST_CHECK_EQUAL( ip->ihl(), 5u );
80 BOOST_CHECK_EQUAL( ip.size(), 20u );
82 senf::UDPPacket udp (senf::UDPPacket::createAfter(ip));
84 BOOST_CHECK( ! ip->validateChecksum() );
87 BOOST_CHECK_EQUAL( ip->length(), 28u );
88 BOOST_CHECK_EQUAL( ip->protocol(), 17u );
89 BOOST_CHECK_EQUAL( ip->checksum(), 0xbad2 );
91 // Check, that the checksum field is correctly skipped
93 BOOST_CHECK_EQUAL( ip->checksum(), 0xbad2 );
95 BOOST_CHECK( ip->validateChecksum() );
98 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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