tcp_fastopen_run.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <alexey.kodanev@oracle.com>
  5. TST_SETUP="setup"
  6. TST_TESTFUNC="test"
  7. TST_CNT=2
  8. TST_CLEANUP="cleanup"
  9. TST_MIN_KVER="3.7"
  10. TST_NEEDS_TMPDIR=1
  11. TST_NEEDS_ROOT=1
  12. TST_NEEDS_CMDS="tc"
  13. TST_OPTS="R:"
  14. TST_USAGE=tcp_fastopen_usage
  15. TST_PARSE_ARGS=tcp_fastopen_parse_args
  16. srv_replies=3
  17. tcp_fastopen_usage()
  18. {
  19. echo "-R x Number of requests, after which connection is closed"
  20. }
  21. tcp_fastopen_parse_args()
  22. {
  23. case "$1" in
  24. R) srv_replies=$2 ;;
  25. esac
  26. }
  27. . tst_net.sh
  28. cleanup()
  29. {
  30. tc qdisc del dev $(tst_iface) root netem delay 100 >/dev/null
  31. }
  32. compare()
  33. {
  34. tfo_cmp=$(( 100 - ($time_tfo_on * 100) / $time_tfo_off ))
  35. if [ "$tfo_cmp" -lt 3 ]; then
  36. tst_res TFAIL "$1 perf result is '$tfo_cmp' percent"
  37. else
  38. tst_res TPASS "$1 perf result is '$tfo_cmp' percent"
  39. fi
  40. }
  41. setup()
  42. {
  43. if tst_kvcmp -lt "3.16" && [ "$TST_IPV6" ]; then
  44. tst_brk TCONF "test must be run with kernel 3.16 or newer"
  45. fi
  46. ROD tc qdisc add dev $(tst_iface) root netem delay 100
  47. }
  48. test1()
  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. tst_res TINFO "using new TCP API and set tcp_fastopen to '3'"
  54. tst_netload -H $(tst_ipaddr rhost) -f -t 3 -R $srv_replies
  55. time_tfo_on=$(cat tst_netload.res)
  56. compare
  57. }
  58. test2()
  59. {
  60. tst_kvcmp -lt "4.11" && \
  61. tst_brk TCONF "next test must be run with kernel 4.11 or newer"
  62. tst_res TINFO "using connect() and TCP_FASTOPEN_CONNECT socket option"
  63. tst_netload -H $(tst_ipaddr rhost) -F -t 3 -R $srv_replies
  64. time_tfo_on=$(cat tst_netload.res)
  65. compare
  66. }
  67. tst_run