#include "MIHPacket.hh"
-
using namespace senf;
#define prefix_
INet6Address::from_string("::ffff:5.6.7.8") );
}
+
+BOOST_AUTO_UNIT_TEST(MIHPayload_parse)
+{
+ unsigned char data[] = {
+ // MIH header
+ 0x10, 0x54, 0x00, 0x00, 0x00, 0x15,
+ // variable payload length:
+ 0x00, 0x2a,
+ // source MIHF_ID TLV:
+ 0x01, 0x0f, // type, length
+ 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
+ 0x69, 0x6f, 0x73, 0x2e, 0x64, 0x65, // value ("senf@berlios.de")
+ // destination MIHF_ID TLV:
+ 0x02, 0x04, 0x74, 0x65, 0x73, 0x74, // type, length, value ("test")
+ // MIH Payload (two test tlvs)
+ // first test tlv
+ 0x42, // type
+ 0x0a, // first bit not set, length=10
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, // value
+ // second test tlv
+ 0x43, // type
+ 0x05, // first bit not set, length=5
+ 0x1a, 0x2b, 0x3c, 0x4d, 0x5e // value
+ };
+
+ MIHPacket mihPacket (MIHPacket::create(data));
+ BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 42u);
+
+ BOOST_REQUIRE( mihPacket.next().is<MIHPayloadPacket>() );
+ MIHPayloadPacket mihPayload (mihPacket.next().as<MIHPayloadPacket>());
+
+ BOOST_CHECK_EQUAL( mihPayload->tlv_list().size(), 2u);
+ MIHPayloadPacketParser::tlv_list_t::container tlv_list_container (mihPayload->tlv_list());
+
+ GenericTLVPacket::Parser tlv1 = *tlv_list_container.begin();
+ BOOST_CHECK_EQUAL( tlv1.type(), 0x42);
+ BOOST_CHECK_EQUAL( tlv1.length(), 0x0a);
+ BOOST_CHECK_EQUAL( tlv1.value().size(), 0x0a);
+
+ GenericTLVPacket::Parser tlv2 = *boost::next(tlv_list_container.begin());
+ BOOST_CHECK_EQUAL( tlv2.type(), 0x43);
+ BOOST_CHECK_EQUAL( tlv2.length(), 0x05);
+ BOOST_CHECK_EQUAL( tlv2.value().size(), 0x05);
+}
+
+
+BOOST_AUTO_UNIT_TEST(MIHPayload_create)
+{
+ MIHPacket mihPacket (MIHPacket::create());
+ mihPacket->fragmentNr() = 42;
+ mihPacket->transactionId() = 21;
+ mihPacket->src_mihfId().setString( "senf@berlios.de");
+ mihPacket->dst_mihfId().setString( "test");
+
+ MIHPayloadPacket mihPayload (MIHPayloadPacket::createAfter(mihPacket));
+
+ unsigned char tlv1_value[] = {
+ 0x1a, 0x2b, 0x3c, 0x4d, 0x5e };
+ GenericTLVPacket tlv2 = (GenericTLVPacket::create());
+ tlv2->type() = 0x43;
+ tlv2->value( tlv1_value);
+ tlv2.finalizeThis();
+ mihPayload->tlv_list().push_front( tlv2.parser());
+
+ unsigned char tlv2_value[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
+ GenericTLVPacket tlv1 (GenericTLVPacket::create());
+ tlv1->type() = 0x42;
+ tlv1->value( tlv2_value);
+ tlv1.finalizeThis();
+ mihPayload->tlv_list().push_front( tlv1.parser());
+
+ mihPacket.finalizeAll();
+
+ unsigned char data[] = {
+ // MIH header
+ 0x10, 0x54, 0x00, 0x00, 0x00, 0x15,
+ // variable payload length:
+ 0x00, 0x2a,
+ // source MIHF_ID TLV:
+ 0x01, 0x0f, // type, length
+ 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c,
+ 0x69, 0x6f, 0x73, 0x2e, 0x64, 0x65, // value ("senf@berlios.de")
+ // destination MIHF_ID TLV:
+ 0x02, 0x04, 0x74, 0x65, 0x73, 0x74, // type, length, value ("test")
+ // MIH Payload (two test tlvs)
+ // first test tlv
+ 0x42, // type
+ 0x0a, // first bit not set, length=10
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, // value
+ // second test tlv
+ 0x43, // type
+ 0x05, // first bit not set, length=5
+ 0x1a, 0x2b, 0x3c, 0x4d, 0x5e // value
+ };
+
+ BOOST_CHECK(equal( mihPacket.data().begin(), mihPacket.data().end(), data ));
+}
+
+
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_