Packets/DefaultBundle/MPSPacket: updated finalize method, enhanced unit test
[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 #include "EthernetPacket.hh"
32
33
34 #include "../../Utils/auto_unit_test.hh"
35 #include <boost/test/test_tools.hpp>
36
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 BOOST_AUTO_UNIT_TEST(mplsPacket_parse)
41 {
42     senf::PacketData::byte data[] = {
43         0x00, 0x3e, 0x90, 0x80,  //1st mpls header
44         0x00, 0x3e, 0xb1, 0x80,  // last mpls header
45         0x00    //data
46     };
47     senf::MPLSPacket p (senf::MPLSPacket::create(data));
48
49     BOOST_CHECK_EQUAL( p->label(), 1001u);
50     BOOST_CHECK_EQUAL( p->tc(), 0u );
51     BOOST_CHECK( !p->s());
52     BOOST_CHECK_EQUAL( p->ttl(), 128u );
53
54     std::ostringstream oss (std::ostringstream::out);
55     SENF_CHECK_NO_THROW( p.dump( oss));
56 }
57
58 BOOST_AUTO_UNIT_TEST(mplsPacket_parse_chain)
59 {
60     senf::PacketData::byte data[] = {
61         0x00, 0x3e, 0x90, 0x80,  //1st mpls header
62         0x00, 0x3e, 0xb1, 0x80,  // last mpls header
63         0x00    //data
64     };
65
66     senf::MPLSPacket p (senf::MPLSPacket::create(data));
67
68     BOOST_REQUIRE( p.next().is<senf::MPLSPacket>() );
69     senf::MPLSPacket p2 (p.next().as<senf::MPLSPacket>());
70     BOOST_CHECK( p2->s());
71     BOOST_REQUIRE( p2.next().is<senf::DataPacket>() );
72 }
73
74 BOOST_AUTO_UNIT_TEST(mplsPacket_create)
75 {
76     senf::EthernetPacket eth (senf::EthernetPacket::create());
77     eth->source() = senf::MACAddress::from_string("01:02:03:04:05:06");
78     eth->destination() = senf::MACAddress::from_string("07:08:09:0a:0b:0c");
79
80     senf::MPLSPacket p (senf::MPLSPacket::createAfter(eth));
81     p->label()=4444u;
82     p->ttl()=10u;
83     p->tc()=0x0u;
84
85     senf::MPLSPacket p2 (senf::MPLSPacket::createAfter(p));
86     p->label()=5555u;
87     p->ttl()=10u;
88     p->tc()=0x0u;
89
90     SENF_CHECK_NO_THROW(eth.finalizeAll());
91
92     BOOST_REQUIRE( eth.next().is<senf::MPLSPacket>() );
93     BOOST_REQUIRE( p.next().is<senf::MPLSPacket>() );
94     BOOST_CHECK( p->s());
95     BOOST_CHECK( !p2->s());
96
97 }
98
99
100 ///////////////////////////////cc.e////////////////////////////////////////
101 #undef prefix_
102
103
104 // Local Variables:
105 // mode: c++
106 // fill-column: 100
107 // c-file-style: "senf"
108 // indent-tabs-mode: nil
109 // ispell-local-dictionary: "american"
110 // compile-command: "scons -u test"
111 // comment-column: 40
112 // End: