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 // Thorsten Horstmann <tho@berlios.de>
29 \brief MPESection unit tests */
31 //#include "MPESection.test.hh"
32 //#include "MPESection.test.ih"
35 #include "MPESection.hh"
36 #include <senf/Packets/DefaultBundle/LlcSnapPacket.hh>
37 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
38 #include <senf/Packets/DefaultBundle/IPv4Packet.hh>
40 #include <senf/Utils/auto_unit_test.hh>
41 #include <boost/test/test_tools.hpp>
44 //-/////////////////////////////////////////////////////////////////////////////////////////////////
48 SENF_AUTO_UNIT_TEST(MPESection_parse_chain)
50 // MPE section captured with dvbsnoop
51 unsigned char data[] = {
53 0x3e, 0xb0, 0x77, 0x00, 0x00, 0xc3, 0x00, 0x00,
54 0x04, 0xd8, 0x12, 0x0c,
56 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x00, 0x62,
58 0x01, 0x00, 0x5e, 0x01, 0x02, 0x03, 0x12, 0xb0,
59 0x43, 0x61, 0x5d, 0x99, 0x08, 0x00,
61 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
62 0x01, 0x01, 0xc6, 0xfb, 0xc0, 0xa8, 0x01, 0x01,
63 0xef, 0x01, 0x02, 0x03,
65 0x08, 0x00, 0x0e, 0xa3, 0xf2, 0x72, 0x55, 0xea,
66 0xa2, 0xae, 0x56, 0x47, 0xbb, 0x06, 0x02, 0x00,
67 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
68 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
69 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
70 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
71 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
72 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
74 0xb5, 0x77, 0x4c, 0x3c
77 senf::MPESection sec (senf::MPESection::create(data));
79 BOOST_CHECK_EQUAL( sec->table_id(), 0x3eu );
80 BOOST_CHECK( sec->section_syntax_indicator() );
81 BOOST_CHECK( ! sec->private_indicator() );
82 BOOST_CHECK_EQUAL( sec->section_length(), 0x77u );
83 BOOST_CHECK_EQUAL( sec->mac_addr_6(), 0x0u );
84 BOOST_CHECK_EQUAL( sec->mac_addr_5(), 0x0u );
85 BOOST_CHECK_EQUAL( sec->payload_scrmbl_ctrl(), 0x0u );
86 BOOST_CHECK_EQUAL( sec->addr_scrmbl_ctrl(), 0x0u );
87 BOOST_CHECK ( sec->llc_snap_flag() );
88 BOOST_CHECK ( sec->curr_next_indicator() );
89 BOOST_CHECK_EQUAL( sec->section_num(), 0x0u );
90 BOOST_CHECK_EQUAL( sec->last_section_num(), 0x0u );
91 BOOST_CHECK_EQUAL( sec->real_time_parameters().delta_t(), 0x04du );
92 BOOST_CHECK_EQUAL( sec->real_time_parameters().table_boundary(), 1 );
93 BOOST_CHECK_EQUAL( sec->real_time_parameters().frame_boundary(), 0 );
94 BOOST_CHECK_EQUAL( sec->real_time_parameters().address(), 0x120cu );
95 BOOST_CHECK_EQUAL( sec->crc(), 3044494396u );
96 BOOST_CHECK_EQUAL( sec->crc(), sec->calcCrc() );
98 std::ostringstream oss (std::ostringstream::out);
99 SENF_CHECK_NO_THROW( sec.dump( oss));
101 BOOST_REQUIRE( sec.next().is<senf::LlcSnapPacket>() );
102 senf::LlcSnapPacket llcsnap (sec.next().as<senf::LlcSnapPacket>());
104 BOOST_CHECK_EQUAL( llcsnap->dsap(), 0xaau );
105 BOOST_CHECK_EQUAL( llcsnap->ssap(), 0xaau );
106 BOOST_CHECK_EQUAL( llcsnap->ctrl(), 0x3u );
107 BOOST_CHECK_EQUAL( llcsnap->protocolId(), 0x0u );
108 // in the captured section the llcsnap type/length field was set to the
109 // length of the following ethernet packet; the ethertype 0x6558 (Trans
110 // Ether Bridging [RFC1701]) would be possible as well (see next test)
111 BOOST_CHECK_EQUAL( llcsnap->type_length(), 0x62u );
113 BOOST_REQUIRE( llcsnap.next().is<senf::EthernetPacket>() );
114 senf::EthernetPacket eth (llcsnap.next().as<senf::EthernetPacket>());
116 BOOST_CHECK_EQUAL( eth->destination().value(), senf::MACAddress::from_string("01:00:5e:01:02:03") );
117 BOOST_CHECK_EQUAL( eth->source().value(), senf::MACAddress::from_string("12:b0:43:61:5d:99") );
118 BOOST_CHECK_EQUAL( eth->type_length(), 0x800u );
120 BOOST_REQUIRE( eth.next().is<senf::IPv4Packet>() );
121 senf::IPv4Packet ip (eth.next().as<senf::IPv4Packet>());
123 BOOST_CHECK_EQUAL( ip->version(), 0x4u );
124 BOOST_CHECK_EQUAL( ip->ihl(), 0x5u );
125 BOOST_CHECK_EQUAL( ip->tos(), 0x0u );
126 BOOST_CHECK_EQUAL( ip->length(), 0x54u );
127 BOOST_CHECK_EQUAL( ip->identifier(), 0x0u );
128 BOOST_CHECK_EQUAL( ip->df(), 1 );
129 BOOST_CHECK_EQUAL( ip->mf(), 0 );
130 BOOST_CHECK_EQUAL( ip->frag(), 0x0u );
131 BOOST_CHECK_EQUAL( ip->ttl(), 1 );
132 BOOST_CHECK_EQUAL( ip->protocol(), 1 );
133 BOOST_CHECK_EQUAL( ip->checksum(), 0xc6fb );
134 BOOST_CHECK_EQUAL( ip->source().value(), senf::INet4Address::from_string("192.168.1.1") );
135 BOOST_CHECK_EQUAL( ip->destination().value(), senf::INet4Address::from_string("239.1.2.3") );
139 SENF_AUTO_UNIT_TEST(MPESection_create)
141 senf::MPESection sec (senf::MPESection::create());
142 sec->real_time_parameters().delta_t() = 0x027u;
143 sec->real_time_parameters().table_boundary() = 1;
144 sec->real_time_parameters().frame_boundary() = 0;
145 sec->real_time_parameters().address() = 0xfffffu;
147 // the type/length field will be set to the ethertype 0x6558 (Trans
148 // Ether Bridging [RFC1701]) on finalize()
149 senf::LlcSnapPacket llcsnap (senf::LlcSnapPacket::createAfter(sec));
151 senf::EthernetPacket eth (senf::EthernetPacket::createAfter(llcsnap));
152 eth->destination() = senf::MACAddress::from_string("01:00:5e:01:02:03");
153 eth->source() = senf::MACAddress::from_string("92:4c:a2:1c:da:81");
155 senf::IPv4Packet ip (senf::IPv4Packet::createAfter(eth));
159 ip->source() = senf::INet4Address::from_string("10.1.2.2");
160 ip->destination() = senf::INet4Address::from_string("239.1.2.3");
162 unsigned char payload_data[] = {
164 0x08, 0x00, 0x52, 0x73, 0x0e, 0x02, 0x00, 0x20,
165 0xa4, 0x3a, 0xb4, 0x47, 0x4f, 0xe5, 0x04, 0x00,
166 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
167 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
168 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
169 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
170 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
171 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
173 senf::DataPacket payload (senf::DataPacket::createAfter(ip, payload_data));
177 unsigned char sec_data[] = {
178 0x3e, 0xb0, 0x77, 0x00, 0x00, 0xc3, 0x00, 0x00,
179 0x02, 0x7b, 0xff, 0xff, 0xaa, 0xaa, 0x03, 0x00,
180 0x00, 0x00, 0x65, 0x58, 0x01, 0x00, 0x5e, 0x01,
181 0x02, 0x03, 0x92, 0x4c, 0xa2, 0x1c, 0xda, 0x81,
182 0x08, 0x00, 0x45, 0x00, 0x00, 0x54, 0x00, 0x00,
183 0x40, 0x00, 0x01, 0x01, 0x7c, 0xa2, 0x0a, 0x01,
184 0x02, 0x02, 0xef, 0x01, 0x02, 0x03, 0x08, 0x00,
185 0x52, 0x73, 0x0e, 0x02, 0x00, 0x20, 0xa4, 0x3a,
186 0xb4, 0x47, 0x4f, 0xe5, 0x04, 0x00, 0x08, 0x09,
187 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
188 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
189 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
190 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,
191 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
192 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x52, 0xdf,
195 SENF_CHECK_EQUAL_COLLECTIONS(
196 sec_data, sec_data+sizeof(sec_data), sec.data().begin(), sec.data().end() );
199 //-/////////////////////////////////////////////////////////////////////////////////////////////////
206 // c-file-style: "senf"
207 // indent-tabs-mode: nil
208 // ispell-local-dictionary: "american"
209 // compile-command: "scons -u test"
210 // comment-column: 40