Skip to content

Commit 3ee019c

Browse files
committed
Add unique packets counter, differential loss and diversity calculation #419
1 parent 027aaf5 commit 3ee019c

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

src/rx.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void Receiver::loop_iter(void)
265265

266266

267267
Aggregator::Aggregator(const string &client_addr, int client_port, const string &keypair, uint64_t epoch, uint32_t channel_id) : \
268-
count_p_all(0), count_b_all(0), count_p_dec_err(0), count_p_dec_ok(0), count_p_fec_recovered(0),
268+
count_p_all(0), count_b_all(0), count_p_dec_err(0), count_p_session(0), count_p_data(0), count_p_fec_recovered(0),
269269
count_p_lost(0), count_p_bad(0), count_p_override(0), count_p_outgoing(0), count_b_outgoing(0),
270270
fec_p(NULL), fec_k(-1), fec_n(-1), seq(0), rx_ring{}, rx_ring_front(0), rx_ring_alloc(0),
271271
last_known_block((uint64_t)-1), epoch(epoch), channel_id(channel_id)
@@ -490,8 +490,14 @@ void Aggregator::dump_stats(void)
490490
it->second.snr_min, it->second.snr_sum / it->second.count_all, it->second.snr_max);
491491
}
492492

493-
IPC_MSG("%" PRIu64 "\tPKT\t%u:%u:%u:%u:%u:%u:%u:%u:%u\n", ts, count_p_all, count_b_all, count_p_dec_err,
494-
count_p_dec_ok, count_p_fec_recovered, count_p_lost, count_p_bad, count_p_outgoing, count_b_outgoing);
493+
IPC_MSG("%" PRIu64 "\tPKT\t%u:%u:%u:%u:%u:%u:%u:%u:%u:%u:%u\n", ts,
494+
count_p_all, count_b_all, // incoming
495+
count_p_dec_err, // decryption
496+
count_p_session, count_p_data, // classification
497+
(uint32_t)count_p_uniq.size(), // unique check
498+
count_p_fec_recovered, count_p_lost, // fec recovering
499+
count_p_bad, // internal errors
500+
count_p_outgoing, count_b_outgoing); // outgoing
495501
IPC_MSG_SEND();
496502

497503
if(count_p_override)
@@ -643,8 +649,11 @@ void Aggregator::process_packet(const uint8_t *buf, size_t size, uint8_t wlan_id
643649
return;
644650
}
645651

646-
count_p_dec_ok += 1;
647-
log_rssi(sockaddr, wlan_idx, antenna, rssi, noise, freq, mcs_index, bandwidth);
652+
count_p_session += 1;
653+
654+
// Ignore RSSI (and per-card rx counters) for session packets to simplify calculation
655+
// of lost packets because session packets doesn't have any serial number and it is
656+
// too hard to calculate number of unique session packets
648657

