// 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,
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>() );
MIHGenericPayloadPacket mihPayload (mihPacket.next().as<MIHGenericPayloadPacket>());
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));
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();
// 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,
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() );
// Custom includes
#include <iomanip>
#include <senf/Utils/hexdump.hh>
+#include <senf/Utils/Format.hh>
#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
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);
}
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);
}
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)
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
+ };
+
}
return ss.str();
}
+unsigned int senf::format::IndentHelper::static_level = 0;
+
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
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_
typename boost::enable_if<boost::is_unsigned<typename T::value_type> >::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);
}}