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"
37 ///////////////////////////////cc.p////////////////////////////////////////
39 BOOST_AUTO_UNIT_TEST(MIHPacket_create_string)
41 MIHPacket mihPacket (MIHPacket::create());
43 mihPacket->fragmentNr() = 42;
44 mihPacket->transactionId() = 21;
45 mihPacket->src_mihfId().setString( "senf@berlios.de");
46 mihPacket->dst_mihfId().setString( "test");
47 mihPacket.finalizeThis();
49 unsigned char data[] = {
51 0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x17,
52 // source MIHF_ID TLV:
53 0x01, 0x0f, // type, length
54 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
55 0x69, 0x6f, 0x73, 0x2e, 0x64, 0x65, // value
56 // destination MIHF_ID TLV:
57 0x02, 0x04, 0x74, 0x65, 0x73, 0x74
59 BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
60 BOOST_CHECK_EQUAL( mihPacket->src_mihfId().asString(), "senf@berlios.de");
61 BOOST_CHECK_EQUAL( mihPacket->dst_mihfId().asString(), "test");
63 // now expand a MIHF_ID
64 mihPacket->dst_mihfId().maxLengthValue(253);
65 mihPacket->dst_mihfId().setString( std::string(200, 'x'));
66 mihPacket.finalizeThis();
68 BOOST_CHECK_EQUAL( mihPacket.size(), unsigned(8 + 17 + 203));
69 BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 17 + 203);
70 BOOST_CHECK_EQUAL( mihPacket->dst_mihfId().length(), 200u);
71 BOOST_CHECK_EQUAL( senf::bytes(mihPacket->dst_mihfId()), 203u);
73 std::ostringstream oss (std::ostringstream::out);
74 SENF_CHECK_NO_THROW( mihPacket.dump( oss));
78 BOOST_AUTO_UNIT_TEST(MIHPacket_create_mac)
80 MIHPacket mihPacket (MIHPacket::create());
82 mihPacket->fragmentNr() = 42;
83 mihPacket->transactionId() = 21;
84 mihPacket->src_mihfId().setMACAddress( MACAddress::from_string("01:02:03:04:05:06"));
85 mihPacket->dst_mihfId().setMACAddress( MACAddress::from_string("07:08:09:0a:0b:0c"));
86 mihPacket.finalizeThis();
88 unsigned char data[] = {
90 0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x1c,
91 // source MIHF_ID TLV:
92 0x01, 0x0c, // type, length
93 0x5c, 0x01, 0x5c, 0x02, 0x5c, 0x03, 0x5c, 0x04, 0x5c, 0x05, 0x5c, 0x06, // value (nai-encoded)
94 // destination MIHF_ID TLV:
95 0x02, 0x0c, // type, length
96 0x5c, 0x07, 0x5c, 0x08, 0x5c, 0x09, 0x5c, 0x0a, 0x5c, 0x0b, 0x5c, 0x0c // value (nai-encoded)
98 BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
100 mihPacket->src_mihfId().asMACAddress(),
101 MACAddress::from_string("01:02:03:04:05:06"));
103 mihPacket->dst_mihfId().asMACAddress(),
104 MACAddress::from_string("07:08:09:0a:0b:0c"));
108 BOOST_AUTO_UNIT_TEST(MIHPacket_create_inet4)
110 MIHPacket mihPacket (MIHPacket::create());
112 mihPacket->fragmentNr() = 42;
113 mihPacket->transactionId() = 21;
114 mihPacket->src_mihfId().setINet4Address( INet4Address::from_string("128.129.130.131"));
115 mihPacket->dst_mihfId().setINet4Address( INet4Address::from_string("132.133.134.135"));
116 mihPacket.finalizeThis();
118 unsigned char data[] = {
120 0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x14,
121 // source MIHF_ID TLV:
122 0x01, 0x08, // type, length
123 0x5c, 0x80, 0x5c, 0x81, 0x5c, 0x82, 0x5c, 0x83, // value (nai-encoded)
124 // destination MIHF_ID TLV:
125 0x02, 0x08, // type, length
126 0x5c, 0x84, 0x5c, 0x85, 0x5c, 0x86, 0x5c, 0x87 // value (nai-encoded)
128 BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
130 mihPacket->src_mihfId().asINet4Address(),
131 INet4Address::from_string("128.129.130.131"));
133 mihPacket->dst_mihfId().asINet4Address(),
134 INet4Address::from_string("132.133.134.135"));
138 BOOST_AUTO_UNIT_TEST(MIHPacket_create_inet6)
140 MIHPacket mihPacket (MIHPacket::create());
142 mihPacket->fragmentNr() = 42;
143 mihPacket->transactionId() = 21;
144 mihPacket->src_mihfId().setINet6Address( INet6Address::from_string("::ffff:1.2.3.4"));
145 mihPacket->dst_mihfId().setINet6Address( INet6Address::from_string("::ffff:5.6.7.8"));
146 mihPacket.finalizeThis();
148 unsigned char data[] = {
150 0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x44,
151 // source MIHF_ID TLV:
152 0x01, 0x20, // type, length
153 // value (nai-encoded):
154 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00,
155 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00,
156 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0xff, 0x5c, 0xff,
157 0x5c, 0x01, 0x5c, 0x02, 0x5c, 0x03, 0x5c, 0x04,
158 // destination MIHF_ID TLV:
159 0x02, 0x20, // type, length
160 // value (nai-encoded):
161 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00,
162 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0x00,
163 0x5c, 0x00, 0x5c, 0x00, 0x5c, 0xff, 0x5c, 0xff,
164 0x5c, 0x05, 0x5c, 0x06, 0x5c, 0x07, 0x5c, 0x08
166 BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
168 mihPacket->src_mihfId().asINet6Address(),
169 INet6Address::from_string("::ffff:1.2.3.4"));
171 mihPacket->dst_mihfId().asINet6Address(),
172 INet6Address::from_string("::ffff:5.6.7.8") );
176 BOOST_AUTO_UNIT_TEST(MIHPayload_parse)
178 unsigned char data[] = {
180 0x10, 0x54, 0x00, 0x00, 0x00, 0x15,
181 // variable payload length:
183 // source MIHF_ID TLV:
184 0x01, 0x0f, // type, length
185 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
186 0x69, 0x6f, 0x73, 0x2e, 0x64, 0x65, // value ("senf@berlios.de")
187 // destination MIHF_ID TLV:
188 0x02, 0x04, 0x74, 0x65, 0x73, 0x74, // type, length, value ("test")
189 // MIH Payload (two test tlvs)
192 0x0a, // first bit not set, length=10
193 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, // value
196 0x05, // first bit not set, length=5
197 0x1a, 0x2b, 0x3c, 0x4d, 0x5e // value
200 MIHPacket mihPacket (MIHPacket::create(data));
201 BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 42u);
203 BOOST_REQUIRE( mihPacket.next().is<MIHPayloadPacket>() );
204 MIHPayloadPacket mihPayload (mihPacket.next().as<MIHPayloadPacket>());
206 BOOST_CHECK_EQUAL( mihPayload->tlv_list().size(), 2u);
207 MIHPayloadPacketParser::tlv_list_t::container tlv_list_container (mihPayload->tlv_list());
209 GenericTLVPacket::Parser tlv1 = *tlv_list_container.begin();
210 BOOST_CHECK_EQUAL( tlv1.type(), 0x42);
211 BOOST_CHECK_EQUAL( tlv1.length(), 0x0au);
212 BOOST_CHECK_EQUAL( tlv1.value().size(), 0x0a);
214 GenericTLVPacket::Parser tlv2 = *boost::next(tlv_list_container.begin());
215 BOOST_CHECK_EQUAL( tlv2.type(), 0x43);
216 BOOST_CHECK_EQUAL( tlv2.length(), 0x05u);
217 BOOST_CHECK_EQUAL( tlv2.value().size(), 0x05);
221 BOOST_AUTO_UNIT_TEST(MIHPayload_create)
223 MIHPacket mihPacket (MIHPacket::create());
224 mihPacket->fragmentNr() = 42;
225 mihPacket->transactionId() = 21;
226 mihPacket->src_mihfId().setString( "senf@berlios.de");
227 mihPacket->dst_mihfId().setString( "test");
229 MIHPayloadPacket mihPayload (MIHPayloadPacket::createAfter(mihPacket));
231 unsigned char tlv1_value[] = {
232 0x1a, 0x2b, 0x3c, 0x4d, 0x5e };
233 GenericTLVPacket tlv2 = (GenericTLVPacket::create());
235 tlv2->value( tlv1_value);
237 mihPayload->tlv_list().push_front( tlv2.parser());
239 unsigned char tlv2_value[] = {
240 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
241 GenericTLVPacket tlv1 (GenericTLVPacket::create());
243 tlv1->value( tlv2_value);
245 mihPayload->tlv_list().push_front( tlv1.parser());
247 mihPacket.finalizeAll();
249 unsigned char data[] = {
251 0x10, 0x54, 0x00, 0x00, 0x00, 0x15,
252 // variable payload length:
254 // source MIHF_ID TLV:
255 0x01, 0x0f, // type, length
256 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
257 0x69, 0x6f, 0x73, 0x2e, 0x64, 0x65, // value ("senf@berlios.de")
258 // destination MIHF_ID TLV:
259 0x02, 0x04, 0x74, 0x65, 0x73, 0x74, // type, length, value ("test")
260 // MIH Payload (two test tlvs)
263 0x0a, // first bit not set, length=10
264 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, // value
267 0x05, // first bit not set, length=5
268 0x1a, 0x2b, 0x3c, 0x4d, 0x5e // value
271 BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
275 ///////////////////////////////cc.e////////////////////////////////////////
282 // c-file-style: "senf"
283 // indent-tabs-mode: nil
284 // ispell-local-dictionary: "american"
285 // compile-command: "scons -u test"
286 // comment-column: 40