github.phpd.cn/cilium/cilium@v1.6.12/test/bpf/perf-event-test.sh (about)

     1  #!/bin/bash
     2  
     3  set -e
     4  
     5  TESTDEV=perf_test
     6  TESTDEV1=$TESTDEV
     7  TESTDEV2=${TESTDEV}_peer
     8  
     9  ADDR1="10.254.254.253"
    10  ADDR2="10.254.254.254"
    11  
    12  function cleanup
    13  {
    14  	ip addr del $ADDR1/24 dev $TESTDEV1 2> /dev/null || true
    15  	ip link del $TESTDEV1 2> /dev/null || true
    16  	ip netns exec $TESTDEV2 ip addr del $ADDR2/24 dev $TESTDEV2 2> /dev/null || true
    17  	ip netns del $TESTDEV2 2> /dev/null || true
    18  }
    19  
    20  function setup
    21  {
    22  	ip netns add $TESTDEV2
    23  
    24  	ip link add $TESTDEV1 type veth peer name $TESTDEV2
    25  	ip link set $TESTDEV2 netns $TESTDEV2
    26  	ip link set $TESTDEV1 up
    27  	ip addr add $ADDR1/24 dev $TESTDEV1
    28  
    29  	ip netns exec $TESTDEV2 ip link set $TESTDEV2 up
    30  	ip netns exec $TESTDEV2 ip addr add $ADDR2/24 dev $TESTDEV2
    31  
    32  	tc qdisc replace dev $TESTDEV1 clsact
    33  	tc filter add dev $TESTDEV1 ingress bpf da obj $1
    34  }
    35  
    36  function main
    37  {
    38  	if [ $# -lt 1 ]; then
    39  		echo "usage: $0 <bpf-object-file>"
    40  		exit 1
    41  	fi
    42  
    43  	cleanup
    44  	trap cleanup EXIT
    45  	setup "$@"
    46  
    47  	ping -c 10 $ADDR2&
    48  	timeout 10 ./perf-event-test || true
    49  }
    50  
    51  main "$@"