X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2F80221Bundle%2FMIHPacket.cc;h=7cb720caefccb624ebc3dba0c7fccf02a7f4f92a;hb=1ac8479aaaa1491e2668c6f09d042ae9de1f2113;hp=3e173a8aaf180d1c12ba0500bedf076b6ed30f0e;hpb=32be66071113df31a085821e31414eeb776022fa;p=senf.git diff --git a/Packets/80221Bundle/MIHPacket.cc b/Packets/80221Bundle/MIHPacket.cc index 3e173a8..7cb720c 100644 --- a/Packets/80221Bundle/MIHPacket.cc +++ b/Packets/80221Bundle/MIHPacket.cc @@ -27,11 +27,123 @@ //#include "MIHPacket.ih" // Custom includes - +#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" + << " 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" + << " 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) +{ + 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_