l2udptest_client: only transmit after receiving a tx_request
All checks were successful
/ build-hamnet70 (push) Successful in 33s
/ build-doc (push) Successful in 16s
/ deploy-doc (push) Has been skipped

This commit is contained in:
Simon Ruderich 2025-01-02 09:03:46 +01:00
parent f3f0733a3f
commit cea8145946
4 changed files with 34 additions and 19 deletions

View file

@ -84,7 +84,7 @@ void connection_setup_incoming(connection_ctx_t *ctx)
} }
result_t connection_handle_packet(connection_ctx_t *ctx, const uint8_t *buf, size_t buf_len, layer2_data_packet_t *data_packet) result_t connection_handle_packet(connection_ctx_t *ctx, const uint8_t *buf, size_t buf_len, layer2_data_packet_t *data_packet, bool *tx_req_rcvd)
{ {
// check the connection state // check the connection state
switch(ctx->conn_state) { switch(ctx->conn_state) {
@ -144,7 +144,7 @@ result_t connection_handle_packet(connection_ctx_t *ctx, const uint8_t *buf, siz
const uint8_t *payload = buf + header_size; const uint8_t *payload = buf + header_size;
size_t payload_len = packet_size - header_size; size_t payload_len = packet_size - header_size;
return connection_handle_packet_prechecked(ctx, &header, payload, payload_len, data_packet); return connection_handle_packet_prechecked(ctx, &header, payload, payload_len, data_packet, tx_req_rcvd);
} }
static result_t handle_conn_mgmt( static result_t handle_conn_mgmt(
@ -205,7 +205,8 @@ result_t connection_handle_packet_prechecked(
connection_ctx_t *ctx, connection_ctx_t *ctx,
const layer2_packet_header_t *header, const layer2_packet_header_t *header,
const uint8_t *payload, size_t payload_len, const uint8_t *payload, size_t payload_len,
layer2_data_packet_t *data_packet) layer2_data_packet_t *data_packet,
bool *tx_req_rcvd)
{ {
data_packet->payload_type = L2_PAYLOAD_TYPE_INVALID; data_packet->payload_type = L2_PAYLOAD_TYPE_INVALID;
data_packet->payload_len = 0; data_packet->payload_len = 0;
@ -243,11 +244,14 @@ result_t connection_handle_packet_prechecked(
ctx->last_acked_seq = header->rx_seq_nr; ctx->last_acked_seq = header->rx_seq_nr;
*tx_req_rcvd = false;
switch(header->msg_type) { switch(header->msg_type) {
case L2_MSG_TYPE_EMPTY: case L2_MSG_TYPE_EMPTY:
LOG(LVL_DEBUG, "Empty packet: accepted ACK for %u.", ctx->last_acked_seq); LOG(LVL_DEBUG, "Empty packet: accepted ACK for %u.", ctx->last_acked_seq);
*tx_req_rcvd = header->tx_request;
// empty packets also reset the timeout timer // empty packets also reset the timeout timer
ctx->last_rx_time = get_hires_time(); ctx->last_rx_time = get_hires_time();
@ -263,6 +267,7 @@ result_t connection_handle_packet_prechecked(
return OK; return OK;
case L2_MSG_TYPE_DATA: case L2_MSG_TYPE_DATA:
*tx_req_rcvd = header->tx_request;
break; break;
default: default:

View file

@ -89,13 +89,15 @@ void connection_setup_incoming(connection_ctx_t *ctx);
* \param[in] buf Pointer to the packet data. * \param[in] buf Pointer to the packet data.
* \param[in] buf_len Length of the packet. * \param[in] buf_len Length of the packet.
* \param[out] data_packet Structure will be filled with a received data packet. * \param[out] data_packet Structure will be filled with a received data packet.
* \param[out] tx_req_rcvd Was the tx_request flag set in the decoded packet.
* \returns A result code from the packet handling procedure. * \returns A result code from the packet handling procedure.
*/ */
result_t connection_handle_packet( result_t connection_handle_packet(
connection_ctx_t *ctx, connection_ctx_t *ctx,
const uint8_t *buf, const uint8_t *buf,
size_t buf_len, size_t buf_len,
layer2_data_packet_t *data_packet); layer2_data_packet_t *data_packet,
bool *tx_req_rcvd);
/*!\brief Handle a received packet where the header has already been decoded. /*!\brief Handle a received packet where the header has already been decoded.
* *
@ -109,13 +111,15 @@ result_t connection_handle_packet(
* \param[in] payload Pointer to the payload data. * \param[in] payload Pointer to the payload data.
* \param[in] payload_len Length of the payload data. * \param[in] payload_len Length of the payload data.
* \param[out] data_packet Structure will be filled with a received data packet. * \param[out] data_packet Structure will be filled with a received data packet.
* \param[out] tx_req_rcvd Was the tx_request flag set in the decoded packet.
* \returns A result code from the packet handling procedure. * \returns A result code from the packet handling procedure.
*/ */
result_t connection_handle_packet_prechecked( result_t connection_handle_packet_prechecked(
connection_ctx_t *ctx, connection_ctx_t *ctx,
const layer2_packet_header_t *header, const layer2_packet_header_t *header,
const uint8_t *payload, size_t payload_len, const uint8_t *payload, size_t payload_len,
layer2_data_packet_t *data_packet); layer2_data_packet_t *data_packet,
bool *tx_req_rcvd);
/*!\brief Return the sequence number expected next by our side. /*!\brief Return the sequence number expected next by our side.
*/ */

View file

@ -158,8 +158,9 @@ result_t digipeater_handle_packet(
connection_list_entry_t *head = connection_list_get_head(&ctx->conn_list); connection_list_entry_t *head = connection_list_get_head(&ctx->conn_list);
if(head) { if(head) {
connection_ctx_t *current_conn = &head->connection; connection_ctx_t *current_conn = &head->connection;
bool tx_request_received = false;
result = connection_handle_packet_prechecked( result = connection_handle_packet_prechecked(
current_conn, &header, payload, payload_len, data_packet); current_conn, &header, payload, payload_len, data_packet, &tx_request_received);
} else { } else {
LOG(LVL_WARN, "Digipeater in CONN state, but there is no active connection! Packet dropped."); LOG(LVL_WARN, "Digipeater in CONN state, but there is no active connection! Packet dropped.");
result = OK; result = OK;

View file

@ -141,7 +141,8 @@ result_t connect_to_digipeater(connection_ctx_t *conn)
} }
layer2_data_packet_t data_packet; layer2_data_packet_t data_packet;
result_t err_code = connection_handle_packet(conn, packetbuf, ret, &data_packet); bool tx_request_received = false;
result_t err_code = connection_handle_packet(conn, packetbuf, ret, &data_packet, &tx_request_received);
switch(err_code) { switch(err_code) {
case OK: case OK:
@ -287,14 +288,6 @@ int main(void)
RESULT_CHECK(connect_to_digipeater(&l2conn)); RESULT_CHECK(connect_to_digipeater(&l2conn));
while(m_running) { while(m_running) {
connection_evt_t evt;
RESULT_CHECK(connection_maintain(&l2conn, &evt));
if(evt == CONN_EVT_TIMEOUT) {
LOG(LVL_ERR, "Connection timed out. Shutting down.");
break;
}
// fill the TX queue from the TUN device // fill the TX queue from the TUN device
while(connection_can_enqueue_packet(&l2conn)) { while(connection_can_enqueue_packet(&l2conn)) {
int ret = poll(&pfd_tun, 1, 0 /* timeout */); int ret = poll(&pfd_tun, 1, 0 /* timeout */);
@ -376,10 +369,17 @@ int main(void)
LOG(LVL_DEBUG, "Burst finished: %zd packets sent.", burst_len); LOG(LVL_DEBUG, "Burst finished: %zd packets sent.", burst_len);
} }
// make sure the receiver runs for a minimum amount of time bool may_tx = false;
block_tx_for(TX_SWITCH_BACKOFF_AFTER_RX_ON_MS); while(!may_tx) {
connection_evt_t evt;
RESULT_CHECK(connection_maintain(&l2conn, &evt));
if(evt == CONN_EVT_TIMEOUT) {
LOG(LVL_ERR, "Connection timed out. Shutting down.");
m_running = false;
break;
}
while(get_hires_time() < next_tx_switch_time) {
// ** Receive signal ** // ** Receive signal **
int ret = poll(&pfd_bcast, 1, 10); int ret = poll(&pfd_bcast, 1, 10);
@ -406,7 +406,9 @@ int main(void)
layer2_data_packet_t data_packet; layer2_data_packet_t data_packet;
result_t result = connection_handle_packet(&l2conn, packetbuf, ret, &data_packet); 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(result) { switch(result) {
case OK: case OK:
m_rx_stats.successful_decodes++; m_rx_stats.successful_decodes++;
@ -456,6 +458,9 @@ int main(void)
fprintf(stderr, "r"); fprintf(stderr, "r");
} }
// give the other side some time to switch to rx
sleep_until(next_tx_switch_time);
} }
// ** Cleanup ** // ** Cleanup **