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
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
14 #include <senf/Utils/senflikely.hh>
16 #define prefix_ inline
17 ///////////////////////////////cci.p///////////////////////////////////////
19 prefix_ senf::PacketInterpreterBase::factory_t senf::TIMPacketType::nextPacketType(packet p)
21 // it is assumed that a TIM header is always followed by a regular Ethernet frame
22 return senf::DataPacket::factory();
25 prefix_ void senf::TIMPacketType::finalize(packet p)
27 p->oddSize() << p.size() % 2;
30 prefix_ senf::TIMPacketType::optional_range senf::TIMPacketType::nextPacketRange(packet const & p)
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()) ));
39 prefix_ std::int32_t senf::TIMPacketType::timeStampDiff(std::uint32_t current, std::uint32_t last)
41 static constexpr std::int32_t maxSeq_ = TIMPacketParser::timestamp_t::max_value + 1;
42 static constexpr std::int32_t threshold_ = maxSeq_/10;
44 std::int32_t dist (current - last);
46 if (SENF_UNLIKELY(dist + threshold_ < 0))
47 return dist + maxSeq_;
48 if (SENF_UNLIKELY(dist - (maxSeq_ - threshold_) > 0))
49 return dist - maxSeq_;
54 prefix_ std::int32_t senf::TIMPacketType::seqNoDiff(std::uint32_t current, std::uint32_t last)
56 static constexpr std::int32_t maxSeq_ = TIMPacketParser::sequenceNumber_t::max_value + 1;
57 static constexpr std::int32_t threshold_ = maxSeq_/10;
59 std::int32_t dist (current - last);
61 if (SENF_UNLIKELY(dist + threshold_ < 0))
62 return dist + maxSeq_;
63 if (SENF_UNLIKELY(dist - (maxSeq_ - threshold_) > 0))
64 return dist - maxSeq_;
70 ///////////////////////////////////////////////////////////////////////////
71 // senf::TIMSeqNoStats
73 prefix_ bool senf::TIMSeqNoStats::processSeqNo(TIMPacket const & tim)
75 return update(tim->sequenceNumber(), tim.size() - TIMPacketType::parser::fixed_bytes);
78 prefix_ bool senf::TIMSeqNoStats::processLLSeqNo(TIMPacket const & tim)
80 return update(tim->linkLocalSeqNo(), tim.size() - TIMPacketType::parser::fixed_bytes);
84 ///////////////////////////////////////////////////////////////////////////
85 // senf::TIMTimestampStats
87 prefix_ void senf::TIMTimestampStats::process(TIMPacket const & tim)
89 update(tim.annotation<senf::emu::annotations::Timestamp>().as_milli_seconds((TIMPacketParser::timestamp_t::max_value + 1)), tim->timestamp(), tim->syn());
93 ///////////////////////////////cci.e///////////////////////////////////////