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 senf::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 senf::TIMPacketType::finalize(packet p)
26 {
27  p->oddSize() << p.size() % 2;
28 }
29 
30 prefix_ senf::TIMPacketType::optional_range senf::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 senf::TIMPacketType::timeStampDiff(std::uint32_t current, std::uint32_t last)
40 {
41  static constexpr std::int32_t maxSeq_ = TIMPacketParser::timestamp_t::max_value + 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 senf::TIMPacketType::seqNoDiff(std::uint32_t current, std::uint32_t last)
55 {
56  static constexpr std::int32_t maxSeq_ = TIMPacketParser::sequenceNumber_t::max_value + 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 
70 ///////////////////////////////////////////////////////////////////////////
71 // senf::TIMSeqNoStats
72 
73 prefix_ bool senf::TIMSeqNoStats::processSeqNo(TIMPacket const & tim)
74 {
75  return update(tim->sequenceNumber(), tim.size() - TIMPacketType::parser::fixed_bytes);
76 }
77 
78 prefix_ bool senf::TIMSeqNoStats::processLLSeqNo(TIMPacket const & tim)
79 {
80  return update(tim->linkLocalSeqNo(), tim.size() - TIMPacketType::parser::fixed_bytes);
81 }
82 
83 
84 ///////////////////////////////////////////////////////////////////////////
85 // senf::TIMTimestampStats
86 
87 prefix_ void senf::TIMTimestampStats::process(TIMPacket const & tim)
88 {
89  update(tim.annotation<senf::emu::annotations::Timestamp>().as_milli_seconds((TIMPacketParser::timestamp_t::max_value + 1)), tim->timestamp(), tim->syn());
90 }
91 
92 
93 ///////////////////////////////cci.e///////////////////////////////////////
94 #undef prefix_