mirror of
https://github.com/torvalds/linux.git
synced 2024-12-13 22:53:20 +00:00
cd5385029f
xdping allows us to get latency estimates from XDP. Output looks like this: ./xdping -I eth4 192.168.55.8 Setting up XDP for eth4, please wait... XDP setup disrupts network connectivity, hit Ctrl+C to quit Normal ping RTT data [Ignore final RTT; it is distorted by XDP using the reply] PING 192.168.55.8 (192.168.55.8) from 192.168.55.7 eth4: 56(84) bytes of data. 64 bytes from 192.168.55.8: icmp_seq=1 ttl=64 time=0.302 ms 64 bytes from 192.168.55.8: icmp_seq=2 ttl=64 time=0.208 ms 64 bytes from 192.168.55.8: icmp_seq=3 ttl=64 time=0.163 ms 64 bytes from 192.168.55.8: icmp_seq=8 ttl=64 time=0.275 ms 4 packets transmitted, 4 received, 0% packet loss, time 3079ms rtt min/avg/max/mdev = 0.163/0.237/0.302/0.054 ms XDP RTT data: 64 bytes from 192.168.55.8: icmp_seq=5 ttl=64 time=0.02808 ms 64 bytes from 192.168.55.8: icmp_seq=6 ttl=64 time=0.02804 ms 64 bytes from 192.168.55.8: icmp_seq=7 ttl=64 time=0.02815 ms 64 bytes from 192.168.55.8: icmp_seq=8 ttl=64 time=0.02805 ms The xdping program loads the associated xdping_kern.o BPF program and attaches it to the specified interface. If run in client mode (the default), it will add a map entry keyed by the target IP address; this map will store RTT measurements, current sequence number etc. Finally in client mode the ping command is executed, and the xdping BPF program will use the last ICMP reply, reformulate it as an ICMP request with the next sequence number and XDP_TX it. After the reply to that request is received we can measure RTT and repeat until the desired number of measurements is made. This is why the sequence numbers in the normal ping are 1, 2, 3 and 8. We XDP_TX a modified version of ICMP reply 4 and keep doing this until we get the 4 replies we need; hence the networking stack only sees reply 8, where we have XDP_PASSed it upstream since we are done. In server mode (-s), xdping simply takes ICMP requests and replies to them in XDP rather than passing the request up to the networking stack. No map entry is required. xdping can be run in native XDP mode (the default, or specified via -N) or in skb mode (-S). A test program test_xdping.sh exercises some of these options. Note that native XDP does not seem to XDP_TX for veths, hence -N is not tested. Looking at the code, it looks like XDP_TX is supported so I'm not sure if that's expected. Running xdping in native mode for ixgbe as both client and server works fine. Changes since v4 - close fds on cleanup (Song Liu) Changes since v3 - fixed seq to be __be16 (Song Liu) - fixed fd checks in xdping.c (Song Liu) Changes since v2 - updated commit message to explain why seq number of last ICMP reply is 8 not 4 (Song Liu) - updated types of seq number, raddr and eliminated csum variable in xdpclient/xdpserver functions as it was not needed (Song Liu) - added XDPING_DEFAULT_COUNT definition and usage specification of default/max counts (Song Liu) Changes since v1 - moved from RFC to PATCH - removed unused variable in ipv4_csum() (Song Liu) - refactored ICMP checks into icmp_check() function called by client and server programs and reworked client and server programs due to lack of shared code (Song Liu) - added checks to ensure that SKB and native mode are not requested together (Song Liu) Signed-off-by: Alan Maguire <alan.maguire@oracle.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
100 lines
2.0 KiB
Bash
Executable File
100 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
# xdping tests
|
|
# Here we setup and teardown configuration required to run
|
|
# xdping, exercising its options.
|
|
#
|
|
# Setup is similar to test_tunnel tests but without the tunnel.
|
|
#
|
|
# Topology:
|
|
# ---------
|
|
# root namespace | tc_ns0 namespace
|
|
# |
|
|
# ---------- | ----------
|
|
# | veth1 | --------- | veth0 |
|
|
# ---------- peer ----------
|
|
#
|
|
# Device Configuration
|
|
# --------------------
|
|
# Root namespace with BPF
|
|
# Device names and addresses:
|
|
# veth1 IP: 10.1.1.200
|
|
# xdp added to veth1, xdpings originate from here.
|
|
#
|
|
# Namespace tc_ns0 with BPF
|
|
# Device names and addresses:
|
|
# veth0 IPv4: 10.1.1.100
|
|
# For some tests xdping run in server mode here.
|
|
#
|
|
|
|
readonly TARGET_IP="10.1.1.100"
|
|
readonly TARGET_NS="xdp_ns0"
|
|
|
|
readonly LOCAL_IP="10.1.1.200"
|
|
|
|
setup()
|
|
{
|
|
ip netns add $TARGET_NS
|
|
ip link add veth0 type veth peer name veth1
|
|
ip link set veth0 netns $TARGET_NS
|
|
ip netns exec $TARGET_NS ip addr add ${TARGET_IP}/24 dev veth0
|
|
ip addr add ${LOCAL_IP}/24 dev veth1
|
|
ip netns exec $TARGET_NS ip link set veth0 up
|
|
ip link set veth1 up
|
|
}
|
|
|
|
cleanup()
|
|
{
|
|
set +e
|
|
ip netns delete $TARGET_NS 2>/dev/null
|
|
ip link del veth1 2>/dev/null
|
|
if [[ $server_pid -ne 0 ]]; then
|
|
kill -TERM $server_pid
|
|
fi
|
|
}
|
|
|
|
test()
|
|
{
|
|
client_args="$1"
|
|
server_args="$2"
|
|
|
|
echo "Test client args '$client_args'; server args '$server_args'"
|
|
|
|
server_pid=0
|
|
if [[ -n "$server_args" ]]; then
|
|
ip netns exec $TARGET_NS ./xdping $server_args &
|
|
server_pid=$!
|
|
sleep 10
|
|
fi
|
|
./xdping $client_args $TARGET_IP
|
|
|
|
if [[ $server_pid -ne 0 ]]; then
|
|
kill -TERM $server_pid
|
|
server_pid=0
|
|
fi
|
|
|
|
echo "Test client args '$client_args'; server args '$server_args': PASS"
|
|
}
|
|
|
|
set -e
|
|
|
|
server_pid=0
|
|
|
|
trap cleanup EXIT
|
|
|
|
setup
|
|
|
|
for server_args in "" "-I veth0 -s -S" ; do
|
|
# client in skb mode
|
|
client_args="-I veth1 -S"
|
|
test "$client_args" "$server_args"
|
|
|
|
# client with count of 10 RTT measurements.
|
|
client_args="-I veth1 -S -c 10"
|
|
test "$client_args" "$server_args"
|
|
done
|
|
|
|
echo "OK. All tests passed"
|
|
exit 0
|