2 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 #include <vnet/tcp/tcp.h>
17 #define TCP_TEST_I(_cond, _comment, _args...) \
19 int _evald = (_cond); \
21 fformat(stderr, "FAIL:%d: " _comment "\n", \
24 fformat(stderr, "PASS:%d: " _comment "\n", \
30 #define TCP_TEST(_cond, _comment, _args...) \
32 if (!TCP_TEST_I(_cond, _comment, ##_args)) { \
38 scoreboard_trace_elt_t sb_trace[] = {};
42 tcp_test_scoreboard_replay (vlib_main_t * vm, unformat_input_t * input)
45 tcp_connection_t _tc, *tc = &_tc;
48 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
50 if (unformat (input, "detail"))
54 clib_error_t *e = clib_error_return
55 (0, "unknown input `%U'", format_unformat_error, input);
56 clib_error_report (e);
61 #if TCP_SCOREBOARD_TRACE
62 tc->sack_sb.trace = sb_trace;
64 s = tcp_scoreboard_replay (s, tc, verbose);
65 vlib_cli_output (vm, "%v", s);
70 tcp_test_sack_rx (vlib_main_t * vm, unformat_input_t * input)
72 tcp_connection_t _tc, *tc = &_tc;
73 sack_scoreboard_t *sb = &tc->sack_sb;
74 sack_block_t *sacks = 0, block;
75 sack_scoreboard_hole_t *hole;
78 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
80 if (unformat (input, "verbose"))
82 else if (unformat (input, "replay"))
83 return tcp_test_scoreboard_replay (vm, input);
86 clib_memset (tc, 0, sizeof (*tc));
88 tc->flags |= TCP_CONN_FAST_RECOVERY | TCP_CONN_RECOVERY;
90 tc->snd_una_max = 1000;
92 tc->rcv_opts.flags |= TCP_OPTS_FLAG_SACK;
94 scoreboard_init (&tc->sack_sb);
96 for (i = 0; i < 1000 / 100; i++)
98 block.start = i * 100;
99 block.end = (i + 1) * 100;
100 vec_add1 (sacks, block);
107 for (i = 0; i < 1000 / 200; i++)
109 vec_add1 (tc->rcv_opts.sacks, sacks[i * 2]);
111 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
112 tcp_rcv_sacks (tc, 0);
115 vlib_cli_output (vm, "sb after even blocks (mss %u):\n%U",
116 tc->snd_mss, format_tcp_scoreboard, sb, tc);
118 TCP_TEST ((pool_elts (sb->holes) == 5),
119 "scoreboard has %d elements", pool_elts (sb->holes));
121 /* First SACK block should be rejected */
122 hole = scoreboard_first_hole (sb);
123 TCP_TEST ((hole->start == 0 && hole->end == 200),
124 "first hole start %u end %u", hole->start, hole->end);
125 hole = scoreboard_last_hole (sb);
126 TCP_TEST ((hole->start == 900 && hole->end == 1000),
127 "last hole start %u end %u", hole->start, hole->end);
128 TCP_TEST ((sb->sacked_bytes == 400), "sacked bytes %d", sb->sacked_bytes);
129 TCP_TEST ((!sb->is_reneging), "is not reneging");
130 TCP_TEST ((sb->last_sacked_bytes == 400),
131 "last sacked bytes %d", sb->last_sacked_bytes);
132 TCP_TEST ((sb->high_sacked == 900), "high sacked %u", sb->high_sacked);
133 TCP_TEST ((sb->lost_bytes == 300), "lost bytes %u", sb->lost_bytes);
136 * Inject odd blocks except the last
140 vec_reset_length (tc->rcv_opts.sacks);
141 for (i = 0; i < 800 / 200; i++)
143 vec_add1 (tc->rcv_opts.sacks, sacks[i * 2 + 1]);
145 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
146 tcp_rcv_sacks (tc, 0);
149 vlib_cli_output (vm, "\nsb after odd blocks:\n%U", format_tcp_scoreboard,
152 hole = scoreboard_first_hole (sb);
153 TCP_TEST ((pool_elts (sb->holes) == 2),
154 "scoreboard has %d holes", pool_elts (sb->holes));
155 TCP_TEST ((hole->start == 0 && hole->end == 100),
156 "first hole start %u end %u", hole->start, hole->end);
157 TCP_TEST ((sb->sacked_bytes == 800), "sacked bytes %d", sb->sacked_bytes);
158 TCP_TEST ((!sb->is_reneging), "is not reneging");
159 TCP_TEST ((sb->high_sacked == 900), "high sacked %u", sb->high_sacked);
160 TCP_TEST ((sb->last_sacked_bytes == 400),
161 "last sacked bytes %d", sb->last_sacked_bytes);
162 TCP_TEST ((sb->lost_bytes == 100), "lost bytes %u", sb->lost_bytes);
165 * Ack until byte 100 - this is reneging because we should ack until 900
167 tcp_rcv_sacks (tc, 100);
169 vlib_cli_output (vm, "\nack until byte 100:\n%U", format_tcp_scoreboard,
172 TCP_TEST ((pool_elts (sb->holes) == 1), "scoreboard has %d elements",
173 pool_elts (sb->holes));
174 TCP_TEST ((sb->is_reneging), "is reneging");
177 * Make sure we accept duplicate acks while reneging.
184 vec_add1 (tc->rcv_opts.sacks, block);
186 tcp_rcv_sacks (tc, 100);
187 TCP_TEST ((pool_elts (sb->holes) == 1), "scoreboard has %d elements",
188 pool_elts (sb->holes));
189 TCP_TEST ((sb->is_reneging), "is reneging");
190 TCP_TEST ((sb->last_sacked_bytes == 50), "last sacked bytes %d",
191 sb->last_sacked_bytes);
192 TCP_TEST ((sb->rxt_sacked == 50), "last rxt sacked bytes %d",
198 tcp_rcv_sacks (tc, 950);
199 TCP_TEST ((sb->high_sacked == 950), "max sacked byte %u", sb->high_sacked);
200 TCP_TEST ((sb->sacked_bytes == 0), "sacked bytes %d", sb->sacked_bytes);
201 TCP_TEST ((sb->last_sacked_bytes == 0),
202 "last sacked bytes %d", sb->last_sacked_bytes);
203 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
204 TCP_TEST ((!sb->is_reneging), "is not reneging");
207 * Sack [960 970] [980 990]
212 vec_reset_length (tc->rcv_opts.sacks);
215 vec_add1 (tc->rcv_opts.sacks, block);
219 vec_add1 (tc->rcv_opts.sacks, block);
221 tcp_rcv_sacks (tc, 950);
222 TCP_TEST ((sb->high_sacked == 990), "max sacked byte %u", sb->high_sacked);
223 TCP_TEST ((sb->sacked_bytes == 20), "sacked bytes %d", sb->sacked_bytes);
224 TCP_TEST ((sb->last_sacked_bytes == 20),
225 "last sacked bytes %d", sb->last_sacked_bytes);
226 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
227 TCP_TEST ((!sb->is_reneging), "is not reneging");
228 TCP_TEST ((sb->rxt_sacked == 15), "last rxt sacked bytes %d",
232 * Ack up to 960 (reneging) + [961 971]
234 tc->rcv_opts.sacks[0].start = 961;
235 tc->rcv_opts.sacks[0].end = 971;
237 tcp_rcv_sacks (tc, 960);
239 TCP_TEST ((sb->is_reneging), "is reneging");
240 TCP_TEST ((sb->sacked_bytes == 21), "sacked bytes %d", sb->sacked_bytes);
241 TCP_TEST ((sb->last_sacked_bytes == 1),
242 "last sacked bytes %d", sb->last_sacked_bytes);
243 TCP_TEST ((sb->rxt_sacked == 11), "last rxt sacked bytes %d",
245 TCP_TEST ((sb->last_bytes_delivered == 0), "last bytes delivered %d",
246 sb->last_bytes_delivered);
249 * Ack up to 960 (reneging) + [961 990]
252 tc->rcv_opts.sacks[0].start = 961;
253 tc->rcv_opts.sacks[0].end = 990;
255 tcp_rcv_sacks (tc, 960);
257 TCP_TEST ((sb->is_reneging), "is reneging");
258 TCP_TEST ((sb->sacked_bytes == 30), "sacked bytes %d", sb->sacked_bytes);
259 TCP_TEST ((sb->last_sacked_bytes == 9),
260 "last sacked bytes %d", sb->last_sacked_bytes);
261 TCP_TEST ((sb->rxt_sacked == 9), "last rxt sacked bytes %d",
265 * Sack remaining bytes [990 1000]
267 tc->rcv_opts.sacks[0].start = 990;
268 tc->rcv_opts.sacks[0].end = 1000;
270 tcp_rcv_sacks (tc, 960);
272 TCP_TEST ((sb->is_reneging), "is reneging");
273 TCP_TEST ((sb->sacked_bytes == 40), "sacked bytes %d", sb->sacked_bytes);
274 TCP_TEST ((sb->last_sacked_bytes == 10),
275 "last sacked bytes %d", sb->last_sacked_bytes);
276 TCP_TEST ((sb->rxt_sacked == 0), "last rxt sacked bytes %d",
278 TCP_TEST (pool_elts (sb->holes) == 0, "no holes left");
281 * Ack up to 970 no sack blocks
283 vec_reset_length (tc->rcv_opts.sacks);
284 tc->rcv_opts.flags &= ~TCP_OPTS_FLAG_SACK;
285 tcp_rcv_sacks (tc, 970);
287 TCP_TEST ((sb->is_reneging), "is reneging");
288 TCP_TEST ((sb->sacked_bytes == 30), "sacked bytes %d", sb->sacked_bytes);
289 TCP_TEST ((sb->last_sacked_bytes == 0),
290 "last sacked bytes %d", sb->last_sacked_bytes);
291 TCP_TEST ((sb->rxt_sacked == 0), "last rxt sacked bytes %d",
298 tcp_rcv_sacks (tc, 1000);
299 TCP_TEST ((sb->high_sacked == 1000), "max sacked byte %u", sb->high_sacked);
300 TCP_TEST ((sb->sacked_bytes == 0), "sacked bytes %d", sb->sacked_bytes);
301 TCP_TEST (sb->last_bytes_delivered == 30, "last bytes delivered %d",
302 sb->last_bytes_delivered);
303 TCP_TEST ((sb->last_sacked_bytes == 0),
304 "last sacked bytes %d", sb->last_sacked_bytes);
305 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
306 TCP_TEST ((!sb->is_reneging), "is not reneging");
312 tc->rcv_opts.flags |= TCP_OPTS_FLAG_SACK;
313 vec_reset_length (tc->rcv_opts.sacks);
317 vec_add1 (tc->rcv_opts.sacks, block);
319 tc->snd_una_max = 1500;
322 tcp_rcv_sacks (tc, 1000);
325 vlib_cli_output (vm, "\nadd [1200, 1300] snd_una_max 1500, snd_una 1000:"
326 " \n%U", format_tcp_scoreboard, sb, tc);
328 TCP_TEST ((!sb->is_reneging), "is not reneging");
329 TCP_TEST ((pool_elts (sb->holes) == 2),
330 "scoreboard has %d holes", pool_elts (sb->holes));
331 hole = scoreboard_first_hole (sb);
332 TCP_TEST ((hole->start == 1000 && hole->end == 1200),
333 "first hole start %u end %u", hole->start, hole->end);
334 TCP_TEST ((sb->high_sacked == 1300), "max sacked byte %u", sb->high_sacked);
335 hole = scoreboard_last_hole (sb);
336 TCP_TEST ((hole->start == 1300 && hole->end == 1500),
337 "last hole start %u end %u", hole->start, hole->end);
338 TCP_TEST ((sb->sacked_bytes == 100), "sacked bytes %d", sb->sacked_bytes);
339 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
345 vec_reset_length (tc->rcv_opts.sacks);
346 /* Ack up to 1300 to avoid reneging */
347 tcp_rcv_sacks (tc, 1300);
350 vlib_cli_output (vm, "\nsb ack up to byte 1300:\n%U",
351 format_tcp_scoreboard, sb, tc);
353 TCP_TEST ((sb->sacked_bytes == 0), "sacked bytes %d", sb->sacked_bytes);
354 TCP_TEST ((pool_elts (sb->holes) == 1),
355 "scoreboard has %d elements", pool_elts (sb->holes));
356 TCP_TEST ((sb->last_bytes_delivered == 100), "last bytes delivered %d",
357 sb->last_bytes_delivered);
358 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
359 TCP_TEST ((sb->head != TCP_INVALID_SACK_HOLE_INDEX), "head %u", sb->head);
360 TCP_TEST ((sb->tail != TCP_INVALID_SACK_HOLE_INDEX), "tail %u", sb->tail);
361 TCP_TEST ((!sb->is_reneging), "is not reneging");
364 * Add some more blocks and then remove all
366 vec_reset_length (tc->rcv_opts.sacks);
368 tc->snd_nxt = tc->snd_una_max = 1900;
369 for (i = 0; i < 5; i++)
371 block.start = i * 100 + 1200;
372 block.end = (i + 1) * 100 + 1200;
373 vec_add1 (tc->rcv_opts.sacks, block);
375 tcp_rcv_sacks (tc, 1900);
377 scoreboard_clear (sb);
379 vlib_cli_output (vm, "\nsb cleared all:\n%U", format_tcp_scoreboard, sb,
382 TCP_TEST ((pool_elts (sb->holes) == 0),
383 "number of holes %d", pool_elts (sb->holes));
384 TCP_TEST ((sb->head == TCP_INVALID_SACK_HOLE_INDEX), "head %u", sb->head);
385 TCP_TEST ((sb->tail == TCP_INVALID_SACK_HOLE_INDEX), "tail %u", sb->tail);
388 * Re-inject odd blocks and ack them all
392 tc->snd_una_max = 1000;
394 vec_reset_length (tc->rcv_opts.sacks);
395 for (i = 0; i < 5; i++)
397 vec_add1 (tc->rcv_opts.sacks, sacks[i * 2 + 1]);
399 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
400 tcp_rcv_sacks (tc, 0);
402 vlib_cli_output (vm, "\nsb added odd blocks snd_una 0 snd_una_max 1000:"
403 "\n%U", format_tcp_scoreboard, sb, tc);
404 TCP_TEST ((pool_elts (sb->holes) == 5),
405 "scoreboard has %d elements", pool_elts (sb->holes));
406 TCP_TEST ((sb->lost_bytes == 300), "lost bytes %u", sb->lost_bytes);
407 hole = scoreboard_last_hole (sb);
408 TCP_TEST ((hole->end == 900), "last hole end %u", hole->end);
409 TCP_TEST ((sb->high_sacked == 1000), "high sacked %u", sb->high_sacked);
412 * Renege bytes from 950 to 1000
414 tcp_rcv_sacks (tc, 950);
417 vlib_cli_output (vm, "\nack [0, 950]:\n%U", format_tcp_scoreboard, sb,
420 TCP_TEST ((pool_elts (sb->holes) == 0), "scoreboard has %d elements",
421 pool_elts (sb->holes));
422 TCP_TEST ((sb->is_reneging), "is reneging");
423 TCP_TEST ((sb->sacked_bytes == 50), "sacked bytes %d", sb->sacked_bytes);
424 TCP_TEST ((sb->last_sacked_bytes == 0), "last sacked bytes %d",
425 sb->last_sacked_bytes);
426 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
427 TCP_TEST ((sb->high_sacked == 1000), "high sacked %u", sb->high_sacked);
429 scoreboard_clear (sb);
432 * Inject one block, ack it and overlap hole
436 tc->snd_una_max = 1000;
441 vec_add1 (tc->rcv_opts.sacks, block);
442 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
444 tcp_rcv_sacks (tc, 0);
447 vlib_cli_output (vm, "\nsb added [100, 500] snd_una 0 snd_una_max 1000:"
448 "\n%U", format_tcp_scoreboard, sb, tc);
450 tcp_rcv_sacks (tc, 800);
453 vlib_cli_output (vm, "\nsb ack [0, 800]:\n%U", format_tcp_scoreboard, sb,
456 TCP_TEST ((pool_elts (sb->holes) == 1),
457 "scoreboard has %d elements", pool_elts (sb->holes));
458 TCP_TEST ((!sb->is_reneging), "is not reneging");
459 TCP_TEST ((sb->sacked_bytes == 0), "sacked bytes %d", sb->sacked_bytes);
460 TCP_TEST ((sb->last_sacked_bytes == 0), "last sacked bytes %d",
461 sb->last_sacked_bytes);
462 TCP_TEST ((sb->last_bytes_delivered == 400),
463 "last bytes delivered %d", sb->last_bytes_delivered);
464 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
465 TCP_TEST ((sb->head != TCP_INVALID_SACK_HOLE_INDEX), "head %u", sb->head);
466 TCP_TEST ((sb->tail != TCP_INVALID_SACK_HOLE_INDEX), "tail %u", sb->tail);
469 * One hole close to head, patch head, split in two and start acking
472 scoreboard_clear (sb);
474 tc->snd_una_max = 1000;
479 vec_add1 (tc->rcv_opts.sacks, block);
480 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
482 tcp_rcv_sacks (tc, 0);
484 vlib_cli_output (vm, "\nsb added [500, 1000]:\n%U",
485 format_tcp_scoreboard, sb, tc);
486 TCP_TEST ((sb->sacked_bytes == 500), "sacked bytes %d", sb->sacked_bytes);
487 TCP_TEST ((sb->last_sacked_bytes == 500), "last sacked bytes %d",
488 sb->last_sacked_bytes);
489 TCP_TEST ((sb->lost_bytes == 500), "lost bytes %u", sb->lost_bytes);
491 vec_reset_length (tc->rcv_opts.sacks);
494 vec_add1 (tc->rcv_opts.sacks, block);
495 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
496 tcp_rcv_sacks (tc, 100);
498 vlib_cli_output (vm, "\nsb added [0, 100] [300, 400]:\n%U",
499 format_tcp_scoreboard, sb, tc);
500 TCP_TEST ((pool_elts (sb->holes) == 2),
501 "scoreboard has %d elements", pool_elts (sb->holes));
502 TCP_TEST ((sb->sacked_bytes == 600), "sacked bytes %d", sb->sacked_bytes);
503 TCP_TEST ((sb->last_sacked_bytes == 100), "last sacked bytes %d",
504 sb->last_sacked_bytes);
505 TCP_TEST ((sb->last_bytes_delivered == 0), "last bytes delivered %d",
506 sb->last_bytes_delivered);
507 TCP_TEST ((sb->lost_bytes == 300), "lost bytes %u", sb->lost_bytes);
510 * Ack [100 300] in two steps
512 * Step 1. Ack [100 200] which delivers 100 of the bytes lost
515 tcp_rcv_sacks (tc, 200);
516 TCP_TEST ((sb->sacked_bytes == 600), "sacked bytes %d", sb->sacked_bytes);
517 TCP_TEST ((sb->last_bytes_delivered == 0), "last bytes delivered %d",
518 sb->last_bytes_delivered);
519 TCP_TEST ((sb->lost_bytes == 200), "lost bytes %u", sb->lost_bytes);
522 * Step 2. Ack up to 300, although 300 400 is sacked, so this is interpreted
526 tcp_rcv_sacks (tc, 300);
528 vlib_cli_output (vm, "\nacked [100, 300] in two steps:\n%U",
529 format_tcp_scoreboard, sb, tc);
530 TCP_TEST ((sb->sacked_bytes == 600), "sacked bytes %d", sb->sacked_bytes);
531 TCP_TEST ((sb->lost_bytes == 100), "lost bytes %u", sb->lost_bytes);
532 TCP_TEST ((sb->last_bytes_delivered == 0), "last bytes delivered %d",
533 sb->last_bytes_delivered);
534 TCP_TEST ((sb->is_reneging), "is reneging");
537 * Ack [300 500]. Delivers reneged segment [300 400] and reneges bytes
541 tcp_rcv_sacks (tc, 500);
543 vlib_cli_output (vm, "\nacked [400, 500]:\n%U", format_tcp_scoreboard, sb,
545 TCP_TEST ((pool_elts (sb->holes) == 0),
546 "scoreboard has %d elements", pool_elts (sb->holes));
547 TCP_TEST ((sb->sacked_bytes == 500), "sacked bytes %d", sb->sacked_bytes);
548 TCP_TEST ((sb->last_sacked_bytes == 0), "last sacked bytes %d",
549 sb->last_sacked_bytes);
550 TCP_TEST ((sb->last_bytes_delivered == 100), "last bytes delivered %d",
551 sb->last_bytes_delivered);
552 TCP_TEST ((sb->is_reneging), "is reneging");
553 TCP_TEST ((sb->head == TCP_INVALID_SACK_HOLE_INDEX), "head %u", sb->head);
554 TCP_TEST ((sb->tail == TCP_INVALID_SACK_HOLE_INDEX), "tail %u", sb->tail);
557 * Ack up to 1000 to deliver all bytes
560 tcp_rcv_sacks (tc, 1000);
562 vlib_cli_output (vm, "\nAck high sacked:\n%U", format_tcp_scoreboard, sb,
564 TCP_TEST ((sb->last_sacked_bytes == 0), "last sacked bytes %d",
565 sb->last_sacked_bytes);
566 TCP_TEST ((sb->last_bytes_delivered == 500), "last bytes delivered %d",
567 sb->last_bytes_delivered);
568 TCP_TEST ((!sb->is_reneging), "is not reneging");
571 * Add [1200, 1500] and test that [1000, 1200] is lost (bytes condition)
572 * snd_una = 1000 and snd_una_max = 1600
575 tc->snd_nxt = tc->snd_una_max = 1600;
576 vec_reset_length (tc->rcv_opts.sacks);
579 vec_add1 (tc->rcv_opts.sacks, block);
580 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
581 tcp_rcv_sacks (tc, 1000);
583 vlib_cli_output (vm, "\nacked [1200, 1500] test first hole is lost:\n%U",
584 format_tcp_scoreboard, sb, tc);
585 TCP_TEST ((pool_elts (sb->holes) == 2), "scoreboard has %d elements",
586 pool_elts (sb->holes));
587 TCP_TEST ((sb->sacked_bytes == 300), "sacked bytes %d", sb->sacked_bytes);
588 TCP_TEST ((sb->last_sacked_bytes == 300), "last sacked bytes %d",
589 sb->last_sacked_bytes);
590 TCP_TEST ((sb->last_bytes_delivered == 0), "last bytes delivered %d",
591 sb->last_bytes_delivered);
592 TCP_TEST ((sb->lost_bytes == 200), "lost bytes %u", sb->lost_bytes);
593 TCP_TEST ((!sb->is_reneging), "is not reneging");
598 scoreboard_clear (sb);
599 vec_reset_length (tc->rcv_opts.sacks);
605 tc->flags |= TCP_CONN_FAST_RECOVERY | TCP_CONN_RECOVERY;
607 tc->snd_una_max = 1000;
613 vec_add1 (tc->rcv_opts.sacks, block);
614 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
616 tcp_rcv_sacks (tc, 0);
618 TCP_TEST ((sb->sacked_bytes == 400), "sacked bytes %d", sb->sacked_bytes);
619 TCP_TEST ((sb->last_sacked_bytes == 400), "last sacked bytes %d",
620 sb->last_sacked_bytes);
621 TCP_TEST ((!sb->is_reneging), "is not reneging");
624 * Renege, sack all of the remaining bytes and cover some rxt bytes
627 tc->rcv_opts.sacks[0].start = 500;
628 tc->rcv_opts.sacks[0].end = 1000;
630 tcp_rcv_sacks (tc, 100);
632 TCP_TEST ((sb->sacked_bytes == 900), "sacked bytes %d", sb->sacked_bytes);
633 TCP_TEST ((sb->last_sacked_bytes == 500), "last sacked bytes %d",
634 sb->last_sacked_bytes);
635 TCP_TEST (sb->is_reneging, "is reneging");
636 TCP_TEST ((sb->rxt_sacked == 300), "last rxt sacked bytes %d",
643 tcp_test_sack_tx (vlib_main_t * vm, unformat_input_t * input)
645 tcp_connection_t _tc, *tc = &_tc;
647 int i, verbose = 0, expected;
649 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
651 if (unformat (input, "verbose"))
655 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
661 clib_memset (tc, 0, sizeof (*tc));
664 * Add odd sack block pairs
666 for (i = 1; i < 10; i += 2)
668 tcp_update_sack_list (tc, i * 100, (i + 1) * 100);
671 TCP_TEST ((vec_len (tc->snd_sacks) == 5), "sack blocks %d expected %d",
672 vec_len (tc->snd_sacks), 5);
673 TCP_TEST ((tc->snd_sacks[0].start = 900),
674 "first sack block start %u expected %u", tc->snd_sacks[0].start,
678 * Try to add one extra
680 sacks = vec_dup (tc->snd_sacks);
682 tcp_update_sack_list (tc, 1100, 1200);
684 vlib_cli_output (vm, "add new segment [1100, 1200]\n%U",
685 format_tcp_sacks, tc);
686 expected = 5 < TCP_MAX_SACK_BLOCKS ? 6 : 5;
687 TCP_TEST ((vec_len (tc->snd_sacks) == expected),
688 "sack blocks %d expected %d", vec_len (tc->snd_sacks), expected);
689 TCP_TEST ((tc->snd_sacks[0].start == 1100),
690 "first sack block start %u expected %u", tc->snd_sacks[0].start,
694 vec_free (tc->snd_sacks);
695 tc->snd_sacks = sacks;
698 * Overlap first 2 segment
701 tcp_update_sack_list (tc, 300, 300);
703 vlib_cli_output (vm, "overlap first 2 segments:\n%U",
704 format_tcp_sacks, tc);
705 TCP_TEST ((vec_len (tc->snd_sacks) == 3), "sack blocks %d expected %d",
706 vec_len (tc->snd_sacks), 3);
707 TCP_TEST ((tc->snd_sacks[0].start == 900),
708 "first sack block start %u expected %u", tc->snd_sacks[0].start,
714 tcp_update_sack_list (tc, 1100, 1200);
716 vlib_cli_output (vm, "add new segment [1100, 1200]\n%U",
717 format_tcp_sacks, tc);
718 TCP_TEST ((vec_len (tc->snd_sacks) == 4), "sack blocks %d expected %d",
719 vec_len (tc->snd_sacks), 4);
720 TCP_TEST ((tc->snd_sacks[0].start == 1100),
721 "first sack block start %u expected %u", tc->snd_sacks[0].start,
725 * Join middle segments
727 tcp_update_sack_list (tc, 800, 900);
729 vlib_cli_output (vm, "join middle segments [800, 900]\n%U",
730 format_tcp_sacks, tc);
732 TCP_TEST ((vec_len (tc->snd_sacks) == 3), "sack blocks %d expected %d",
733 vec_len (tc->snd_sacks), 3);
734 TCP_TEST ((tc->snd_sacks[0].start == 700),
735 "first sack block start %u expected %u", tc->snd_sacks[0].start,
739 * Advance rcv_nxt to overlap all
742 tcp_update_sack_list (tc, 1200, 1200);
744 vlib_cli_output (vm, "advance rcv_nxt to 1200\n%U", format_tcp_sacks, tc);
745 TCP_TEST ((vec_len (tc->snd_sacks) == 0), "sack blocks %d expected %d",
746 vec_len (tc->snd_sacks), 0);
750 * Add 2 blocks, overwrite first and update rcv_nxt to also remove it
753 vec_reset_length (tc->snd_sacks);
756 tcp_update_sack_list (tc, 100, 200);
757 tcp_update_sack_list (tc, 300, 400);
760 vlib_cli_output (vm, "add [100, 200] [300, 400]\n%U",
761 format_tcp_sacks, tc);
762 TCP_TEST ((vec_len (tc->snd_sacks) == 2),
763 "sack blocks %d expected %d", vec_len (tc->snd_sacks), 2);
764 TCP_TEST ((tc->snd_sacks[0].start == 300),
765 "first sack block start %u expected %u", tc->snd_sacks[0].start,
769 tcp_update_sack_list (tc, 100, 100);
771 vlib_cli_output (vm, "add [100, 200] rcv_nxt = 100\n%U",
772 format_tcp_sacks, tc);
773 TCP_TEST ((vec_len (tc->snd_sacks) == 1),
774 "sack blocks %d expected %d", vec_len (tc->snd_sacks), 1);
775 TCP_TEST ((tc->snd_sacks[0].start == 300),
776 "first sack block start %u expected %u", tc->snd_sacks[0].start,
782 tcp_test_sack (vlib_main_t * vm, unformat_input_t * input)
787 if (unformat_check_input (input) == UNFORMAT_END_OF_INPUT)
789 if (tcp_test_sack_tx (vm, input))
794 if (tcp_test_sack_rx (vm, input))
801 if (unformat (input, "tx"))
803 res = tcp_test_sack_tx (vm, input);
805 else if (unformat (input, "rx"))
807 res = tcp_test_sack_rx (vm, input);
815 tcp_test_lookup (vlib_main_t * vm, unformat_input_t * input)
817 session_main_t *smm = &session_main;
818 transport_connection_t _tc1, *tc1 = &_tc1, _tc2, *tc2 = &_tc2, *tconn;
819 tcp_connection_t *tc;
821 u8 cmp = 0, is_filtered = 0;
825 * Allocate fake session and connection 1
827 pool_get (smm->wrk[0].sessions, s);
828 clib_memset (s, 0, sizeof (*s));
829 s->session_index = sidx = s - smm->wrk[0].sessions;
831 tc = tcp_connection_alloc (0);
832 tc->connection.s_index = s->session_index;
833 s->connection_index = tc->connection.c_index;
835 tc->connection.lcl_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000101);
836 tc->connection.rmt_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000103);
837 tc->connection.lcl_port = 35051;
838 tc->connection.rmt_port = 53764;
839 tc->connection.proto = TRANSPORT_PROTO_TCP;
840 tc->connection.is_ip4 = 1;
841 clib_memcpy_fast (tc1, &tc->connection, sizeof (*tc1));
844 * Allocate fake session and connection 2
846 pool_get (smm->wrk[0].sessions, s);
847 clib_memset (s, 0, sizeof (*s));
848 s->session_index = s - smm->wrk[0].sessions;
850 tc = tcp_connection_alloc (0);
851 tc->connection.s_index = s->session_index;
852 s->connection_index = tc->connection.c_index;
854 tc->connection.lcl_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000101);
855 tc->connection.rmt_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000102);
856 tc->connection.lcl_port = 38225;
857 tc->connection.rmt_port = 53764;
858 tc->connection.proto = TRANSPORT_PROTO_TCP;
859 tc->connection.is_ip4 = 1;
860 clib_memcpy_fast (tc2, &tc->connection, sizeof (*tc2));
863 * Confirm that connection lookup works
866 s1 = pool_elt_at_index (smm->wrk[0].sessions, sidx);
867 session_lookup_add_connection (tc1, session_handle (s1));
868 tconn = session_lookup_connection_wt4 (0, &tc1->lcl_ip.ip4,
870 tc1->lcl_port, tc1->rmt_port,
871 tc1->proto, 0, &is_filtered);
873 TCP_TEST ((tconn != 0), "connection exists");
874 cmp = (memcmp (&tconn->rmt_ip, &tc1->rmt_ip, sizeof (tc1->rmt_ip)) == 0);
875 TCP_TEST ((cmp), "rmt ip is identical %d", cmp);
876 TCP_TEST ((tconn->lcl_port == tc1->lcl_port),
877 "rmt port is identical %d", tconn->lcl_port == tc1->lcl_port);
880 * Non-existing connection lookup should not work
883 tconn = session_lookup_connection_wt4 (0, &tc2->lcl_ip.ip4,
885 tc2->lcl_port, tc2->rmt_port,
886 tc2->proto, 0, &is_filtered);
887 TCP_TEST ((tconn == 0), "lookup result should be null");
890 * Delete and lookup again
892 session_lookup_del_connection (tc1);
893 tconn = session_lookup_connection_wt4 (0, &tc1->lcl_ip.ip4,
895 tc1->lcl_port, tc1->rmt_port,
896 tc1->proto, 0, &is_filtered);
897 TCP_TEST ((tconn == 0), "lookup result should be null");
898 tconn = session_lookup_connection_wt4 (0, &tc2->lcl_ip.ip4,
900 tc2->lcl_port, tc2->rmt_port,
901 tc2->proto, 0, &is_filtered);
902 TCP_TEST ((tconn == 0), "lookup result should be null");
905 * Re-add and lookup tc2
907 session_lookup_add_connection (tc1, tc1->s_index);
908 tconn = session_lookup_connection_wt4 (0, &tc2->lcl_ip.ip4,
910 tc2->lcl_port, tc2->rmt_port,
911 tc2->proto, 0, &is_filtered);
912 TCP_TEST ((tconn == 0), "lookup result should be null");
918 tcp_test_session (vlib_main_t * vm, unformat_input_t * input)
921 tcp_connection_t *tc0;
922 ip4_address_t local, remote;
923 u16 local_port, remote_port;
927 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
929 if (unformat (input, "del"))
931 else if (unformat (input, "add"))
939 local.as_u32 = clib_host_to_net_u32 (0x06000101);
940 remote.as_u32 = clib_host_to_net_u32 (0x06000102);
941 local_port = clib_host_to_net_u16 (1234);
942 remote_port = clib_host_to_net_u16 (11234);
944 tc0 = tcp_connection_alloc (0);
946 tc0->state = TCP_STATE_ESTABLISHED;
948 tc0->c_lcl_port = local_port;
949 tc0->c_rmt_port = remote_port;
951 tc0->c_thread_index = 0;
952 tc0->c_lcl_ip4.as_u32 = local.as_u32;
953 tc0->c_rmt_ip4.as_u32 = remote.as_u32;
954 tc0->rcv_opts.mss = 1450;
955 tcp_connection_init_vars (tc0);
957 TCP_EVT (TCP_EVT_OPEN, tc0);
959 if (session_stream_accept (&tc0->connection, 0 /* listener index */ ,
960 0 /* thread index */ , 0 /* notify */ ))
961 clib_warning ("stream_session_accept failed");
963 session_stream_accept_notify (&tc0->connection);
967 tc0 = tcp_connection_get (0 /* connection index */ , 0 /* thread */ );
968 tc0->state = TCP_STATE_CLOSED;
969 session_transport_closing_notify (&tc0->connection);
976 tbt_seq_lt (u32 a, u32 b)
978 return seq_lt (a, b);
982 tcp_test_delivery (vlib_main_t * vm, unformat_input_t * input)
984 u32 thread_index = 0, snd_una, *min_seqs = 0;
985 tcp_rate_sample_t _rs = { 0 }, *rs = &_rs;
986 tcp_connection_t _tc, *tc = &_tc;
987 sack_scoreboard_t *sb = &tc->sack_sb;
988 int __clib_unused verbose = 0, i;
989 u64 rate = 1000, burst = 100;
990 sack_block_t *sacks = 0;
991 tcp_byte_tracker_t *bt;
992 rb_node_t *root, *rbn;
993 tcp_bt_sample_t *bts;
995 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
997 if (unformat (input, "verbose"))
1001 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1007 /* Init data structures */
1008 memset (tc, 0, sizeof (*tc));
1009 session_main.wrk[thread_index].last_vlib_time = 1;
1010 transport_connection_tx_pacer_update (&tc->connection, rate, 1e6);
1016 * Track simple bursts without rxt
1019 /* 1) track first burst a time 1 */
1020 tcp_bt_track_tx (tc, burst);
1022 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1023 TCP_TEST (pool_elts (bt->samples) == 1, "should have 1 sample");
1024 bts = pool_elt_at_index (bt->samples, bt->head);
1025 TCP_TEST (bts->min_seq == tc->snd_una, "min seq should be snd_una");
1026 TCP_TEST (bts->next == TCP_BTS_INVALID_INDEX, "next should be invalid");
1027 TCP_TEST (bts->prev == TCP_BTS_INVALID_INDEX, "prev should be invalid");
1028 TCP_TEST (bts->delivered_time == 1, "delivered time should be 1");
1029 TCP_TEST (bts->delivered == 0, "delivered should be 0");
1030 TCP_TEST (!(bts->flags & TCP_BTS_IS_RXT), "not retransmitted");
1031 TCP_TEST (!(bts->flags & TCP_BTS_IS_APP_LIMITED), "not app limited");
1033 /* 2) check delivery rate at time 2 */
1034 session_main.wrk[thread_index].last_vlib_time = 2;
1035 tc->snd_una = tc->snd_nxt = burst;
1036 tc->bytes_acked = burst;
1038 tcp_bt_sample_delivery_rate (tc, rs);
1040 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1041 TCP_TEST (pool_elts (bt->samples) == 0, "sample should've been consumed");
1042 TCP_TEST (tc->delivered_time == 2, "delivered time should be 2");
1043 TCP_TEST (tc->delivered == burst, "delivered should be 100");
1044 TCP_TEST (rs->interval_time == 1, "ack time should be 1");
1045 TCP_TEST (rs->delivered == burst, "delivered should be 100");
1046 TCP_TEST (rs->prior_delivered == 0, "sample delivered should be 0");
1047 TCP_TEST (!(rs->flags & TCP_BTS_IS_RXT), "not retransmitted");
1048 TCP_TEST (tc->first_tx_time == 1, "first_tx_time %u", tc->first_tx_time);
1050 /* 3) track second burst at time 2 */
1051 tcp_bt_track_tx (tc, burst);
1052 tc->snd_nxt += burst;
1054 /* 4) track second burst at time 3 */
1055 session_main.wrk[thread_index].last_vlib_time = 3;
1056 tcp_bt_track_tx (tc, burst);
1057 tc->snd_nxt += burst;
1059 TCP_TEST (pool_elts (bt->samples) == 2, "should have 2 samples");
1061 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1062 bts = pool_elt_at_index (bt->samples, bt->head);
1063 TCP_TEST (bts->min_seq == tc->snd_una, "min seq should be snd_una");
1064 TCP_TEST (bts->next == bt->tail, "next should tail");
1066 bts = pool_elt_at_index (bt->samples, bt->tail);
1067 TCP_TEST (bts->min_seq == tc->snd_nxt - burst,
1068 "min seq should be snd_nxt prior to burst");
1069 TCP_TEST (bts->prev == bt->head, "prev should be head");
1071 /* 5) check delivery rate at time 4 */
1072 session_main.wrk[thread_index].last_vlib_time = 4;
1073 tc->snd_una = tc->snd_nxt;
1074 tc->bytes_acked = 2 * burst;
1076 tcp_bt_sample_delivery_rate (tc, rs);
1078 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1079 TCP_TEST (pool_elts (bt->samples) == 0, "sample should've been consumed");
1080 TCP_TEST (tc->delivered_time == 4, "delivered time should be 4");
1081 TCP_TEST (tc->delivered == 3 * burst, "delivered should be 300 is %u",
1083 TCP_TEST (rs->interval_time == 2, "ack time should be 2");
1084 TCP_TEST (rs->delivered == 2 * burst, "delivered should be 200");
1085 TCP_TEST (rs->prior_delivered == burst, "delivered should be 100");
1086 TCP_TEST (!(rs->flags & TCP_BTS_IS_RXT), "not retransmitted");
1087 TCP_TEST (tc->first_tx_time == 2, "first_tx_time %u", tc->first_tx_time);
1090 * Track retransmissions
1092 * snd_una should be 300 at this point
1095 snd_una = tc->snd_una;
1097 /* 1) track first burst at time 4 */
1098 tcp_bt_track_tx (tc, burst);
1099 tc->snd_nxt += burst;
1101 /* 2) track second burst at time 5 */
1102 session_main.wrk[thread_index].last_vlib_time = 5;
1103 tcp_bt_track_tx (tc, burst);
1104 tc->snd_nxt += burst;
1106 /* 3) track third burst at time 6 */
1107 session_main.wrk[thread_index].last_vlib_time = 6;
1108 tcp_bt_track_tx (tc, burst);
1109 tc->snd_nxt += burst;
1111 /* 4) track fourth burst at time 7 */
1112 session_main.wrk[thread_index].last_vlib_time = 7;
1113 /* Limited until last burst is acked */
1114 tc->app_limited = snd_una + 4 * burst - 1;
1115 tcp_bt_track_tx (tc, burst);
1116 tc->snd_nxt += burst;
1118 /* 5) check delivery rate at time 8
1120 * tc->snd_una = snd_una + 10
1122 * [snd_una + burst, snd_una + burst + 10]
1123 * [snd_una + 2 * burst + 10, snd_una + 2 * burst + 20]
1125 session_main.wrk[thread_index].last_vlib_time = 8;
1127 tc->bytes_acked = 10;
1128 sb->last_sacked_bytes = 20;
1130 TCP_TEST (pool_elts (bt->samples) == 4, "there should be 4 samples");
1132 vec_validate (sacks, 1);
1133 sacks[0].start = snd_una + burst;
1134 sacks[0].end = snd_una + burst + 10;
1135 sacks[1].start = snd_una + 2 * burst + 10;
1136 sacks[1].end = snd_una + 2 * burst + 20;
1137 tc->rcv_opts.sacks = sacks;
1139 tcp_bt_sample_delivery_rate (tc, rs);
1141 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1142 TCP_TEST (pool_elts (bt->samples) == 7, "there should be 7 samples %u",
1143 pool_elts (bt->samples));
1144 TCP_TEST (tc->delivered_time == 8, "delivered time should be 8");
1145 TCP_TEST (tc->delivered == 3 * burst + 30, "delivered should be %u is %u",
1146 3 * burst + 30, tc->delivered);
1147 /* All 3 samples have the same delivered number of bytes. So the first is
1148 * the reference for delivery estimate. */
1149 TCP_TEST (rs->interval_time == 4, "ack time should be 4 is %.2f",
1151 TCP_TEST (rs->delivered == 30, "delivered should be 30");
1152 TCP_TEST (rs->prior_delivered == 3 * burst,
1153 "sample delivered should be %u", 3 * burst);
1154 TCP_TEST (!(rs->flags & TCP_BTS_IS_RXT), "not retransmitted");
1155 TCP_TEST (!(rs->flags & TCP_BTS_IS_APP_LIMITED), "not app limited");
1156 /* All 3 samples have the same delivered number of bytes. The first
1157 * sets the first tx time */
1158 TCP_TEST (tc->first_tx_time == 4, "first_tx_time %u", tc->first_tx_time);
1160 /* 6) Retransmit and track at time 9
1162 * delivered = 3 * burst + 30
1163 * delivered_time = 8 (last ack)
1166 * [snd_una + 10, snd_una + burst]
1167 * [snd_una + burst + 10, snd_una + 2 * burst + 10]
1168 * [snd_una + 2 * burst + 20, snd_una + 4 * burst]
1170 session_main.wrk[thread_index].last_vlib_time = 9;
1172 tcp_bt_track_rxt (tc, snd_una + 10, snd_una + burst);
1173 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1174 /* The retransmit covers everything left from first burst */
1175 TCP_TEST (pool_elts (bt->samples) == 7, "there should be 7 samples %u",
1176 pool_elts (bt->samples));
1178 tcp_bt_track_rxt (tc, snd_una + burst + 10, snd_una + 2 * burst + 10);
1179 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1180 TCP_TEST (pool_elts (bt->samples) == 6, "there should be 6 samples %u",
1181 pool_elts (bt->samples));
1183 /* Retransmit covers last sample entirely so it should be removed */
1184 tcp_bt_track_rxt (tc, snd_una + 2 * burst + 20, snd_una + 4 * burst);
1185 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1186 TCP_TEST (pool_elts (bt->samples) == 5, "there should be 5 samples %u",
1187 pool_elts (bt->samples));
1189 vec_validate (min_seqs, 4);
1190 min_seqs[0] = snd_una + 10;
1191 min_seqs[1] = snd_una + burst;
1192 min_seqs[2] = snd_una + burst + 10;
1193 min_seqs[3] = snd_una + 2 * burst + 10;
1194 min_seqs[4] = snd_una + 2 * burst + 20;
1196 root = bt->sample_lookup.nodes + bt->sample_lookup.root;
1197 bts = bt->samples + bt->head;
1198 for (i = 0; i < vec_len (min_seqs); i++)
1200 if (bts->min_seq != min_seqs[i])
1201 TCP_TEST (0, "should be %u is %u", min_seqs[i], bts->min_seq);
1202 rbn = rb_tree_search_subtree_custom (&bt->sample_lookup, root,
1203 bts->min_seq, tbt_seq_lt);
1204 if (rbn->opaque != bts - bt->samples)
1205 TCP_TEST (0, "lookup should work");
1206 bts = bt->samples + bts->next;
1209 /* 7) check delivery rate at time 10
1211 * tc->snd_una = snd_una + 2 * burst
1213 * [snd_una + 2 * burst + 20, snd_una + 2 * burst + 30]
1214 * [snd_una + 2 * burst + 50, snd_una + 2 * burst + 60]
1216 session_main.wrk[thread_index].last_vlib_time = 10;
1217 tc->snd_una = snd_una + 2 * burst;
1218 tc->bytes_acked = 2 * burst - 10;
1219 sb->last_sacked_bytes = 20;
1221 sacks[0].start = snd_una + 2 * burst + 20;
1222 sacks[0].end = snd_una + 2 * burst + 30;
1223 sacks[1].start = snd_una + 2 * burst + 50;
1224 sacks[1].end = snd_una + 2 * burst + 60;
1226 tcp_bt_sample_delivery_rate (tc, rs);
1228 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1229 TCP_TEST (pool_elts (bt->samples) == 5, "num samples should be 5 is %u",
1230 pool_elts (bt->samples));
1231 TCP_TEST (tc->delivered_time == 10, "delivered time should be 10");
1232 TCP_TEST (tc->delivered == 5 * burst + 40, "delivered should be %u is %u",
1233 5 * burst + 40, tc->delivered);
1234 /* A rxt was acked and delivered time for it is 8 (last ack time) so
1235 * ack_time is 2 (8 - 10). However, first_tx_time for rxt was 4 and rxt
1236 * time 9. Therefore snd_time is 5 (9 - 4)*/
1237 TCP_TEST (rs->interval_time == 5, "ack time should be 5 is %.2f",
1239 /* delivered_now - delivered_rxt ~ 5 * burst + 40 - 3 * burst - 30 */
1240 TCP_TEST (rs->delivered == 2 * burst + 10, "delivered should be 210 is %u",
1242 TCP_TEST (rs->prior_delivered == 3 * burst + 30,
1243 "sample delivered should be %u", 3 * burst + 30);
1244 TCP_TEST (rs->flags & TCP_BTS_IS_RXT, "is retransmitted");
1245 /* Sample is app limited because of the retransmits */
1246 TCP_TEST (rs->flags & TCP_BTS_IS_APP_LIMITED, "is app limited");
1247 TCP_TEST (tc->app_limited, "app limited should be set");
1248 TCP_TEST (tc->first_tx_time == 9, "first_tx_time %u", tc->first_tx_time);
1252 * 8) check delivery rate at time 11
1254 session_main.wrk[thread_index].last_vlib_time = 11;
1255 tc->snd_una = tc->snd_nxt;
1256 tc->bytes_acked = 2 * burst;
1257 sb->last_sacked_bytes = 0;
1258 sb->last_bytes_delivered = 40;
1260 memset (rs, 0, sizeof (*rs));
1261 tcp_bt_sample_delivery_rate (tc, rs);
1263 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1264 TCP_TEST (pool_elts (bt->samples) == 0, "num samples should be 0 is %u",
1265 pool_elts (bt->samples));
1266 TCP_TEST (tc->delivered_time == 11, "delivered time should be 11");
1267 TCP_TEST (tc->delivered == 7 * burst, "delivered should be %u is %u",
1268 7 * burst, tc->delivered);
1269 /* Delivered time at retransmit was 8 so ack_time is 11 - 8 = 3. However,
1270 * first_tx_time for rxt was 4 and rxt time was 9. Therefore snd_time
1272 TCP_TEST (rs->interval_time == 5, "ack time should be 5 is %.2f",
1274 /* delivered_now - delivered_rxt ~ 7 * burst - 3 * burst - 30.
1275 * That's because we didn't retransmit any new segment. */
1276 TCP_TEST (rs->delivered == 4 * burst - 30, "delivered should be 160 is %u",
1278 TCP_TEST (rs->prior_delivered == 3 * burst + 30,
1279 "sample delivered should be %u", 3 * burst + 30);
1280 TCP_TEST (rs->flags & TCP_BTS_IS_RXT, "is retransmitted");
1281 TCP_TEST (rs->flags & TCP_BTS_IS_APP_LIMITED, "is app limited");
1282 TCP_TEST (tc->app_limited == 0, "app limited should be cleared");
1283 TCP_TEST (tc->first_tx_time == 9, "first_tx_time %u", tc->first_tx_time);
1289 tcp_bt_track_tx (tc, burst);
1290 tc->snd_nxt += burst;
1292 session_main.wrk[thread_index].last_vlib_time = 12;
1293 tcp_bt_track_tx (tc, burst);
1294 tc->snd_nxt += burst;
1296 tcp_bt_flush_samples (tc);
1302 vec_free (min_seqs);
1303 tcp_bt_cleanup (tc);
1307 static clib_error_t *
1308 tcp_test (vlib_main_t * vm,
1309 unformat_input_t * input, vlib_cli_command_t * cmd_arg)
1313 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1315 if (unformat (input, "sack"))
1317 res = tcp_test_sack (vm, input);
1319 else if (unformat (input, "session"))
1321 res = tcp_test_session (vm, input);
1323 else if (unformat (input, "lookup"))
1325 res = tcp_test_lookup (vm, input);
1327 else if (unformat (input, "delivery"))
1329 res = tcp_test_delivery (vm, input);
1331 else if (unformat (input, "all"))
1333 if ((res = tcp_test_sack (vm, input)))
1335 if ((res = tcp_test_lookup (vm, input)))
1337 if ((res = tcp_test_delivery (vm, input)))
1346 return clib_error_return (0, "TCP unit test failed");
1351 VLIB_CLI_COMMAND (tcp_test_command, static) =
1354 .short_help = "internal tcp unit tests",
1355 .function = tcp_test,
1360 * fd.io coding-style-patch-verification: ON
1363 * eval: (c-set-style "gnu")