test_xdping.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # xdping tests
  4. # Here we setup and teardown configuration required to run
  5. # xdping, exercising its options.
  6. #
  7. # Setup is similar to test_tunnel tests but without the tunnel.
  8. #
  9. # Topology:
  10. # ---------
  11. # root namespace | tc_ns0 namespace
  12. # |
  13. # ---------- | ----------
  14. # | veth1 | --------- | veth0 |
  15. # ---------- peer ----------
  16. #
  17. # Device Configuration
  18. # --------------------
  19. # Root namespace with BPF
  20. # Device names and addresses:
  21. # veth1 IP: 10.1.1.200
  22. # xdp added to veth1, xdpings originate from here.
  23. #
  24. # Namespace tc_ns0 with BPF
  25. # Device names and addresses:
  26. # veth0 IPv4: 10.1.1.100
  27. # For some tests xdping run in server mode here.
  28. #
  29. readonly TARGET_IP="10.1.1.100"
  30. readonly TARGET_NS="xdp_ns0"
  31. readonly LOCAL_IP="10.1.1.200"
  32. setup()
  33. {
  34. ip netns add $TARGET_NS
  35. ip link add veth0 type veth peer name veth1
  36. ip link set veth0 netns $TARGET_NS
  37. ip netns exec $TARGET_NS ip addr add ${TARGET_IP}/24 dev veth0
  38. ip addr add ${LOCAL_IP}/24 dev veth1
  39. ip netns exec $TARGET_NS ip link set veth0 up
  40. ip link set veth1 up
  41. }
  42. cleanup()
  43. {
  44. set +e
  45. ip netns delete $TARGET_NS 2>/dev/null
  46. ip link del veth1 2>/dev/null
  47. if [[ $server_pid -ne 0 ]]; then
  48. kill -TERM $server_pid
  49. fi
  50. }
  51. test()
  52. {
  53. client_args="$1"
  54. server_args="$2"
  55. echo "Test client args '$client_args'; server args '$server_args'"
  56. server_pid=0
  57. if [[ -n "$server_args" ]]; then
  58. ip netns exec $TARGET_NS ./xdping $server_args &
  59. server_pid=$!
  60. sleep 10
  61. fi
  62. ./xdping $client_args $TARGET_IP
  63. if [[ $server_pid -ne 0 ]]; then
  64. kill -TERM $server_pid
  65. server_pid=0
  66. fi
  67. echo "Test client args '$client_args'; server args '$server_args': PASS"
  68. }
  69. set -e
  70. server_pid=0
  71. trap cleanup EXIT
  72. setup
  73. for server_args in "" "-I veth0 -s -S" ; do
  74. # client in skb mode
  75. client_args="-I veth1 -S"
  76. test "$client_args" "$server_args"
  77. # client with count of 10 RTT measurements.
  78. client_args="-I veth1 -S -c 10"
  79. test "$client_args" "$server_args"
  80. done
  81. # Test drv mode
  82. test "-I veth1 -N" "-I veth0 -s -N"
  83. test "-I veth1 -N -c 10" "-I veth0 -s -N"
  84. echo "OK. All tests passed"
  85. exit 0