From d908c1670228110bc7f2c02a3600020bef5b8170 Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Sat, 22 Feb 2025 21:31:12 +0100 Subject: [PATCH] test_connection: verify correct seq. number overflow for incoming packets --- impl/test/unittest/test_connection.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/impl/test/unittest/test_connection.c b/impl/test/unittest/test_connection.c index 23c9343..a119d5d 100644 --- a/impl/test/unittest/test_connection.c +++ b/impl/test/unittest/test_connection.c @@ -285,5 +285,32 @@ int main(void) ASSERT_STATE(expected_state, conn); + LOG(LVL_INFO, "Generating 15 packets starting from the expected sequence number (4)."); + LOG(LVL_INFO, "Reception must resume correctly and all packets must be accepted."); + + for(size_t i = 0; i < 15; i++) { + // build connection parameters packet + header.dst_addr = dut_address; + header.src_addr = peer_address; + header.msg_type = L2_MSG_TYPE_DATA; + header.rx_seq_nr = 0; + header.tx_seq_nr = (4+i) % 16; // sequence numbers are valid from 0 to 15 + header.tx_request = i == 14; + + static_payload[0] = L2_PAYLOAD_TYPE_IPV4; + static_payload[1] = i; + + payload_len = 2; + + packet_len = layer2_encode_packet(&header, static_payload, payload_len, packet_buf, sizeof(packet_buf)); + + result_t result = connection_handle_packet(&conn, packet_buf, packet_len, &data_packet, &tx_req_rcvd); + + ASSERT_RESULT(OK, result); + } + + expected_state.next_expected_seq = 3; + ASSERT_STATE(expected_state, conn); + LOG(LVL_INFO, ">>> All assertions successful."); }