1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 # 3 # 4 # Send packets with transmit timestamps over l 4 # Send packets with transmit timestamps over loopback with netem 5 # Verify that timestamps correspond to netem d 5 # Verify that timestamps correspond to netem delay 6 6 7 set -e 7 set -e 8 8 9 setup() { 9 setup() { 10 # set 1ms delay on lo egress 10 # set 1ms delay on lo egress 11 tc qdisc add dev lo root netem delay 1 11 tc qdisc add dev lo root netem delay 10ms 12 12 13 # set 2ms delay on ifb0 egress 13 # set 2ms delay on ifb0 egress 14 modprobe ifb 14 modprobe ifb 15 ip link add ifb_netem0 type ifb 15 ip link add ifb_netem0 type ifb 16 ip link set dev ifb_netem0 up 16 ip link set dev ifb_netem0 up 17 tc qdisc add dev ifb_netem0 root netem 17 tc qdisc add dev ifb_netem0 root netem delay 20ms 18 18 19 # redirect lo ingress through ifb0 egr 19 # redirect lo ingress through ifb0 egress 20 tc qdisc add dev lo handle ffff: ingre 20 tc qdisc add dev lo handle ffff: ingress 21 tc filter add dev lo parent ffff: \ 21 tc filter add dev lo parent ffff: \ 22 u32 match mark 0 0xffff \ 22 u32 match mark 0 0xffff \ 23 action mirred egress redirect 23 action mirred egress redirect dev ifb_netem0 24 } 24 } 25 25 26 run_test_v4v6() { 26 run_test_v4v6() { 27 # SND will be delayed 10ms 27 # SND will be delayed 10ms 28 # ACK will be delayed 60ms: 10 + 20 ms 28 # ACK will be delayed 60ms: 10 + 20 ms round-trip 29 # allow +/- tolerance of 8ms 29 # allow +/- tolerance of 8ms 30 # wait for ACK to be queued 30 # wait for ACK to be queued 31 local -r args="$@ -v 10000 -V 60000 -t 31 local -r args="$@ -v 10000 -V 60000 -t 8000 -S 80000" 32 32 33 ./txtimestamp ${args} -4 -L 127.0.0.1 33 ./txtimestamp ${args} -4 -L 127.0.0.1 34 ./txtimestamp ${args} -6 -L ::1 34 ./txtimestamp ${args} -6 -L ::1 35 } 35 } 36 36 37 run_test_tcpudpraw() { 37 run_test_tcpudpraw() { 38 local -r args=$@ 38 local -r args=$@ 39 39 40 run_test_v4v6 ${args} # tcp 40 run_test_v4v6 ${args} # tcp 41 run_test_v4v6 ${args} -u # udp 41 run_test_v4v6 ${args} -u # udp 42 run_test_v4v6 ${args} -r # raw 42 run_test_v4v6 ${args} -r # raw 43 run_test_v4v6 ${args} -R # raw 43 run_test_v4v6 ${args} -R # raw (IPPROTO_RAW) 44 run_test_v4v6 ${args} -P # pf_p 44 run_test_v4v6 ${args} -P # pf_packet 45 } 45 } 46 46 47 run_test_all() { 47 run_test_all() { 48 setup 48 setup 49 run_test_tcpudpraw # sets 49 run_test_tcpudpraw # setsockopt 50 run_test_tcpudpraw -C # cmsg 50 run_test_tcpudpraw -C # cmsg 51 run_test_tcpudpraw -n # time 51 run_test_tcpudpraw -n # timestamp w/o data 52 echo "OK. All tests passed" 52 echo "OK. All tests passed" 53 } 53 } 54 54 55 run_test_one() { 55 run_test_one() { 56 setup 56 setup 57 ./txtimestamp $@ 57 ./txtimestamp $@ 58 } 58 } 59 59 60 usage() { 60 usage() { 61 echo "Usage: $0 [ -r | --run ] <txtime 61 echo "Usage: $0 [ -r | --run ] <txtimestamp args> | [ -h | --help ]" 62 echo " (no args) Run all tests" 62 echo " (no args) Run all tests" 63 echo " -r|--run Run an individual te 63 echo " -r|--run Run an individual test with arguments" 64 echo " -h|--help Help" 64 echo " -h|--help Help" 65 } 65 } 66 66 67 main() { 67 main() { 68 if [[ $# -eq 0 ]]; then 68 if [[ $# -eq 0 ]]; then 69 run_test_all 69 run_test_all 70 else 70 else 71 if [[ "$1" = "-r" || "$1" == " 71 if [[ "$1" = "-r" || "$1" == "--run" ]]; then 72 shift 72 shift 73 run_test_one $@ 73 run_test_one $@ 74 else 74 else 75 usage 75 usage 76 fi 76 fi 77 fi 77 fi 78 } 78 } 79 79 80 if [[ -z "$(ip netns identify)" ]]; then 80 if [[ -z "$(ip netns identify)" ]]; then 81 ./in_netns.sh $0 $@ 81 ./in_netns.sh $0 $@ 82 else 82 else 83 main $@ 83 main $@ 84 fi 84 fi
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.