Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # Send packets with transmit timestamps over loopback with netem
0005 # Verify that timestamps correspond to netem delay
0006 
0007 set -e
0008 
0009 setup() {
0010         # set 1ms delay on lo egress
0011         tc qdisc add dev lo root netem delay 1ms
0012 
0013         # set 2ms delay on ifb0 egress
0014         modprobe ifb
0015         ip link add ifb_netem0 type ifb
0016         ip link set dev ifb_netem0 up
0017         tc qdisc add dev ifb_netem0 root netem delay 2ms
0018 
0019         # redirect lo ingress through ifb0 egress
0020         tc qdisc add dev lo handle ffff: ingress
0021         tc filter add dev lo parent ffff: \
0022                 u32 match mark 0 0xffff \
0023                 action mirred egress redirect dev ifb_netem0
0024 }
0025 
0026 run_test_v4v6() {
0027         # SND will be delayed 1000us
0028         # ACK will be delayed 6000us: 1 + 2 ms round-trip
0029         local -r args="$@ -v 1000 -V 6000"
0030 
0031         ./txtimestamp ${args} -4 -L 127.0.0.1
0032         ./txtimestamp ${args} -6 -L ::1
0033 }
0034 
0035 run_test_tcpudpraw() {
0036         local -r args=$@
0037 
0038         run_test_v4v6 ${args}           # tcp
0039         run_test_v4v6 ${args} -u        # udp
0040         run_test_v4v6 ${args} -r        # raw
0041         run_test_v4v6 ${args} -R        # raw (IPPROTO_RAW)
0042         run_test_v4v6 ${args} -P        # pf_packet
0043 }
0044 
0045 run_test_all() {
0046         setup
0047         run_test_tcpudpraw              # setsockopt
0048         run_test_tcpudpraw -C           # cmsg
0049         run_test_tcpudpraw -n           # timestamp w/o data
0050         echo "OK. All tests passed"
0051 }
0052 
0053 run_test_one() {
0054         setup
0055         ./txtimestamp $@
0056 }
0057 
0058 usage() {
0059         echo "Usage: $0 [ -r | --run ] <txtimestamp args> | [ -h | --help ]"
0060         echo "  (no args)  Run all tests"
0061         echo "  -r|--run  Run an individual test with arguments"
0062         echo "  -h|--help Help"
0063 }
0064 
0065 main() {
0066         if [[ $# -eq 0 ]]; then
0067                 run_test_all
0068         else
0069                 if [[ "$1" = "-r" || "$1" == "--run" ]]; then
0070                         shift
0071                         run_test_one $@
0072                 else
0073                         usage
0074                 fi
0075         fi
0076 }
0077 
0078 if [[ -z "$(ip netns identify)" ]]; then
0079         ./in_netns.sh $0 $@
0080 else
0081         main $@
0082 fi