2 # SPDX-License-Identifier: GPL-2.0
4 # Regression tests for the SO_TXTIME interface
9 readonly BIN="./so_txtime"
11 readonly RAND="$(mktemp -u XXXXXX)"
12 readonly NSPREFIX="ns-${RAND}"
13 readonly NS1="${NSPREFIX}1"
14 readonly NS2="${NSPREFIX}2"
16 readonly SADDR4='192.168.1.1'
17 readonly DADDR4='192.168.1.2'
18 readonly SADDR6='fd::1'
19 readonly DADDR6='fd::2'
28 # Create virtual ethernet pair between network namespaces
32 ip link add "${DEV}" netns "${NS1}" type veth \
33 peer name "${DEV}" netns "${NS2}"
35 # Bring the devices up
36 ip -netns "${NS1}" link set "${DEV}" up
37 ip -netns "${NS2}" link set "${DEV}" up
39 # Set fixed MAC addresses on the devices
40 ip -netns "${NS1}" link set dev "${DEV}" address 02:02:02:02:02:02
41 ip -netns "${NS2}" link set dev "${DEV}" address 06:06:06:06:06:06
43 # Add fixed IP addresses to the devices
44 ip -netns "${NS1}" addr add 192.168.1.1/24 dev "${DEV}"
45 ip -netns "${NS2}" addr add 192.168.1.2/24 dev "${DEV}"
46 ip -netns "${NS1}" addr add fd::1/64 dev "${DEV}" nodad
47 ip -netns "${NS2}" addr add fd::2/64 dev "${DEV}" nodad
50 local readonly IP="$1"
51 local readonly CLOCK="$2"
52 local readonly TXARGS="$3"
53 local readonly RXARGS="$4"
55 if [[ "${IP}" == "4" ]]; then
56 local readonly SADDR="${SADDR4}"
57 local readonly DADDR="${DADDR4}"
58 elif [[ "${IP}" == "6" ]]; then
59 local readonly SADDR="${SADDR6}"
60 local readonly DADDR="${DADDR6}"
62 echo "Invalid IP version ${IP}"
66 local readonly START="$(date +%s%N --date="+ 0.1 seconds")"
67 ip netns exec "${NS2}" "${BIN}" -"${IP}" -c "${CLOCK}" -t "${START}" -S "${SADDR}" -D "${DADDR}" "${RXARGS}" -r &
68 ip netns exec "${NS1}" "${BIN}" -"${IP}" -c "${CLOCK}" -t "${START}" -S "${SADDR}" -D "${DADDR}" "${TXARGS}"
72 ip netns exec "${NS1}" tc qdisc add dev "${DEV}" root fq
73 do_test 4 mono a,-1 a,-1
74 do_test 6 mono a,0 a,0
75 do_test 6 mono a,10 a,10
76 do_test 4 mono a,10,b,20 a,10,b,20
77 do_test 6 mono a,20,b,10 b,20,a,20
79 if ip netns exec "${NS1}" tc qdisc replace dev "${DEV}" root etf clockid CLOCK_TAI delta 400000; then
80 ! do_test 4 tai a,-1 a,-1
81 ! do_test 6 tai a,0 a,0
82 do_test 6 tai a,10 a,10
83 do_test 4 tai a,10,b,20 a,10,b,20
84 do_test 6 tai a,20,b,10 b,10,a,20
86 echo "tc ($(tc -V)) does not support qdisc etf. skipping"
89 echo OK. All tests passed