so_txtime.sh (2434B)
1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# Regression tests for the SO_TXTIME interface 5 6set -e 7 8readonly DEV="veth0" 9readonly BIN="./so_txtime" 10 11readonly RAND="$(mktemp -u XXXXXX)" 12readonly NSPREFIX="ns-${RAND}" 13readonly NS1="${NSPREFIX}1" 14readonly NS2="${NSPREFIX}2" 15 16readonly SADDR4='192.168.1.1' 17readonly DADDR4='192.168.1.2' 18readonly SADDR6='fd::1' 19readonly DADDR6='fd::2' 20 21cleanup() { 22 ip netns del "${NS2}" 23 ip netns del "${NS1}" 24} 25 26trap cleanup EXIT 27 28# Create virtual ethernet pair between network namespaces 29ip netns add "${NS1}" 30ip netns add "${NS2}" 31 32ip link add "${DEV}" netns "${NS1}" type veth \ 33 peer name "${DEV}" netns "${NS2}" 34 35# Bring the devices up 36ip -netns "${NS1}" link set "${DEV}" up 37ip -netns "${NS2}" link set "${DEV}" up 38 39# Set fixed MAC addresses on the devices 40ip -netns "${NS1}" link set dev "${DEV}" address 02:02:02:02:02:02 41ip -netns "${NS2}" link set dev "${DEV}" address 06:06:06:06:06:06 42 43# Add fixed IP addresses to the devices 44ip -netns "${NS1}" addr add 192.168.1.1/24 dev "${DEV}" 45ip -netns "${NS2}" addr add 192.168.1.2/24 dev "${DEV}" 46ip -netns "${NS1}" addr add fd::1/64 dev "${DEV}" nodad 47ip -netns "${NS2}" addr add fd::2/64 dev "${DEV}" nodad 48 49do_test() { 50 local readonly IP="$1" 51 local readonly CLOCK="$2" 52 local readonly TXARGS="$3" 53 local readonly RXARGS="$4" 54 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}" 61 else 62 echo "Invalid IP version ${IP}" 63 exit 1 64 fi 65 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}" 69 wait "$!" 70} 71 72ip netns exec "${NS1}" tc qdisc add dev "${DEV}" root fq 73do_test 4 mono a,-1 a,-1 74do_test 6 mono a,0 a,0 75do_test 6 mono a,10 a,10 76do_test 4 mono a,10,b,20 a,10,b,20 77do_test 6 mono a,20,b,10 b,20,a,20 78 79if 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 85else 86 echo "tc ($(tc -V)) does not support qdisc etf. skipping" 87fi 88 89echo OK. All tests passed