selftests: mlxsw: RED: Test offload of mirror on RED early_drop qevent
authorPetr Machata <petrm@mellanox.com>
Fri, 10 Jul 2020 21:55:15 +0000 (00:55 +0300)
committerDavid S. Miller <davem@davemloft.net>
Tue, 14 Jul 2020 00:22:22 +0000 (17:22 -0700)
Add a selftest for offloading a mirror action attached to the block
associated with RED early_drop qevent.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh
tools/testing/selftests/drivers/net/mlxsw/sch_red_ets.sh
tools/testing/selftests/drivers/net/mlxsw/sch_red_root.sh

index 0d347d48c112510ce91b95a3e8aa0849f2b6543b..45042105ead7654ad6aae68b7316f47afadda663 100644 (file)
@@ -121,6 +121,7 @@ h1_destroy()
 h2_create()
 {
        host_create $h2 2
+       tc qdisc add dev $h2 clsact
 
        # Some of the tests in this suite use multicast traffic. As this traffic
        # enters BR2_10 resp. BR2_11, it is flooded to all other ports. Thus
@@ -141,6 +142,7 @@ h2_create()
 h2_destroy()
 {
        ethtool -s $h2 autoneg on
+       tc qdisc del dev $h2 clsact
        host_destroy $h2
 }
 
@@ -336,6 +338,17 @@ get_qdisc_npackets()
                qdisc_stats_get $swp3 $(get_qdisc_handle $vlan) .packets
 }
 
+send_packets()
+{
+       local vlan=$1; shift
+       local proto=$1; shift
+       local pkts=$1; shift
+
+       $MZ $h2.$vlan -p 8000 -a own -b $h3_mac \
+           -A $(ipaddr 2 $vlan) -B $(ipaddr 3 $vlan) \
+           -t $proto -q -c $pkts "$@"
+}
+
 # This sends traffic in an attempt to build a backlog of $size. Returns 0 on
 # success. After 10 failed attempts it bails out and returns 1. It dumps the
 # backlog size to stdout.
@@ -364,9 +377,7 @@ build_backlog()
                        return 1
                fi
 
-               $MZ $h2.$vlan -p 8000 -a own -b $h3_mac \
-                   -A $(ipaddr 2 $vlan) -B $(ipaddr 3 $vlan) \
-                   -t $proto -q -c $pkts "$@"
+               send_packets $vlan $proto $pkts "$@"
        done
 }
 
@@ -531,3 +542,92 @@ do_mc_backlog_test()
 
        log_test "TC $((vlan - 10)): Qdisc reports MC backlog"
 }
+
+do_drop_test()
+{
+       local vlan=$1; shift
+       local limit=$1; shift
+       local trigger=$1; shift
+       local subtest=$1; shift
+       local fetch_counter=$1; shift
+       local backlog
+       local base
+       local now
+       local pct
+
+       RET=0
+
+       start_traffic $h1.$vlan $(ipaddr 1 $vlan) $(ipaddr 3 $vlan) $h3_mac
+
+       # Create a bit of a backlog and observe no mirroring due to drops.
+       qevent_rule_install_$subtest
+       base=$($fetch_counter)
+
+       build_backlog $vlan $((2 * limit / 3)) udp >/dev/null
+
+       busywait 1100 until_counter_is ">= $((base + 1))" $fetch_counter >/dev/null
+       check_fail $? "Spurious packets observed without buffer pressure"
+
+       qevent_rule_uninstall_$subtest
+
+       # Push to the queue until it's at the limit. The configured limit is
+       # rounded by the qdisc and then by the driver, so this is the best we
+       # can do to get to the real limit of the system. Do this with the rules
+       # uninstalled so that the inevitable drops don't get counted.
+       build_backlog $vlan $((3 * limit / 2)) udp >/dev/null
+
+       qevent_rule_install_$subtest
+       base=$($fetch_counter)
+
+       send_packets $vlan udp 11
+
+       now=$(busywait 1100 until_counter_is ">= $((base + 10))" $fetch_counter)
+       check_err $? "Dropped packets not observed: 11 expected, $((now - base)) seen"
+
+       # When no extra traffic is injected, there should be no mirroring.
+       busywait 1100 until_counter_is ">= $((base + 20))" $fetch_counter >/dev/null
+       check_fail $? "Spurious packets observed"
+
+       # When the rule is uninstalled, there should be no mirroring.
+       qevent_rule_uninstall_$subtest
+       send_packets $vlan udp 11
+       busywait 1100 until_counter_is ">= $((base + 20))" $fetch_counter >/dev/null
+       check_fail $? "Spurious packets observed after uninstall"
+
+       log_test "TC $((vlan - 10)): ${trigger}ped packets $subtest'd"
+
+       stop_traffic
+       sleep 1
+}
+
+qevent_rule_install_mirror()
+{
+       tc filter add block 10 pref 1234 handle 102 matchall skip_sw \
+          action mirred egress mirror dev $swp2 hw_stats disabled
+}
+
+qevent_rule_uninstall_mirror()
+{
+       tc filter del block 10 pref 1234 handle 102 matchall
+}
+
+qevent_counter_fetch_mirror()
+{
+       tc_rule_handle_stats_get "dev $h2 ingress" 101
+}
+
+do_drop_mirror_test()
+{
+       local vlan=$1; shift
+       local limit=$1; shift
+       local qevent_name=$1; shift
+
+       tc filter add dev $h2 ingress pref 1 handle 101 prot ip \
+          flower skip_sw ip_proto udp \
+          action drop
+
+       do_drop_test "$vlan" "$limit" "$qevent_name" mirror \
+                    qevent_counter_fetch_mirror
+
+       tc filter del dev $h2 ingress pref 1 handle 101 flower
+}
index 1c36c576613b5e6536a3c98d75c953bbdbd7306c..c8968b041beafd0481164e8cf61e293b2c3d6a63 100755 (executable)
@@ -7,6 +7,7 @@ ALL_TESTS="
        ecn_nodrop_test
        red_test
        mc_backlog_test
+       red_mirror_test
 "
 : ${QDISC:=ets}
 source sch_red_core.sh
@@ -83,6 +84,16 @@ mc_backlog_test()
        uninstall_qdisc
 }
 
+red_mirror_test()
+{
+       install_qdisc qevent early_drop block 10
+
+       do_drop_mirror_test 10 $BACKLOG1 early_drop
+       do_drop_mirror_test 11 $BACKLOG2 early_drop
+
+       uninstall_qdisc
+}
+
 trap cleanup EXIT
 
 setup_prepare
index 558667ea11ec96474a1b0a92692f7eba6a07b8e9..ede9c38d3effec14287d468663c1051c82fe8088 100755 (executable)
@@ -7,6 +7,7 @@ ALL_TESTS="
        ecn_nodrop_test
        red_test
        mc_backlog_test
+       red_mirror_test
 "
 source sch_red_core.sh
 
@@ -57,6 +58,13 @@ mc_backlog_test()
        uninstall_qdisc
 }
 
+red_mirror_test()
+{
+       install_qdisc qevent early_drop block 10
+       do_drop_mirror_test 10 $BACKLOG
+       uninstall_qdisc
+}
+
 trap cleanup EXIT
 
 setup_prepare