xref: /aosp_15_r20/external/ltp/testcases/network/tcp_fastopen/tcp_fastopen_run.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2014-2018 Oracle and/or its affiliates. All Rights Reserved.
4# Author: Alexey Kodanev <[email protected]>
5
6TST_SETUP="setup"
7TST_TESTFUNC="test"
8TST_CNT=2
9TST_CLEANUP="cleanup"
10TST_MIN_KVER="3.7"
11TST_NEEDS_TMPDIR=1
12TST_NEEDS_ROOT=1
13TST_NEEDS_CMDS="tc"
14TST_NEEDS_DRIVERS="sch_netem"
15TST_OPTS="R:"
16TST_USAGE=tcp_fastopen_usage
17TST_PARSE_ARGS=tcp_fastopen_parse_args
18
19srv_replies=3
20
21tcp_fastopen_usage()
22{
23	echo "-R x    Number of requests, after which connection is closed"
24}
25
26tcp_fastopen_parse_args()
27{
28	case "$1" in
29	R) srv_replies=$2 ;;
30	esac
31}
32
33
34cleanup()
35{
36	tc qdisc del dev $(tst_iface) root netem delay 100 >/dev/null
37}
38
39setup()
40{
41	if tst_kvcmp -lt "3.16" && [ "$TST_IPV6" ]; then
42		tst_brk TCONF "test must be run with kernel 3.16 or newer"
43	fi
44
45	ROD tc qdisc add dev $(tst_iface) root netem delay 100
46}
47
48test1()
49{
50	tst_res TINFO "using old TCP API and set tcp_fastopen to '0'"
51	tst_netload -H $(tst_ipaddr rhost) -t 0 -R $srv_replies
52	time_tfo_off=$(cat tst_netload.res)
53
54	tst_res TINFO "using new TCP API and set tcp_fastopen to '3'"
55	tst_netload -H $(tst_ipaddr rhost) -f -t 3 -R $srv_replies
56	time_tfo_on=$(cat tst_netload.res)
57
58	tst_netload_compare $time_tfo_off $time_tfo_on 3
59}
60
61test2()
62{
63	tst_kvcmp -lt "4.11" && \
64		tst_brk TCONF "next test must be run with kernel 4.11 or newer"
65
66	tst_res TINFO "using connect() and TCP_FASTOPEN_CONNECT socket option"
67	tst_netload -H $(tst_ipaddr rhost) -F -t 3 -R $srv_replies
68	time_tfo_on=$(cat tst_netload.res)
69
70	tst_netload_compare $time_tfo_off $time_tfo_on 3
71}
72
73. tst_net.sh
74tst_run
75