TIMPacket.cci
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 
14 #include <senf/Utils/senflikely.hh>
15 
16 #define prefix_ inline
17 ///////////////////////////////cci.p///////////////////////////////////////
18 
19 prefix_ senf::PacketInterpreterBase::factory_t wiback::TIMPacketType::nextPacketType(packet p)
20 {
21  // it is assumed that a TIM header is always followed by a regular Ethernet frame
22  return senf::DataPacket::factory();
23 }
24 
25 prefix_ void wiback::TIMPacketType::finalize(packet p)
26 {
27  p->oddSize() << p.size() % 2;
28 }
29 
30 prefix_ wiback::TIMPacketType::optional_range wiback::TIMPacketType::nextPacketRange(packet const & p)
31 {
32  return SENF_UNLIKELY(p.data().size() < parser::fixed_bytes) ?
33  PacketTypeBase::no_range() :
34  optional_range( range(
35  p.data().begin() + parser::fixed_bytes,
36  p.data().end() - ((p.size() % 2) ? 0 : p->oddSize()) ));
37 }
38 
39 prefix_ std::int32_t wiback::TIMPacketType::timeStampDiff(std::uint32_t current, std::uint32_t last)
40 {
41  static constexpr std::int32_t maxSeq_ = 0x3fff+1;
42  static constexpr std::int32_t threshold_ = maxSeq_/10;
43 
44  std::int32_t dist (current - last);
45 
46  if (SENF_UNLIKELY(dist + threshold_ < 0))
47  return dist + maxSeq_;
48  if (SENF_UNLIKELY(dist - (maxSeq_ - threshold_) > 0))
49  return dist - maxSeq_;
50 
51  return dist;
52 }
53 
54 prefix_ std::int32_t wiback::TIMPacketType::seqNoDiff(std::uint32_t current, std::uint32_t last)
55 {
56  static constexpr std::int32_t maxSeq_ = 0xffffff+1;
57  static constexpr std::int32_t threshold_ = maxSeq_/10;
58 
59  std::int32_t dist (current - last);
60 
61  if (SENF_UNLIKELY(dist + threshold_ < 0))
62  return dist + maxSeq_;
63  if (SENF_UNLIKELY(dist - (maxSeq_ - threshold_) > 0))
64  return dist - maxSeq_;
65 
66  return dist;
67 }
68 
69 ///////////////////////////////cci.e///////////////////////////////////////
70 #undef prefix_