SNDUPacket.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 "SNDUPacket.hh"
18 //#include "SNDUPacket.ih"
19 
20 // Custom includes
21 #include <iomanip>
22 
23 #define prefix_
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
27  const
28 {
29  return std::for_each(
30  data().begin(),
31  boost::prior(data().end(), 4),
32  ule_crc32() ).checksum();
33 }
34 
35 //prefix_ senf::SNDUPacketType::key_t senf::SNDUPacketType::nextPacketKey(packet p)
36 //{
37 // return p->type();
38 //}
39 
41 {
42  p->init();
43 }
44 
46 {
47  if (p.data().size() < 8)
48  return no_factory();
49  PacketInterpreterBase::factory_t f (no_factory());
50  if (p->type() < 1536) {
53  if (e) f = e->factory();
54  }
55  else {
58  if (e) f = e->factory();
59  }
60  return f;
61 }
62 
65 {
66  if (p.data().size() < 8)
67  return no_range();
68 
69  size_type sz = 2 + 2; // D-Bit + 15 bits length + 16 bits type field
70  if (! p->d_bit() )
71  sz += 6; // + 6 Byte NPA destination address
72  return range(
73  boost::next(p.data().begin(), sz),
74  boost::prior(p.data().end(), 4)); // - 32 bits crc
75 }
76 
77 prefix_ void senf::SNDUPacketType::dump(packet p, std::ostream & os)
78 {
79  os << "SNDUPacket:\n"
80  << std::dec
81  << senf::fieldName("d_bit") << p->d_bit() << "\n"
82  << senf::fieldName("length") << unsigned(p->length()) << "\n"
83  << std::hex
84  << senf::fieldName("type") << "0x" << unsigned(p->type()) << "\n"
85  << std::dec
86  << senf::fieldName("crc") << unsigned(p->crc()) << "\n";
87 }
88 
90 {
91  return 2 + 2 + 4; // D-Bit + 15 bits length + 16 bits type field + 32 bits crc
92 }
93 
95 {
96  return 2 + 2; // D-Bit + 15 bits length + 16 bits type field
97 }
98 
99 //-/////////////////////////////////////////////////////////////////////////////////////////////////
100 #undef prefix_
101 
102 
103 // Local Variables:
104 // mode: c++
105 // fill-column: 100
106 // c-file-style: "senf"
107 // indent-tabs-mode: nil
108 // ispell-local-dictionary: "american"
109 // compile-command: "scons -u test"
110 // comment-column: 40
111 // End:
boost::crc_optimal< 32, 0x04C11DB7, 0xFFFFFFFF, 0, false, false > ule_crc32
Definition: SNDUPacket.hh:109
static PacketParserBase::size_type initHeadSize()
Definition: SNDUPacket.cc:94
std::string fieldName(std::string const &s)
Definition: DumpFormat.cc:28
static PacketParserBase::size_type initSize()
Definition: SNDUPacket.cc:89
static void init(packet p)
Definition: SNDUPacket.cc:40
iterator begin() const
Return iterator to beginning.
SNDUPacket public header.
static optional_range nextPacketRange(packet p)
Definition: SNDUPacket.cc:64
PacketData & data() const
Access the packets raw data container.
iterator end() const
Return iterator to end.
Protocol specific packet handle.
Definition: Packet.hh:87
senf::detail::packet::size_type size_type
Definition: PacketType.hh:106
static void dump(packet p, std::ostream &os)
Definition: SNDUPacket.cc:77
PacketInterpreterBase::range range
Definition: PacketType.hh:110
detail::PacketRegistryImpl< typename Tag::key_t >::Entry Entry
detail::packet::size_type size_type
Unsigned integral type.
nothrow
boost::uint32_t calcCrc() const
Definition: SNDUPacket.cc:26
size_type size() const
Returns the number of bytes in the packet data.
#define prefix_
Definition: SNDUPacket.cc:23
boost::optional< range > optional_range
PacketData & data() const
Access the packets raw data container.
Packet registration facility
static factory_t nextPacketType(packet p)
Definition: SNDUPacket.cc:45