1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4source lib.sh 5 6IP4=172.16.0.1/24 7TGT4=172.16.0.2 8IP6=2001:db8:1::1/64 9TGT6=2001:db8:1::2 10 11cleanup() 12{ 13 cleanup_ns $NS 14} 15 16trap cleanup EXIT 17 18# Namespaces 19setup_ns NS 20 21ip netns exec $NS sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null 22 23# Connectivity 24ip -netns $NS link add type dummy 25ip -netns $NS link set dev dummy0 up 26ip -netns $NS addr add $IP4 dev dummy0 27ip -netns $NS addr add $IP6 dev dummy0 28 29# Need FQ for TXTIME 30ip netns exec $NS tc qdisc replace dev dummy0 root fq 31 32# Test 33BAD=0 34TOTAL=0 35 36check_result() { 37 ((TOTAL++)) 38 if [ $1 -ne 0 ]; then 39 echo " Case $4 returned $1, expected 0" 40 ((BAD++)) 41 elif [ "$2" != "$3" ]; then 42 echo " Case $4 returned '$2', expected '$3'" 43 ((BAD++)) 44 fi 45} 46 47for i in "-4 $TGT4" "-6 $TGT6"; do 48 for p in u i r; do 49 [ $p == "u" ] && prot=UDPv${i:1:2} 50 [ $p == "i" ] && prot=ICMPv${i:1:2} 51 [ $p == "r" ] && prot=RAWv${i:1:2} 52 53 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234) 54 check_result $? "$ts" "" "$prot - no options" 55 56 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t | wc -l) 57 check_result $? "$ts" "2" "$prot - ts cnt" 58 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t | 59 sed -n "s/.*SCHED ts0 [0-9].*/OK/p") 60 check_result $? "$ts" "OK" "$prot - ts0 SCHED" 61 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t | 62 sed -n "s/.*SND ts0 [0-9].*/OK/p") 63 check_result $? "$ts" "OK" "$prot - ts0 SND" 64 65 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t -d 1000 | 66 awk '/SND/ { if ($3 > 1000) print "OK"; }') 67 check_result $? "$ts" "OK" "$prot - TXTIME abs" 68 69 ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t -d 1000 | 70 awk '/SND/ {snd=$3} 71 /SCHED/ {sch=$3} 72 END { if (snd - sch > 500) print "OK"; }') 73 check_result $? "$ts" "OK" "$prot - TXTIME rel" 74 done 75done 76 77# Summary 78if [ $BAD -ne 0 ]; then 79 echo "FAIL - $BAD/$TOTAL cases failed" 80 exit 1 81else 82 echo "OK" 83 exit 0 84fi 85