From: tho Date: Mon, 19 Oct 2009 11:05:44 +0000 (+0000) Subject: Packets/80221Bundle: added more MIH-TLVs X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=9c0d069987191bce78e13cdba410c34d34e736c2;p=senf.git Packets/80221Bundle: added more MIH-TLVs Utils/Format: added indent helper git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1502 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/80221Bundle/MIHPacket.test.cc b/senf/Packets/80221Bundle/MIHPacket.test.cc index 1ba5e0e..64d2ff1 100644 --- a/senf/Packets/80221Bundle/MIHPacket.test.cc +++ b/senf/Packets/80221Bundle/MIHPacket.test.cc @@ -216,7 +216,7 @@ BOOST_AUTO_UNIT_TEST(MIHPayload_parse) // MIH header 0x10, 0x54, 0x00, 0x00, 0x00, 0x15, // variable payload length: - 0x00, 0x2a, + 0x00, 0x29, // source MIHF_ID TLV: 0x01, 0x0f, // type, length 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c, @@ -229,13 +229,13 @@ BOOST_AUTO_UNIT_TEST(MIHPayload_parse) 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 + 0x0c, // type + 0x04, // first bit not set, length=4 + 0x1a, 0x2b, 0x3c, 0x4d // value }; MIHPacket mihPacket (MIHPacket::create(data)); - BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 42u); + BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 41u); BOOST_REQUIRE( mihPacket.next().is() ); MIHGenericPayloadPacket mihPayload (mihPacket.next().as()); @@ -250,9 +250,9 @@ BOOST_AUTO_UNIT_TEST(MIHPayload_parse) BOOST_CHECK_EQUAL( tlv1.value().size(), 0x0a); MIHGenericTLVParser tlv2 = *boost::next(tlvListContainer.begin()); - BOOST_CHECK_EQUAL( tlv2.type(), 0x43); - BOOST_CHECK_EQUAL( tlv2.length(), 0x05u); - BOOST_CHECK_EQUAL( tlv2.value().size(), 0x05); + BOOST_CHECK_EQUAL( tlv2.type(), 0x0c); + BOOST_CHECK_EQUAL( tlv2.length(), 0x04u); + BOOST_CHECK_EQUAL( tlv2.value().size(), 0x04); std::ostringstream oss (std::ostringstream::out); SENF_CHECK_NO_THROW( mihPayload.dump( oss)); @@ -278,9 +278,9 @@ BOOST_AUTO_UNIT_TEST(MIHPayload_create) tlv1.value( tlv1_value); unsigned char tlv2_value[] = { - 0x1a, 0x2b, 0x3c, 0x4d, 0x5e }; + 0x1a, 0x2b, 0x3c, 0x4d }; MIHGenericTLVParser tlv2 ( tlvListContainer.push_back_space()); - tlv2.type() = 0x43; + tlv2.type() = 0x0c; tlv2.value( tlv2_value); mihPacket.finalizeAll(); @@ -289,7 +289,7 @@ BOOST_AUTO_UNIT_TEST(MIHPayload_create) // MIH header 0x10, 0x54, 0x00, 0x00, 0x00, 0x15, // variable payload length: - 0x00, 0x2a, + 0x00, 0x29, // source MIHF_ID TLV: 0x01, 0x0f, // type, length 0x73, 0x65, 0x6e, 0x66, 0x40, 0x62, 0x65, 0x72, 0x6c, @@ -302,9 +302,9 @@ BOOST_AUTO_UNIT_TEST(MIHPayload_create) 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 + 0x0c, // type + 0x04, // first bit not set, length=4 + 0x1a, 0x2b, 0x3c, 0x4d // value }; SENF_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data), mihPacket.data().begin(), mihPacket.data().end() ); diff --git a/senf/Packets/80221Bundle/TLVParser.cc b/senf/Packets/80221Bundle/TLVParser.cc index 8f9d942..45622fb 100644 --- a/senf/Packets/80221Bundle/TLVParser.cc +++ b/senf/Packets/80221Bundle/TLVParser.cc @@ -29,12 +29,15 @@ // Custom includes #include #include +#include #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// SENF_PACKET_TLV_REGISTRY_REGISTER( senf::MIHFSrcIdTLVParser ); SENF_PACKET_TLV_REGISTRY_REGISTER( senf::MIHFDstIdTLVParser ); +SENF_PACKET_TLV_REGISTRY_REGISTER( senf::MIHStatusTLVParser ); +SENF_PACKET_TLV_REGISTRY_REGISTER( senf::MIHValidTimeIntervalTLVParser ); /////////////////////////////////////////////////////////////////////////// // senf::MIHFIdTLVParser @@ -42,9 +45,10 @@ SENF_PACKET_TLV_REGISTRY_REGISTER( senf::MIHFDstIdTLVParser ); prefix_ void senf::MIHFIdTLVParser::dump(std::ostream & os) const { - os << senf::fieldName(" type") << unsigned (type()) << "\n" - << senf::fieldName(" length") << unsigned (length()) << "\n" - << " value:\n"; + senf::format::IndentHelper indent; + os << indent << "type: " << unsigned (type()) << std::endl + << indent << "length: " << unsigned (length()) << std::endl + << indent << "value:\n"; std::string src_mihfId (asString()); hexdump(src_mihfId.begin(), src_mihfId.end(), os); } @@ -111,7 +115,8 @@ prefix_ senf::MIHFId senf::MIHFIdTLVParser::valueAs(MIHFId::Type type) prefix_ void senf::MIHFSrcIdTLVParser::dump(std::ostream & os) const { - os << " source MIHF_Id TLV:\n"; + senf::format::IndentHelper indent; + os << indent << "source MIHF_Id TLV:\n"; MIHFIdTLVParser::dump(os); } @@ -121,12 +126,84 @@ prefix_ void senf::MIHFSrcIdTLVParser::dump(std::ostream & os) prefix_ void senf::MIHFDstIdTLVParser::dump(std::ostream & os) const { - os << " destination MIHF_Id TLV:\n"; + senf::format::IndentHelper indent; + os << indent << "destination MIHF_Id TLV:\n"; MIHFIdTLVParser::dump(os); } /////////////////////////////////////////////////////////////////////////// -// MIHBaseTLVParser +// senf::MIHStatusTLVParser + +prefix_ void senf::MIHStatusTLVParser::dump(std::ostream & os) + const +{ + senf::format::IndentHelper indent; + os << indent << "Status TLV:" << std::endl; + indent.increase(); + os << indent << "type: " << unsigned( type()) << std::endl + << indent << "length: " << unsigned( length()) << " byte(s)" << std::endl + << indent << "value: " << unsigned( value()); + switch (value()) { + case Success: + os << " (Success)" << std::endl; + return; + case UnspecifiedFailure: + os << " (Unspecified Failure)" << std::endl; + return; + case Rejected: + os << " (Rejected)" << std::endl; + return; + case AuthorizationFailure: + os << " (Authorization Failure)" << std::endl; + return; + case NetworkError: + os << " (Network Error)" << std::endl; + return; + } + os << " (???; invalid value!)" << std::endl; +} + +/////////////////////////////////////////////////////////////////////////// +// senf::MIHRegisterReqCodeTLVParser + +prefix_ void senf::MIHRegisterReqCodeTLVParser::dump(std::ostream & os) + const +{ + senf::format::IndentHelper indent; + os << indent << "Register Request Code TLV:" << std::endl; + indent.increase(); + os << indent << "type: " << unsigned( type()) << std::endl + << indent << "length: " << unsigned( length()) << " byte(s)" << std::endl + << indent << "value: " << unsigned( value()); + switch (value()) { + case Registration: + os << " (Registration)" << std::endl; + return; + case ReRegistration: + os << " (Re-Registration)" << std::endl; + return; + } + os << " (???; invalid value!)" << std::endl; +} + +/////////////////////////////////////////////////////////////////////////// +// senf::MIHValidTimeIntervalTLVParser + +prefix_ void senf::MIHValidTimeIntervalTLVParser::dump(std::ostream & os) + const +{ + senf::format::IndentHelper indent; + os << indent << "Valid Time Interval TLV:" << std::endl; + indent.increase(); + os << indent << "type: " << unsigned( type()) << std::endl + << indent << "length: " << unsigned( length()) << " byte(s)" << std::endl + << indent << "value: " << unsigned( value()) + << ( value()==0 ? " (infinite)" : " seconds") << std::endl; +} + + +/////////////////////////////////////////////////////////////////////////// +// senf::MIHBaseTLVParser prefix_ senf::safe_data_iterator senf::MIHBaseTLVParser::resizeValueField( MIHTLVLengthParser::value_type size) diff --git a/senf/Packets/80221Bundle/TLVParser.hh b/senf/Packets/80221Bundle/TLVParser.hh index e6caf9c..b93f925 100644 --- a/senf/Packets/80221Bundle/TLVParser.hh +++ b/senf/Packets/80221Bundle/TLVParser.hh @@ -244,6 +244,61 @@ namespace senf { void dump(std::ostream & os) const; }; + + /** \brief Parser for 802.21 Status TLV + */ + struct MIHStatusTLVParser : public MIHBaseTLVParser + { + # include SENF_PARSER() + SENF_PARSER_INHERIT ( MIHBaseTLVParser ); + SENF_PARSER_FIELD ( value, UInt8Parser ); + SENF_PARSER_FINALIZE( MIHStatusTLVParser ); + SENF_PARSER_INIT() { + defaultInit(); + type() << typeId+0; + length_() = 1; + } + static type_t::value_type const typeId = 3; + void dump(std::ostream & os) const; ///< dump string representation to given stream + + enum StatusCode { + Success, UnspecifiedFailure, Rejected, AuthorizationFailure, NetworkError }; + }; + + struct MIHRegisterReqCodeTLVParser : public MIHBaseTLVParser + { + # include SENF_PARSER() + SENF_PARSER_INHERIT ( MIHBaseTLVParser ); + SENF_PARSER_FIELD ( value, UInt8Parser ); + SENF_PARSER_FINALIZE ( MIHRegisterReqCodeTLVParser ); + + SENF_PARSER_INIT() { + defaultInit(); + type() = typeId+0; + length_() = 1; + } + static type_t::value_type const typeId = 11; + void dump(std::ostream & os) const; ///< dump string representation to given stream + + enum RequestCode { Registration, ReRegistration }; + }; + + struct MIHValidTimeIntervalTLVParser : public MIHBaseTLVParser + { + # include SENF_PARSER() + SENF_PARSER_INHERIT ( MIHBaseTLVParser ); + SENF_PARSER_FIELD ( value, UInt32Parser ); + SENF_PARSER_FINALIZE ( MIHValidTimeIntervalTLVParser ); + + SENF_PARSER_INIT() { + defaultInit(); + type() = typeId+0; + length_() = 4; + } + static type_t::value_type const typeId = 12; + void dump(std::ostream & os) const; ///< dump string representation to given stream + }; + } diff --git a/senf/Utils/Format.cc b/senf/Utils/Format.cc index 78d3e8d..e824b39 100644 --- a/senf/Utils/Format.cc +++ b/senf/Utils/Format.cc @@ -152,6 +152,8 @@ prefix_ std::string senf::format::detail::dumpintUnsigned(unsigned long long v, return ss.str(); } +unsigned int senf::format::IndentHelper::static_level = 0; + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ diff --git a/senf/Utils/Format.cci b/senf/Utils/Format.cci index 7871b7d..ff8f87b 100644 --- a/senf/Utils/Format.cci +++ b/senf/Utils/Format.cci @@ -150,6 +150,13 @@ prefix_ senf::format::eng const & senf::format::eng::right() return *this; } +prefix_ std::ostream & senf::format::operator<<(std::ostream & os, senf::format::IndentHelper const & indent) +{ + for (unsigned int i = 0; i < indent.static_level; ++i) + os << " "; + return os; +} + ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ diff --git a/senf/Utils/Format.hh b/senf/Utils/Format.hh index 7c6e424..180c39e 100644 --- a/senf/Utils/Format.hh +++ b/senf/Utils/Format.hh @@ -203,6 +203,20 @@ namespace format { typename boost::enable_if >::type * = 0); #endif + + class IndentHelper + { + static unsigned int static_level; + + unsigned int instance_level; + public: + IndentHelper () : instance_level(1) { ++static_level; } + ~IndentHelper () { static_level -= instance_level; } + void increase() { ++static_level; ++instance_level; } + + friend std::ostream & operator<<(std::ostream & os, IndentHelper const & indent); + }; + std::ostream & operator<<(std::ostream & os, IndentHelper const & indent); }}