]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: hsr: Add tests for more link faults with PRP
authorFelix Maurer <fmaurer@redhat.com>
Thu, 5 Feb 2026 13:57:32 +0000 (14:57 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 10 Feb 2026 11:02:29 +0000 (12:02 +0100)
Add tests where one link has different rates of packet loss or reorders
packets. PRP should still be able to recover from these link faults and
show no packet loss.  However, it is acceptable to receive some level of
duplicate packets. This matches the current specification (IEC
62439-3:2021) of the duplicate discard algorithm that requires it to be
"designed such that it never rejects a legitimate frame, while occasional
acceptance of a duplicate can be tolerated." The rate of acceptable
duplicates in this test is intentionally high (10%) to make the test
stable, the values I observed in the worst test cases (20% loss) are around
5% duplicates.

The duplicates occur because of the 10ms ping interval in the test. As
blocks expire after 400ms based on the timestamp of the first received
sequence number in the block, every approx. 40th will lead to a new, clean
block being used where the sequence number hasn't been seen before. As this
occurs on both nodes in the test (for requests and replies), we observe
around 20 duplicate frames.

Signed-off-by: Felix Maurer <fmaurer@redhat.com>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://patch.msgid.link/7b36506d3a80e53786fe56526cf6046c74dfeee1.1770299429.git.fmaurer@redhat.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
tools/testing/selftests/net/hsr/link_faults.sh

index 7ff14dcd32e7247a350f9bb4e0fe400bf0c9c54a..1959bea171470e632db187adccf8f98666c1f32a 100755 (executable)
@@ -11,10 +11,16 @@ ALL_TESTS="
        test_cut_link_hsrv1
        test_clean_prp
        test_cut_link_prp
+       test_packet_loss_prp
+       test_high_packet_loss_prp
+       test_reordering_prp
 "
 
-# The tests are running ping for 5sec with a relatively short interval with a
-# cut link, which should be recoverable by HSR/PRP.
+# The tests are running ping for 5sec with a relatively short interval in
+# different scenarios with faulty links (cut links, packet loss, delay,
+# reordering) that should be recoverable by HSR/PRP. The ping interval (10ms)
+# is short enough that the base delay (50ms) leads to a queue in the netem
+# qdiscs which is needed for reordering.
 
 setup_hsr_topo()
 {
@@ -160,6 +166,7 @@ check_ping()
 {
        local node="$1"
        local dst="$2"
+       local accepted_dups="$3"
        local ping_args="-q -i 0.01 -c 400"
 
        log_info "Running ping $node -> $dst"
@@ -178,7 +185,9 @@ check_ping()
                loss="${BASH_REMATCH[1]}"
        fi
 
-       check_err "$dups" "Unexpected duplicate packets (${dups})"
+       if [ "$dups" -gt "$accepted_dups" ]; then
+               check_err 1 "Unexpected duplicate packets (${dups})"
+       fi
        if [ "$loss" != "0%" ]; then
                check_err 1 "Unexpected packet loss (${loss})"
        fi
@@ -197,7 +206,7 @@ test_clean()
                return
        fi
 
-       check_ping "$node1" "100.64.0.2"
+       check_ping "$node1" "100.64.0.2" 0
 
        log_test "${tname}"
 }
@@ -237,7 +246,7 @@ test_cut_link()
                log_info "Cutting link"
                ip -net "$node1" link set vethB down
        ) &
-       check_ping "$node1" "100.64.0.2"
+       check_ping "$node1" "100.64.0.2" 0
 
        wait
        log_test "${tname}"
@@ -259,6 +268,66 @@ test_cut_link_prp()
        test_cut_link "PRP"
 }
 
+test_packet_loss()
+{
+       local proto="$1"
+       local loss="$2"
+
+       RET=0
+       tname="${FUNCNAME[0]} - ${proto}, ${loss}"
+
+       setup_topo "$proto"
+       if ((RET != ksft_pass)); then
+               log_test "${tname} setup"
+               return
+       fi
+
+       # Packet loss with lower delay makes sure the packets on the lossy link
+       # arrive first.
+       tc -net "$node1" qdisc add dev vethA root netem delay 50ms
+       tc -net "$node1" qdisc add dev vethB root netem delay 20ms loss "$loss"
+
+       check_ping "$node1" "100.64.0.2" 40
+
+       log_test "${tname}"
+}
+
+test_packet_loss_prp()
+{
+       test_packet_loss "PRP" "20%"
+}
+
+test_high_packet_loss_prp()
+{
+       test_packet_loss "PRP" "80%"
+}
+
+test_reordering()
+{
+       local proto="$1"
+
+       RET=0
+       tname="${FUNCNAME[0]} - ${proto}"
+
+       setup_topo "$proto"
+       if ((RET != ksft_pass)); then
+               log_test "${tname} setup"
+               return
+       fi
+
+       tc -net "$node1" qdisc add dev vethA root netem delay 50ms
+       tc -net "$node1" qdisc add dev vethB root netem delay 50ms reorder 20%
+
+       check_ping "$node1" "100.64.0.2" 40
+
+       log_test "${tname}"
+}
+
+test_reordering_prp()
+{
+       test_reordering "PRP"
+}
+
 cleanup()
 {
        cleanup_all_ns