649658
if (memcmp(session_key, new_session_data->session_key, sizeof(session_key)) != 0)
650659
{
@@ -686,7 +695,7 @@ void Aggregator::process_packet(const uint8_t *buf, size_t size, uint8_t wlan_id
686695
return;
687696
}
688697

689-
count_p_dec_ok += 1;
698+
count_p_data += 1;
690699
log_rssi(sockaddr, wlan_idx, antenna, rssi, noise, freq, mcs_index, bandwidth);
691700

692701
assert(decrypted_len >= sizeof(wpacket_hdr_t));
@@ -695,6 +704,8 @@ void Aggregator::process_packet(const uint8_t *buf, size_t size, uint8_t wlan_id
695704
uint64_t block_idx = be64toh(block_hdr->data_nonce) >> 8;
696705
uint8_t fragment_idx = (uint8_t)(be64toh(block_hdr->data_nonce) & 0xff);
697706

707+
count_p_uniq.insert(be64toh(block_hdr->data_nonce));
708+
698709
// Should never happend due to generating new session key on tx side
699710
if (block_idx > MAX_BLOCK_IDX)
700711
{

src/rx.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <stdio.h>
2626
#include <errno.h>
2727
#include <string>
28+
#include <set>
2829
#include <string.h>
2930
#include <stdexcept>
3031

@@ -172,7 +173,9 @@ class Aggregator : public BaseAggregator
172173
count_p_all = 0;
173174
count_b_all = 0;
174175
count_p_dec_err = 0;
175-
count_p_dec_ok = 0;
176+
count_p_session = 0;
177+
count_p_data = 0;
178+
count_p_uniq.clear();
176179
count_p_fec_recovered = 0;
177180
count_p_lost = 0;
178181
count_p_bad = 0;
@@ -185,7 +188,9 @@ class Aggregator : public BaseAggregator
185188
uint32_t count_p_all;
186189
uint32_t count_b_all;
187190
uint32_t count_p_dec_err;
188-
uint32_t count_p_dec_ok;
191+
uint32_t count_p_session;
192+
uint32_t count_p_data;
193+
std::set<uint32_t> count_p_uniq;
189194
uint32_t count_p_fec_recovered;
190195
uint32_t count_p_lost;
191196
uint32_t count_p_bad;

wfb_ng/cli.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,11 @@ def draw_rx(self, attrs):
175175
def _norm(l):
176176
return (1000 * l[0] // self.log_interval, l[1])
177177

178+
diversity = p['data'][0] / p['uniq'][0] if p['uniq'][0] > 0 else 0
179+
178180
msg_l = (('{recv} %4d$ (%d)' % _norm(p['all']), 0),
179181
('{udp} %4d$ (%d)' % _norm(p['out']), 0),
182+
('sess %4d$ (%d)' % _norm(p['session']), 0),
180183
('fec_r %4d$ (%d)' % _norm(p['fec_rec']), curses.A_REVERSE if p['fec_rec'][0] else 0),
181184
('lost %4d$ (%d)' % _norm(p['lost']), curses.A_REVERSE if p['lost'][0] else 0),
182185
('d_err %4d$ (%d)' % _norm(p['dec_err']), curses.A_REVERSE if p['dec_err'][0] else 0),
@@ -193,7 +196,9 @@ def _norm(l):
193196
human_rate(1000 * p['out_bytes'][0] / self.log_interval))
194197

195198
if session_d:
196-
flow_str += '{FEC:} %(fec_k)d/%(fec_n)d' % (session_d)
199+
flow_str += '{FEC:} %(fec_k)d/%(fec_n)d ' % (session_d)
200+
201+
flow_str += '{Diversity:} %.2f' % (diversity,)
197202

198203
addstr_markup(window, 0, 20, flow_str)
199204

@@ -205,15 +210,17 @@ def _norm(l):
205210
lpad = ''
206211
rpad = ''
207212

208-
addstr_markup(window, 2, 20, '{Freq MCS BW %s[ANT]%s pkt/s} {RSSI} [dBm] {SNR} [dB]' % (lpad, rpad))
213+
addstr_markup(window, 2, 20, '{Freq MCS BW %s[ANT]%s pkt/s dloss} {RSSI} [dBm] {SNR} [dB]' % (lpad, rpad))
209214
for y, (((freq, mcs_index, bandwith), ant_id), v) in enumerate(sorted(stats_d.items()), 3):
210215
pkt_s, rssi_min, rssi_avg, rssi_max, snr_min, snr_avg, snr_max = v
211216
if y < ymax:
212217
active_tx = ((ant_id >> 8) == tx_wlan)
213-
addstr_markup(window, y, 20, '%04d %3d %2d %s%s%s %4d %3d < {%3d} < %3d %3d < {%3d} < %3d' % \
218+
diff_loss = max(p['uniq'][0] - pkt_s, 0)
219+
addstr_markup(window, y, 20, '%04d %3d %2d %s%s%s %4d %s%4d%s %3d < {%3d} < %3d %3d < {%3d} < %3d' % \
214220
(freq, mcs_index, bandwith,
215221
'{' if active_tx else '', format_ant(ant_id), '}' if active_tx else '',
216222
1000 * pkt_s // self.log_interval,
223+
'{' if diff_loss else '', 1000 * diff_loss // self.log_interval, '}' if diff_loss else '',
217224
rssi_min, rssi_avg, rssi_max,
218225
snr_min, snr_avg, snr_max), 0 if active_tx else curses.A_DIM)
219226
else:

wfb_ng/protocols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def lineReceived(self, line):
409409
if len(cols) != 3:
410410
raise BadTelemetry()
411411

412-
k_tuple = ('all', 'all_bytes', 'dec_err', 'dec_ok', 'fec_rec', 'lost', 'bad', 'out', 'out_bytes')
412+
k_tuple = ('all', 'all_bytes', 'dec_err', 'session', 'data', 'uniq', 'fec_rec', 'lost', 'bad', 'out', 'out_bytes')
413413
counters = tuple(int(i) for i in cols[2].split(':'))
414414
assert len(counters) == len(k_tuple)
415415

0 commit comments

Comments
 (0)