From 176770eef5f750c242ba7d769130dc05bd91323c Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Sat, 4 Jan 2025 16:16:39 +0100 Subject: [PATCH] l2udptest_client: Improve code readability; only count valid data in statistics --- impl/test/layer2_over_udp/l2udptest_client.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/impl/test/layer2_over_udp/l2udptest_client.c b/impl/test/layer2_over_udp/l2udptest_client.c index 5a5e681..cccdcbc 100644 --- a/impl/test/layer2_over_udp/l2udptest_client.c +++ b/impl/test/layer2_over_udp/l2udptest_client.c @@ -408,10 +408,18 @@ int main(void) bool tx_request_received = false; result_t result = connection_handle_packet(&l2conn, packetbuf, ret, &data_packet, &tx_request_received); - may_tx = may_tx || tx_request_received; + + // Switch to TX when a packet with tx_request=1 was decoded successfully. + // Note that this even triggers if the packet is out of sequence (but not for corrupted packets). + if(tx_request_received) { + may_tx = true; + } + switch(result) { case OK: + // update statistics m_rx_stats.successful_decodes++; + total_bytes += ret; if(data_packet.payload_len != 0) { rx_data_to_tun(&data_packet); @@ -436,8 +444,6 @@ int main(void) break; } - total_bytes += ret; - uint64_t new = get_hires_time(); if(new >= next_stats_print_time) { double rate = total_bytes * 1e9 / (new - old);