From: tho Date: Tue, 27 Jan 2009 14:15:40 +0000 (+0000) Subject: added generic MIHPayload Packet X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=927817c0fca43d120341438204cab2d4ef2a033f;p=senf.git added generic MIHPayload Packet git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1080 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/80221Bundle/MIHPacket.cc b/Packets/80221Bundle/MIHPacket.cc index d762b15..7cb720c 100644 --- a/Packets/80221Bundle/MIHPacket.cc +++ b/Packets/80221Bundle/MIHPacket.cc @@ -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_ diff --git a/Packets/80221Bundle/MIHPacket.hh b/Packets/80221Bundle/MIHPacket.hh index 7128135..0b970ff 100644 --- a/Packets/80221Bundle/MIHPacket.hh +++ b/Packets/80221Bundle/MIHPacket.hh @@ -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 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 + { + typedef PacketTypeMixin mixin; + typedef ConcretePacket packet; + typedef MIHPayloadPacketParser parser; + + using mixin::nextPacketRange; + using mixin::init; + using mixin::initSize; + + static void dump(packet p, std::ostream &os); + }; + + typedef ConcretePacket MIHPayloadPacket; + + } diff --git a/Packets/80221Bundle/MIHPacket.test.cc b/Packets/80221Bundle/MIHPacket.test.cc index d4f4df0..ccb376a 100644 --- a/Packets/80221Bundle/MIHPacket.test.cc +++ b/Packets/80221Bundle/MIHPacket.test.cc @@ -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 mihPayload (mihPacket.next().as()); + + 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_