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>
16 #include <vnet/tcp/tcp_inlines.h>
18 #define TCP_TEST_I(_cond, _comment, _args...) \
20 int _evald = (_cond); \
22 fformat(stderr, "FAIL:%d: " _comment "\n", \
25 fformat(stderr, "PASS:%d: " _comment "\n", \
31 #define TCP_TEST(_cond, _comment, _args...) \
33 if (!TCP_TEST_I(_cond, _comment, ##_args)) { \
39 scoreboard_trace_elt_t sb_trace[] = {};
43 tcp_test_scoreboard_replay (vlib_main_t * vm, unformat_input_t * input)
46 tcp_connection_t _tc, *tc = &_tc;
49 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
51 if (unformat (input, "detail"))
55 clib_error_t *e = clib_error_return
56 (0, "unknown input `%U'", format_unformat_error, input);
57 clib_error_report (e);
62 #if TCP_SCOREBOARD_TRACE
63 tc->sack_sb.trace = sb_trace;
65 s = tcp_scoreboard_replay (s, tc, verbose);
66 vlib_cli_output (vm, "%v", s);
71 tcp_test_sack_rx (vlib_main_t * vm, unformat_input_t * input)
73 tcp_connection_t _tc, *tc = &_tc;
74 sack_scoreboard_t *sb = &tc->sack_sb;
75 sack_block_t *sacks = 0, block;
76 sack_scoreboard_hole_t *hole;
79 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
81 if (unformat (input, "verbose"))
83 else if (unformat (input, "replay"))
84 return tcp_test_scoreboard_replay (vm, input);
87 clib_memset (tc, 0, sizeof (*tc));
89 tc->flags |= TCP_CONN_FAST_RECOVERY | TCP_CONN_RECOVERY;
91 tc->snd_una_max = 1000;
93 tc->rcv_opts.flags |= TCP_OPTS_FLAG_SACK;
95 scoreboard_init (&tc->sack_sb);
97 for (i = 0; i < 1000 / 100; i++)
99 block.start = i * 100;
100 block.end = (i + 1) * 100;
101 vec_add1 (sacks, block);
108 for (i = 0; i < 1000 / 200; i++)
110 vec_add1 (tc->rcv_opts.sacks, sacks[i * 2]);
112 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
113 tcp_rcv_sacks (tc, 0);
116 vlib_cli_output (vm, "sb after even blocks (mss %u):\n%U",
117 tc->snd_mss, format_tcp_scoreboard, sb, tc);
119 TCP_TEST ((pool_elts (sb->holes) == 5),
120 "scoreboard has %d elements", pool_elts (sb->holes));
122 /* First SACK block should be rejected */
123 hole = scoreboard_first_hole (sb);
124 TCP_TEST ((hole->start == 0 && hole->end == 200),
125 "first hole start %u end %u", hole->start, hole->end);
126 hole = scoreboard_last_hole (sb);
127 TCP_TEST ((hole->start == 900 && hole->end == 1000),
128 "last hole start %u end %u", hole->start, hole->end);
129 TCP_TEST ((sb->sacked_bytes == 400), "sacked bytes %d", sb->sacked_bytes);
130 TCP_TEST ((!sb->is_reneging), "is not reneging");
131 TCP_TEST ((sb->last_sacked_bytes == 400),
132 "last sacked bytes %d", sb->last_sacked_bytes);
133 TCP_TEST ((sb->high_sacked == 900), "high sacked %u", sb->high_sacked);
134 TCP_TEST ((sb->lost_bytes == 300), "lost bytes %u", sb->lost_bytes);
137 * Inject odd blocks except the last
141 vec_reset_length (tc->rcv_opts.sacks);
142 for (i = 0; i < 800 / 200; i++)
144 vec_add1 (tc->rcv_opts.sacks, sacks[i * 2 + 1]);
146 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
147 tcp_rcv_sacks (tc, 0);
150 vlib_cli_output (vm, "\nsb after odd blocks:\n%U", format_tcp_scoreboard,
153 hole = scoreboard_first_hole (sb);
154 TCP_TEST ((pool_elts (sb->holes) == 2),
155 "scoreboard has %d holes", pool_elts (sb->holes));
156 TCP_TEST ((hole->start == 0 && hole->end == 100),
157 "first hole start %u end %u", hole->start, hole->end);
158 TCP_TEST ((sb->sacked_bytes == 800), "sacked bytes %d", sb->sacked_bytes);
159 TCP_TEST ((!sb->is_reneging), "is not reneging");
160 TCP_TEST ((sb->high_sacked == 900), "high sacked %u", sb->high_sacked);
161 TCP_TEST ((sb->last_sacked_bytes == 400),
162 "last sacked bytes %d", sb->last_sacked_bytes);
163 TCP_TEST ((sb->lost_bytes == 100), "lost bytes %u", sb->lost_bytes);
166 * Ack until byte 100 - this is reneging because we should ack until 900
168 tcp_rcv_sacks (tc, 100);
170 vlib_cli_output (vm, "\nack until byte 100:\n%U", format_tcp_scoreboard,
173 TCP_TEST ((pool_elts (sb->holes) == 1), "scoreboard has %d elements",
174 pool_elts (sb->holes));
175 TCP_TEST ((sb->is_reneging), "is reneging");
178 * Make sure we accept duplicate acks while reneging.
185 vec_add1 (tc->rcv_opts.sacks, block);
187 tcp_rcv_sacks (tc, 100);
188 TCP_TEST ((pool_elts (sb->holes) == 1), "scoreboard has %d elements",
189 pool_elts (sb->holes));
190 TCP_TEST ((sb->is_reneging), "is reneging");
191 TCP_TEST ((sb->last_sacked_bytes == 50), "last sacked bytes %d",
192 sb->last_sacked_bytes);
193 TCP_TEST ((sb->rxt_sacked == 50), "last rxt sacked bytes %d",
199 tcp_rcv_sacks (tc, 950);
200 TCP_TEST ((sb->high_sacked == 950), "max sacked byte %u", sb->high_sacked);
201 TCP_TEST ((sb->sacked_bytes == 0), "sacked bytes %d", sb->sacked_bytes);
202 TCP_TEST ((sb->last_sacked_bytes == 0),
203 "last sacked bytes %d", sb->last_sacked_bytes);
204 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
205 TCP_TEST ((!sb->is_reneging), "is not reneging");
208 * Sack [960 970] [980 990]
213 vec_reset_length (tc->rcv_opts.sacks);
216 vec_add1 (tc->rcv_opts.sacks, block);
220 vec_add1 (tc->rcv_opts.sacks, block);
222 tcp_rcv_sacks (tc, 950);
223 TCP_TEST ((sb->high_sacked == 990), "max sacked byte %u", sb->high_sacked);
224 TCP_TEST ((sb->sacked_bytes == 20), "sacked bytes %d", sb->sacked_bytes);
225 TCP_TEST ((sb->last_sacked_bytes == 20),
226 "last sacked bytes %d", sb->last_sacked_bytes);
227 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
228 TCP_TEST ((!sb->is_reneging), "is not reneging");
229 TCP_TEST ((sb->rxt_sacked == 15), "last rxt sacked bytes %d",
233 * Ack up to 960 (reneging) + [961 971]
235 tc->rcv_opts.sacks[0].start = 961;
236 tc->rcv_opts.sacks[0].end = 971;
238 tcp_rcv_sacks (tc, 960);
240 TCP_TEST ((sb->is_reneging), "is reneging");
241 TCP_TEST ((sb->sacked_bytes == 21), "sacked bytes %d", sb->sacked_bytes);
242 TCP_TEST ((sb->last_sacked_bytes == 1),
243 "last sacked bytes %d", sb->last_sacked_bytes);
244 TCP_TEST ((sb->rxt_sacked == 11), "last rxt sacked bytes %d",
246 TCP_TEST ((sb->last_bytes_delivered == 0), "last bytes delivered %d",
247 sb->last_bytes_delivered);
250 * Ack up to 960 (reneging) + [961 990]
253 tc->rcv_opts.sacks[0].start = 961;
254 tc->rcv_opts.sacks[0].end = 990;
256 tcp_rcv_sacks (tc, 960);
258 TCP_TEST ((sb->is_reneging), "is reneging");
259 TCP_TEST ((sb->sacked_bytes == 30), "sacked bytes %d", sb->sacked_bytes);
260 TCP_TEST ((sb->last_sacked_bytes == 9),
261 "last sacked bytes %d", sb->last_sacked_bytes);
262 TCP_TEST ((sb->rxt_sacked == 9), "last rxt sacked bytes %d",
266 * Sack remaining bytes [990 1000]
268 tc->rcv_opts.sacks[0].start = 990;
269 tc->rcv_opts.sacks[0].end = 1000;
271 tcp_rcv_sacks (tc, 960);
273 TCP_TEST ((sb->is_reneging), "is reneging");
274 TCP_TEST ((sb->sacked_bytes == 40), "sacked bytes %d", sb->sacked_bytes);
275 TCP_TEST ((sb->last_sacked_bytes == 10),
276 "last sacked bytes %d", sb->last_sacked_bytes);
277 TCP_TEST ((sb->rxt_sacked == 0), "last rxt sacked bytes %d",
279 TCP_TEST (pool_elts (sb->holes) == 0, "no holes left");
282 * Ack up to 970 no sack blocks
284 vec_reset_length (tc->rcv_opts.sacks);
285 tc->rcv_opts.flags &= ~TCP_OPTS_FLAG_SACK;
286 tcp_rcv_sacks (tc, 970);
288 TCP_TEST ((sb->is_reneging), "is reneging");
289 TCP_TEST ((sb->sacked_bytes == 30), "sacked bytes %d", sb->sacked_bytes);
290 TCP_TEST ((sb->last_sacked_bytes == 0),
291 "last sacked bytes %d", sb->last_sacked_bytes);
292 TCP_TEST ((sb->rxt_sacked == 0), "last rxt sacked bytes %d",
299 tcp_rcv_sacks (tc, 1000);
300 TCP_TEST ((sb->high_sacked == 1000), "max sacked byte %u", sb->high_sacked);
301 TCP_TEST ((sb->sacked_bytes == 0), "sacked bytes %d", sb->sacked_bytes);
302 TCP_TEST (sb->last_bytes_delivered == 30, "last bytes delivered %d",
303 sb->last_bytes_delivered);
304 TCP_TEST ((sb->last_sacked_bytes == 0),
305 "last sacked bytes %d", sb->last_sacked_bytes);
306 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
307 TCP_TEST ((!sb->is_reneging), "is not reneging");
313 tc->rcv_opts.flags |= TCP_OPTS_FLAG_SACK;
314 vec_reset_length (tc->rcv_opts.sacks);
318 vec_add1 (tc->rcv_opts.sacks, block);
320 tc->snd_una_max = 1500;
323 tcp_rcv_sacks (tc, 1000);
326 vlib_cli_output (vm, "\nadd [1200, 1300] snd_una_max 1500, snd_una 1000:"
327 " \n%U", format_tcp_scoreboard, sb, tc);
329 TCP_TEST ((!sb->is_reneging), "is not reneging");
330 TCP_TEST ((pool_elts (sb->holes) == 2),
331 "scoreboard has %d holes", pool_elts (sb->holes));
332 hole = scoreboard_first_hole (sb);
333 TCP_TEST ((hole->start == 1000 && hole->end == 1200),
334 "first hole start %u end %u", hole->start, hole->end);
335 TCP_TEST ((sb->high_sacked == 1300), "max sacked byte %u", sb->high_sacked);
336 hole = scoreboard_last_hole (sb);
337 TCP_TEST ((hole->start == 1300 && hole->end == 1500),
338 "last hole start %u end %u", hole->start, hole->end);
339 TCP_TEST ((sb->sacked_bytes == 100), "sacked bytes %d", sb->sacked_bytes);
340 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
346 vec_reset_length (tc->rcv_opts.sacks);
347 /* Ack up to 1300 to avoid reneging */
348 tcp_rcv_sacks (tc, 1300);
351 vlib_cli_output (vm, "\nsb ack up to byte 1300:\n%U",
352 format_tcp_scoreboard, sb, tc);
354 TCP_TEST ((sb->sacked_bytes == 0), "sacked bytes %d", sb->sacked_bytes);
355 TCP_TEST ((pool_elts (sb->holes) == 1),
356 "scoreboard has %d elements", pool_elts (sb->holes));
357 TCP_TEST ((sb->last_bytes_delivered == 100), "last bytes delivered %d",
358 sb->last_bytes_delivered);
359 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
360 TCP_TEST ((sb->head != TCP_INVALID_SACK_HOLE_INDEX), "head %u", sb->head);
361 TCP_TEST ((sb->tail != TCP_INVALID_SACK_HOLE_INDEX), "tail %u", sb->tail);
362 TCP_TEST ((!sb->is_reneging), "is not reneging");
365 * Add some more blocks and then remove all
367 vec_reset_length (tc->rcv_opts.sacks);
369 tc->snd_nxt = tc->snd_una_max = 1900;
370 for (i = 0; i < 5; i++)
372 block.start = i * 100 + 1200;
373 block.end = (i + 1) * 100 + 1200;
374 vec_add1 (tc->rcv_opts.sacks, block);
376 tcp_rcv_sacks (tc, 1900);
378 scoreboard_clear (sb);
380 vlib_cli_output (vm, "\nsb cleared all:\n%U", format_tcp_scoreboard, sb,
383 TCP_TEST ((pool_elts (sb->holes) == 0),
384 "number of holes %d", pool_elts (sb->holes));
385 TCP_TEST ((sb->head == TCP_INVALID_SACK_HOLE_INDEX), "head %u", sb->head);
386 TCP_TEST ((sb->tail == TCP_INVALID_SACK_HOLE_INDEX), "tail %u", sb->tail);
389 * Re-inject odd blocks and ack them all
393 tc->snd_una_max = 1000;
395 vec_reset_length (tc->rcv_opts.sacks);
396 for (i = 0; i < 5; i++)
398 vec_add1 (tc->rcv_opts.sacks, sacks[i * 2 + 1]);
400 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
401 tcp_rcv_sacks (tc, 0);
403 vlib_cli_output (vm, "\nsb added odd blocks snd_una 0 snd_una_max 1000:"
404 "\n%U", format_tcp_scoreboard, sb, tc);
405 TCP_TEST ((pool_elts (sb->holes) == 5),
406 "scoreboard has %d elements", pool_elts (sb->holes));
407 TCP_TEST ((sb->lost_bytes == 300), "lost bytes %u", sb->lost_bytes);
408 hole = scoreboard_last_hole (sb);
409 TCP_TEST ((hole->end == 900), "last hole end %u", hole->end);
410 TCP_TEST ((sb->high_sacked == 1000), "high sacked %u", sb->high_sacked);
413 * Renege bytes from 950 to 1000
415 tcp_rcv_sacks (tc, 950);
418 vlib_cli_output (vm, "\nack [0, 950]:\n%U", format_tcp_scoreboard, sb,
421 TCP_TEST ((pool_elts (sb->holes) == 0), "scoreboard has %d elements",
422 pool_elts (sb->holes));
423 TCP_TEST ((sb->is_reneging), "is reneging");
424 TCP_TEST ((sb->sacked_bytes == 50), "sacked bytes %d", sb->sacked_bytes);
425 TCP_TEST ((sb->last_sacked_bytes == 0), "last sacked bytes %d",
426 sb->last_sacked_bytes);
427 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
428 TCP_TEST ((sb->high_sacked == 1000), "high sacked %u", sb->high_sacked);
430 scoreboard_clear (sb);
433 * Inject one block, ack it and overlap hole
437 tc->snd_una_max = 1000;
442 vec_add1 (tc->rcv_opts.sacks, block);
443 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
445 tcp_rcv_sacks (tc, 0);
448 vlib_cli_output (vm, "\nsb added [100, 500] snd_una 0 snd_una_max 1000:"
449 "\n%U", format_tcp_scoreboard, sb, tc);
451 tcp_rcv_sacks (tc, 800);
454 vlib_cli_output (vm, "\nsb ack [0, 800]:\n%U", format_tcp_scoreboard, sb,
457 TCP_TEST ((pool_elts (sb->holes) == 1),
458 "scoreboard has %d elements", pool_elts (sb->holes));
459 TCP_TEST ((!sb->is_reneging), "is not reneging");
460 TCP_TEST ((sb->sacked_bytes == 0), "sacked bytes %d", sb->sacked_bytes);
461 TCP_TEST ((sb->last_sacked_bytes == 0), "last sacked bytes %d",
462 sb->last_sacked_bytes);
463 TCP_TEST ((sb->last_bytes_delivered == 400),
464 "last bytes delivered %d", sb->last_bytes_delivered);
465 TCP_TEST ((sb->lost_bytes == 0), "lost bytes %u", sb->lost_bytes);
466 TCP_TEST ((sb->head != TCP_INVALID_SACK_HOLE_INDEX), "head %u", sb->head);
467 TCP_TEST ((sb->tail != TCP_INVALID_SACK_HOLE_INDEX), "tail %u", sb->tail);
470 * One hole close to head, patch head, split in two and start acking
473 scoreboard_clear (sb);
475 tc->snd_una_max = 1000;
480 vec_add1 (tc->rcv_opts.sacks, block);
481 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
483 tcp_rcv_sacks (tc, 0);
485 vlib_cli_output (vm, "\nsb added [500, 1000]:\n%U",
486 format_tcp_scoreboard, sb, tc);
487 TCP_TEST ((sb->sacked_bytes == 500), "sacked bytes %d", sb->sacked_bytes);
488 TCP_TEST ((sb->last_sacked_bytes == 500), "last sacked bytes %d",
489 sb->last_sacked_bytes);
490 TCP_TEST ((sb->lost_bytes == 500), "lost bytes %u", sb->lost_bytes);
492 vec_reset_length (tc->rcv_opts.sacks);
495 vec_add1 (tc->rcv_opts.sacks, block);
496 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
497 tcp_rcv_sacks (tc, 100);
499 vlib_cli_output (vm, "\nsb added [0, 100] [300, 400]:\n%U",
500 format_tcp_scoreboard, sb, tc);
501 TCP_TEST ((pool_elts (sb->holes) == 2),
502 "scoreboard has %d elements", pool_elts (sb->holes));
503 TCP_TEST ((sb->sacked_bytes == 600), "sacked bytes %d", sb->sacked_bytes);
504 TCP_TEST ((sb->last_sacked_bytes == 100), "last sacked bytes %d",
505 sb->last_sacked_bytes);
506 TCP_TEST ((sb->last_bytes_delivered == 0), "last bytes delivered %d",
507 sb->last_bytes_delivered);
508 TCP_TEST ((sb->lost_bytes == 300), "lost bytes %u", sb->lost_bytes);
511 * Ack [100 300] in two steps
513 * Step 1. Ack [100 200] which delivers 100 of the bytes lost
516 tcp_rcv_sacks (tc, 200);
517 TCP_TEST ((sb->sacked_bytes == 600), "sacked bytes %d", sb->sacked_bytes);
518 TCP_TEST ((sb->last_bytes_delivered == 0), "last bytes delivered %d",
519 sb->last_bytes_delivered);
520 TCP_TEST ((sb->lost_bytes == 200), "lost bytes %u", sb->lost_bytes);
523 * Step 2. Ack up to 300, although 300 400 is sacked, so this is interpreted
527 tcp_rcv_sacks (tc, 300);
529 vlib_cli_output (vm, "\nacked [100, 300] in two steps:\n%U",
530 format_tcp_scoreboard, sb, tc);
531 TCP_TEST ((sb->sacked_bytes == 600), "sacked bytes %d", sb->sacked_bytes);
532 TCP_TEST ((sb->lost_bytes == 100), "lost bytes %u", sb->lost_bytes);
533 TCP_TEST ((sb->last_bytes_delivered == 0), "last bytes delivered %d",
534 sb->last_bytes_delivered);
535 TCP_TEST ((sb->is_reneging), "is reneging");
538 * Ack [300 500]. Delivers reneged segment [300 400] and reneges bytes
542 tcp_rcv_sacks (tc, 500);
544 vlib_cli_output (vm, "\nacked [400, 500]:\n%U", format_tcp_scoreboard, sb,
546 TCP_TEST ((pool_elts (sb->holes) == 0),
547 "scoreboard has %d elements", pool_elts (sb->holes));
548 TCP_TEST ((sb->sacked_bytes == 500), "sacked bytes %d", sb->sacked_bytes);
549 TCP_TEST ((sb->last_sacked_bytes == 0), "last sacked bytes %d",
550 sb->last_sacked_bytes);
551 TCP_TEST ((sb->last_bytes_delivered == 100), "last bytes delivered %d",
552 sb->last_bytes_delivered);
553 TCP_TEST ((sb->is_reneging), "is reneging");
554 TCP_TEST ((sb->head == TCP_INVALID_SACK_HOLE_INDEX), "head %u", sb->head);
555 TCP_TEST ((sb->tail == TCP_INVALID_SACK_HOLE_INDEX), "tail %u", sb->tail);
558 * Ack up to 1000 to deliver all bytes
561 tcp_rcv_sacks (tc, 1000);
563 vlib_cli_output (vm, "\nAck high sacked:\n%U", format_tcp_scoreboard, sb,
565 TCP_TEST ((sb->last_sacked_bytes == 0), "last sacked bytes %d",
566 sb->last_sacked_bytes);
567 TCP_TEST ((sb->last_bytes_delivered == 500), "last bytes delivered %d",
568 sb->last_bytes_delivered);
569 TCP_TEST ((!sb->is_reneging), "is not reneging");
572 * Add [1200, 1500] and test that [1000, 1200] is lost (bytes condition)
573 * snd_una = 1000 and snd_una_max = 1600
576 tc->snd_nxt = tc->snd_una_max = 1600;
577 vec_reset_length (tc->rcv_opts.sacks);
580 vec_add1 (tc->rcv_opts.sacks, block);
581 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
582 tcp_rcv_sacks (tc, 1000);
584 vlib_cli_output (vm, "\nacked [1200, 1500] test first hole is lost:\n%U",
585 format_tcp_scoreboard, sb, tc);
586 TCP_TEST ((pool_elts (sb->holes) == 2), "scoreboard has %d elements",
587 pool_elts (sb->holes));
588 TCP_TEST ((sb->sacked_bytes == 300), "sacked bytes %d", sb->sacked_bytes);
589 TCP_TEST ((sb->last_sacked_bytes == 300), "last sacked bytes %d",
590 sb->last_sacked_bytes);
591 TCP_TEST ((sb->last_bytes_delivered == 0), "last bytes delivered %d",
592 sb->last_bytes_delivered);
593 TCP_TEST ((sb->lost_bytes == 200), "lost bytes %u", sb->lost_bytes);
594 TCP_TEST ((!sb->is_reneging), "is not reneging");
599 scoreboard_clear (sb);
600 vec_reset_length (tc->rcv_opts.sacks);
606 tc->flags |= TCP_CONN_FAST_RECOVERY | TCP_CONN_RECOVERY;
608 tc->snd_una_max = 1000;
614 vec_add1 (tc->rcv_opts.sacks, block);
615 tc->rcv_opts.n_sack_blocks = vec_len (tc->rcv_opts.sacks);
617 tcp_rcv_sacks (tc, 0);
619 TCP_TEST ((sb->sacked_bytes == 400), "sacked bytes %d", sb->sacked_bytes);
620 TCP_TEST ((sb->last_sacked_bytes == 400), "last sacked bytes %d",
621 sb->last_sacked_bytes);
622 TCP_TEST ((!sb->is_reneging), "is not reneging");
625 * Renege, sack all of the remaining bytes and cover some rxt bytes
628 tc->rcv_opts.sacks[0].start = 500;
629 tc->rcv_opts.sacks[0].end = 1000;
631 tcp_rcv_sacks (tc, 100);
633 TCP_TEST ((sb->sacked_bytes == 900), "sacked bytes %d", sb->sacked_bytes);
634 TCP_TEST ((sb->last_sacked_bytes == 500), "last sacked bytes %d",
635 sb->last_sacked_bytes);
636 TCP_TEST (sb->is_reneging, "is reneging");
637 TCP_TEST ((sb->rxt_sacked == 300), "last rxt sacked bytes %d",
644 tcp_test_sack_tx (vlib_main_t * vm, unformat_input_t * input)
646 tcp_connection_t _tc, *tc = &_tc;
648 int i, verbose = 0, expected;
650 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
652 if (unformat (input, "verbose"))
656 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
662 clib_memset (tc, 0, sizeof (*tc));
665 * Add odd sack block pairs
667 for (i = 1; i < 10; i += 2)
669 tcp_update_sack_list (tc, i * 100, (i + 1) * 100);
672 TCP_TEST ((vec_len (tc->snd_sacks) == 5), "sack blocks %d expected %d",
673 vec_len (tc->snd_sacks), 5);
674 TCP_TEST ((tc->snd_sacks[0].start = 900),
675 "first sack block start %u expected %u", tc->snd_sacks[0].start,
679 * Try to add one extra
681 sacks = vec_dup (tc->snd_sacks);
683 tcp_update_sack_list (tc, 1100, 1200);
685 vlib_cli_output (vm, "add new segment [1100, 1200]\n%U",
686 format_tcp_sacks, tc);
687 expected = 5 < TCP_MAX_SACK_BLOCKS ? 6 : 5;
688 TCP_TEST ((vec_len (tc->snd_sacks) == expected),
689 "sack blocks %d expected %d", vec_len (tc->snd_sacks), expected);
690 TCP_TEST ((tc->snd_sacks[0].start == 1100),
691 "first sack block start %u expected %u", tc->snd_sacks[0].start,
695 vec_free (tc->snd_sacks);
696 tc->snd_sacks = sacks;
699 * Overlap first 2 segment
702 tcp_update_sack_list (tc, 300, 300);
704 vlib_cli_output (vm, "overlap first 2 segments:\n%U",
705 format_tcp_sacks, tc);
706 TCP_TEST ((vec_len (tc->snd_sacks) == 3), "sack blocks %d expected %d",
707 vec_len (tc->snd_sacks), 3);
708 TCP_TEST ((tc->snd_sacks[0].start == 900),
709 "first sack block start %u expected %u", tc->snd_sacks[0].start,
715 tcp_update_sack_list (tc, 1100, 1200);
717 vlib_cli_output (vm, "add new segment [1100, 1200]\n%U",
718 format_tcp_sacks, tc);
719 TCP_TEST ((vec_len (tc->snd_sacks) == 4), "sack blocks %d expected %d",
720 vec_len (tc->snd_sacks), 4);
721 TCP_TEST ((tc->snd_sacks[0].start == 1100),
722 "first sack block start %u expected %u", tc->snd_sacks[0].start,
726 * Join middle segments
728 tcp_update_sack_list (tc, 800, 900);
730 vlib_cli_output (vm, "join middle segments [800, 900]\n%U",
731 format_tcp_sacks, tc);
733 TCP_TEST ((vec_len (tc->snd_sacks) == 3), "sack blocks %d expected %d",
734 vec_len (tc->snd_sacks), 3);
735 TCP_TEST ((tc->snd_sacks[0].start == 700),
736 "first sack block start %u expected %u", tc->snd_sacks[0].start,
740 * Advance rcv_nxt to overlap all
743 tcp_update_sack_list (tc, 1200, 1200);
745 vlib_cli_output (vm, "advance rcv_nxt to 1200\n%U", format_tcp_sacks, tc);
746 TCP_TEST ((vec_len (tc->snd_sacks) == 0), "sack blocks %d expected %d",
747 vec_len (tc->snd_sacks), 0);
751 * Add 2 blocks, overwrite first and update rcv_nxt to also remove it
754 vec_reset_length (tc->snd_sacks);
757 tcp_update_sack_list (tc, 100, 200);
758 tcp_update_sack_list (tc, 300, 400);
761 vlib_cli_output (vm, "add [100, 200] [300, 400]\n%U",
762 format_tcp_sacks, tc);
763 TCP_TEST ((vec_len (tc->snd_sacks) == 2),
764 "sack blocks %d expected %d", vec_len (tc->snd_sacks), 2);
765 TCP_TEST ((tc->snd_sacks[0].start == 300),
766 "first sack block start %u expected %u", tc->snd_sacks[0].start,
770 tcp_update_sack_list (tc, 100, 100);
772 vlib_cli_output (vm, "add [100, 200] rcv_nxt = 100\n%U",
773 format_tcp_sacks, tc);
774 TCP_TEST ((vec_len (tc->snd_sacks) == 1),
775 "sack blocks %d expected %d", vec_len (tc->snd_sacks), 1);
776 TCP_TEST ((tc->snd_sacks[0].start == 300),
777 "first sack block start %u expected %u", tc->snd_sacks[0].start,
783 tcp_test_sack (vlib_main_t * vm, unformat_input_t * input)
788 if (unformat_check_input (input) == UNFORMAT_END_OF_INPUT)
790 if (tcp_test_sack_tx (vm, input))
795 if (tcp_test_sack_rx (vm, input))
802 if (unformat (input, "tx"))
804 res = tcp_test_sack_tx (vm, input);
806 else if (unformat (input, "rx"))
808 res = tcp_test_sack_rx (vm, input);
816 tcp_test_lookup (vlib_main_t * vm, unformat_input_t * input)
818 session_main_t *smm = &session_main;
819 transport_connection_t _tc1, *tc1 = &_tc1, _tc2, *tc2 = &_tc2, *tconn;
820 tcp_connection_t *tc;
822 u8 cmp = 0, is_filtered = 0;
826 * Allocate fake session and connection 1
828 pool_get (smm->wrk[0].sessions, s);
829 clib_memset (s, 0, sizeof (*s));
830 s->session_index = sidx = s - smm->wrk[0].sessions;
832 tc = tcp_connection_alloc (0);
833 tc->connection.s_index = s->session_index;
834 s->connection_index = tc->connection.c_index;
836 tc->connection.lcl_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000101);
837 tc->connection.rmt_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000103);
838 tc->connection.lcl_port = 35051;
839 tc->connection.rmt_port = 53764;
840 tc->connection.proto = TRANSPORT_PROTO_TCP;
841 tc->connection.is_ip4 = 1;
842 clib_memcpy_fast (tc1, &tc->connection, sizeof (*tc1));
845 * Allocate fake session and connection 2
847 pool_get (smm->wrk[0].sessions, s);
848 clib_memset (s, 0, sizeof (*s));
849 s->session_index = s - smm->wrk[0].sessions;
851 tc = tcp_connection_alloc (0);
852 tc->connection.s_index = s->session_index;
853 s->connection_index = tc->connection.c_index;
855 tc->connection.lcl_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000101);
856 tc->connection.rmt_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000102);
857 tc->connection.lcl_port = 38225;
858 tc->connection.rmt_port = 53764;
859 tc->connection.proto = TRANSPORT_PROTO_TCP;
860 tc->connection.is_ip4 = 1;
861 clib_memcpy_fast (tc2, &tc->connection, sizeof (*tc2));
864 * Confirm that connection lookup works
867 s1 = pool_elt_at_index (smm->wrk[0].sessions, sidx);
868 session_lookup_add_connection (tc1, session_handle (s1));
869 tconn = session_lookup_connection_wt4 (0, &tc1->lcl_ip.ip4,
871 tc1->lcl_port, tc1->rmt_port,
872 tc1->proto, 0, &is_filtered);
874 TCP_TEST ((tconn != 0), "connection exists");
875 cmp = (memcmp (&tconn->rmt_ip, &tc1->rmt_ip, sizeof (tc1->rmt_ip)) == 0);
876 TCP_TEST ((cmp), "rmt ip is identical %d", cmp);
877 TCP_TEST ((tconn->lcl_port == tc1->lcl_port),
878 "rmt port is identical %d", tconn->lcl_port == tc1->lcl_port);
881 * Non-existing connection lookup should not work
884 tconn = session_lookup_connection_wt4 (0, &tc2->lcl_ip.ip4,
886 tc2->lcl_port, tc2->rmt_port,
887 tc2->proto, 0, &is_filtered);
888 TCP_TEST ((tconn == 0), "lookup result should be null");
891 * Delete and lookup again
893 session_lookup_del_connection (tc1);
894 tconn = session_lookup_connection_wt4 (0, &tc1->lcl_ip.ip4,
896 tc1->lcl_port, tc1->rmt_port,
897 tc1->proto, 0, &is_filtered);
898 TCP_TEST ((tconn == 0), "lookup result should be null");
899 tconn = session_lookup_connection_wt4 (0, &tc2->lcl_ip.ip4,
901 tc2->lcl_port, tc2->rmt_port,
902 tc2->proto, 0, &is_filtered);
903 TCP_TEST ((tconn == 0), "lookup result should be null");
906 * Re-add and lookup tc2
908 session_lookup_add_connection (tc1, tc1->s_index);
909 tconn = session_lookup_connection_wt4 (0, &tc2->lcl_ip.ip4,
911 tc2->lcl_port, tc2->rmt_port,
912 tc2->proto, 0, &is_filtered);
913 TCP_TEST ((tconn == 0), "lookup result should be null");
919 tcp_test_session (vlib_main_t * vm, unformat_input_t * input)
922 tcp_connection_t *tc0;
923 ip4_address_t local, remote;
924 u16 local_port, remote_port;
928 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
930 if (unformat (input, "del"))
932 else if (unformat (input, "add"))
940 local.as_u32 = clib_host_to_net_u32 (0x06000101);
941 remote.as_u32 = clib_host_to_net_u32 (0x06000102);
942 local_port = clib_host_to_net_u16 (1234);
943 remote_port = clib_host_to_net_u16 (11234);
945 tc0 = tcp_connection_alloc (0);
947 tc0->state = TCP_STATE_ESTABLISHED;
949 tc0->c_lcl_port = local_port;
950 tc0->c_rmt_port = remote_port;
952 tc0->c_thread_index = 0;
953 tc0->c_lcl_ip4.as_u32 = local.as_u32;
954 tc0->c_rmt_ip4.as_u32 = remote.as_u32;
955 tc0->rcv_opts.mss = 1450;
956 tcp_connection_init_vars (tc0);
958 TCP_EVT (TCP_EVT_OPEN, tc0);
960 if (session_stream_accept (&tc0->connection, 0 /* listener index */ ,
961 0 /* thread index */ , 0 /* notify */ ))
962 clib_warning ("stream_session_accept failed");
964 session_stream_accept_notify (&tc0->connection);
968 tc0 = tcp_connection_get (0 /* connection index */ , 0 /* thread */ );
969 tc0->state = TCP_STATE_CLOSED;
970 session_transport_closing_notify (&tc0->connection);
977 tbt_seq_lt (u32 a, u32 b)
979 return seq_lt (a, b);
983 tcp_test_delivery (vlib_main_t * vm, unformat_input_t * input)
985 u32 thread_index = 0, snd_una, *min_seqs = 0;
986 tcp_rate_sample_t _rs = { 0 }, *rs = &_rs;
987 tcp_connection_t _tc, *tc = &_tc;
988 sack_scoreboard_t *sb = &tc->sack_sb;
989 int __clib_unused verbose = 0, i;
990 u64 rate = 1000, burst = 100;
991 sack_block_t *sacks = 0;
992 tcp_byte_tracker_t *bt;
993 rb_node_t *root, *rbn;
994 tcp_bt_sample_t *bts;
996 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
998 if (unformat (input, "verbose"))
1002 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1008 /* Init data structures */
1009 memset (tc, 0, sizeof (*tc));
1010 session_main.wrk[thread_index].last_vlib_time = 1;
1011 transport_connection_tx_pacer_update (&tc->connection, rate, 1e6);
1017 * Track simple bursts without rxt
1020 /* 1) track first burst a time 1 */
1021 tcp_bt_track_tx (tc, burst);
1023 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1024 TCP_TEST (pool_elts (bt->samples) == 1, "should have 1 sample");
1025 bts = pool_elt_at_index (bt->samples, bt->head);
1026 TCP_TEST (bts->min_seq == tc->snd_una, "min seq should be snd_una");
1027 TCP_TEST (bts->next == TCP_BTS_INVALID_INDEX, "next should be invalid");
1028 TCP_TEST (bts->prev == TCP_BTS_INVALID_INDEX, "prev should be invalid");
1029 TCP_TEST (bts->delivered_time == 1, "delivered time should be 1");
1030 TCP_TEST (bts->delivered == 0, "delivered should be 0");
1031 TCP_TEST (!(bts->flags & TCP_BTS_IS_RXT), "not retransmitted");
1032 TCP_TEST (!(bts->flags & TCP_BTS_IS_APP_LIMITED), "not app limited");
1034 /* 2) check delivery rate at time 2 */
1035 session_main.wrk[thread_index].last_vlib_time = 2;
1036 tc->snd_una = tc->snd_nxt = burst;
1037 tc->bytes_acked = burst;
1039 tcp_bt_sample_delivery_rate (tc, rs);
1041 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1042 TCP_TEST (pool_elts (bt->samples) == 0, "sample should've been consumed");
1043 TCP_TEST (tc->delivered_time == 2, "delivered time should be 2");
1044 TCP_TEST (tc->delivered == burst, "delivered should be 100");
1045 TCP_TEST (rs->interval_time == 1, "ack time should be 1");
1046 TCP_TEST (rs->delivered == burst, "delivered should be 100");
1047 TCP_TEST (rs->prior_delivered == 0, "sample delivered should be 0");
1048 TCP_TEST (!(rs->flags & TCP_BTS_IS_RXT), "not retransmitted");
1049 TCP_TEST (tc->first_tx_time == 1, "first_tx_time %u", tc->first_tx_time);
1051 /* 3) track second burst at time 2 */
1052 tcp_bt_track_tx (tc, burst);
1053 tc->snd_nxt += burst;
1055 /* 4) track second burst at time 3 */
1056 session_main.wrk[thread_index].last_vlib_time = 3;
1057 tcp_bt_track_tx (tc, burst);
1058 tc->snd_nxt += burst;
1060 TCP_TEST (pool_elts (bt->samples) == 2, "should have 2 samples");
1062 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1063 bts = pool_elt_at_index (bt->samples, bt->head);
1064 TCP_TEST (bts->min_seq == tc->snd_una, "min seq should be snd_una");
1065 TCP_TEST (bts->next == bt->tail, "next should tail");
1067 bts = pool_elt_at_index (bt->samples, bt->tail);
1068 TCP_TEST (bts->min_seq == tc->snd_nxt - burst,
1069 "min seq should be snd_nxt prior to burst");
1070 TCP_TEST (bts->prev == bt->head, "prev should be head");
1072 /* 5) check delivery rate at time 4 */
1073 session_main.wrk[thread_index].last_vlib_time = 4;
1074 tc->snd_una = tc->snd_nxt;
1075 tc->bytes_acked = 2 * burst;
1077 tcp_bt_sample_delivery_rate (tc, rs);
1079 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1080 TCP_TEST (pool_elts (bt->samples) == 0, "sample should've been consumed");
1081 TCP_TEST (tc->delivered_time == 4, "delivered time should be 4");
1082 TCP_TEST (tc->delivered == 3 * burst, "delivered should be 300 is %u",
1084 TCP_TEST (rs->interval_time == 2, "ack time should be 2");
1085 TCP_TEST (rs->delivered == 2 * burst, "delivered should be 200");
1086 TCP_TEST (rs->prior_delivered == burst, "delivered should be 100");
1087 TCP_TEST (!(rs->flags & TCP_BTS_IS_RXT), "not retransmitted");
1088 TCP_TEST (tc->first_tx_time == 2, "first_tx_time %u", tc->first_tx_time);
1091 * Track retransmissions
1093 * snd_una should be 300 at this point
1096 snd_una = tc->snd_una;
1098 /* 1) track first burst at time 4 */
1099 tcp_bt_track_tx (tc, burst);
1100 tc->snd_nxt += burst;
1102 /* 2) track second burst at time 5 */
1103 session_main.wrk[thread_index].last_vlib_time = 5;
1104 tcp_bt_track_tx (tc, burst);
1105 tc->snd_nxt += burst;
1107 /* 3) track third burst at time 6 */
1108 session_main.wrk[thread_index].last_vlib_time = 6;
1109 tcp_bt_track_tx (tc, burst);
1110 tc->snd_nxt += burst;
1112 /* 4) track fourth burst at time 7 */
1113 session_main.wrk[thread_index].last_vlib_time = 7;
1114 /* Limited until last burst is acked */
1115 tc->app_limited = snd_una + 4 * burst - 1;
1116 tcp_bt_track_tx (tc, burst);
1117 tc->snd_nxt += burst;
1119 /* 5) check delivery rate at time 8
1121 * tc->snd_una = snd_una + 10
1123 * [snd_una + burst, snd_una + burst + 10]
1124 * [snd_una + 2 * burst + 10, snd_una + 2 * burst + 20]
1126 session_main.wrk[thread_index].last_vlib_time = 8;
1128 tc->bytes_acked = 10;
1129 sb->last_sacked_bytes = 20;
1131 TCP_TEST (pool_elts (bt->samples) == 4, "there should be 4 samples");
1133 vec_validate (sacks, 1);
1134 sacks[0].start = snd_una + burst;
1135 sacks[0].end = snd_una + burst + 10;
1136 sacks[1].start = snd_una + 2 * burst + 10;
1137 sacks[1].end = snd_una + 2 * burst + 20;
1138 tc->rcv_opts.sacks = sacks;
1140 tcp_bt_sample_delivery_rate (tc, rs);
1142 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1143 TCP_TEST (pool_elts (bt->samples) == 7, "there should be 7 samples %u",
1144 pool_elts (bt->samples));
1145 TCP_TEST (tc->delivered_time == 8, "delivered time should be 8");
1146 TCP_TEST (tc->delivered == 3 * burst + 30, "delivered should be %u is %u",
1147 3 * burst + 30, tc->delivered);
1148 /* All 3 samples have the same delivered number of bytes. So the first is
1149 * the reference for delivery estimate. */
1150 TCP_TEST (rs->interval_time == 4, "ack time should be 4 is %.2f",
1152 TCP_TEST (rs->delivered == 30, "delivered should be 30");
1153 TCP_TEST (rs->prior_delivered == 3 * burst,
1154 "sample delivered should be %u", 3 * burst);
1155 TCP_TEST (!(rs->flags & TCP_BTS_IS_RXT), "not retransmitted");
1156 TCP_TEST (!(rs->flags & TCP_BTS_IS_APP_LIMITED), "not app limited");
1157 /* All 3 samples have the same delivered number of bytes. The first
1158 * sets the first tx time */
1159 TCP_TEST (tc->first_tx_time == 4, "first_tx_time %u", tc->first_tx_time);
1161 /* 6) Retransmit and track at time 9
1163 * delivered = 3 * burst + 30
1164 * delivered_time = 8 (last ack)
1167 * [snd_una + 10, snd_una + burst]
1168 * [snd_una + burst + 10, snd_una + 2 * burst + 10]
1169 * [snd_una + 2 * burst + 20, snd_una + 4 * burst]
1171 session_main.wrk[thread_index].last_vlib_time = 9;
1173 tcp_bt_track_rxt (tc, snd_una + 10, snd_una + burst);
1174 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1175 /* The retransmit covers everything left from first burst */
1176 TCP_TEST (pool_elts (bt->samples) == 7, "there should be 7 samples %u",
1177 pool_elts (bt->samples));
1179 tcp_bt_track_rxt (tc, snd_una + burst + 10, snd_una + 2 * burst + 10);
1180 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1181 TCP_TEST (pool_elts (bt->samples) == 6, "there should be 6 samples %u",
1182 pool_elts (bt->samples));
1184 /* Retransmit covers last sample entirely so it should be removed */
1185 tcp_bt_track_rxt (tc, snd_una + 2 * burst + 20, snd_una + 4 * burst);
1186 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1187 TCP_TEST (pool_elts (bt->samples) == 5, "there should be 5 samples %u",
1188 pool_elts (bt->samples));
1190 vec_validate (min_seqs, 4);
1191 min_seqs[0] = snd_una + 10;
1192 min_seqs[1] = snd_una + burst;
1193 min_seqs[2] = snd_una + burst + 10;
1194 min_seqs[3] = snd_una + 2 * burst + 10;
1195 min_seqs[4] = snd_una + 2 * burst + 20;
1197 root = bt->sample_lookup.nodes + bt->sample_lookup.root;
1198 bts = bt->samples + bt->head;
1199 for (i = 0; i < vec_len (min_seqs); i++)
1201 if (bts->min_seq != min_seqs[i])
1202 TCP_TEST (0, "should be %u is %u", min_seqs[i], bts->min_seq);
1203 rbn = rb_tree_search_subtree_custom (&bt->sample_lookup, root,
1204 bts->min_seq, tbt_seq_lt);
1205 if (rbn->opaque != bts - bt->samples)
1206 TCP_TEST (0, "lookup should work");
1207 bts = bt->samples + bts->next;
1210 /* 7) check delivery rate at time 10
1212 * tc->snd_una = snd_una + 2 * burst
1214 * [snd_una + 2 * burst + 20, snd_una + 2 * burst + 30]
1215 * [snd_una + 2 * burst + 50, snd_una + 2 * burst + 60]
1217 session_main.wrk[thread_index].last_vlib_time = 10;
1218 tc->snd_una = snd_una + 2 * burst;
1219 tc->bytes_acked = 2 * burst - 10;
1220 sb->last_sacked_bytes = 20;
1222 sacks[0].start = snd_una + 2 * burst + 20;
1223 sacks[0].end = snd_una + 2 * burst + 30;
1224 sacks[1].start = snd_una + 2 * burst + 50;
1225 sacks[1].end = snd_una + 2 * burst + 60;
1227 tcp_bt_sample_delivery_rate (tc, rs);
1229 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1230 TCP_TEST (pool_elts (bt->samples) == 5, "num samples should be 5 is %u",
1231 pool_elts (bt->samples));
1232 TCP_TEST (tc->delivered_time == 10, "delivered time should be 10");
1233 TCP_TEST (tc->delivered == 5 * burst + 40, "delivered should be %u is %u",
1234 5 * burst + 40, tc->delivered);
1235 /* A rxt was acked and delivered time for it is 8 (last ack time) so
1236 * ack_time is 2 (8 - 10). However, first_tx_time for rxt was 4 and rxt
1237 * time 9. Therefore snd_time is 5 (9 - 4)*/
1238 TCP_TEST (rs->interval_time == 5, "ack time should be 5 is %.2f",
1240 /* delivered_now - delivered_rxt ~ 5 * burst + 40 - 3 * burst - 30 */
1241 TCP_TEST (rs->delivered == 2 * burst + 10, "delivered should be 210 is %u",
1243 TCP_TEST (rs->prior_delivered == 3 * burst + 30,
1244 "sample delivered should be %u", 3 * burst + 30);
1245 TCP_TEST (rs->flags & TCP_BTS_IS_RXT, "is retransmitted");
1246 /* Sample is app limited because of the retransmits */
1247 TCP_TEST (rs->flags & TCP_BTS_IS_APP_LIMITED, "is app limited");
1248 TCP_TEST (tc->app_limited, "app limited should be set");
1249 TCP_TEST (tc->first_tx_time == 9, "first_tx_time %u", tc->first_tx_time);
1253 * 8) check delivery rate at time 11
1255 session_main.wrk[thread_index].last_vlib_time = 11;
1256 tc->snd_una = tc->snd_nxt;
1257 tc->bytes_acked = 2 * burst;
1258 sb->last_sacked_bytes = 0;
1259 sb->last_bytes_delivered = 40;
1261 memset (rs, 0, sizeof (*rs));
1262 tcp_bt_sample_delivery_rate (tc, rs);
1264 TCP_TEST (tcp_bt_is_sane (bt), "tracker should be sane");
1265 TCP_TEST (pool_elts (bt->samples) == 0, "num samples should be 0 is %u",
1266 pool_elts (bt->samples));
1267 TCP_TEST (tc->delivered_time == 11, "delivered time should be 11");
1268 TCP_TEST (tc->delivered == 7 * burst, "delivered should be %u is %u",
1269 7 * burst, tc->delivered);
1270 /* Delivered time at retransmit was 8 so ack_time is 11 - 8 = 3. However,
1271 * first_tx_time for rxt was 4 and rxt time was 9. Therefore snd_time
1273 TCP_TEST (rs->interval_time == 5, "ack time should be 5 is %.2f",
1275 /* delivered_now - delivered_rxt ~ 7 * burst - 3 * burst - 30.
1276 * That's because we didn't retransmit any new segment. */
1277 TCP_TEST (rs->delivered == 4 * burst - 30, "delivered should be 160 is %u",
1279 TCP_TEST (rs->prior_delivered == 3 * burst + 30,
1280 "sample delivered should be %u", 3 * burst + 30);
1281 TCP_TEST (rs->flags & TCP_BTS_IS_RXT, "is retransmitted");
1282 TCP_TEST (rs->flags & TCP_BTS_IS_APP_LIMITED, "is app limited");
1283 TCP_TEST (tc->app_limited == 0, "app limited should be cleared");
1284 TCP_TEST (tc->first_tx_time == 9, "first_tx_time %u", tc->first_tx_time);
1290 tcp_bt_track_tx (tc, burst);
1291 tc->snd_nxt += burst;
1293 session_main.wrk[thread_index].last_vlib_time = 12;
1294 tcp_bt_track_tx (tc, burst);
1295 tc->snd_nxt += burst;
1297 tcp_bt_flush_samples (tc);
1303 vec_free (min_seqs);
1304 tcp_bt_cleanup (tc);
1308 static clib_error_t *
1309 tcp_test (vlib_main_t * vm,
1310 unformat_input_t * input, vlib_cli_command_t * cmd_arg)
1314 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1316 if (unformat (input, "sack"))
1318 res = tcp_test_sack (vm, input);
1320 else if (unformat (input, "session"))
1322 res = tcp_test_session (vm, input);
1324 else if (unformat (input, "lookup"))
1326 res = tcp_test_lookup (vm, input);
1328 else if (unformat (input, "delivery"))
1330 res = tcp_test_delivery (vm, input);
1332 else if (unformat (input, "all"))
1334 if ((res = tcp_test_sack (vm, input)))
1336 if ((res = tcp_test_lookup (vm, input)))
1338 if ((res = tcp_test_delivery (vm, input)))
1347 return clib_error_return (0, "TCP unit test failed");
1352 VLIB_CLI_COMMAND (tcp_test_command, static) =
1355 .short_help = "internal tcp unit tests",
1356 .function = tcp_test,
1361 * fd.io coding-style-patch-verification: ON
1364 * eval: (c-set-style "gnu")