so_txtime.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Regression tests for the SO_TXTIME interface
  5. set -e
  6. readonly ksft_skip=4
  7. readonly DEV="veth0"
  8. readonly BIN="./so_txtime"
  9. readonly RAND="$(mktemp -u XXXXXX)"
  10. readonly NSPREFIX="ns-${RAND}"
  11. readonly NS1="${NSPREFIX}1"
  12. readonly NS2="${NSPREFIX}2"
  13. readonly SADDR4='192.168.1.1'
  14. readonly DADDR4='192.168.1.2'
  15. readonly SADDR6='fd::1'
  16. readonly DADDR6='fd::2'
  17. cleanup() {
  18. ip netns del "${NS2}"
  19. ip netns del "${NS1}"
  20. }
  21. trap cleanup EXIT
  22. # Create virtual ethernet pair between network namespaces
  23. ip netns add "${NS1}"
  24. ip netns add "${NS2}"
  25. ip link add "${DEV}" netns "${NS1}" type veth \
  26. peer name "${DEV}" netns "${NS2}"
  27. # Bring the devices up
  28. ip -netns "${NS1}" link set "${DEV}" up
  29. ip -netns "${NS2}" link set "${DEV}" up
  30. # Set fixed MAC addresses on the devices
  31. ip -netns "${NS1}" link set dev "${DEV}" address 02:02:02:02:02:02
  32. ip -netns "${NS2}" link set dev "${DEV}" address 06:06:06:06:06:06
  33. # Add fixed IP addresses to the devices
  34. ip -netns "${NS1}" addr add 192.168.1.1/24 dev "${DEV}"
  35. ip -netns "${NS2}" addr add 192.168.1.2/24 dev "${DEV}"
  36. ip -netns "${NS1}" addr add fd::1/64 dev "${DEV}" nodad
  37. ip -netns "${NS2}" addr add fd::2/64 dev "${DEV}" nodad
  38. run_test() {
  39. local readonly IP="$1"
  40. local readonly CLOCK="$2"
  41. local readonly TXARGS="$3"
  42. local readonly RXARGS="$4"
  43. if [[ "${IP}" == "4" ]]; then
  44. local readonly SADDR="${SADDR4}"
  45. local readonly DADDR="${DADDR4}"
  46. elif [[ "${IP}" == "6" ]]; then
  47. local readonly SADDR="${SADDR6}"
  48. local readonly DADDR="${DADDR6}"
  49. else
  50. echo "Invalid IP version ${IP}"
  51. exit 1
  52. fi
  53. local readonly START="$(date +%s%N --date="+ 0.1 seconds")"
  54. ip netns exec "${NS2}" "${BIN}" -"${IP}" -c "${CLOCK}" -t "${START}" -S "${SADDR}" -D "${DADDR}" "${RXARGS}" -r &
  55. ip netns exec "${NS1}" "${BIN}" -"${IP}" -c "${CLOCK}" -t "${START}" -S "${SADDR}" -D "${DADDR}" "${TXARGS}"
  56. wait "$!"
  57. }
  58. do_test() {
  59. run_test $@
  60. [ $? -ne 0 ] && ret=1
  61. }
  62. do_fail_test() {
  63. run_test $@
  64. [ $? -eq 0 ] && ret=1
  65. }
  66. ip netns exec "${NS1}" tc qdisc add dev "${DEV}" root fq
  67. set +e
  68. ret=0
  69. do_test 4 mono a,-1 a,-1
  70. do_test 6 mono a,0 a,0
  71. do_test 6 mono a,10 a,10
  72. do_test 4 mono a,10,b,20 a,10,b,20
  73. do_test 6 mono a,20,b,10 b,20,a,20
  74. if ip netns exec "${NS1}" tc qdisc replace dev "${DEV}" root etf clockid CLOCK_TAI delta 400000; then
  75. do_fail_test 4 tai a,-1 a,-1
  76. do_fail_test 6 tai a,0 a,0
  77. do_test 6 tai a,10 a,10
  78. do_test 4 tai a,10,b,20 a,10,b,20
  79. do_test 6 tai a,20,b,10 b,10,a,20
  80. else
  81. echo "tc ($(tc -V)) does not support qdisc etf. skipping"
  82. [ $ret -eq 0 ] && ret=$ksft_skip
  83. fi
  84. if [ $ret -eq 0 ]; then
  85. echo OK. All tests passed
  86. elif [[ $ret -ne $ksft_skip && -n "$KSFT_MACHINE_SLOW" ]]; then
  87. echo "Ignoring errors due to slow environment" 1>&2
  88. ret=0
  89. fi
  90. exit $ret