1 #include "test_tcp_oos.h"
2
3 #include "lwip/priv/tcp_priv.h"
4 #include "lwip/stats.h"
5 #include "tcp_helper.h"
6
7 #if !LWIP_STATS || !TCP_STATS || !MEMP_STATS
8 #error "This tests needs TCP- and MEMP-statistics enabled"
9 #endif
10 #if !TCP_QUEUE_OOSEQ
11 #error "This tests needs TCP_QUEUE_OOSEQ enabled"
12 #endif
13
14 /** CHECK_SEGMENTS_ON_OOSEQ:
15 * 1: check count, seqno and len of segments on pcb->ooseq (strict)
16 * 0: only check that bytes are received in correct order (less strict) */
17 #define CHECK_SEGMENTS_ON_OOSEQ 1
18
19 #if CHECK_SEGMENTS_ON_OOSEQ
20 #define EXPECT_OOSEQ(x) EXPECT(x)
21 #else
22 #define EXPECT_OOSEQ(x)
23 #endif
24
25 /* helper functions */
26
27 /** Get the numbers of segments on the ooseq list */
tcp_oos_count(struct tcp_pcb * pcb)28 static int tcp_oos_count(struct tcp_pcb* pcb)
29 {
30 int num = 0;
31 struct tcp_seg* seg = pcb->ooseq;
32 while(seg != NULL) {
33 num++;
34 seg = seg->next;
35 }
36 return num;
37 }
38
39 #if TCP_OOSEQ_MAX_PBUFS && (TCP_OOSEQ_MAX_PBUFS < ((TCP_WND / TCP_MSS) + 1)) && (PBUF_POOL_BUFSIZE >= (TCP_MSS + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))
40 /** Get the numbers of pbufs on the ooseq list */
tcp_oos_pbuf_count(struct tcp_pcb * pcb)41 static int tcp_oos_pbuf_count(struct tcp_pcb* pcb)
42 {
43 int num = 0;
44 struct tcp_seg* seg = pcb->ooseq;
45 while(seg != NULL) {
46 num += pbuf_clen(seg->p);
47 seg = seg->next;
48 }
49 return num;
50 }
51 #endif
52
53 /** Get the seqno of a segment (by index) on the ooseq list
54 *
55 * @param pcb the pcb to check for ooseq segments
56 * @param seg_index index of the segment on the ooseq list
57 * @return seqno of the segment
58 */
59 static u32_t
tcp_oos_seg_seqno(struct tcp_pcb * pcb,int seg_index)60 tcp_oos_seg_seqno(struct tcp_pcb* pcb, int seg_index)
61 {
62 int num = 0;
63 struct tcp_seg* seg = pcb->ooseq;
64
65 /* then check the actual segment */
66 while(seg != NULL) {
67 if(num == seg_index) {
68 return seg->tcphdr->seqno;
69 }
70 num++;
71 seg = seg->next;
72 }
73 fail();
74 return 0;
75 }
76
77 /** Get the tcplen (datalen + SYN/FIN) of a segment (by index) on the ooseq list
78 *
79 * @param pcb the pcb to check for ooseq segments
80 * @param seg_index index of the segment on the ooseq list
81 * @return tcplen of the segment
82 */
83 static int
tcp_oos_seg_tcplen(struct tcp_pcb * pcb,int seg_index)84 tcp_oos_seg_tcplen(struct tcp_pcb* pcb, int seg_index)
85 {
86 int num = 0;
87 struct tcp_seg* seg = pcb->ooseq;
88
89 /* then check the actual segment */
90 while(seg != NULL) {
91 if(num == seg_index) {
92 return TCP_TCPLEN(seg);
93 }
94 num++;
95 seg = seg->next;
96 }
97 fail();
98 return -1;
99 }
100
101 /** Get the tcplen (datalen + SYN/FIN) of all segments on the ooseq list
102 *
103 * @param pcb the pcb to check for ooseq segments
104 * @return tcplen of all segment
105 */
106 static int
tcp_oos_tcplen(struct tcp_pcb * pcb)107 tcp_oos_tcplen(struct tcp_pcb* pcb)
108 {
109 int len = 0;
110 struct tcp_seg* seg = pcb->ooseq;
111
112 /* then check the actual segment */
113 while(seg != NULL) {
114 len += TCP_TCPLEN(seg);
115 seg = seg->next;
116 }
117 return len;
118 }
119
120 /* Setup/teardown functions */
121
122 static void
tcp_oos_setup(void)123 tcp_oos_setup(void)
124 {
125 tcp_remove_all();
126 }
127
128 static void
tcp_oos_teardown(void)129 tcp_oos_teardown(void)
130 {
131 tcp_remove_all();
132 netif_list = NULL;
133 netif_default = NULL;
134 }
135
136
137
138 /* Test functions */
139
140 /** create multiple segments and pass them to tcp_input in a wrong
141 * order to see if ooseq-caching works correctly
142 * FIN is received in out-of-sequence segments only */
START_TEST(test_tcp_recv_ooseq_FIN_OOSEQ)143 START_TEST(test_tcp_recv_ooseq_FIN_OOSEQ)
144 {
145 struct test_tcp_counters counters;
146 struct tcp_pcb* pcb;
147 struct pbuf *p_8_9, *p_4_8, *p_4_10, *p_2_14, *p_fin, *pinseq;
148 char data[] = {
149 1, 2, 3, 4,
150 5, 6, 7, 8,
151 9, 10, 11, 12,
152 13, 14, 15, 16};
153 ip_addr_t remote_ip, local_ip, netmask;
154 u16_t data_len;
155 u16_t remote_port = 0x100, local_port = 0x101;
156 struct netif netif;
157 LWIP_UNUSED_ARG(_i);
158
159 /* initialize local vars */
160 memset(&netif, 0, sizeof(netif));
161 IP_ADDR4(&local_ip, 192, 168, 1, 1);
162 IP_ADDR4(&remote_ip, 192, 168, 1, 2);
163 IP_ADDR4(&netmask, 255, 255, 255, 0);
164 test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
165 data_len = sizeof(data);
166 /* initialize counter struct */
167 memset(&counters, 0, sizeof(counters));
168 counters.expected_data_len = data_len;
169 counters.expected_data = data;
170
171 /* create and initialize the pcb */
172 pcb = test_tcp_new_counters_pcb(&counters);
173 EXPECT_RET(pcb != NULL);
174 tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
175
176 /* create segments */
177 /* pinseq is sent as last segment! */
178 pinseq = tcp_create_rx_segment(pcb, &data[0], 4, 0, 0, TCP_ACK);
179 /* p1: 8 bytes before FIN */
180 /* seqno: 8..16 */
181 p_8_9 = tcp_create_rx_segment(pcb, &data[8], 8, 8, 0, TCP_ACK|TCP_FIN);
182 /* p2: 4 bytes before p1, including the first 4 bytes of p1 (partly duplicate) */
183 /* seqno: 4..11 */
184 p_4_8 = tcp_create_rx_segment(pcb, &data[4], 8, 4, 0, TCP_ACK);
185 /* p3: same as p2 but 2 bytes longer */
186 /* seqno: 4..13 */
187 p_4_10 = tcp_create_rx_segment(pcb, &data[4], 10, 4, 0, TCP_ACK);
188 /* p4: 14 bytes before FIN, includes data from p1 and p2, plus partly from pinseq */
189 /* seqno: 2..15 */
190 p_2_14 = tcp_create_rx_segment(pcb, &data[2], 14, 2, 0, TCP_ACK);
191 /* FIN, seqno 16 */
192 p_fin = tcp_create_rx_segment(pcb, NULL, 0,16, 0, TCP_ACK|TCP_FIN);
193 EXPECT(pinseq != NULL);
194 EXPECT(p_8_9 != NULL);
195 EXPECT(p_4_8 != NULL);
196 EXPECT(p_4_10 != NULL);
197 EXPECT(p_2_14 != NULL);
198 EXPECT(p_fin != NULL);
199 if ((pinseq != NULL) && (p_8_9 != NULL) && (p_4_8 != NULL) && (p_4_10 != NULL) && (p_2_14 != NULL) && (p_fin != NULL)) {
200 /* pass the segment to tcp_input */
201 test_tcp_input(p_8_9, &netif);
202 /* check if counters are as expected */
203 EXPECT(counters.close_calls == 0);
204 EXPECT(counters.recv_calls == 0);
205 EXPECT(counters.recved_bytes == 0);
206 EXPECT(counters.err_calls == 0);
207 /* check ooseq queue */
208 EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
209 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 8);
210 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 9); /* includes FIN */
211
212 /* pass the segment to tcp_input */
213 test_tcp_input(p_4_8, &netif);
214 /* check if counters are as expected */
215 EXPECT(counters.close_calls == 0);
216 EXPECT(counters.recv_calls == 0);
217 EXPECT(counters.recved_bytes == 0);
218 EXPECT(counters.err_calls == 0);
219 /* check ooseq queue */
220 EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
221 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 4);
222 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 4);
223 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 8);
224 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 9); /* includes FIN */
225
226 /* pass the segment to tcp_input */
227 test_tcp_input(p_4_10, &netif);
228 /* check if counters are as expected */
229 EXPECT(counters.close_calls == 0);
230 EXPECT(counters.recv_calls == 0);
231 EXPECT(counters.recved_bytes == 0);
232 EXPECT(counters.err_calls == 0);
233 /* ooseq queue: unchanged */
234 EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
235 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 4);
236 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 4);
237 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 8);
238 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 9); /* includes FIN */
239
240 /* pass the segment to tcp_input */
241 test_tcp_input(p_2_14, &netif);
242 /* check if counters are as expected */
243 EXPECT(counters.close_calls == 0);
244 EXPECT(counters.recv_calls == 0);
245 EXPECT(counters.recved_bytes == 0);
246 EXPECT(counters.err_calls == 0);
247 /* check ooseq queue */
248 EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
249 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 2);
250 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 15); /* includes FIN */
251
252 /* pass the segment to tcp_input */
253 test_tcp_input(p_fin, &netif);
254 /* check if counters are as expected */
255 EXPECT(counters.close_calls == 0);
256 EXPECT(counters.recv_calls == 0);
257 EXPECT(counters.recved_bytes == 0);
258 EXPECT(counters.err_calls == 0);
259 /* ooseq queue: unchanged */
260 EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
261 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 2);
262 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 15); /* includes FIN */
263
264 /* pass the segment to tcp_input */
265 test_tcp_input(pinseq, &netif);
266 /* check if counters are as expected */
267 EXPECT(counters.close_calls == 1);
268 EXPECT(counters.recv_calls == 1);
269 EXPECT(counters.recved_bytes == data_len);
270 EXPECT(counters.err_calls == 0);
271 EXPECT(pcb->ooseq == NULL);
272 }
273
274 /* make sure the pcb is freed */
275 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
276 tcp_abort(pcb);
277 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
278 }
279 END_TEST
280
281
282 /** create multiple segments and pass them to tcp_input in a wrong
283 * order to see if ooseq-caching works correctly
284 * FIN is received IN-SEQUENCE at the end */
START_TEST(test_tcp_recv_ooseq_FIN_INSEQ)285 START_TEST(test_tcp_recv_ooseq_FIN_INSEQ)
286 {
287 struct test_tcp_counters counters;
288 struct tcp_pcb* pcb;
289 struct pbuf *p_1_2, *p_4_8, *p_3_11, *p_2_12, *p_15_1, *p_15_1a, *pinseq, *pinseqFIN;
290 char data[] = {
291 1, 2, 3, 4,
292 5, 6, 7, 8,
293 9, 10, 11, 12,
294 13, 14, 15, 16};
295 ip_addr_t remote_ip, local_ip, netmask;
296 u16_t data_len;
297 u16_t remote_port = 0x100, local_port = 0x101;
298 struct netif netif;
299 LWIP_UNUSED_ARG(_i);
300
301 /* initialize local vars */
302 memset(&netif, 0, sizeof(netif));
303 IP_ADDR4(&local_ip, 192, 168, 1, 1);
304 IP_ADDR4(&remote_ip, 192, 168, 1, 2);
305 IP_ADDR4(&netmask, 255, 255, 255, 0);
306 test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
307 data_len = sizeof(data);
308 /* initialize counter struct */
309 memset(&counters, 0, sizeof(counters));
310 counters.expected_data_len = data_len;
311 counters.expected_data = data;
312
313 /* create and initialize the pcb */
314 pcb = test_tcp_new_counters_pcb(&counters);
315 EXPECT_RET(pcb != NULL);
316 tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
317
318 /* create segments */
319 /* p1: 7 bytes - 2 before FIN */
320 /* seqno: 1..2 */
321 p_1_2 = tcp_create_rx_segment(pcb, &data[1], 2, 1, 0, TCP_ACK);
322 /* p2: 4 bytes before p1, including the first 4 bytes of p1 (partly duplicate) */
323 /* seqno: 4..11 */
324 p_4_8 = tcp_create_rx_segment(pcb, &data[4], 8, 4, 0, TCP_ACK);
325 /* p3: same as p2 but 2 bytes longer and one byte more at the front */
326 /* seqno: 3..13 */
327 p_3_11 = tcp_create_rx_segment(pcb, &data[3], 11, 3, 0, TCP_ACK);
328 /* p4: 13 bytes - 2 before FIN - should be ignored as contained in p1 and p3 */
329 /* seqno: 2..13 */
330 p_2_12 = tcp_create_rx_segment(pcb, &data[2], 12, 2, 0, TCP_ACK);
331 /* pinseq is the first segment that is held back to create ooseq! */
332 /* seqno: 0..3 */
333 pinseq = tcp_create_rx_segment(pcb, &data[0], 4, 0, 0, TCP_ACK);
334 /* p5: last byte before FIN */
335 /* seqno: 15 */
336 p_15_1 = tcp_create_rx_segment(pcb, &data[15], 1, 15, 0, TCP_ACK);
337 /* p6: same as p5, should be ignored */
338 p_15_1a= tcp_create_rx_segment(pcb, &data[15], 1, 15, 0, TCP_ACK);
339 /* pinseqFIN: last 2 bytes plus FIN */
340 /* only segment containing seqno 14 and FIN */
341 pinseqFIN = tcp_create_rx_segment(pcb, &data[14], 2, 14, 0, TCP_ACK|TCP_FIN);
342 EXPECT(pinseq != NULL);
343 EXPECT(p_1_2 != NULL);
344 EXPECT(p_4_8 != NULL);
345 EXPECT(p_3_11 != NULL);
346 EXPECT(p_2_12 != NULL);
347 EXPECT(p_15_1 != NULL);
348 EXPECT(p_15_1a != NULL);
349 EXPECT(pinseqFIN != NULL);
350 if ((pinseq != NULL) && (p_1_2 != NULL) && (p_4_8 != NULL) && (p_3_11 != NULL) && (p_2_12 != NULL)
351 && (p_15_1 != NULL) && (p_15_1a != NULL) && (pinseqFIN != NULL)) {
352 /* pass the segment to tcp_input */
353 test_tcp_input(p_1_2, &netif);
354 /* check if counters are as expected */
355 EXPECT(counters.close_calls == 0);
356 EXPECT(counters.recv_calls == 0);
357 EXPECT(counters.recved_bytes == 0);
358 EXPECT(counters.err_calls == 0);
359 /* check ooseq queue */
360 EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
361 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
362 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 2);
363
364 /* pass the segment to tcp_input */
365 test_tcp_input(p_4_8, &netif);
366 /* check if counters are as expected */
367 EXPECT(counters.close_calls == 0);
368 EXPECT(counters.recv_calls == 0);
369 EXPECT(counters.recved_bytes == 0);
370 EXPECT(counters.err_calls == 0);
371 /* check ooseq queue */
372 EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
373 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
374 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 2);
375 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 4);
376 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 8);
377
378 /* pass the segment to tcp_input */
379 test_tcp_input(p_3_11, &netif);
380 /* check if counters are as expected */
381 EXPECT(counters.close_calls == 0);
382 EXPECT(counters.recv_calls == 0);
383 EXPECT(counters.recved_bytes == 0);
384 EXPECT(counters.err_calls == 0);
385 /* check ooseq queue */
386 EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
387 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
388 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 2);
389 /* p_3_11 has removed p_4_8 from ooseq */
390 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 3);
391 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 11);
392
393 /* pass the segment to tcp_input */
394 test_tcp_input(p_2_12, &netif);
395 /* check if counters are as expected */
396 EXPECT(counters.close_calls == 0);
397 EXPECT(counters.recv_calls == 0);
398 EXPECT(counters.recved_bytes == 0);
399 EXPECT(counters.err_calls == 0);
400 /* check ooseq queue */
401 EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
402 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
403 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 1);
404 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 2);
405 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 12);
406
407 /* pass the segment to tcp_input */
408 test_tcp_input(pinseq, &netif);
409 /* check if counters are as expected */
410 EXPECT(counters.close_calls == 0);
411 EXPECT(counters.recv_calls == 1);
412 EXPECT(counters.recved_bytes == 14);
413 EXPECT(counters.err_calls == 0);
414 EXPECT(pcb->ooseq == NULL);
415
416 /* pass the segment to tcp_input */
417 test_tcp_input(p_15_1, &netif);
418 /* check if counters are as expected */
419 EXPECT(counters.close_calls == 0);
420 EXPECT(counters.recv_calls == 1);
421 EXPECT(counters.recved_bytes == 14);
422 EXPECT(counters.err_calls == 0);
423 /* check ooseq queue */
424 EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
425 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 15);
426 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 1);
427
428 /* pass the segment to tcp_input */
429 test_tcp_input(p_15_1a, &netif);
430 /* check if counters are as expected */
431 EXPECT(counters.close_calls == 0);
432 EXPECT(counters.recv_calls == 1);
433 EXPECT(counters.recved_bytes == 14);
434 EXPECT(counters.err_calls == 0);
435 /* check ooseq queue: unchanged */
436 EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
437 EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 15);
438 EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 1);
439
440 /* pass the segment to tcp_input */
441 test_tcp_input(pinseqFIN, &netif);
442 /* check if counters are as expected */
443 EXPECT(counters.close_calls == 1);
444 EXPECT(counters.recv_calls == 2);
445 EXPECT(counters.recved_bytes == data_len);
446 EXPECT(counters.err_calls == 0);
447 EXPECT(pcb->ooseq == NULL);
448 }
449
450 /* make sure the pcb is freed */
451 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
452 tcp_abort(pcb);
453 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
454 }
455 END_TEST
456
457 static char data_full_wnd[TCP_WND + TCP_MSS];
458
459 /** create multiple segments and pass them to tcp_input with the first segment missing
460 * to simulate overruning the rxwin with ooseq queueing enabled */
START_TEST(test_tcp_recv_ooseq_overrun_rxwin)461 START_TEST(test_tcp_recv_ooseq_overrun_rxwin)
462 {
463 #if !TCP_OOSEQ_MAX_BYTES && !TCP_OOSEQ_MAX_PBUFS
464 int i, k;
465 struct test_tcp_counters counters;
466 struct tcp_pcb* pcb;
467 struct pbuf *pinseq, *p_ovr;
468 ip_addr_t remote_ip, local_ip, netmask;
469 u16_t remote_port = 0x100, local_port = 0x101;
470 struct netif netif;
471 int datalen = 0;
472 int datalen2;
473
474 for(i = 0; i < (int)sizeof(data_full_wnd); i++) {
475 data_full_wnd[i] = (char)i;
476 }
477
478 /* initialize local vars */
479 memset(&netif, 0, sizeof(netif));
480 IP_ADDR4(&local_ip, 192, 168, 1, 1);
481 IP_ADDR4(&remote_ip, 192, 168, 1, 2);
482 IP_ADDR4(&netmask, 255, 255, 255, 0);
483 test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
484 /* initialize counter struct */
485 memset(&counters, 0, sizeof(counters));
486 counters.expected_data_len = TCP_WND;
487 counters.expected_data = data_full_wnd;
488
489 /* create and initialize the pcb */
490 pcb = test_tcp_new_counters_pcb(&counters);
491 EXPECT_RET(pcb != NULL);
492 tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
493 pcb->rcv_nxt = 0x8000;
494
495 /* create segments */
496 /* pinseq is sent as last segment! */
497 pinseq = tcp_create_rx_segment(pcb, &data_full_wnd[0], TCP_MSS, 0, 0, TCP_ACK);
498
499 for(i = TCP_MSS, k = 0; i < TCP_WND; i += TCP_MSS, k++) {
500 int count, expected_datalen;
501 struct pbuf *p = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)],
502 TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
503 EXPECT_RET(p != NULL);
504 /* pass the segment to tcp_input */
505 test_tcp_input(p, &netif);
506 /* check if counters are as expected */
507 EXPECT(counters.close_calls == 0);
508 EXPECT(counters.recv_calls == 0);
509 EXPECT(counters.recved_bytes == 0);
510 EXPECT(counters.err_calls == 0);
511 /* check ooseq queue */
512 count = tcp_oos_count(pcb);
513 EXPECT_OOSEQ(count == k+1);
514 datalen = tcp_oos_tcplen(pcb);
515 if (i + TCP_MSS < TCP_WND) {
516 expected_datalen = (k+1)*TCP_MSS;
517 } else {
518 expected_datalen = TCP_WND - TCP_MSS;
519 }
520 if (datalen != expected_datalen) {
521 EXPECT_OOSEQ(datalen == expected_datalen);
522 }
523 }
524
525 /* pass in one more segment, cleary overrunning the rxwin */
526 p_ovr = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)], TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
527 EXPECT_RET(p_ovr != NULL);
528 /* pass the segment to tcp_input */
529 test_tcp_input(p_ovr, &netif);
530 /* check if counters are as expected */
531 EXPECT(counters.close_calls == 0);
532 EXPECT(counters.recv_calls == 0);
533 EXPECT(counters.recved_bytes == 0);
534 EXPECT(counters.err_calls == 0);
535 /* check ooseq queue */
536 EXPECT_OOSEQ(tcp_oos_count(pcb) == k);
537 datalen2 = tcp_oos_tcplen(pcb);
538 EXPECT_OOSEQ(datalen == datalen2);
539
540 /* now pass inseq */
541 test_tcp_input(pinseq, &netif);
542 EXPECT(pcb->ooseq == NULL);
543
544 /* make sure the pcb is freed */
545 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
546 tcp_abort(pcb);
547 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
548 #endif /* !TCP_OOSEQ_MAX_BYTES && !TCP_OOSEQ_MAX_PBUFS */
549 LWIP_UNUSED_ARG(_i);
550 }
551 END_TEST
552
553 /** similar to above test, except seqno starts near the max rxwin */
START_TEST(test_tcp_recv_ooseq_overrun_rxwin_edge)554 START_TEST(test_tcp_recv_ooseq_overrun_rxwin_edge)
555 {
556 #if !TCP_OOSEQ_MAX_BYTES && !TCP_OOSEQ_MAX_PBUFS
557 int i, k;
558 struct test_tcp_counters counters;
559 struct tcp_pcb* pcb;
560 struct pbuf *pinseq, *p_ovr;
561 ip_addr_t remote_ip, local_ip, netmask;
562 u16_t remote_port = 0x100, local_port = 0x101;
563 struct netif netif;
564 int datalen = 0;
565 int datalen2;
566
567 for(i = 0; i < (int)sizeof(data_full_wnd); i++) {
568 data_full_wnd[i] = (char)i;
569 }
570
571 /* initialize local vars */
572 memset(&netif, 0, sizeof(netif));
573 IP_ADDR4(&local_ip, 192, 168, 1, 1);
574 IP_ADDR4(&remote_ip, 192, 168, 1, 2);
575 IP_ADDR4(&netmask, 255, 255, 255, 0);
576 test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
577 /* initialize counter struct */
578 memset(&counters, 0, sizeof(counters));
579 counters.expected_data_len = TCP_WND;
580 counters.expected_data = data_full_wnd;
581
582 /* create and initialize the pcb */
583 pcb = test_tcp_new_counters_pcb(&counters);
584 EXPECT_RET(pcb != NULL);
585 tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
586 pcb->rcv_nxt = 0xffffffff - (TCP_WND / 2);
587
588 /* create segments */
589 /* pinseq is sent as last segment! */
590 pinseq = tcp_create_rx_segment(pcb, &data_full_wnd[0], TCP_MSS, 0, 0, TCP_ACK);
591
592 for(i = TCP_MSS, k = 0; i < TCP_WND; i += TCP_MSS, k++) {
593 int count, expected_datalen;
594 struct pbuf *p = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)],
595 TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
596 EXPECT_RET(p != NULL);
597 /* pass the segment to tcp_input */
598 test_tcp_input(p, &netif);
599 /* check if counters are as expected */
600 EXPECT(counters.close_calls == 0);
601 EXPECT(counters.recv_calls == 0);
602 EXPECT(counters.recved_bytes == 0);
603 EXPECT(counters.err_calls == 0);
604 /* check ooseq queue */
605 count = tcp_oos_count(pcb);
606 EXPECT_OOSEQ(count == k+1);
607 datalen = tcp_oos_tcplen(pcb);
608 if (i + TCP_MSS < TCP_WND) {
609 expected_datalen = (k+1)*TCP_MSS;
610 } else {
611 expected_datalen = TCP_WND - TCP_MSS;
612 }
613 if (datalen != expected_datalen) {
614 EXPECT_OOSEQ(datalen == expected_datalen);
615 }
616 }
617
618 /* pass in one more segment, cleary overrunning the rxwin */
619 p_ovr = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)], TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
620 EXPECT_RET(p_ovr != NULL);
621 /* pass the segment to tcp_input */
622 test_tcp_input(p_ovr, &netif);
623 /* check if counters are as expected */
624 EXPECT(counters.close_calls == 0);
625 EXPECT(counters.recv_calls == 0);
626 EXPECT(counters.recved_bytes == 0);
627 EXPECT(counters.err_calls == 0);
628 /* check ooseq queue */
629 EXPECT_OOSEQ(tcp_oos_count(pcb) == k);
630 datalen2 = tcp_oos_tcplen(pcb);
631 EXPECT_OOSEQ(datalen == datalen2);
632
633 /* now pass inseq */
634 test_tcp_input(pinseq, &netif);
635 EXPECT(pcb->ooseq == NULL);
636
637 /* make sure the pcb is freed */
638 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
639 tcp_abort(pcb);
640 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
641 #endif /* !TCP_OOSEQ_MAX_BYTES && !TCP_OOSEQ_MAX_PBUFS */
642 LWIP_UNUSED_ARG(_i);
643 }
644 END_TEST
645
START_TEST(test_tcp_recv_ooseq_max_bytes)646 START_TEST(test_tcp_recv_ooseq_max_bytes)
647 {
648 #if TCP_OOSEQ_MAX_BYTES && (TCP_OOSEQ_MAX_BYTES < (TCP_WND + 1)) && (PBUF_POOL_BUFSIZE >= (TCP_MSS + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))
649 int i, k;
650 struct test_tcp_counters counters;
651 struct tcp_pcb* pcb;
652 struct pbuf *p_ovr;
653 ip_addr_t remote_ip, local_ip, netmask;
654 u16_t remote_port = 0x100, local_port = 0x101;
655 struct netif netif;
656 int datalen = 0;
657 int datalen2;
658
659 for(i = 0; i < sizeof(data_full_wnd); i++) {
660 data_full_wnd[i] = (char)i;
661 }
662
663 /* initialize local vars */
664 memset(&netif, 0, sizeof(netif));
665 IP_ADDR4(&local_ip, 192, 168, 1, 1);
666 IP_ADDR4(&remote_ip, 192, 168, 1, 2);
667 IP_ADDR4(&netmask, 255, 255, 255, 0);
668 test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
669 /* initialize counter struct */
670 memset(&counters, 0, sizeof(counters));
671 counters.expected_data_len = TCP_WND;
672 counters.expected_data = data_full_wnd;
673
674 /* create and initialize the pcb */
675 pcb = test_tcp_new_counters_pcb(&counters);
676 EXPECT_RET(pcb != NULL);
677 tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
678 pcb->rcv_nxt = 0x8000;
679
680 /* don't 'recv' the first segment (1 byte) so that all other segments will be ooseq */
681
682 /* create segments and 'recv' them */
683 for(k = 1, i = 1; k < TCP_OOSEQ_MAX_BYTES; k += TCP_MSS, i++) {
684 int count;
685 struct pbuf *p = tcp_create_rx_segment(pcb, &data_full_wnd[k],
686 TCP_MSS, k, 0, TCP_ACK);
687 EXPECT_RET(p != NULL);
688 EXPECT_RET(p->next == NULL);
689 /* pass the segment to tcp_input */
690 test_tcp_input(p, &netif);
691 /* check if counters are as expected */
692 EXPECT(counters.close_calls == 0);
693 EXPECT(counters.recv_calls == 0);
694 EXPECT(counters.recved_bytes == 0);
695 EXPECT(counters.err_calls == 0);
696 /* check ooseq queue */
697 count = tcp_oos_pbuf_count(pcb);
698 EXPECT_OOSEQ(count == i);
699 datalen = tcp_oos_tcplen(pcb);
700 EXPECT_OOSEQ(datalen == (i * TCP_MSS));
701 }
702
703 /* pass in one more segment, overrunning the limit */
704 p_ovr = tcp_create_rx_segment(pcb, &data_full_wnd[k+1], 1, k+1, 0, TCP_ACK);
705 EXPECT_RET(p_ovr != NULL);
706 /* pass the segment to tcp_input */
707 test_tcp_input(p_ovr, &netif);
708 /* check if counters are as expected */
709 EXPECT(counters.close_calls == 0);
710 EXPECT(counters.recv_calls == 0);
711 EXPECT(counters.recved_bytes == 0);
712 EXPECT(counters.err_calls == 0);
713 /* check ooseq queue (ensure the new segment was not accepted) */
714 EXPECT_OOSEQ(tcp_oos_count(pcb) == (i-1));
715 datalen2 = tcp_oos_tcplen(pcb);
716 EXPECT_OOSEQ(datalen2 == ((i-1) * TCP_MSS));
717
718 /* make sure the pcb is freed */
719 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
720 tcp_abort(pcb);
721 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
722 #endif /* TCP_OOSEQ_MAX_BYTES && (TCP_OOSEQ_MAX_BYTES < (TCP_WND + 1)) && (PBUF_POOL_BUFSIZE >= (TCP_MSS + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)) */
723 LWIP_UNUSED_ARG(_i);
724 }
725 END_TEST
726
START_TEST(test_tcp_recv_ooseq_max_pbufs)727 START_TEST(test_tcp_recv_ooseq_max_pbufs)
728 {
729 #if TCP_OOSEQ_MAX_PBUFS && (TCP_OOSEQ_MAX_PBUFS < ((TCP_WND / TCP_MSS) + 1)) && (PBUF_POOL_BUFSIZE >= (TCP_MSS + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))
730 int i;
731 struct test_tcp_counters counters;
732 struct tcp_pcb* pcb;
733 struct pbuf *p_ovr;
734 ip_addr_t remote_ip, local_ip, netmask;
735 u16_t remote_port = 0x100, local_port = 0x101;
736 struct netif netif;
737 int datalen = 0;
738 int datalen2;
739
740 for(i = 0; i < sizeof(data_full_wnd); i++) {
741 data_full_wnd[i] = (char)i;
742 }
743
744 /* initialize local vars */
745 memset(&netif, 0, sizeof(netif));
746 IP_ADDR4(&local_ip, 192, 168, 1, 1);
747 IP_ADDR4(&remote_ip, 192, 168, 1, 2);
748 IP_ADDR4(&netmask, 255, 255, 255, 0);
749 test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
750 /* initialize counter struct */
751 memset(&counters, 0, sizeof(counters));
752 counters.expected_data_len = TCP_WND;
753 counters.expected_data = data_full_wnd;
754
755 /* create and initialize the pcb */
756 pcb = test_tcp_new_counters_pcb(&counters);
757 EXPECT_RET(pcb != NULL);
758 tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
759 pcb->rcv_nxt = 0x8000;
760
761 /* don't 'recv' the first segment (1 byte) so that all other segments will be ooseq */
762
763 /* create segments and 'recv' them */
764 for(i = 1; i <= TCP_OOSEQ_MAX_PBUFS; i++) {
765 int count;
766 struct pbuf *p = tcp_create_rx_segment(pcb, &data_full_wnd[i],
767 1, i, 0, TCP_ACK);
768 EXPECT_RET(p != NULL);
769 EXPECT_RET(p->next == NULL);
770 /* pass the segment to tcp_input */
771 test_tcp_input(p, &netif);
772 /* check if counters are as expected */
773 EXPECT(counters.close_calls == 0);
774 EXPECT(counters.recv_calls == 0);
775 EXPECT(counters.recved_bytes == 0);
776 EXPECT(counters.err_calls == 0);
777 /* check ooseq queue */
778 count = tcp_oos_pbuf_count(pcb);
779 EXPECT_OOSEQ(count == i);
780 datalen = tcp_oos_tcplen(pcb);
781 EXPECT_OOSEQ(datalen == i);
782 }
783
784 /* pass in one more segment, overrunning the limit */
785 p_ovr = tcp_create_rx_segment(pcb, &data_full_wnd[i+1], 1, i+1, 0, TCP_ACK);
786 EXPECT_RET(p_ovr != NULL);
787 /* pass the segment to tcp_input */
788 test_tcp_input(p_ovr, &netif);
789 /* check if counters are as expected */
790 EXPECT(counters.close_calls == 0);
791 EXPECT(counters.recv_calls == 0);
792 EXPECT(counters.recved_bytes == 0);
793 EXPECT(counters.err_calls == 0);
794 /* check ooseq queue (ensure the new segment was not accepted) */
795 EXPECT_OOSEQ(tcp_oos_count(pcb) == (i-1));
796 datalen2 = tcp_oos_tcplen(pcb);
797 EXPECT_OOSEQ(datalen2 == (i-1));
798
799 /* make sure the pcb is freed */
800 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
801 tcp_abort(pcb);
802 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
803 #endif /* TCP_OOSEQ_MAX_PBUFS && (TCP_OOSEQ_MAX_BYTES < (TCP_WND + 1)) && (PBUF_POOL_BUFSIZE >= (TCP_MSS + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)) */
804 LWIP_UNUSED_ARG(_i);
805 }
806 END_TEST
807
808 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)809 check_rx_counters(struct tcp_pcb *pcb, struct test_tcp_counters *counters, u32_t exp_close_calls, u32_t exp_rx_calls,
810 u32_t exp_rx_bytes, u32_t exp_err_calls, int exp_oos_count, int exp_oos_len)
811 {
812 int oos_len;
813 EXPECT(counters->close_calls == exp_close_calls);
814 EXPECT(counters->recv_calls == exp_rx_calls);
815 EXPECT(counters->recved_bytes == exp_rx_bytes);
816 EXPECT(counters->err_calls == exp_err_calls);
817 /* check that pbuf is queued in ooseq */
818 EXPECT_OOSEQ(tcp_oos_count(pcb) == exp_oos_count);
819 oos_len = tcp_oos_tcplen(pcb);
820 EXPECT_OOSEQ(exp_oos_len == oos_len);
821 }
822
823 /* this test uses 4 packets:
824 * - data (len=TCP_MSS)
825 * - FIN
826 * - data after FIN (len=1) (invalid)
827 * - 2nd FIN (invalid)
828 *
829 * the parameter 'delay_packet' is a bitmask that choses which on these packets is ooseq
830 */
test_tcp_recv_ooseq_double_FINs(int delay_packet)831 static void test_tcp_recv_ooseq_double_FINs(int delay_packet)
832 {
833 int i, k;
834 struct test_tcp_counters counters;
835 struct tcp_pcb* pcb;
836 struct pbuf *p_normal_fin, *p_data_after_fin, *p, *p_2nd_fin_ooseq;
837 ip_addr_t remote_ip, local_ip, netmask;
838 u16_t remote_port = 0x100, local_port = 0x101;
839 struct netif netif;
840 u32_t exp_rx_calls = 0, exp_rx_bytes = 0, exp_close_calls = 0, exp_oos_pbufs = 0, exp_oos_tcplen = 0;
841 int first_dropped = 0xff;
842
843 for(i = 0; i < (int)sizeof(data_full_wnd); i++) {
844 data_full_wnd[i] = (char)i;
845 }
846
847 /* initialize local vars */
848 memset(&netif, 0, sizeof(netif));
849 IP_ADDR4(&local_ip, 192, 168, 1, 1);
850 IP_ADDR4(&remote_ip, 192, 168, 1, 2);
851 IP_ADDR4(&netmask, 255, 255, 255, 0);
852 test_tcp_init_netif(&netif, NULL, &local_ip, &netmask);
853 /* initialize counter struct */
854 memset(&counters, 0, sizeof(counters));
855 counters.expected_data_len = TCP_WND;
856 counters.expected_data = data_full_wnd;
857
858 /* create and initialize the pcb */
859 pcb = test_tcp_new_counters_pcb(&counters);
860 EXPECT_RET(pcb != NULL);
861 tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
862 pcb->rcv_nxt = 0x8000;
863
864 /* create segments */
865 p = tcp_create_rx_segment(pcb, &data_full_wnd[0], TCP_MSS, 0, 0, TCP_ACK);
866 p_normal_fin = tcp_create_rx_segment(pcb, NULL, 0, TCP_MSS, 0, TCP_ACK|TCP_FIN);
867 k = 1;
868 p_data_after_fin = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS+1], k, TCP_MSS+1, 0, TCP_ACK);
869 p_2nd_fin_ooseq = tcp_create_rx_segment(pcb, NULL, 0, TCP_MSS+1+k, 0, TCP_ACK|TCP_FIN);
870
871 if(delay_packet & 1) {
872 /* drop normal data */
873 first_dropped = 1;
874 } else {
875 /* send normal data */
876 test_tcp_input(p, &netif);
877 exp_rx_calls++;
878 exp_rx_bytes += TCP_MSS;
879 }
880 /* check if counters are as expected */
881 check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
882
883 if(delay_packet & 2) {
884 /* drop FIN */
885 if(first_dropped > 2) {
886 first_dropped = 2;
887 }
888 } else {
889 /* send FIN */
890 test_tcp_input(p_normal_fin, &netif);
891 if (first_dropped < 2) {
892 /* already dropped packets, this one is ooseq */
893 exp_oos_pbufs++;
894 exp_oos_tcplen++;
895 } else {
896 /* inseq */
897 exp_close_calls++;
898 }
899 }
900 /* check if counters are as expected */
901 check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
902
903 if(delay_packet & 4) {
904 /* drop data-after-FIN */
905 if(first_dropped > 3) {
906 first_dropped = 3;
907 }
908 } else {
909 /* send data-after-FIN */
910 test_tcp_input(p_data_after_fin, &netif);
911 if (first_dropped < 3) {
912 /* already dropped packets, this one is ooseq */
913 if (delay_packet & 2) {
914 /* correct FIN was ooseq */
915 exp_oos_pbufs++;
916 exp_oos_tcplen += k;
917 }
918 } else {
919 /* inseq: no change */
920 }
921 }
922 /* check if counters are as expected */
923 check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
924
925 if(delay_packet & 8) {
926 /* drop 2nd-FIN */
927 if(first_dropped > 4) {
928 first_dropped = 4;
929 }
930 } else {
931 /* send 2nd-FIN */
932 test_tcp_input(p_2nd_fin_ooseq, &netif);
933 if (first_dropped < 3) {
934 /* already dropped packets, this one is ooseq */
935 if (delay_packet & 2) {
936 /* correct FIN was ooseq */
937 exp_oos_pbufs++;
938 exp_oos_tcplen++;
939 }
940 } else {
941 /* inseq: no change */
942 }
943 }
944 /* check if counters are as expected */
945 check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
946
947 if(delay_packet & 1) {
948 /* dropped normal data before */
949 test_tcp_input(p, &netif);
950 exp_rx_calls++;
951 exp_rx_bytes += TCP_MSS;
952 if((delay_packet & 2) == 0) {
953 /* normal FIN was NOT delayed */
954 exp_close_calls++;
955 exp_oos_pbufs = exp_oos_tcplen = 0;
956 }
957 }
958 /* check if counters are as expected */
959 check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
960
961 if(delay_packet & 2) {
962 /* dropped normal FIN before */
963 test_tcp_input(p_normal_fin, &netif);
964 exp_close_calls++;
965 exp_oos_pbufs = exp_oos_tcplen = 0;
966 }
967 /* check if counters are as expected */
968 check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
969
970 if(delay_packet & 4) {
971 /* dropped data-after-FIN before */
972 test_tcp_input(p_data_after_fin, &netif);
973 }
974 /* check if counters are as expected */
975 check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
976
977 if(delay_packet & 8) {
978 /* dropped 2nd-FIN before */
979 test_tcp_input(p_2nd_fin_ooseq, &netif);
980 }
981 /* check if counters are as expected */
982 check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
983
984 /* check that ooseq data has been dumped */
985 EXPECT(pcb->ooseq == NULL);
986
987 /* make sure the pcb is freed */
988 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
989 tcp_abort(pcb);
990 EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
991 }
992
993 /** create multiple segments and pass them to tcp_input with the first segment missing
994 * to simulate overruning the rxwin with ooseq queueing enabled */
995 #define FIN_TEST(name, num) \
996 START_TEST(name) \
997 { \
998 LWIP_UNUSED_ARG(_i); \
999 test_tcp_recv_ooseq_double_FINs(num); \
1000 } \
1001 END_TEST
1002 FIN_TEST(test_tcp_recv_ooseq_double_FIN_0, 0)
1003 FIN_TEST(test_tcp_recv_ooseq_double_FIN_1, 1)
1004 FIN_TEST(test_tcp_recv_ooseq_double_FIN_2, 2)
1005 FIN_TEST(test_tcp_recv_ooseq_double_FIN_3, 3)
1006 FIN_TEST(test_tcp_recv_ooseq_double_FIN_4, 4)
1007 FIN_TEST(test_tcp_recv_ooseq_double_FIN_5, 5)
1008 FIN_TEST(test_tcp_recv_ooseq_double_FIN_6, 6)
1009 FIN_TEST(test_tcp_recv_ooseq_double_FIN_7, 7)
1010 FIN_TEST(test_tcp_recv_ooseq_double_FIN_8, 8)
1011 FIN_TEST(test_tcp_recv_ooseq_double_FIN_9, 9)
1012 FIN_TEST(test_tcp_recv_ooseq_double_FIN_10, 10)
1013 FIN_TEST(test_tcp_recv_ooseq_double_FIN_11, 11)
1014 FIN_TEST(test_tcp_recv_ooseq_double_FIN_12, 12)
1015 FIN_TEST(test_tcp_recv_ooseq_double_FIN_13, 13)
1016 FIN_TEST(test_tcp_recv_ooseq_double_FIN_14, 14)
1017 FIN_TEST(test_tcp_recv_ooseq_double_FIN_15, 15)
1018
1019
1020 /** Create the suite including all tests for this module */
1021 Suite *
tcp_oos_suite(void)1022 tcp_oos_suite(void)
1023 {
1024 testfunc tests[] = {
1025 TESTFUNC(test_tcp_recv_ooseq_FIN_OOSEQ),
1026 TESTFUNC(test_tcp_recv_ooseq_FIN_INSEQ),
1027 TESTFUNC(test_tcp_recv_ooseq_overrun_rxwin),
1028 TESTFUNC(test_tcp_recv_ooseq_overrun_rxwin_edge),
1029 TESTFUNC(test_tcp_recv_ooseq_max_bytes),
1030 TESTFUNC(test_tcp_recv_ooseq_max_pbufs),
1031 TESTFUNC(test_tcp_recv_ooseq_double_FIN_0),
1032 TESTFUNC(test_tcp_recv_ooseq_double_FIN_1),
1033 TESTFUNC(test_tcp_recv_ooseq_double_FIN_2),
1034 TESTFUNC(test_tcp_recv_ooseq_double_FIN_3),
1035 TESTFUNC(test_tcp_recv_ooseq_double_FIN_4),
1036 TESTFUNC(test_tcp_recv_ooseq_double_FIN_5),
1037 TESTFUNC(test_tcp_recv_ooseq_double_FIN_6),
1038 TESTFUNC(test_tcp_recv_ooseq_double_FIN_7),
1039 TESTFUNC(test_tcp_recv_ooseq_double_FIN_8),
1040 TESTFUNC(test_tcp_recv_ooseq_double_FIN_9),
1041 TESTFUNC(test_tcp_recv_ooseq_double_FIN_10),
1042 TESTFUNC(test_tcp_recv_ooseq_double_FIN_11),
1043 TESTFUNC(test_tcp_recv_ooseq_double_FIN_12),
1044 TESTFUNC(test_tcp_recv_ooseq_double_FIN_13),
1045 TESTFUNC(test_tcp_recv_ooseq_double_FIN_14),
1046 TESTFUNC(test_tcp_recv_ooseq_double_FIN_15)
1047 };
1048 return create_suite("TCP_OOS", tests, sizeof(tests)/sizeof(testfunc), tcp_oos_setup, tcp_oos_teardown);
1049 }
1050