Skip to content
Snippets Groups Projects
Commit 8528c4e5 authored by tho's avatar tho
Browse files

added generic MIHPayload Packet

parent 9e1d2908
No related branches found
No related tags found
No related merge requests found
......@@ -132,6 +132,19 @@ prefix_ void senf::MIHPacketType::finalize(packet p)
}
prefix_ senf::PacketInterpreterBase::factory_t senf::MIHPacketType::nextPacketType(packet p)
{
return MIHPayloadPacket::factory();
}
prefix_ void senf::MIHPayloadPacketType::dump(packet p, std::ostream &os)
{
boost::io::ios_all_saver ias(os);
os << "MIH Payload (service specific TLVs):\n";
}
#undef prefix_
......
......@@ -155,9 +155,38 @@ namespace senf {
static void dump(packet p, std::ostream &os);
static void finalize(packet p);
static factory_t nextPacketType(packet p);
};
typedef ConcretePacket<MIHPacketType> MIHPacket;
struct MIHPayloadPacketParser : public PacketParserBase
{
# include SENF_PARSER()
SENF_PARSER_LIST ( tlv_list, packetSize(), GenericTLVPacketParser );
SENF_PARSER_FINALIZE ( MIHPayloadPacketParser );
};
struct MIHPayloadPacketType
: public PacketTypeBase,
public PacketTypeMixin<MIHPayloadPacketType>
{
typedef PacketTypeMixin<MIHPayloadPacketType> mixin;
typedef ConcretePacket<MIHPayloadPacketType> packet;
typedef MIHPayloadPacketParser parser;
using mixin::nextPacketRange;
using mixin::init;
using mixin::initSize;
static void dump(packet p, std::ostream &os);
};
typedef ConcretePacket<MIHPayloadPacketType> MIHPayloadPacket;
}
......
......@@ -31,7 +31,6 @@
#include "MIHPacket.hh"
using namespace senf;
#define prefix_
......@@ -170,6 +169,106 @@ BOOST_AUTO_UNIT_TEST(MIHPacket_create_inet6)
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_
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment