test_connection: test handling of (lost) data packets
All checks were successful
/ build-hamnet70 (push) Successful in 37s
/ build-doc (push) Successful in 17s
/ deploy-doc (push) Has been skipped

This commit is contained in:
Thomas Kolb 2025-02-22 21:01:37 +01:00
commit 84d15331c2

View file

@ -233,5 +233,57 @@ int main(void)
ASSERT_STATE(expected_state, conn);
LOG(LVL_INFO, ">>> Checking data packet reception and lost packet handling.");
LOG(LVL_INFO, "Generating a burst of 5 packets where the 4th is lost.");
for(size_t i = 0; i < 5; 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 = i+1; // 0 were Connection Parameters, 1 is the first data packet
header.tx_request = (i == 4);
static_payload[0] = L2_PAYLOAD_TYPE_IPV4;
static_payload[1] = i;
static_payload[i+2] = i;
payload_len = i+3;
packet_len = layer2_encode_packet(&header, static_payload, payload_len, packet_buf, sizeof(packet_buf));
if(i == 3) {
// packet 4 is corrupted
packet_buf[3] = 0x42;
}
result_t result = connection_handle_packet(&conn, packet_buf, packet_len, &data_packet, &tx_req_rcvd);
const static result_t EXPECTED_RESULTS[5] = {
OK, OK, OK, ERR_INTEGRITY, ERR_SEQUENCE
};
ASSERT_RESULT(EXPECTED_RESULTS[i], result);
if(result == OK) {
LOG(LVL_DEBUG, "Checking decode result for packet %zu (%zu bytes)", i, payload_len-1);
// check that payload length and type are decoded correctly
ASSERT_EQUAL_UINT(payload_len-1, data_packet.payload_len);
ASSERT_EQUAL_UINT(L2_PAYLOAD_TYPE_IPV4, data_packet.payload_type);
// verify the complete packet data
for(size_t k = 0; k < payload_len-1; k++) {
ASSERT_EQUAL_UINT(static_payload[k+1], data_packet.payload[k]);
}
}
}
// after the connection was accepted, the connection must switch to established state.
expected_state.next_expected_seq = 4;
ASSERT_STATE(expected_state, conn);
LOG(LVL_INFO, ">>> All assertions successful.");
}