X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2F80221Bundle%2FMIHPacket.hh;h=8b5453568c880551d189f49caa839368d58520c7;hb=57daeae6f2e924ce3f16f9677c3474f531cba9e5;hp=1d1c22604fcfcb801affcd4de58342e040388530;hpb=29a39b247b75454ad25f3f9dc7a524debf8e805c;p=senf.git diff --git a/senf/Packets/80221Bundle/MIHPacket.hh b/senf/Packets/80221Bundle/MIHPacket.hh index 1d1c226..8b54535 100644 --- a/senf/Packets/80221Bundle/MIHPacket.hh +++ b/senf/Packets/80221Bundle/MIHPacket.hh @@ -28,144 +28,14 @@ // Custom includes #include -#include -#include -#include -#include "TLVPacket.hh" -#include -#include -#include - +#include "TLVParser.hh" +#include "MIHMessageRegistry.hh" //#include "MIHPacket.mpp" -///////////////////////////////hh.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { - struct MIHMessageRegistry { - // MIH messages registry - typedef boost::uint16_t key_t; - }; - -# define SENF_MIH_PACKET_REGISTRY_REGISTER( packet ) \ - SENF_PACKET_REGISTRY_REGISTER( \ - senf::MIHMessageRegistry, packet::type::MESSAGE_ID, packet ) - - class MIHFId - : public boost::variant< boost::blank, senf::MACAddress, senf::INet4Address, - senf::INet6Address, std::string, senf::EUI64 >, - public boost::less_than_comparable, - public boost::equality_comparable - { - public: - enum Type { Empty, MACAddress, INet4Address, INet6Address, String, EUI64 }; - - MIHFId(); ///< Create empty instance. - MIHFId(senf::MACAddress const & addr); ///< Construct id with given MACAddress - MIHFId(senf::INet4Address const & addr); ///< Construct id with given INet4Address - MIHFId(senf::INet6Address const & addr); ///< Construct id with given INet6Address - MIHFId(std::string const & addr); ///< Construct id with given String - MIHFId(senf::EUI64 const & addr); ///< Construct id with given EUI64 - - Type type() const; - bool operator==(MIHFId const & other) const; - bool operator<(MIHFId const & other) const; - - private: - struct GetTypeVisitor : public boost::static_visitor { - Type operator()(boost::blank const &) const { return Empty; } - Type operator()(senf::MACAddress const &) const { return MACAddress; } - Type operator()(senf::INet4Address const &) const { return INet4Address; } - Type operator()(senf::INet6Address const &) const { return INet6Address; } - Type operator()(std::string const & ) const { return String; } - Type operator()(senf::EUI64 const &) const { return EUI64; } - }; - struct EqualsVisitor : public boost::static_visitor { - template - bool operator()(T const &, U const &) const { - return false; - } - template - bool operator()( const T & lhs, const T & rhs ) const { - return lhs == rhs; - } - }; - struct LessThanVisitor : public boost::static_visitor { - template - bool operator()(T const &, U const &) const { - return false; - } - template - bool operator()( const T & lhs, const T & rhs ) const { - return lhs < rhs; - } - }; - }; - - - /** \brief Parse a MIHF_ID - - the maximum length of a MIHF_ID is 253 octets (see F.3.11 in 802.21) - we could set maxLengthValue in init(), but for the most MIHF_IDs the default - maximum length of 127 should be enough. - - \note you must call mihfIdPacket.maxLengthValue( 253) *before* - setting longer MIHF_IDs values. - */ - class MIHFId_TLVParser : public MIHBaseTLVParser - { - # include SENF_PARSER() - SENF_PARSER_INHERIT ( MIHBaseTLVParser ); - SENF_PARSER_SKIP ( length(), 0 ); - SENF_PARSER_FINALIZE ( MIHFId_TLVParser ); - - public: - std::string asString() const; - void setString(std::string const &id); - - senf::MACAddress asMACAddress() const; - void setMACAddress(senf::MACAddress const &mac); - - senf::INet4Address asINet4Address() const; - void setINet4Address(senf::INet4Address const &addr); - - senf::INet6Address asINet6Address() const; - void setINet6Address(senf::INet6Address const &addr); - - senf::EUI64 asEUI64() const; - void setEUI64(senf::EUI64 const &addr); - - MIHFId valueAs(MIHFId::Type type) const; - - private: - template - struct binaryNAIEncoder { - binaryNAIEncoder(OutputIterator &i) : i_(i) {} - void operator()(const boost::uint8_t &v) const { - *i_++ = '\\'; - *i_++ = v; - } - OutputIterator &i_; - }; - template - static boost::function_output_iterator > getNAIEncodedOutputIterator(OutputIterator i) { - return boost::make_function_output_iterator(binaryNAIEncoder(i)); - } - - struct binaryNAIDecoder { - binaryNAIDecoder() : readNextByte_(true) {} - bool operator()(const boost::uint8_t &v) { - readNextByte_ = readNextByte_ ? false : true; - return readNextByte_; - } - bool readNextByte_; - }; - template - static boost::filter_iterator getNAIDecodedIterator(Iterator begin, Iterator end) { - return boost::make_filter_iterator(begin, end); - } - }; - /** \brief Parse a MIH packet Parser implementing the MIH header. The fields implemented are: @@ -191,24 +61,23 @@ namespace senf { SENF_PARSER_BITFIELD ( sid, 4, unsigned ); SENF_PARSER_BITFIELD ( opcode, 2, unsigned ); SENF_PARSER_BITFIELD ( aid, 10, unsigned ); - + SENF_PARSER_SKIP_BITS ( 4 ); SENF_PARSER_BITFIELD ( transactionId, 12, unsigned ); SENF_PARSER_FIELD_RO ( payloadLength, UInt16Parser ); - + SENF_PARSER_GOTO_OFFSET( 8, 8); // just to limit the offset calculation - + // Source MIHF Id - SENF_PARSER_FIELD ( src_mihfId, MIHFId_TLVParser ); + SENF_PARSER_FIELD ( src_mihfId, MIHFSrcIdTLVParser ); // Destination MIHF Id - SENF_PARSER_FIELD ( dst_mihfId, MIHFId_TLVParser ); + SENF_PARSER_FIELD ( dst_mihfId, MIHFDstIdTLVParser ); SENF_PARSER_FINALIZE ( MIHPacketParser ); SENF_PARSER_INIT() { + defaultInit(); version_() = 1; - src_mihfId().type() = 1; - dst_mihfId().type() = 2; } friend class MIHPacketType; @@ -228,9 +97,7 @@ namespace senf { : public PacketTypeBase, public PacketTypeMixin { -#ifndef DOXYGEN typedef PacketTypeMixin mixin; -#endif typedef ConcretePacket packet; ///< MIH packet typedef typedef MIHPacketParser parser; ///< typedef to the parser of MIH packet @@ -242,44 +109,48 @@ namespace senf { static void dump(packet p, std::ostream &os); static void finalize(packet p); static factory_t nextPacketType(packet p); + static void validate(packet p); }; - /** \brief MIH packet typedef */ + /** \brief MIH packet typedef + \ingroup protocolbundle_80221 + */ typedef ConcretePacket MIHPacket; - struct MIHPayloadPacketParser : public PacketParserBase + struct MIHGenericPayloadPacketParser : public PacketParserBase { # include SENF_PARSER() - SENF_PARSER_LIST ( tlv_list, packetSize(), MIHGenericTLVPacketParser ); - SENF_PARSER_FINALIZE ( MIHPayloadPacketParser ); + SENF_PARSER_LIST ( tlvList, packetSize(), MIHGenericTLVParser ); + SENF_PARSER_FINALIZE ( MIHGenericPayloadPacketParser ); }; - struct MIHPayloadPacketType + struct MIHGenericPayloadPacketType : public PacketTypeBase, - public PacketTypeMixin + public PacketTypeMixin { -#ifndef DOXYGEN - typedef PacketTypeMixin mixin; -#endif - typedef ConcretePacket packet; ///< MIH Payload packet typedef - typedef MIHPayloadPacketParser parser; ///< typedef to the parser of MIH Payload packet + typedef PacketTypeMixin mixin; + typedef ConcretePacket packet; ///< MIH Payload packet typedef + typedef MIHGenericPayloadPacketParser parser; ///< typedef to the parser of MIH Payload packet using mixin::nextPacketRange; using mixin::init; using mixin::initSize; - /** \brief Dump given MIHPayload in readable form to given output stream */ + /** \brief Dump given MIHGenericPayload in readable form to given output stream */ static void dump(packet p, std::ostream &os); + static void finalize(packet p); }; - /** \brief MIH Payload packet typedef */ - typedef ConcretePacket MIHPayloadPacket; + /** \brief MIH Payload packet typedef + \ingroup protocolbundle_80221 + */ + typedef ConcretePacket MIHGenericPayloadPacket; } -///////////////////////////////hh.e//////////////////////////////////////// -#include "MIHPacket.cci" +//-///////////////////////////////////////////////////////////////////////////////////////////////// +//#include "MIHPacket.cci" //#include "MIHPacket.ct" //#include "MIHPacket.cti" #endif