mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-11-18 20:10:53 +00:00
added unit tests for data-after-FIN
This commit is contained in:
parent
bcfe3dacc6
commit
7524f9006e
@ -526,6 +526,220 @@ START_TEST(test_tcp_recv_ooseq_overrun_rxwin)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static void
|
||||
check_rx_counters(struct tcp_pcb *pcb, struct test_tcp_counters *counters, u32_t exp_close_calls, u32_t exp_rx_calls,
|
||||
u32_t exp_rx_bytes, u32_t exp_err_calls, int exp_oos_count, int exp_oos_len)
|
||||
{
|
||||
int oos_len;
|
||||
EXPECT(counters->close_calls == exp_close_calls);
|
||||
EXPECT(counters->recv_calls == exp_rx_calls);
|
||||
EXPECT(counters->recved_bytes == exp_rx_bytes);
|
||||
EXPECT(counters->err_calls == exp_err_calls);
|
||||
/* check that pbuf is queued in ooseq */
|
||||
EXPECT_OOSEQ(tcp_oos_count(pcb) == exp_oos_count);
|
||||
oos_len = tcp_oos_tcplen(pcb);
|
||||
EXPECT_OOSEQ(exp_oos_len == oos_len);
|
||||
}
|
||||
|
||||
/* this test uses 4 packets:
|
||||
* - data (len=TCP_MSS)
|
||||
* - FIN
|
||||
* - data after FIN (len=1) (invalid)
|
||||
* - 2nd FIN (invalid)
|
||||
*
|
||||
* the parameter 'delay_packet' is a bitmask that choses which on these packets is ooseq
|
||||
*/
|
||||
static void test_tcp_recv_ooseq_double_FINs(int delay_packet)
|
||||
{
|
||||
int i, k;
|
||||
struct test_tcp_counters counters;
|
||||
struct tcp_pcb* pcb;
|
||||
struct pbuf *p_normal_fin, *p_data_after_fin, *p, *p_2nd_fin_ooseq;
|
||||
ip_addr_t remote_ip, local_ip;
|
||||
u16_t remote_port = 0x100, local_port = 0x101;
|
||||
struct netif netif;
|
||||
u32_t exp_rx_calls = 0, exp_rx_bytes = 0, exp_close_calls = 0, exp_oos_pbufs = 0, exp_oos_tcplen = 0;
|
||||
int first_dropped = 0xff;
|
||||
int last_dropped = 0;
|
||||
|
||||
for(i = 0; i < sizeof(data_full_wnd); i++) {
|
||||
data_full_wnd[i] = (char)i;
|
||||
}
|
||||
|
||||
/* initialize local vars */
|
||||
memset(&netif, 0, sizeof(netif));
|
||||
IP4_ADDR(&local_ip, 192, 168, 1, 1);
|
||||
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
|
||||
/* initialize counter struct */
|
||||
memset(&counters, 0, sizeof(counters));
|
||||
counters.expected_data_len = TCP_WND;
|
||||
counters.expected_data = data_full_wnd;
|
||||
|
||||
/* create and initialize the pcb */
|
||||
pcb = test_tcp_new_counters_pcb(&counters);
|
||||
EXPECT_RET(pcb != NULL);
|
||||
tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
|
||||
pcb->rcv_nxt = 0x8000;
|
||||
|
||||
/* create segments */
|
||||
p = tcp_create_rx_segment(pcb, &data_full_wnd[0], TCP_MSS, 0, 0, TCP_ACK);
|
||||
p_normal_fin = tcp_create_rx_segment(pcb, NULL, 0, TCP_MSS, 0, TCP_ACK|TCP_FIN);
|
||||
k = 1;
|
||||
p_data_after_fin = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS+1], k, TCP_MSS+1, 0, TCP_ACK);
|
||||
p_2nd_fin_ooseq = tcp_create_rx_segment(pcb, NULL, 0, TCP_MSS+1+k, 0, TCP_ACK|TCP_FIN);
|
||||
|
||||
if(delay_packet & 1) {
|
||||
/* drop normal data */
|
||||
first_dropped = 1;
|
||||
last_dropped = 1;
|
||||
} else {
|
||||
/* send normal data */
|
||||
test_tcp_input(p, &netif);
|
||||
exp_rx_calls++;
|
||||
exp_rx_bytes += TCP_MSS;
|
||||
}
|
||||
/* check if counters are as expected */
|
||||
check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
|
||||
|
||||
if(delay_packet & 2) {
|
||||
/* drop FIN */
|
||||
if(first_dropped > 2) {
|
||||
first_dropped = 2;
|
||||
}
|
||||
last_dropped = 2;
|
||||
} else {
|
||||
/* send FIN */
|
||||
test_tcp_input(p_normal_fin, &netif);
|
||||
if (first_dropped < 2) {
|
||||
/* already dropped packets, this one is ooseq */
|
||||
exp_oos_pbufs++;
|
||||
exp_oos_tcplen++;
|
||||
} else {
|
||||
/* inseq */
|
||||
exp_close_calls++;
|
||||
}
|
||||
}
|
||||
/* check if counters are as expected */
|
||||
check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
|
||||
|
||||
if(delay_packet & 4) {
|
||||
/* drop data-after-FIN */
|
||||
if(first_dropped > 3) {
|
||||
first_dropped = 3;
|
||||
}
|
||||
last_dropped = 3;
|
||||
} else {
|
||||
/* send data-after-FIN */
|
||||
test_tcp_input(p_data_after_fin, &netif);
|
||||
if (first_dropped < 3) {
|
||||
/* already dropped packets, this one is ooseq */
|
||||
if (delay_packet & 2) {
|
||||
/* correct FIN was ooseq */
|
||||
exp_oos_pbufs++;
|
||||
exp_oos_tcplen += k;
|
||||
}
|
||||
} else {
|
||||
/* inseq: no change */
|
||||
}
|
||||
}
|
||||
/* check if counters are as expected */
|
||||
check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
|
||||
|
||||
if(delay_packet & 8) {
|
||||
/* drop 2nd-FIN */
|
||||
if(first_dropped > 4) {
|
||||
first_dropped = 4;
|
||||
}
|
||||
last_dropped = 4;
|
||||
} else {
|
||||
/* send 2nd-FIN */
|
||||
test_tcp_input(p_2nd_fin_ooseq, &netif);
|
||||
if (first_dropped < 3) {
|
||||
/* already dropped packets, this one is ooseq */
|
||||
if (delay_packet & 2) {
|
||||
/* correct FIN was ooseq */
|
||||
exp_oos_pbufs++;
|
||||
exp_oos_tcplen++;
|
||||
}
|
||||
} else {
|
||||
/* inseq: no change */
|
||||
}
|
||||
}
|
||||
/* check if counters are as expected */
|
||||
check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
|
||||
|
||||
if(delay_packet & 1) {
|
||||
/* dropped normal data before */
|
||||
test_tcp_input(p, &netif);
|
||||
exp_rx_calls++;
|
||||
exp_rx_bytes += TCP_MSS;
|
||||
if((delay_packet & 2) == 0) {
|
||||
/* normal FIN was NOT delayed */
|
||||
exp_close_calls++;
|
||||
exp_oos_pbufs = exp_oos_tcplen = 0;
|
||||
}
|
||||
}
|
||||
/* check if counters are as expected */
|
||||
check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
|
||||
|
||||
if(delay_packet & 2) {
|
||||
/* dropped normal FIN before */
|
||||
test_tcp_input(p_normal_fin, &netif);
|
||||
exp_close_calls++;
|
||||
exp_oos_pbufs = exp_oos_tcplen = 0;
|
||||
}
|
||||
/* check if counters are as expected */
|
||||
check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
|
||||
|
||||
if(delay_packet & 4) {
|
||||
/* dropped data-after-FIN before */
|
||||
test_tcp_input(p_data_after_fin, &netif);
|
||||
}
|
||||
/* check if counters are as expected */
|
||||
check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
|
||||
|
||||
if(delay_packet & 8) {
|
||||
/* dropped 2nd-FIN before */
|
||||
test_tcp_input(p_2nd_fin_ooseq, &netif);
|
||||
}
|
||||
/* check if counters are as expected */
|
||||
check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
|
||||
|
||||
/* check that ooseq data has been dumped */
|
||||
EXPECT(pcb->ooseq == NULL);
|
||||
|
||||
/* make sure the pcb is freed */
|
||||
EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 1);
|
||||
tcp_abort(pcb);
|
||||
EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 0);
|
||||
}
|
||||
|
||||
/** create multiple segments and pass them to tcp_input with the first segment missing
|
||||
* to simulate overruning the rxwin with ooseq queueing enabled */
|
||||
#define FIN_TEST(name, num) \
|
||||
START_TEST(name) \
|
||||
{ \
|
||||
LWIP_UNUSED_ARG(_i); \
|
||||
test_tcp_recv_ooseq_double_FINs(num); \
|
||||
} \
|
||||
END_TEST
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_0, 0)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_1, 1)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_2, 2)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_3, 3)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_4, 4)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_5, 5)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_6, 6)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_7, 7)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_8, 8)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_9, 9)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_10, 10)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_11, 11)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_12, 12)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_13, 13)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_14, 14)
|
||||
FIN_TEST(test_tcp_recv_ooseq_double_FIN_15, 15)
|
||||
|
||||
|
||||
/** Create the suite including all tests for this module */
|
||||
Suite *
|
||||
@ -535,6 +749,22 @@ tcp_oos_suite(void)
|
||||
test_tcp_recv_ooseq_FIN_OOSEQ,
|
||||
test_tcp_recv_ooseq_FIN_INSEQ,
|
||||
test_tcp_recv_ooseq_overrun_rxwin,
|
||||
test_tcp_recv_ooseq_double_FIN_0,
|
||||
test_tcp_recv_ooseq_double_FIN_1,
|
||||
test_tcp_recv_ooseq_double_FIN_2,
|
||||
test_tcp_recv_ooseq_double_FIN_3,
|
||||
test_tcp_recv_ooseq_double_FIN_4,
|
||||
test_tcp_recv_ooseq_double_FIN_5,
|
||||
test_tcp_recv_ooseq_double_FIN_6,
|
||||
test_tcp_recv_ooseq_double_FIN_7,
|
||||
test_tcp_recv_ooseq_double_FIN_8,
|
||||
test_tcp_recv_ooseq_double_FIN_9,
|
||||
test_tcp_recv_ooseq_double_FIN_10,
|
||||
test_tcp_recv_ooseq_double_FIN_11,
|
||||
test_tcp_recv_ooseq_double_FIN_12,
|
||||
test_tcp_recv_ooseq_double_FIN_13,
|
||||
test_tcp_recv_ooseq_double_FIN_14,
|
||||
test_tcp_recv_ooseq_double_FIN_15
|
||||
};
|
||||
return create_suite("TCP_OOS", tests, sizeof(tests)/sizeof(TFun), tcp_oos_setup, tcp_oos_teardown);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user