4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
25 //#include "EthernetPacket.test.hh"
26 //#include "EthernetPacket.test.ih"
29 #include "EthernetPacket.hh"
30 #include "LlcSnapPacket.hh"
31 #include "IPv4Packet.hh"
33 #include "../../Utils/auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
39 BOOST_AUTO_UNIT_TEST(ethernetPacket_parse)
41 senf::PacketData::byte data[] = {
42 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // destination MAC
43 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, // source MAC
46 senf::EthernetPacket p (senf::EthernetPacket::create(data));
48 BOOST_CHECK_EQUAL( p->destination()[3], 0x04 );
49 BOOST_CHECK_EQUAL( p->source()[0], 0x07 );
50 BOOST_CHECK_EQUAL( p->type_length(), 0x1011 );
52 std::ostringstream oss (std::ostringstream::out);
53 SENF_CHECK_NO_THROW( p.dump( oss));
56 BOOST_AUTO_UNIT_TEST(ethernetPacket_parse_chain)
58 unsigned char data[] = {
59 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // destination MAC
60 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, // source MAC
61 0x81, 0x00, // EtherType: VLan
62 0x92, 0x34, // VLAN prio, cfi, id
63 0xab, 0xcd, // EtherType
64 0xf0, 0xf1, 0xf2, 0xf3, 0xf4
66 senf::EthernetPacket p (senf::EthernetPacket::create(data));
68 BOOST_REQUIRE( p.next().is<senf::EthVLanPacket>() );
69 senf::EthVLanPacket v (p.next().as<senf::EthVLanPacket>());
70 BOOST_CHECK_EQUAL( v->priority(), 4u );
71 BOOST_CHECK( v->cfi() );
72 BOOST_CHECK_EQUAL( v->vlanId(), 0x234u );
73 BOOST_CHECK_EQUAL( v->type(), 0xabcd );
74 BOOST_CHECK( v.next().is<senf::DataPacket>() );
75 BOOST_CHECK_EQUAL( *v.next().data().begin(), 0xf0 );
78 BOOST_AUTO_UNIT_TEST(ethernetPacket_create)
80 senf::EthernetPacket eth (senf::EthernetPacket::create());
81 eth->source() = senf::MACAddress::from_string("01:02:03:04:05:06");
82 eth->destination() = senf::MACAddress::from_string("07:08:09:0a:0b:0c");
84 senf::EthVLanPacket vlan (senf::EthVLanPacket::createAfter(eth));
85 vlan->priority() = 9u;
87 vlan->vlanId() = 0x234u;
90 BOOST_CHECK_EQUAL(eth->type_length(), 0x8100u);
91 BOOST_CHECK_EQUAL(vlan->type(), 0u);
93 senf::IPv4Packet ip (senf::IPv4Packet::createAfter(vlan));
95 BOOST_CHECK_EQUAL(vlan->type(), 0x0800u);
98 BOOST_AUTO_UNIT_TEST(ethernetPacket_llcsnap)
100 senf::EthernetPacket eth (senf::EthernetPacket::create());
101 eth->source() = senf::MACAddress::from_string("01:02:03:04:05:06");
102 eth->destination() = senf::MACAddress::from_string("07:08:09:0a:0b:0c");
104 senf::LlcSnapPacket llcsnap (senf::LlcSnapPacket::createAfter(eth));
105 senf::DataPacket payload (senf::DataPacket::createAfter(
106 llcsnap, std::string("Hello, world!")));
109 BOOST_CHECK_EQUAL( eth->type_length(), 8u + 13u);
110 BOOST_CHECK_EQUAL( llcsnap->dsap(), 0xaa );
111 BOOST_CHECK_EQUAL( llcsnap->ssap(), 0xaa );
112 BOOST_CHECK_EQUAL( llcsnap->ctrl(), 0x03 );
113 BOOST_CHECK_EQUAL( llcsnap->protocolId(), 0x000000u );
114 BOOST_CHECK_EQUAL( llcsnap->type_length(), 0u);
116 senf::IPv4Packet ip (senf::IPv4Packet::createAfter(llcsnap));
118 BOOST_CHECK_EQUAL(llcsnap->type_length(), 0x0800u);
121 ///////////////////////////////cc.e////////////////////////////////////////
128 // c-file-style: "senf"
129 // indent-tabs-mode: nil
130 // ispell-local-dictionary: "american"
131 // compile-command: "scons -u test"
132 // comment-column: 40