From 6b2b0f13609e852251ff65aa9acc53be76214ddb Mon Sep 17 00:00:00 2001 From: Evgeny Date: Thu, 11 Jun 2026 09:55:30 +0300 Subject: [PATCH] etcp: per-link acked bytes/packets counters + BBR debug logging - Add acked_bytes/acked_packets to struct ETCP_LINK (init, reset, increment per ACK) - Add DEBUG_CATEGORY_BBR (23) for BBR-specific debug output - Add BBR input/output DEBUG_DEBUG around bbr_main call in etcp_ack_recv - Add "bbr" category name to debug_config and etcpmon GUI --- lib/debug_config.c | 1 + lib/debug_config.h | 3 ++- src/etcp.c | 20 ++++++++++++++++++-- src/etcp_connections.c | 2 ++ src/etcp_connections.h | 2 ++ tools/etcpmon/etcpmon_gui.c | 2 +- 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/debug_config.c b/lib/debug_config.c index ad1b1c4a..5e954f8e 100644 --- a/lib/debug_config.c +++ b/lib/debug_config.c @@ -127,6 +127,7 @@ static const struct { {"nat", DEBUG_CATEGORY_NAT}, {"keepalive", DEBUG_CATEGORY_KEEPALIVE}, {"etcp_route", DEBUG_CATEGORY_ETCPROUTE}, + {"bbr", DEBUG_CATEGORY_BBR}, {"all", DEBUG_CATEGORY_ALL}, {NULL, DEBUG_CATEGORY_NONE} }; diff --git a/lib/debug_config.h b/lib/debug_config.h index 6fb6c748..8808de92 100644 --- a/lib/debug_config.h +++ b/lib/debug_config.h @@ -60,7 +60,8 @@ typedef int debug_category_t; #define DEBUG_CATEGORY_NAT 20 // EIM NAT module #define DEBUG_CATEGORY_KEEPALIVE 21 // Link keepalive logic #define DEBUG_CATEGORY_ETCPROUTE 22 // ETCP routing -#define DEBUG_CATEGORY_COUNT 23 // Total number of categories +#define DEBUG_CATEGORY_BBR 23 // BBR congestion control +#define DEBUG_CATEGORY_COUNT 24 // Total number of categories #define DEBUG_CATEGORY_ALL (-1) // special value for all categories /* Debug configuration structure */ diff --git a/src/etcp.c b/src/etcp.c index a0dc958c..7f15983a 100644 --- a/src/etcp.c +++ b/src/etcp.c @@ -394,6 +394,8 @@ void etcp_conn_reset(struct ETCP_CONN* etcp) { l->inflight_bytes = 0; l->inflight_packets = 0; l->delivered_bytes = 0; + l->acked_bytes = 0; + l->acked_packets = 0; l->last_ack_time_tb = get_time_tb(); l = l->next; } @@ -1243,14 +1245,28 @@ void etcp_ack_recv(struct ETCP_CONN* etcp, uint32_t seq, uint16_t ts, uint16_t d link->delivered_bytes += rs.delivered; link->last_ack_time_tb = now_tb; - uint32_t new_cwnd = link->inflight_lim_bytes; - uint32_t new_pacing = link->bbr_pacing_rate; + DEBUG_DEBUG(DEBUG_CATEGORY_BBR, "[L%u] BBR in: seq=%u del=%u iv=%uus rtt=%uus pri=%u infl=%u lost=%d app=%d cwnd=%u", + link->local_link_id, seq, rs.delivered, rs.interval_us, rs.rtt_us, + rs.prior_delivered, rs.tx_in_flight, rs.lost, rs.is_app_limited, + link->inflight_lim_bytes); + + uint32_t old_cwnd = link->inflight_lim_bytes; + uint32_t old_pacing = link->bbr_pacing_rate; + uint32_t new_cwnd = old_cwnd; + uint32_t new_pacing = old_pacing; bbr_main(link->bbr, &rs, &new_cwnd, &new_pacing, link->mtu, link->inflight_bytes, (link->inflight_bytes >= link->inflight_lim_bytes)); etcp_link_update_inflight_lim(link, new_cwnd); link->bbr_pacing_rate = new_pacing; link->bandwidth = (uint32_t)((uint64_t)new_pacing * 8 / 1000); link->bbr_loss_since_ack = 0; + + DEBUG_DEBUG(DEBUG_CATEGORY_BBR, "[L%u] BBR out: cwnd %u→%u pace %u→%u bw=%uK mode=%d cyc=%d infl=%u", + link->local_link_id, old_cwnd, new_cwnd, old_pacing, new_pacing, + link->bandwidth, link->bbr->mode, link->bbr->cycle_idx, link->inflight_bytes); + + link->acked_bytes += acked_pkt->ll.len; + link->acked_packets++; } diff --git a/src/etcp_connections.c b/src/etcp_connections.c index 2d52705f..b78ad0c5 100644 --- a/src/etcp_connections.c +++ b/src/etcp_connections.c @@ -795,6 +795,8 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn link->burst_target_bdp = 0; link->delivered_bytes = 0; + link->acked_bytes = 0; + link->acked_packets = 0; link->last_ack_time_tb = get_time_tb(); link->bbr_pacing_rate = 0; link->bbr_loss_since_ack = 0; diff --git a/src/etcp_connections.h b/src/etcp_connections.h index 5fb2c0e4..638d04e7 100644 --- a/src/etcp_connections.h +++ b/src/etcp_connections.h @@ -182,6 +182,8 @@ struct ETCP_LINK { size_t total_encrypted; size_t total_decrypted; uint32_t total_retransmissions; + uint64_t acked_bytes; // подтверждённых байт на этом линке + uint64_t acked_packets; // подтверждённых пакетов на этом линке uint16_t rtt_last; // round trip (время отправки + приёма) uint32_t jitter; // Current jitter [>>16] x0.1 ms diff --git a/tools/etcpmon/etcpmon_gui.c b/tools/etcpmon/etcpmon_gui.c index aa831ebc..5b556db8 100644 --- a/tools/etcpmon/etcpmon_gui.c +++ b/tools/etcpmon/etcpmon_gui.c @@ -750,7 +750,7 @@ static void CreateControls(struct etcpmon_app* app) { "UASYNC","LL_QUEUE","CONNECTION","ETCP","CRYPTO", "MEMORY","TIMING","CONFIG","TUN","ROUTING", "TIMERS","NORMALIZER","BGP","SOCKET","CONTROL", - "DUMP","TRAFFIC","DEBUG_CAT","GENERAL","NAT","KEEPALIVE","ETCPROUTE" + "DUMP","TRAFFIC","DEBUG_CAT","GENERAL","NAT","KEEPALIVE","ETCPROUTE","BBR" }; int ncat = sizeof(cat_names) / sizeof(cat_names[0]); app->debug_cat_count = ncat;