test_tcp_oos.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. #include "test_tcp_oos.h"
  2. #include "lwip/tcp_impl.h"
  3. #include "lwip/stats.h"
  4. #include "tcp_helper.h"
  5. #if !LWIP_STATS || !TCP_STATS || !MEMP_STATS
  6. #error "This tests needs TCP- and MEMP-statistics enabled"
  7. #endif
  8. #if !TCP_QUEUE_OOSEQ
  9. #error "This tests needs TCP_QUEUE_OOSEQ enabled"
  10. #endif
  11. /** CHECK_SEGMENTS_ON_OOSEQ:
  12. * 1: check count, seqno and len of segments on pcb->ooseq (strict)
  13. * 0: only check that bytes are received in correct order (less strict) */
  14. #define CHECK_SEGMENTS_ON_OOSEQ 1
  15. #if CHECK_SEGMENTS_ON_OOSEQ
  16. #define EXPECT_OOSEQ(x) EXPECT(x)
  17. #else
  18. #define EXPECT_OOSEQ(x)
  19. #endif
  20. /* helper functions */
  21. /** Get the numbers of segments on the ooseq list */
  22. static int tcp_oos_count(struct tcp_pcb* pcb)
  23. {
  24. int num = 0;
  25. struct tcp_seg* seg = pcb->ooseq;
  26. while(seg != NULL) {
  27. num++;
  28. seg = seg->next;
  29. }
  30. return num;
  31. }
  32. /** Get the seqno of a segment (by index) on the ooseq list
  33. *
  34. * @param pcb the pcb to check for ooseq segments
  35. * @param seg_index index of the segment on the ooseq list
  36. * @return seqno of the segment
  37. */
  38. static u32_t
  39. tcp_oos_seg_seqno(struct tcp_pcb* pcb, int seg_index)
  40. {
  41. int num = 0;
  42. struct tcp_seg* seg = pcb->ooseq;
  43. /* then check the actual segment */
  44. while(seg != NULL) {
  45. if(num == seg_index) {
  46. return seg->tcphdr->seqno;
  47. }
  48. num++;
  49. seg = seg->next;
  50. }
  51. fail();
  52. return 0;
  53. }
  54. /** Get the tcplen (datalen + SYN/FIN) of a segment (by index) on the ooseq list
  55. *
  56. * @param pcb the pcb to check for ooseq segments
  57. * @param seg_index index of the segment on the ooseq list
  58. * @return tcplen of the segment
  59. */
  60. static int
  61. tcp_oos_seg_tcplen(struct tcp_pcb* pcb, int seg_index)
  62. {
  63. int num = 0;
  64. struct tcp_seg* seg = pcb->ooseq;
  65. /* then check the actual segment */
  66. while(seg != NULL) {
  67. if(num == seg_index) {
  68. return TCP_TCPLEN(seg);
  69. }
  70. num++;
  71. seg = seg->next;
  72. }
  73. fail();
  74. return -1;
  75. }
  76. /** Get the tcplen (datalen + SYN/FIN) of all segments on the ooseq list
  77. *
  78. * @param pcb the pcb to check for ooseq segments
  79. * @return tcplen of all segment
  80. */
  81. static int
  82. tcp_oos_tcplen(struct tcp_pcb* pcb)
  83. {
  84. int len = 0;
  85. struct tcp_seg* seg = pcb->ooseq;
  86. /* then check the actual segment */
  87. while(seg != NULL) {
  88. len += TCP_TCPLEN(seg);
  89. seg = seg->next;
  90. }
  91. return len;
  92. }
  93. /* Setup/teardown functions */
  94. static void
  95. tcp_oos_setup(void)
  96. {
  97. tcp_remove_all();
  98. }
  99. static void
  100. tcp_oos_teardown(void)
  101. {
  102. tcp_remove_all();
  103. }
  104. /* Test functions */
  105. /** create multiple segments and pass them to tcp_input in a wrong
  106. * order to see if ooseq-caching works correctly
  107. * FIN is received in out-of-sequence segments only */
  108. START_TEST(test_tcp_recv_ooseq_FIN_OOSEQ)
  109. {
  110. struct test_tcp_counters counters;
  111. struct tcp_pcb* pcb;
  112. struct pbuf *p_8_9, *p_4_8, *p_4_10, *p_2_14, *p_fin, *pinseq;
  113. char data[] = {
  114. 1, 2, 3, 4,
  115. 5, 6, 7, 8,
  116. 9, 10, 11, 12,
  117. 13, 14, 15, 16};
  118. ip_addr_t remote_ip, local_ip;
  119. u16_t data_len;
  120. u16_t remote_port = 0x100, local_port = 0x101;
  121. struct netif netif;
  122. LWIP_UNUSED_ARG(_i);
  123. /* initialize local vars */
  124. memset(&netif, 0, sizeof(netif));
  125. IP4_ADDR(&local_ip, 192, 168, 1, 1);
  126. IP4_ADDR(&remote_ip, 192, 168, 1, 2);
  127. data_len = sizeof(data);
  128. /* initialize counter struct */
  129. memset(&counters, 0, sizeof(counters));
  130. counters.expected_data_len = data_len;
  131. counters.expected_data = data;
  132. /* create and initialize the pcb */
  133. pcb = test_tcp_new_counters_pcb(&counters);
  134. EXPECT_RET(pcb != NULL);
  135. tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
  136. /* create segments */
  137. /* pinseq is sent as last segment! */
  138. pinseq = tcp_create_rx_segment(pcb, &data[0], 4, 0, 0, TCP_ACK);
  139. /* p1: 8 bytes before FIN */
  140. /* seqno: 8..16 */
  141. p_8_9 = tcp_create_rx_segment(pcb, &data[8], 8, 8, 0, TCP_ACK|TCP_FIN);
  142. /* p2: 4 bytes before p1, including the first 4 bytes of p1 (partly duplicate) */
  143. /* seqno: 4..11 */
  144. p_4_8 = tcp_create_rx_segment(pcb, &data[4], 8, 4, 0, TCP_ACK);
  145. /* p3: same as p2 but 2 bytes longer */
  146. /* seqno: 4..13 */
  147. p_4_10 = tcp_create_rx_segment(pcb, &data[4], 10, 4, 0, TCP_ACK);
  148. /* p4: 14 bytes before FIN, includes data from p1 and p2, plus partly from pinseq */
  149. /* seqno: 2..15 */
  150. p_2_14 = tcp_create_rx_segment(pcb, &data[2], 14, 2, 0, TCP_ACK);
  151. /* FIN, seqno 16 */
  152. p_fin = tcp_create_rx_segment(pcb, NULL, 0,16, 0, TCP_ACK|TCP_FIN);
  153. EXPECT(pinseq != NULL);
  154. EXPECT(p_8_9 != NULL);
  155. EXPECT(p_4_8 != NULL);
  156. EXPECT(p_4_10 != NULL);
  157. EXPECT(p_2_14 != NULL);
  158. EXPECT(p_fin != NULL);
  159. if ((pinseq != NULL) && (p_8_9 != NULL) && (p_4_8 != NULL) && (p_4_10 != NULL) && (p_2_14 != NULL) && (p_fin != NULL)) {
  160. /* pass the segment to tcp_input */
  161. test_tcp_input(p_8_9, &netif);
  162. /* check if counters are as expected */
  163. EXPECT(counters.close_calls == 0);
  164. EXPECT(counters.recv_calls == 0);
  165. EXPECT(counters.recved_bytes == 0);
  166. EXPECT(counters.err_calls == 0);
  167. /* check ooseq queue */
  168. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  169. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 8);
  170. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 9); /* includes FIN */
  171. /* pass the segment to tcp_input */
  172. test_tcp_input(p_4_8, &netif);
  173. /* check if counters are as expected */
  174. EXPECT(counters.close_calls == 0);
  175. EXPECT(counters.recv_calls == 0);
  176. EXPECT(counters.recved_bytes == 0);
  177. EXPECT(counters.err_calls == 0);
  178. /* check ooseq queue */
  179. EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
  180. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 4);
  181. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 4);
  182. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 8);
  183. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 9); /* includes FIN */
  184. /* pass the segment to tcp_input */
  185. test_tcp_input(p_4_10, &netif);
  186. /* check if counters are as expected */
  187. EXPECT(counters.close_calls == 0);
  188. EXPECT(counters.recv_calls == 0);
  189. EXPECT(counters.recved_bytes == 0);
  190. EXPECT(counters.err_calls == 0);
  191. /* ooseq queue: unchanged */
  192. EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
  193. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 4);
  194. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 4);
  195. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 8);
  196. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 9); /* includes FIN */
  197. /* pass the segment to tcp_input */
  198. test_tcp_input(p_2_14, &netif);
  199. /* check if counters are as expected */
  200. EXPECT(counters.close_calls == 0);
  201. EXPECT(counters.recv_calls == 0);
  202. EXPECT(counters.recved_bytes == 0);
  203. EXPECT(counters.err_calls == 0);
  204. /* check ooseq queue */
  205. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  206. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 2);
  207. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 15); /* includes FIN */
  208. /* pass the segment to tcp_input */
  209. test_tcp_input(p_fin, &netif);
  210. /* check if counters are as expected */
  211. EXPECT(counters.close_calls == 0);
  212. EXPECT(counters.recv_calls == 0);
  213. EXPECT(counters.recved_bytes == 0);
  214. EXPECT(counters.err_calls == 0);
  215. /* ooseq queue: unchanged */
  216. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  217. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 2);
  218. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 15); /* includes FIN */
  219. /* pass the segment to tcp_input */
  220. test_tcp_input(pinseq, &netif);
  221. /* check if counters are as expected */
  222. EXPECT(counters.close_calls == 1);
  223. EXPECT(counters.recv_calls == 1);
  224. EXPECT(counters.recved_bytes == data_len);
  225. EXPECT(counters.err_calls == 0);
  226. EXPECT(pcb->ooseq == NULL);
  227. }
  228. /* make sure the pcb is freed */
  229. EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 1);
  230. tcp_abort(pcb);
  231. EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 0);
  232. }
  233. END_TEST
  234. /** create multiple segments and pass them to tcp_input in a wrong
  235. * order to see if ooseq-caching works correctly
  236. * FIN is received IN-SEQUENCE at the end */
  237. START_TEST(test_tcp_recv_ooseq_FIN_INSEQ)
  238. {
  239. struct test_tcp_counters counters;
  240. struct tcp_pcb* pcb;
  241. struct pbuf *p_1_2, *p_4_8, *p_3_11, *p_2_12, *p_15_1, *p_15_1a, *pinseq, *pinseqFIN;
  242. char data[] = {
  243. 1, 2, 3, 4,
  244. 5, 6, 7, 8,
  245. 9, 10, 11, 12,
  246. 13, 14, 15, 16};
  247. ip_addr_t remote_ip, local_ip;
  248. u16_t data_len;
  249. u16_t remote_port = 0x100, local_port = 0x101;
  250. struct netif netif;
  251. LWIP_UNUSED_ARG(_i);
  252. /* initialize local vars */
  253. memset(&netif, 0, sizeof(netif));
  254. IP4_ADDR(&local_ip, 192, 168, 1, 1);
  255. IP4_ADDR(&remote_ip, 192, 168, 1, 2);
  256. data_len = sizeof(data);
  257. /* initialize counter struct */
  258. memset(&counters, 0, sizeof(counters));
  259. counters.expected_data_len = data_len;
  260. counters.expected_data = data;
  261. /* create and initialize the pcb */
  262. pcb = test_tcp_new_counters_pcb(&counters);
  263. EXPECT_RET(pcb != NULL);
  264. tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
  265. /* create segments */
  266. /* p1: 7 bytes - 2 before FIN */
  267. /* seqno: 1..2 */
  268. p_1_2 = tcp_create_rx_segment(pcb, &data[1], 2, 1, 0, TCP_ACK);
  269. /* p2: 4 bytes before p1, including the first 4 bytes of p1 (partly duplicate) */
  270. /* seqno: 4..11 */
  271. p_4_8 = tcp_create_rx_segment(pcb, &data[4], 8, 4, 0, TCP_ACK);
  272. /* p3: same as p2 but 2 bytes longer and one byte more at the front */
  273. /* seqno: 3..13 */
  274. p_3_11 = tcp_create_rx_segment(pcb, &data[3], 11, 3, 0, TCP_ACK);
  275. /* p4: 13 bytes - 2 before FIN - should be ignored as contained in p1 and p3 */
  276. /* seqno: 2..13 */
  277. p_2_12 = tcp_create_rx_segment(pcb, &data[2], 12, 2, 0, TCP_ACK);
  278. /* pinseq is the first segment that is held back to create ooseq! */
  279. /* seqno: 0..3 */
  280. pinseq = tcp_create_rx_segment(pcb, &data[0], 4, 0, 0, TCP_ACK);
  281. /* p5: last byte before FIN */
  282. /* seqno: 15 */
  283. p_15_1 = tcp_create_rx_segment(pcb, &data[15], 1, 15, 0, TCP_ACK);
  284. /* p6: same as p5, should be ignored */
  285. p_15_1a= tcp_create_rx_segment(pcb, &data[15], 1, 15, 0, TCP_ACK);
  286. /* pinseqFIN: last 2 bytes plus FIN */
  287. /* only segment containing seqno 14 and FIN */
  288. pinseqFIN = tcp_create_rx_segment(pcb, &data[14], 2, 14, 0, TCP_ACK|TCP_FIN);
  289. EXPECT(pinseq != NULL);
  290. EXPECT(p_1_2 != NULL);
  291. EXPECT(p_4_8 != NULL);
  292. EXPECT(p_3_11 != NULL);
  293. EXPECT(p_2_12 != NULL);
  294. EXPECT(p_15_1 != NULL);
  295. EXPECT(p_15_1a != NULL);
  296. EXPECT(pinseqFIN != NULL);
  297. if ((pinseq != NULL) && (p_1_2 != NULL) && (p_4_8 != NULL) && (p_3_11 != NULL) && (p_2_12 != NULL)
  298. && (p_15_1 != NULL) && (p_15_1a != NULL) && (pinseqFIN != NULL)) {
  299. /* pass the segment to tcp_input */
  300. test_tcp_input(p_1_2, &netif);
  301. /* check if counters are as expected */
  302. EXPECT(counters.close_calls == 0);
  303. EXPECT(counters.recv_calls == 0);
  304. EXPECT(counters.recved_bytes == 0);
  305. EXPECT(counters.err_calls == 0);
  306. /* check ooseq queue */
  307. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  308. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
  309. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 2);
  310. /* pass the segment to tcp_input */
  311. test_tcp_input(p_4_8, &netif);
  312. /* check if counters are as expected */
  313. EXPECT(counters.close_calls == 0);
  314. EXPECT(counters.recv_calls == 0);
  315. EXPECT(counters.recved_bytes == 0);
  316. EXPECT(counters.err_calls == 0);
  317. /* check ooseq queue */
  318. EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
  319. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
  320. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 2);
  321. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 4);
  322. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 8);
  323. /* pass the segment to tcp_input */
  324. test_tcp_input(p_3_11, &netif);
  325. /* check if counters are as expected */
  326. EXPECT(counters.close_calls == 0);
  327. EXPECT(counters.recv_calls == 0);
  328. EXPECT(counters.recved_bytes == 0);
  329. EXPECT(counters.err_calls == 0);
  330. /* check ooseq queue */
  331. EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
  332. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
  333. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 2);
  334. /* p_3_11 has removed p_4_8 from ooseq */
  335. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 3);
  336. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 11);
  337. /* pass the segment to tcp_input */
  338. test_tcp_input(p_2_12, &netif);
  339. /* check if counters are as expected */
  340. EXPECT(counters.close_calls == 0);
  341. EXPECT(counters.recv_calls == 0);
  342. EXPECT(counters.recved_bytes == 0);
  343. EXPECT(counters.err_calls == 0);
  344. /* check ooseq queue */
  345. EXPECT_OOSEQ(tcp_oos_count(pcb) == 2);
  346. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 1);
  347. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 1);
  348. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 1) == 2);
  349. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 1) == 12);
  350. /* pass the segment to tcp_input */
  351. test_tcp_input(pinseq, &netif);
  352. /* check if counters are as expected */
  353. EXPECT(counters.close_calls == 0);
  354. EXPECT(counters.recv_calls == 1);
  355. EXPECT(counters.recved_bytes == 14);
  356. EXPECT(counters.err_calls == 0);
  357. EXPECT(pcb->ooseq == NULL);
  358. /* pass the segment to tcp_input */
  359. test_tcp_input(p_15_1, &netif);
  360. /* check if counters are as expected */
  361. EXPECT(counters.close_calls == 0);
  362. EXPECT(counters.recv_calls == 1);
  363. EXPECT(counters.recved_bytes == 14);
  364. EXPECT(counters.err_calls == 0);
  365. /* check ooseq queue */
  366. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  367. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 15);
  368. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 1);
  369. /* pass the segment to tcp_input */
  370. test_tcp_input(p_15_1a, &netif);
  371. /* check if counters are as expected */
  372. EXPECT(counters.close_calls == 0);
  373. EXPECT(counters.recv_calls == 1);
  374. EXPECT(counters.recved_bytes == 14);
  375. EXPECT(counters.err_calls == 0);
  376. /* check ooseq queue: unchanged */
  377. EXPECT_OOSEQ(tcp_oos_count(pcb) == 1);
  378. EXPECT_OOSEQ(tcp_oos_seg_seqno(pcb, 0) == 15);
  379. EXPECT_OOSEQ(tcp_oos_seg_tcplen(pcb, 0) == 1);
  380. /* pass the segment to tcp_input */
  381. test_tcp_input(pinseqFIN, &netif);
  382. /* check if counters are as expected */
  383. EXPECT(counters.close_calls == 1);
  384. EXPECT(counters.recv_calls == 2);
  385. EXPECT(counters.recved_bytes == data_len);
  386. EXPECT(counters.err_calls == 0);
  387. EXPECT(pcb->ooseq == NULL);
  388. }
  389. /* make sure the pcb is freed */
  390. EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 1);
  391. tcp_abort(pcb);
  392. EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 0);
  393. }
  394. END_TEST
  395. static char data_full_wnd[TCP_WND];
  396. /** create multiple segments and pass them to tcp_input with the first segment missing
  397. * to simulate overruning the rxwin with ooseq queueing enabled */
  398. START_TEST(test_tcp_recv_ooseq_overrun_rxwin)
  399. {
  400. int i, k;
  401. struct test_tcp_counters counters;
  402. struct tcp_pcb* pcb;
  403. struct pbuf *pinseq, *p_ovr;
  404. ip_addr_t remote_ip, local_ip;
  405. u16_t remote_port = 0x100, local_port = 0x101;
  406. struct netif netif;
  407. int datalen = 0;
  408. int datalen2;
  409. LWIP_UNUSED_ARG(_i);
  410. for(i = 0; i < sizeof(data_full_wnd); i++) {
  411. data_full_wnd[i] = (char)i;
  412. }
  413. /* initialize local vars */
  414. memset(&netif, 0, sizeof(netif));
  415. IP4_ADDR(&local_ip, 192, 168, 1, 1);
  416. IP4_ADDR(&remote_ip, 192, 168, 1, 2);
  417. /* initialize counter struct */
  418. memset(&counters, 0, sizeof(counters));
  419. counters.expected_data_len = TCP_WND;
  420. counters.expected_data = data_full_wnd;
  421. /* create and initialize the pcb */
  422. pcb = test_tcp_new_counters_pcb(&counters);
  423. EXPECT_RET(pcb != NULL);
  424. tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
  425. pcb->rcv_nxt = 0x8000;
  426. /* create segments */
  427. /* pinseq is sent as last segment! */
  428. pinseq = tcp_create_rx_segment(pcb, &data_full_wnd[0], TCP_MSS, 0, 0, TCP_ACK);
  429. for(i = TCP_MSS, k = 0; i < TCP_WND; i += TCP_MSS, k++) {
  430. int count, expected_datalen;
  431. struct pbuf *p = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)],
  432. TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
  433. EXPECT(p != NULL);
  434. /* pass the segment to tcp_input */
  435. test_tcp_input(p, &netif);
  436. /* check if counters are as expected */
  437. EXPECT(counters.close_calls == 0);
  438. EXPECT(counters.recv_calls == 0);
  439. EXPECT(counters.recved_bytes == 0);
  440. EXPECT(counters.err_calls == 0);
  441. /* check ooseq queue */
  442. count = tcp_oos_count(pcb);
  443. EXPECT_OOSEQ(count == k+1);
  444. datalen = tcp_oos_tcplen(pcb);
  445. if (i + TCP_MSS < TCP_WND) {
  446. expected_datalen = (k+1)*TCP_MSS;
  447. } else {
  448. expected_datalen = TCP_WND - TCP_MSS;
  449. }
  450. if (datalen != expected_datalen) {
  451. EXPECT_OOSEQ(datalen == expected_datalen);
  452. }
  453. }
  454. /* pass in one more segment, cleary overrunning the rxwin */
  455. p_ovr = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)], TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
  456. EXPECT(p_ovr != NULL);
  457. /* pass the segment to tcp_input */
  458. test_tcp_input(p_ovr, &netif);
  459. /* check if counters are as expected */
  460. EXPECT(counters.close_calls == 0);
  461. EXPECT(counters.recv_calls == 0);
  462. EXPECT(counters.recved_bytes == 0);
  463. EXPECT(counters.err_calls == 0);
  464. /* check ooseq queue */
  465. EXPECT_OOSEQ(tcp_oos_count(pcb) == k);
  466. datalen2 = tcp_oos_tcplen(pcb);
  467. EXPECT_OOSEQ(datalen == datalen2);
  468. /* now pass inseq */
  469. test_tcp_input(pinseq, &netif);
  470. EXPECT(pcb->ooseq == NULL);
  471. /* make sure the pcb is freed */
  472. EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 1);
  473. tcp_abort(pcb);
  474. EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 0);
  475. }
  476. END_TEST
  477. /** Create the suite including all tests for this module */
  478. Suite *
  479. tcp_oos_suite(void)
  480. {
  481. TFun tests[] = {
  482. test_tcp_recv_ooseq_FIN_OOSEQ,
  483. test_tcp_recv_ooseq_FIN_INSEQ,
  484. test_tcp_recv_ooseq_overrun_rxwin,
  485. };
  486. return create_suite("TCP_OOS", tests, sizeof(tests)/sizeof(TFun), tcp_oos_setup, tcp_oos_teardown);
  487. }