4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Thorsten Horstmann <tho@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.
24 \brief MIHPacket unit tests */
26 //#include "MIHPacket.test.hh"
27 //#include "MIHPacket.test.ih"
29 #include "../../Utils/auto_unit_test.hh"
30 #include <boost/test/test_tools.hpp>
32 #include "MIHPacket.hh"
38 ///////////////////////////////cc.p////////////////////////////////////////
40 BOOST_AUTO_UNIT_TEST(MIHPacket_create_string)
42 MIHPacket mihPacket (MIHPacket::create());
44 mihPacket->fragmentNr() = 42;
45 mihPacket->transactionId() = 21;
46 mihPacket->src_mihfId().setString( "senf@berlios.de");
47 mihPacket->dst_mihfId().setString( "test");
48 mihPacket.finalizeThis();
50 unsigned char data[] = {
52 0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x17,
53 // source MIHF_ID TLV:
54 0x01, 0x0f, // type, length
55 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
56 0x69, 0x6f, 0x73, 0x2e, 0x64, 0x65, // value
57 // destination MIHF_ID TLV:
58 0x02, 0x04, 0x74, 0x65, 0x73, 0x74
60 BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
61 BOOST_CHECK_EQUAL( mihPacket->src_mihfId().asString(), "senf@berlios.de");
62 BOOST_CHECK_EQUAL( mihPacket->dst_mihfId().asString(), "test");
64 // now expand a MIHF_ID
65 mihPacket->dst_mihfId().maxLengthValue(253);
66 mihPacket->dst_mihfId().setString( std::string(200, 'x'));
67 mihPacket.finalizeThis();
69 BOOST_CHECK_EQUAL( mihPacket.size(), 8 + 17 + 203);
70 BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 17 + 203);
71 BOOST_CHECK_EQUAL( mihPacket->dst_mihfId().length(), 200);
72 BOOST_CHECK_EQUAL( senf::bytes(mihPacket->dst_mihfId()), 203);
76 BOOST_AUTO_UNIT_TEST(MIHPacket_create_mac)
78 MIHPacket mihPacket (MIHPacket::create());
80 mihPacket->fragmentNr() = 42;
81 mihPacket->transactionId() = 21;
82 mihPacket->src_mihfId().setMACAddress( MACAddress::from_string("01:02:03:04:05:06"));
83 mihPacket->dst_mihfId().setMACAddress( MACAddress::from_string("07:08:09:0a:0b:0c"));
84 mihPacket.finalizeThis();
86 unsigned char data[] = {
88 0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x1c,
89 // source MIHF_ID TLV:
90 0x01, 0x0c, // type, length
91 0x5c, 0x01, 0x5c, 0x02, 0x5c, 0x03, 0x5c, 0x04, 0x5c, 0x05, 0x5c, 0x06, // value (nai-encoded)
92 // destination MIHF_ID TLV:
93 0x02, 0x0c, // type, length
94 0x5c, 0x07, 0x5c, 0x08, 0x5c, 0x09, 0x5c, 0x0a, 0x5c, 0x0b, 0x5c, 0x0c // value (nai-encoded)
96 BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
98 mihPacket->src_mihfId().asMACAddress(),
99 MACAddress::from_string("01:02:03:04:05:06"));
101 mihPacket->dst_mihfId().asMACAddress(),
102 MACAddress::from_string("07:08:09:0a:0b:0c"));
106 BOOST_AUTO_UNIT_TEST(MIHPacket_create_inet4)
108 MIHPacket mihPacket (MIHPacket::create());
110 mihPacket->fragmentNr() = 42;
111 mihPacket->transactionId() = 21;
112 mihPacket->src_mihfId().setINet4Address( INet4Address::from_string("128.129.130.131"));
113 mihPacket->dst_mihfId().setINet4Address( INet4Address::from_string("132.133.134.135"));
114 mihPacket.finalizeThis();
116 unsigned char data[] = {
118 0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x14,
119 // source MIHF_ID TLV:
120 0x01, 0x08, // type, length
121 0x5c, 0x80, 0x5c, 0x81, 0x5c, 0x82, 0x5c, 0x83, // value (nai-encoded)
122 // destination MIHF_ID TLV:
123 0x02, 0x08, // type, length
124 0x5c, 0x84, 0x5c, 0x85, 0x5c, 0x86, 0x5c, 0x87 // value (nai-encoded)
126 BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
128 mihPacket->src_mihfId().asINet4Address(),
129 INet4Address::from_string("128.129.130.131"));
131 mihPacket->dst_mihfId().asINet4Address(),
132 INet4Address::from_string("132.133.134.135"));
136 BOOST_AUTO_UNIT_TEST(MIHPacket_create_inet6)
138 MIHPacket mihPacket (MIHPacket::create());
140 mihPacket->fragmentNr() = 42;
141 mihPacket->transactionId() = 21;
142 mihPacket->src_mihfId().setINet6Address( INet6Address::from_string("::ffff:1.2.3.4"));
143 mihPacket->dst_mihfId().setINet6Address( INet6Address::from_string("::ffff:5.6.7.8"));
144 mihPacket.finalizeThis();
146 unsigned char data[] = {
148 0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x44,
149 // source MIHF_ID TLV:
150 0x01, 0x20, // type, length
151 // value (nai-encoded):
152 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00,
153 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00,
154 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0xff, 0x5c, 0xff,
155 0x5c, 0x01, 0x5c, 0x02, 0x5c, 0x03, 0x5c, 0x04,
156 // destination MIHF_ID TLV:
157 0x02, 0x20, // type, length
158 // value (nai-encoded):
159 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00,
160 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00,
161 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0xff, 0x5c, 0xff,
162 0x5c, 0x05, 0x5c, 0x06, 0x5c, 0x07, 0x5c, 0x08
164 BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
166 mihPacket->src_mihfId().asINet6Address(),
167 INet6Address::from_string("::ffff:1.2.3.4"));
169 mihPacket->dst_mihfId().asINet6Address(),
170 INet6Address::from_string("::ffff:5.6.7.8") );
173 ///////////////////////////////cc.e////////////////////////////////////////
180 // c-file-style: "senf"
181 // indent-tabs-mode: nil
182 // ispell-local-dictionary: "american"
183 // compile-command: "scons -u test"
184 // comment-column: 40