NEW FILE HEADER / COPYRIGHT FORMAT
[senf.git] / Packets / MPEGDVBBundle / MPESection.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 //     Thorsten Horstmann <tho@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 // Unit tests
24
25 //#include "MPESection.test.hh"
26 //#include "MPESection.test.ih"
27
28 // Custom includes
29 #include "MPESection.hh"
30
31 #include "../../Utils/auto_unit_test.hh"
32 #include "../../Packets/DefaultBundle/LlcSnapPacket.hh"
33 #include "../../Packets/DefaultBundle/EthernetPacket.hh"
34 #include "../../Packets/DefaultBundle/IPv4Packet.hh"
35 #include <boost/test/test_tools.hpp>
36 #include <senf/Utils/hexdump.hh>
37
38 #define prefix_
39 ///////////////////////////////cc.p////////////////////////////////////////
40
41 using namespace senf;
42
43 BOOST_AUTO_UNIT_TEST(MPESection_parse_chain)
44 {
45     // MPE section captured with dvbsnoop
46     unsigned char data[] = { 
47             // MPE Header
48             0x3e, 0xb0, 0x77, 0x00, 0x00, 0xc3, 0x00, 0x00,
49             0x04, 0xd8, 0x12, 0x0c,
50             // LLC/SNAP Header
51             0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x00, 0x62,
52             // Ethernet Header
53             0x01, 0x00, 0x5e, 0x01, 0x02, 0x03, 0x12, 0xb0,
54             0x43, 0x61, 0x5d, 0x99, 0x08, 0x00, 
55             // IPv4 Header
56             0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
57             0x01, 0x01, 0xc6, 0xfb, 0xc0, 0xa8, 0x01, 0x01,
58             0xef, 0x01, 0x02, 0x03, 
59             // Payload (ICMP)
60             0x08, 0x00, 0x0e, 0xa3, 0xf2, 0x72, 0x55, 0xea, 
61             0xa2, 0xae, 0x56, 0x47, 0xbb, 0x06, 0x02, 0x00, 
62             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
63             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
64             0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 
65             0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 
66             0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 
67             0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
68             // MPE Trailer (crc)
69             0xb5, 0x77, 0x4c, 0x3c
70     };
71             
72     senf::MPESection sec (senf::MPESection::create(data));
73     
74     BOOST_CHECK_EQUAL(   sec->table_id(),                0x3eu       );
75     BOOST_CHECK(         sec->section_syntax_indicator()             );
76     BOOST_CHECK(       ! sec->private_indicator()                    );
77     BOOST_CHECK_EQUAL(   sec->section_length(),          0x77u       );
78     BOOST_CHECK_EQUAL(   sec->mac_addr_6(),              0x0u        );
79     BOOST_CHECK_EQUAL(   sec->mac_addr_5(),              0x0u        );
80     BOOST_CHECK_EQUAL(   sec->payload_scrmbl_ctrl(),     0x0u        );
81     BOOST_CHECK_EQUAL(   sec->addr_scrmbl_ctrl(),        0x0u        );
82     BOOST_CHECK      (   sec->llc_snap_flag()                        );
83     BOOST_CHECK      (   sec->curr_next_indicator()                  );
84     BOOST_CHECK_EQUAL(   sec->section_num(),             0x0u        );
85     BOOST_CHECK_EQUAL(   sec->last_section_num(),        0x0u        );
86     BOOST_CHECK_EQUAL(   sec->real_time_parameters().delta_t(),        0x4du   );
87     BOOST_CHECK_EQUAL(   sec->real_time_parameters().table_boundary(), 1       );
88     BOOST_CHECK_EQUAL(   sec->real_time_parameters().frame_boundary(), 0       );
89     BOOST_CHECK_EQUAL(   sec->real_time_parameters().address(),        0x120cu );
90     BOOST_CHECK_EQUAL(   sec->crc(), 3044494396u                     );
91     
92     BOOST_REQUIRE( sec.next().is<senf::LlcSnapPacket>() );
93     senf::LlcSnapPacket llcsnap (sec.next().as<senf::LlcSnapPacket>());
94
95     BOOST_CHECK_EQUAL( llcsnap->dsap(), 0xaau        );
96     BOOST_CHECK_EQUAL( llcsnap->ssap(), 0xaau        );
97     BOOST_CHECK_EQUAL( llcsnap->ctrl(), 0x3u         );
98     BOOST_CHECK_EQUAL( llcsnap->protocolId(), 0u     );
99     BOOST_CHECK_EQUAL( llcsnap->type_length(), 0x62u );
100
101     BOOST_REQUIRE( llcsnap.next().is<senf::EthernetPacket>() );
102     senf::EthernetPacket eth (llcsnap.next().as<senf::EthernetPacket>());
103     
104     BOOST_CHECK_EQUAL( eth->destination().value(), senf::MACAddress::from_string("01:00:5e:01:02:03") );
105     BOOST_CHECK_EQUAL( eth->source().value(),      senf::MACAddress::from_string("12:b0:43:61:5d:99") );
106     BOOST_CHECK_EQUAL( eth->type_length(),         0x800u                                             );
107
108     BOOST_REQUIRE( eth.next().is<senf::IPv4Packet>() );
109     senf::IPv4Packet ip (eth.next().as<senf::IPv4Packet>());
110     
111     BOOST_CHECK_EQUAL( ip->version(),    0x4u   );
112     BOOST_CHECK_EQUAL( ip->ihl(),        0x5u   );
113     BOOST_CHECK_EQUAL( ip->tos(),        0x0u   );
114     BOOST_CHECK_EQUAL( ip->length(),     0x54u  );
115     BOOST_CHECK_EQUAL( ip->identifier(), 0x0u   );
116     BOOST_CHECK_EQUAL( ip->df(),         1      );
117     BOOST_CHECK_EQUAL( ip->mf(),         0      );
118     BOOST_CHECK_EQUAL( ip->frag(),       0x0u   );
119     BOOST_CHECK_EQUAL( ip->ttl(),        1      );
120     BOOST_CHECK_EQUAL( ip->protocol(),   1      );
121     BOOST_CHECK_EQUAL( ip->checksum(),   0xc6fb );
122     BOOST_CHECK_EQUAL( ip->source().value(),      senf::INet4Address::from_string("192.168.1.1") );
123     BOOST_CHECK_EQUAL( ip->destination().value(), senf::INet4Address::from_string("239.1.2.3")   );
124 }
125
126
127 BOOST_AUTO_UNIT_TEST(MPESection_create)
128 {
129     senf::MPESection sec (senf::MPESection::create());
130     sec->real_time_parameters().delta_t()        = 0x4du;
131     sec->real_time_parameters().table_boundary() = 1;
132     sec->real_time_parameters().frame_boundary() = 0;
133     sec->real_time_parameters().address()        = 0x120cu;
134     
135     senf::LlcSnapPacket llcsnap (senf::LlcSnapPacket::createAfter(sec));
136     
137     senf::EthernetPacket eth (senf::EthernetPacket::createAfter(llcsnap));
138     eth->destination() = senf::MACAddress::from_string("01:00:5e:01:02:03");
139     eth->source()      = senf::MACAddress::from_string("12:b0:43:61:5d:99");
140     
141     senf::IPv4Packet ip (senf::IPv4Packet::createAfter(eth));
142     ip->df()          = 1;
143     ip->ttl()         = 1;
144     ip->protocol()    = 1;
145     ip->source()      = senf::INet4Address::from_string("192.168.1.1");
146     ip->destination() = senf::INet4Address::from_string("239.1.2.3");
147     
148     unsigned char payload_data[] = { 
149             // Payload (ICMP)
150             0x08, 0x00, 0x0e, 0xa3, 0xf2, 0x72, 0x55, 0xea, 
151             0xa2, 0xae, 0x56, 0x47, 0xbb, 0x06, 0x02, 0x00, 
152             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
153             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
154             0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 
155             0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 
156             0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 
157             0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
158     };
159     senf::DataPacket payload (senf::DataPacket::createAfter(ip, payload_data));
160     
161     sec.finalize();
162 }
163
164 ///////////////////////////////cc.e////////////////////////////////////////
165 #undef prefix_
166
167 \f
168 // Local Variables:
169 // mode: c++
170 // fill-column: 100
171 // c-file-style: "senf"
172 // indent-tabs-mode: nil
173 // ispell-local-dictionary: "american"
174 // compile-command: "scons -u test"
175 // comment-column: 40
176 // End: