Run one iperf3 stream per CPU, each pinned with taskset, over the PPPoE session. Count the IPv4 and IPv6 session frames leaving the client's veth with flower filters and check that they match the frames and bytes ppp0 counted. A frame sent while the counters are read can be counted by only one of them, so they are read until two reads 100 ms apart agree. This covers concurrent use of the PPP transmit path and its per-CPU statistics. Signed-off-by: Julius Bairaktaris --- tools/testing/selftests/net/ppp/config | 4 ++ tools/testing/selftests/net/ppp/pppoe.sh | 83 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/tools/testing/selftests/net/ppp/config b/tools/testing/selftests/net/ppp/config index 843545df8f03..e7ba52a36026 100644 --- a/tools/testing/selftests/net/ppp/config +++ b/tools/testing/selftests/net/ppp/config @@ -1,5 +1,9 @@ CONFIG_IPV6=y CONFIG_L2TP=m +CONFIG_NET_ACT_GACT=m +CONFIG_NET_CLS_ACT=y +CONFIG_NET_CLS_FLOWER=m +CONFIG_NET_SCH_INGRESS=m CONFIG_PACKET=y CONFIG_PPP=m CONFIG_PPP_ASYNC=m diff --git a/tools/testing/selftests/net/ppp/pppoe.sh b/tools/testing/selftests/net/ppp/pppoe.sh index f67b51df7490..93c8dbb58818 100755 --- a/tools/testing/selftests/net/ppp/pppoe.sh +++ b/tools/testing/selftests/net/ppp/pppoe.sh @@ -17,6 +17,8 @@ cleanup() { trap cleanup EXIT require_command pppoe-server +require_command taskset +require_command jq ppp_common_init modprobe -q pppoe @@ -34,6 +36,82 @@ ip link set "$VETH_CLIENT" netns "$NS_CLIENT" ip -netns "$NS_SERVER" link set "$VETH_SERVER" up ip -netns "$NS_CLIENT" link set "$VETH_CLIENT" up +# Print the client's ppp0 transmit counters, then those of the IPv4 and +# IPv6 PPPoE session frames leaving its veth. PPP control frames go to +# the channel directly and are counted by neither. +client_tx_stats() { + local stat + + for stat in tx_packets tx_bytes; do + ip netns exec "$NS_CLIENT" \ + cat "/sys/class/net/ppp0/statistics/$stat" + done + tc -n "$NS_CLIENT" -s -j filter show dev "$VETH_CLIENT" egress | + jq '[.[].options.actions[0].stats // empty] | + (map(.packets) | add), (map(.bytes) | add)' +} + +# A frame sent while the counters are read can be counted by only one of +# them. Read them until two reads 100 ms apart agree. +client_tx_stats_settled() { + local prev cur i + + prev=$(client_tx_stats) + for ((i = 0; i < 50; i++)); do + sleep 0.1 + cur=$(client_tx_stats) + [ "$cur" = "$prev" ] && break + prev=$cur + done + echo "$cur" +} + +# Send TCP streams from every CPU at once, then check that each frame +# counted by the PPP device left the Ethernet device exactly once. +ppp_test_parallel() { + local ncpus cpu i pids=() before after d=() proto + + # PPP protocol numbers of IPv4 and IPv6 + tc -n "$NS_CLIENT" qdisc add dev "$VETH_CLIENT" clsact + for proto in 0x0021 0x0057; do + tc -n "$NS_CLIENT" filter add dev "$VETH_CLIENT" egress \ + protocol ppp_ses flower ppp_proto "$proto" action pass + done + + ncpus=$(nproc) + [ "$ncpus" -gt 8 ] && ncpus=8 + for ((cpu = 0; cpu < ncpus; cpu++)); do + ip netns exec "$NS_SERVER" iperf3 -s -1 -D -p $((5301 + cpu)) + wait_local_port_listen "$NS_SERVER" $((5301 + cpu)) tcp + done + + mapfile -t before < <(client_tx_stats_settled) + for ((cpu = 0; cpu < ncpus; cpu++)); do + ip netns exec "$NS_CLIENT" taskset -c "$cpu" \ + iperf3 -c "$IP_SERVER" -p $((5301 + cpu)) -Z -t 3 \ + > /dev/null & + pids+=($!) + done + for i in "${pids[@]}"; do + wait "$i" + check_err $? "iperf3 client failed" + done + mapfile -t after < <(client_tx_stats_settled) + + # 0-1: ppp0 packets and bytes; 2-3: the same on the veth + for i in 0 1 2 3; do + d[i]=$((after[i] - before[i])) + done + echo "ppp0: ${d[0]} packets, ${d[1]} bytes; veth: ${d[2]}, ${d[3]}" + + [ "${d[0]}" -gt 0 ] && [ "${d[0]}" -eq "${d[2]}" ] + check_err $? "PPP and Ethernet packet counts differ" + + # Ethernet (14), PPPoE (6) and PPP protocol (2) header per frame + [ "${d[3]}" -eq $((d[1] + 22 * d[0])) ] + check_err $? "PPP and Ethernet byte counts differ" +} + # Start socat as syslog listener socat -v -u UNIX-RECV:/dev/log OPEN:/dev/null > "$PPPOE_LOG" 2>&1 & SOCAT_PID=$! @@ -53,6 +131,11 @@ ppp_test_connectivity log_test "PPPoE" +RET=0 +ppp_test_parallel + +log_test "PPPoE parallel transmit" + # Dump syslog messages if the test failed if [ "$RET" -ne 0 ]; then while read -r _sign _date _time len _from _to -- 2.53.0