so_txtime.sh 2.4 KB

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