Packets/DefaultBundle/MPLSPacket: added MPLS Ethertype to Ethernet registry
[senf.git] / Packets / DefaultBundle / MPLSPacket.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Christian Niephaus <cni@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 MPLSPacket unit tests */
25
26 //#include "MPLSPacket.test.hh"
27 //#include "MPLSPacket.test.ih"
28
29 // Custom includes
30 #include "MPLSPacket.hh"
31
32
33 #include "../../Utils/auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
35
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 BOOST_AUTO_UNIT_TEST(mplsPacket_parse)
40 {
41     senf::PacketData::byte data[] = {
42         0x00, 0x3e, 0x90, 0x80,  //1st mpls header
43         0x00, 0x3e, 0xb1, 0x80,  // last mpls header
44         0x00    //data
45     };
46     senf::MPLSPacket p (senf::MPLSPacket::create(data));
47
48     BOOST_CHECK_EQUAL( p->label(), 1001u);
49     BOOST_CHECK_EQUAL( p->tc(), 0u );
50     BOOST_CHECK( !p->s());
51     BOOST_CHECK_EQUAL( p->ttl(), 128u );
52
53     std::ostringstream oss (std::ostringstream::out);
54     SENF_CHECK_NO_THROW( p.dump( oss));
55 }
56
57 BOOST_AUTO_UNIT_TEST(mplsPacket_parse_chain)
58 {
59     senf::PacketData::byte data[] = {
60         0x00, 0x3e, 0x90, 0x80,  //1st mpls header
61         0x00, 0x3e, 0xb1, 0x80,  // last mpls header
62         0x00    //data
63     };
64
65     senf::MPLSPacket p (senf::MPLSPacket::create(data));
66
67     BOOST_REQUIRE( p.next().is<senf::MPLSPacket>() );
68     senf::MPLSPacket p2 (p.next().as<senf::MPLSPacket>());
69     BOOST_CHECK( p2->s());
70     BOOST_REQUIRE( p2.next().is<senf::DataPacket>() );
71 }
72
73 BOOST_AUTO_UNIT_TEST(mplsPacket_create)
74 {
75     senf::MPLSPacket p (senf::MPLSPacket::create());
76     p->label()=4444u;
77     p->ttl()=10u;
78     p->s()=true;
79     p->tc()=0x0u;
80
81     SENF_CHECK_NO_THROW(p.finalizeThis());
82
83 }
84
85
86 ///////////////////////////////cc.e////////////////////////////////////////
87 #undef prefix_
88
89
90 // Local Variables:
91 // mode: c++
92 // fill-column: 100
93 // c-file-style: "senf"
94 // indent-tabs-mode: nil
95 // ispell-local-dictionary: "american"
96 // compile-command: "scons -u test"
97 // comment-column: 40
98 // End: