Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # xdping tests
0005 #   Here we setup and teardown configuration required to run
0006 #   xdping, exercising its options.
0007 #
0008 #   Setup is similar to test_tunnel tests but without the tunnel.
0009 #
0010 # Topology:
0011 # ---------
0012 #     root namespace   |     tc_ns0 namespace
0013 #                      |
0014 #      ----------      |     ----------
0015 #      |  veth1  | --------- |  veth0  |
0016 #      ----------    peer    ----------
0017 #
0018 # Device Configuration
0019 # --------------------
0020 # Root namespace with BPF
0021 # Device names and addresses:
0022 #       veth1 IP: 10.1.1.200
0023 #       xdp added to veth1, xdpings originate from here.
0024 #
0025 # Namespace tc_ns0 with BPF
0026 # Device names and addresses:
0027 #       veth0 IPv4: 10.1.1.100
0028 #       For some tests xdping run in server mode here.
0029 #
0030 
0031 readonly TARGET_IP="10.1.1.100"
0032 readonly TARGET_NS="xdp_ns0"
0033 
0034 readonly LOCAL_IP="10.1.1.200"
0035 
0036 setup()
0037 {
0038         ip netns add $TARGET_NS
0039         ip link add veth0 type veth peer name veth1
0040         ip link set veth0 netns $TARGET_NS
0041         ip netns exec $TARGET_NS ip addr add ${TARGET_IP}/24 dev veth0
0042         ip addr add ${LOCAL_IP}/24 dev veth1
0043         ip netns exec $TARGET_NS ip link set veth0 up
0044         ip link set veth1 up
0045 }
0046 
0047 cleanup()
0048 {
0049         set +e
0050         ip netns delete $TARGET_NS 2>/dev/null
0051         ip link del veth1 2>/dev/null
0052         if [[ $server_pid -ne 0 ]]; then
0053                 kill -TERM $server_pid
0054         fi
0055 }
0056 
0057 test()
0058 {
0059         client_args="$1"
0060         server_args="$2"
0061 
0062         echo "Test client args '$client_args'; server args '$server_args'"
0063 
0064         server_pid=0
0065         if [[ -n "$server_args" ]]; then
0066                 ip netns exec $TARGET_NS ./xdping $server_args &
0067                 server_pid=$!
0068                 sleep 10
0069         fi
0070         ./xdping $client_args $TARGET_IP
0071 
0072         if [[ $server_pid -ne 0 ]]; then
0073                 kill -TERM $server_pid
0074                 server_pid=0
0075         fi
0076 
0077         echo "Test client args '$client_args'; server args '$server_args': PASS"
0078 }
0079 
0080 set -e
0081 
0082 server_pid=0
0083 
0084 trap cleanup EXIT
0085 
0086 setup
0087 
0088 for server_args in "" "-I veth0 -s -S" ; do
0089         # client in skb mode
0090         client_args="-I veth1 -S"
0091         test "$client_args" "$server_args"
0092 
0093         # client with count of 10 RTT measurements.
0094         client_args="-I veth1 -S -c 10"
0095         test "$client_args" "$server_args"
0096 done
0097 
0098 # Test drv mode
0099 test "-I veth1 -N" "-I veth0 -s -N"
0100 test "-I veth1 -N -c 10" "-I veth0 -s -N"
0101 
0102 echo "OK. All tests passed"
0103 exit 0