X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2F80221Bundle%2FMIHPacket.cc;h=f2e61243268743ac754851e98cd327d1c41bc9e5;hb=5443435c4c2b6e4386c5334b5b8358273f2bae93;hp=1a398f116bb1dfa6daedb20931298b72fba9a748;hpb=45f1f7608c81c1d5e417c97a3e9273e0282d6a0d;p=senf.git diff --git a/Packets/80221Bundle/MIHPacket.cc b/Packets/80221Bundle/MIHPacket.cc index 1a398f1..f2e6124 100644 --- a/Packets/80221Bundle/MIHPacket.cc +++ b/Packets/80221Bundle/MIHPacket.cc @@ -27,33 +27,127 @@ //#include "MIHPacket.ih" // Custom includes -#include "MIHPacket.hh" #include "../../Packets/Packets.hh" +#include "../../Utils/hexdump.hh" #include #define prefix_ +prefix_ std::string senf::MIHFId_TLVParser::asString() + const +{ + return std::string( i(1+length_bytes()), i(1+length_bytes()+length()) ); +} + +prefix_ void senf::MIHFId_TLVParser::setString(std::string const &id) +{ + size_type str_size (id.size()); + // the maximum length of a MIHF_ID is 253 octets (see F.3.11 in 802.21) + if (str_size > 253) + throw std::length_error("maximum length of a MIHF_ID is 253 octets"); + safe_data_iterator si = resizeValue( str_size); + std::copy( id.begin(), id.end(), si); +} + + +prefix_ senf::MACAddress senf::MIHFId_TLVParser::asMACAddress() + const +{ + return MACAddress::from_data( + getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+12) )); +} + +prefix_ void senf::MIHFId_TLVParser::setMACAddress(senf::MACAddress const &mac) +{ + safe_data_iterator si = resizeValue(12); + std::copy( mac.begin(), mac.end(), getNAIEncodedOutputIterator(si)); +} + + +prefix_ senf::INet4Address senf::MIHFId_TLVParser::asINet4Address() + const +{ + return INet4Address::from_data( + getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+8) )); +} + +prefix_ void senf::MIHFId_TLVParser::setINet4Address(senf::INet4Address const &addr) +{ + safe_data_iterator si = resizeValue(8); + std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si)); +} + +prefix_ senf::INet6Address senf::MIHFId_TLVParser::asINet6Address() + const +{ + return INet6Address::from_data( + getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+32) )); +} + +prefix_ void senf::MIHFId_TLVParser::setINet6Address(senf::INet6Address const &addr) +{ + safe_data_iterator si = resizeValue(32); + std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si)); +} + + prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os) { boost::io::ios_all_saver ias(os); os << "MIH Packet:\n" - << " protocol header:\n" << "\n" - << " Version: " << unsigned( p->version()) << "\n" - << " Ack-Request: " << p->ackRequest() << "\n" - << " Ack-Response: " << p->ackResponse() << "\n" - << " UIR: " << p->uir() << "\n" - << " more fragment: " << p->moreFragment() << "\n" - << " fragment number: " << p->fragmentNr() << "\n" - << " message ID (MID):\n" - << " SID: " << unsigned( p->sid()) << "\n" - << " Opcode: " << unsigned( p->opcode()) << "\n" - << " AID: " << unsigned( p->aid()) << "\n" - << " Transaction ID: " << unsigned( p->transactionId()) << "\n" - << " payload length: " << unsigned( p->payloadLength()) << "\n"; + << " protocol header:\n" + << " Version: " << unsigned( p->version()) << "\n" + << " Ack-Request: " << p->ackRequest() << "\n" + << " Ack-Response: " << p->ackResponse() << "\n" + << " UIR: " << p->uir() << "\n" + << " more fragment: " << p->moreFragment() << "\n" + << " fragment number: " << p->fragmentNr() << "\n" + << " message ID (MID): " << unsigned( p->messageId()) << "\n" + << " SID: " << unsigned( p->sid()) << "\n" + << " Opcode: " << unsigned( p->opcode()) << "\n" + << " AID: " << unsigned( p->aid()) << "\n" + << " Transaction ID: " << unsigned( p->transactionId()) << "\n" + << " payload length: " << unsigned( p->payloadLength()) << "\n" + << " source MIHF_Id TLV:\n" + << " type: " << unsigned (p->src_mihfId().type()) << "\n" + << " length: " << unsigned (p->src_mihfId().length()) << "\n" + << " value:\n"; + std::string src_mihfId (p->src_mihfId().asString()); + hexdump(src_mihfId.begin(), src_mihfId.end(), os); + os << " destination MIHF_Id TLV:\n" + << " type: " << unsigned (p->dst_mihfId().type()) << "\n" + << " length: " << unsigned (p->dst_mihfId().length()) << "\n" + << " value:\n"; + std::string dst_mihfId (p->dst_mihfId().asString()); + hexdump(dst_mihfId.begin(), dst_mihfId.end(), os); +} + + +prefix_ void senf::MIHPacketType::finalize(packet p) +{ + p->src_mihfId().shrinkLength(); + p->dst_mihfId().shrinkLength(); + p->payloadLength_() << p.size() - 8; +} + + +prefix_ senf::PacketInterpreterBase::factory_t senf::MIHPacketType::nextPacketType(packet p) +{ + if (p.data().size() < initSize()) + return no_factory(); + PkReg_Entry const * e (PacketRegistry::lookup( p->messageId(), nothrow )); + return e ? e->factory() : 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" + << " ToDo!\n"; +} + #undef prefix_