1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# Send packets with transmit timestamps over loopback with netem 5# Verify that timestamps correspond to netem delay 6 7set -e 8 9setup() { 10 # set 1ms delay on lo egress 11 tc qdisc add dev lo root netem delay 1ms 12 13 # set 2ms delay on ifb0 egress 14 modprobe ifb 15 ip link add ifb_netem0 type ifb 16 ip link set dev ifb_netem0 up 17 tc qdisc add dev ifb_netem0 root netem delay 2ms 18 19 # redirect lo ingress through ifb0 egress 20 tc qdisc add dev lo handle ffff: ingress 21 tc filter add dev lo parent ffff: \ 22 u32 match mark 0 0xffff \ 23 action mirred egress redirect dev ifb_netem0 24} 25 26run_test_v4v6() { 27 # SND will be delayed 1000us 28 # ACK will be delayed 6000us: 1 + 2 ms round-trip 29 local -r args="$@ -v 1000 -V 6000" 30 31 ./txtimestamp ${args} -4 -L 127.0.0.1 32 ./txtimestamp ${args} -6 -L ::1 33} 34 35run_test_tcpudpraw() { 36 local -r args=$@ 37 38 run_test_v4v6 ${args} # tcp 39 run_test_v4v6 ${args} -u # udp 40 run_test_v4v6 ${args} -r # raw 41 run_test_v4v6 ${args} -R # raw (IPPROTO_RAW) 42 run_test_v4v6 ${args} -P # pf_packet 43} 44 45run_test_all() { 46 run_test_tcpudpraw # setsockopt 47 run_test_tcpudpraw -C # cmsg 48 run_test_tcpudpraw -n # timestamp w/o data 49} 50 51if [[ "$(ip netns identify)" == "root" ]]; then 52 ../../net/in_netns.sh $0 $@ 53else 54 setup 55 run_test_all 56 echo "OK. All tests passed" 57fi 58