PacketStatistics.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 
14 #include "PacketStatistics.hh"
15 
16 // Custom includes
19 
20 #define prefix_
21 //-/////////////////////////////////////////////////////////////////////////////////////////////////
22 
23 
25 {
26  clear();
27 }
28 
30 {
31  length.clear();
32  rate.clear();
33  rssi.clear();
34 
36  retries = aggregated = 0;
37 }
38 
39 prefix_ bool PacketStatistics::analyze(senf::AnnotationsPacket const & ap, std::uint16_t payloadSize)
40 {
41  length.accumulate(payloadSize);
42 
43  if (!ap)
44  return true;
45 
46  retries += ap->retransmitted();
47  aggregated += ap->aggregated();
48  airtime += senf::ClockService::microseconds(ap->airTime());
49 
50  if (ap->rssi() != 0) {
51  rssi.accumulate(ap->rssi());
52  }
53 
54  return true;
55 }
56 
57 static std::string formatEng(senf::StatisticsData const & data)
58 {
59  return senf::str(senf::format::eng(data.avg, data.stddev).setprecision(6).showpoint().uppercase());
60 }
61 
62 static std::string formatCSV(senf::StatisticsData const & data)
63 {
64  std::stringstream ss;
65  if (data.cnt == 0)
66  ss << NAN << "," << NAN << "," << NAN << "," << NAN;
67  else
68  ss << data.min << "," << data.avg << "," << data.max << "," << data.stddev;
69 
70  return ss.str();
71 }
72 
73 
74 prefix_ void PacketStatistics::dump(std::ostream & os, senf::ClockService::clock_type const & actualDuration, bool csv)
75 {
76  if (csv) {
77  } else {
78  os << " pkts " << length.count() << " size " << formatEng(length.data()) << " rssi " << formatEng(rssi.data()) << " rate " << formatEng(rate.data())
79  << " airTime " << senf::ClockService::in_microseconds(airtime) << "us retries " << retries << " aggregated " << aggregated;
80  }
81 }
82 
83 prefix_ FlowStatistics::FlowStatistics(std::uint8_t Sbits, std::int32_t SmaxLate, std::uint8_t Tbits)
84  : seqNoStats(Sbits, SmaxLate),
85  tstampStats(Tbits)
86 {
87  clear();
88 }
89 
91 {
93 
94  seqNoStats.clear();
96 }
97 
98 prefix_ bool FlowStatistics::analyze(senf::AnnotationsPacket const & ap, std::uint16_t payloadSize, std::uint32_t seqNo, std::uint32_t txTSamp, std::uint32_t rxTStamp)
99 {
100  if (!PacketStatistics::analyze(ap, payloadSize))
101  return false;
102 
103  seqNoStats.update(seqNo, payloadSize);
104  tstampStats.update(txTSamp, rxTStamp, true);
105 
106  return true;
107 }
108 
109 prefix_ void FlowStatistics::dump(std::ostream & os, senf::ClockService::clock_type const & actualDuration, bool csv)
110 {
111  PacketStatistics::dump(os, actualDuration, csv);
112 
113  if (csv) {
114  } else {
115  os << " good " << seqNoStats.good << " goodBytes " << seqNoStats.goodBytes << " late " << seqNoStats.late << "/" << seqNoStats.lateMax << " duplicate " << seqNoStats.duplicate
116  << " lost " << seqNoStats.lost << " lostLate " << seqNoStats.lostLate << " resyncs " << seqNoStats.resyncs << " pdv " << formatEng(tstampStats.pdv.data());
117  }
118 }
119 
120 
122  : FlowStatistics(32, 128, 32)
123 {
124 }
125 
127 {
128  std::uint32_t txTSamp (std::int64_t(mgen->txTimeSeconds()) * 1000 + std::int64_t(mgen->txTimeMicroseconds()) / 1000);
129  std::uint32_t rxTSamp (mgen.annotation<senf::emu::annotations::Timestamp>().as_milli_seconds());
130  return FlowStatistics::analyze(ap, mgen.size(), mgen->sequenceNumber(), txTSamp, rxTSamp);
131 }
132 
134  : FlowStatistics(32, 128, 32)
135 {
136 }
137 
139 {
140  std::uint32_t txTSamp (std::int64_t(iperf->tv_sec()) * 1000 + std::int64_t(iperf->tv_usec()) / 1000);
141  std::uint32_t rxTSamp (iperf.annotation<senf::emu::annotations::Timestamp>().as_milli_seconds());
142  return FlowStatistics::analyze(ap, iperf.size(), iperf->id(), txTSamp, rxTSamp);
143 }
144 
146  : FlowStatistics(22, 128, 14)
147 {
148 }
149 
151 {
152  std::uint32_t txTSamp (tim->timestamp());
153  std::uint32_t rxTSamp (tim.annotation<senf::emu::annotations::Timestamp>().as_milli_seconds(senf::TIMPacketParser::timestamp_t::max_value + 1));
154  return FlowStatistics::analyze(ap, tim.size(), tim->sequenceNumber(), txTSamp, rxTSamp);
155 }
156 
157 //-/////////////////////////////////////////////////////////////////////////////////////////////////
158 #undef prefix_
void update(std::uint32_t txTStamp, std::uint32_t rxTStamp, bool updateDelay)
config::time_type clock_type
virtual void dump(std::ostream &os, senf::ClockService::clock_type const &actualDuration, bool csv)
bool analyze(senf::AnnotationsPacket const &ap, std::uint16_t payloadSize, std::uint32_t seqNo, std::uint32_t txTSamp, std::uint32_t rxTStamp)
senf::ClockService::clock_type airtime
senf::TimestampStatistics tstampStats
#define prefix_
u8 data[SPECTRAL_HT20_NUM_BINS]
StatisticAccumulator< std::uint32_t > pdv
Annotations public header.
senf::SequenceNumberStatistics seqNoStats
void dump(std::ostream &os, senf::ClockService::clock_type const &actualDuration, bool csv)
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_microseconds(clock_type const &v)
streamable_type eng(float v, float d=NAN)
Incoming packet timestamp.
Definition: Annotations.hh:86
virtual void clear()
static SENF_CLOCKSERVICE_CONSTEXPR clock_type microseconds(int64_type const &v)
FlowStatistics(std::uint8_t Sbits, std::int32_t SmaxLate, std::uint8_t Tbits)
Annotation & annotation()
bool update(std::uint32_t seqNo, std::uint32_t payloadSize)
bool analyze(senf::AnnotationsPacket const &ap, std::uint16_t payloadSize)
std::uint32_t as_milli_seconds(std::uint32_t modulo=0xffffffff) const
WLANInterface public header.
bool analyze(senf::TIMPacket const &tim, senf::AnnotationsPacket const &ap)
std::uint64_t retries
size_type size() const
bool analyze(IperfUDPPacket const &iperf, senf::AnnotationsPacket const &ap)
bool analyze(MGENPacket const &mgen, senf::AnnotationsPacket const &ap)
std::uint64_t aggregated