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 wiback::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 wiback::TIMPacketType::finalize(packet p)
27 p->oddSize() << p.size() % 2;
30 prefix_ wiback::TIMPacketType::optional_range wiback::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 wiback::TIMPacketType::timeStampDiff(std::uint32_t current, std::uint32_t last)
41 static constexpr std::int32_t maxSeq_ = 0x3fff+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 wiback::TIMPacketType::seqNoDiff(std::uint32_t current, std::uint32_t last)
56 static constexpr std::int32_t maxSeq_ = 0xffffff+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_;
69 ///////////////////////////////cci.e///////////////////////////////////////