MIHPacket.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #include "MIHPacket.hh"
18 //#include "MIHPacket.ih"
19 
20 // Custom includes
21 #include <boost/io/ios_state.hpp>
22 #include <senf/Utils/String.hh>
23 
24 #define prefix_
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
30 
31 //-/////////////////////////////////////////////////////////////////////////////////////////////////
32 // MIHPacketType
33 
34 prefix_ void senf::MIHPacketType::dump(packet p, std::ostream & os)
35 {
36  boost::io::ios_all_saver ias(os);
37  os << "MIH Packet:\n"
38  << " protocol header:\n"
39  << senf::fieldName(" version") << unsigned( p->version()) << "\n"
40  << senf::fieldName(" ack request") << p->ackRequest() << "\n"
41  << senf::fieldName(" ack response") << p->ackResponse() << "\n"
42  << senf::fieldName(" UIR") << p->uir() << "\n"
43  << senf::fieldName(" more fragments") << p->moreFragment() << "\n"
44  << senf::fieldName(" fragment number") << p->fragmentNr() << "\n"
45  << senf::fieldName(" message ID (MID)") << unsigned( p->messageId()) << "\n"
46  << senf::fieldName(" sid") << unsigned( p->sid()) << "\n"
47  << senf::fieldName(" opcode") << unsigned( p->opcode()) << "\n"
48  << senf::fieldName(" aid") << unsigned( p->aid()) << "\n"
49  << senf::fieldName(" transaction id") << unsigned( p->transactionId()) << "\n"
50  << senf::fieldName(" payload length") << unsigned( p->payloadLength()) << "\n";
51  p->src_mihfId().dump( os);
52  p->dst_mihfId().dump( os);
53 }
54 
56 {
57  p->src_mihfId().finalize();
58  p->dst_mihfId().finalize();
59  p->payloadLength_() << p.size() - 8u;
60  p->messageId() << key(p.next(nothrow));
61 }
62 
64 {
65  if (p.data().size() < initSize())
66  return no_factory();
69  return e ? e->factory() : MIHGenericPayloadPacket::factory();
70 }
71 
73 {
74  try {
75  if (p.data().size() < initSize())
76  throw InvalidMIHPacketException("truncated MIH message; packet size:") << p.data().size();
77  if (p.data().size() < p->payloadLength() + 8u)
78  throw InvalidMIHPacketException("truncated MIH message; packet size:") << p.data().size() << "; payloadLength:" << p->payloadLength();
79  if (p->version() != 1)
80  throw InvalidMIHPacketException("invalid MIH version: ") << p->version();
81  if (p.next(senf::nothrow))
82  MIHMessageRegistry::instance().validate( p->messageId(), p.next());
83  } catch (TruncatedPacketException & e) {
84  throw InvalidMIHPacketException("truncated MIH message");
85  }
86 }
87 
88 //-/////////////////////////////////////////////////////////////////////////////////////////////////
89 // MIHGenericPayloadPacketType
90 
92 {
93  boost::io::ios_all_saver ias(os);
94  os << "MIH Payload (service specific TLVs):\n";
95  typedef parser::tlvList_t::container_type tlvListContainer_t;
96  tlvListContainer_t tlvListContainer (p->tlvList());
97  for (tlvListContainer_t::const_iterator i = tlvListContainer.begin(); i != tlvListContainer.end(); ++i)
98  i->dump( os);
99 }
100 
102 {
103  typedef parser::tlvList_t::container_type tlvContainer_t;
104  tlvContainer_t tlvs (p->tlvList() );
105  for (tlvContainer_t::iterator i (tlvs.begin()); i != tlvs.end(); ++i) {
106  MIHGenericTLVParser p (*i);
107  p.finalize();
108  }
109 }
110 
111 
112 //-/////////////////////////////////////////////////////////////////////////////////////////////////
113 #undef prefix_
114 
115 
116 // Local Variables:
117 // mode: c++
118 // fill-column: 100
119 // c-file-style: "senf"
120 // indent-tabs-mode: nil
121 // ispell-local-dictionary: "american"
122 // compile-command: "scons -u test"
123 // comment-column: 40
124 // End:
static void dump(packet p, std::ostream &os)
Dump given MIH packet in readable form to given output stream.
Definition: MIHPacket.cc:34
static const EtherTypes::key_t etherType
Definition: MIHPacket.hh:106
static optional_key_t key(Packet const &p)
Find key of packet from registry.
SENF_PACKET_REGISTRY_REGISTER(senf::EtherTypes, senf::MIHPacketType::etherType, senf::MIHPacket)
static factory_t nextPacketType(packet p)
Definition: MIHPacket.cc:63
static void validate(packet p)
Definition: MIHPacket.cc:72
std::string fieldName(std::string const &s)
Definition: DumpFormat.cc:28
static void finalize(packet p)
Definition: MIHPacket.cc:101
#define prefix_
Definition: MIHPacket.cc:24
void finalize()
shrink size of the TLV length field to minimum
MIH protocol public header.
PacketData & data() const
Access the packets raw data container.
raw_container::const_iterator const_iterator
Definition: PacketTypes.hh:70
static size_type initSize()
Get size of new (empty) packet.
Protocol specific packet handle.
Definition: Packet.hh:87
static void finalize(packet p)
Definition: MIHPacket.cc:55
Packet next() const
Get next packet in chain.
raw_container::iterator iterator
Definition: PacketTypes.hh:69
SENF_PACKET_INSTANTIATE_TEMPLATE(senf::MIHPacket)
EtherType registry.
Definition: Registries.hh:34
detail::PacketRegistryImpl< typename Tag::key_t >::Entry Entry
nothrow
size_type size() const
Returns the number of bytes in the packet data.
static factory_t no_factory()
size_type size() const
Return size of packet in bytes.
static factory_t factory()
Return factory for packets of specific type.
static void dump(packet p, std::ostream &os)
Dump given MIHGenericPayload in readable form to given output stream.
Definition: MIHPacket.cc:91
Packet registration facility
Parser for a generic TLV packet.
Definition: TLVParser.hh:31
Invalid packet data access.
Definition: PacketData.hh:175