selftests: mlxsw: Add a scale test for RIF MAC profiles
authorDanielle Ratson <danieller@nvidia.com>
Tue, 26 Oct 2021 09:42:22 +0000 (12:42 +0300)
committerDavid S. Miller <davem@davemloft.net>
Tue, 26 Oct 2021 12:35:58 +0000 (13:35 +0100)
Query the maximum number of supported RIF MAC profiles using
devlink-resource and verify that all available MAC profiles can be utilized
and that an error is generated when user space tries to exceed this number.

Output example in Spectrum-2:

$ TESTS='rif_mac_profile' ./resource_scale.sh
TEST: 'rif_mac_profile' 4                                           [ OK ]
TEST: 'rif_mac_profile' overflow 5                                  [ OK ]

Signed-off-by: Danielle Ratson <danieller@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/drivers/net/mlxsw/rif_mac_profile_scale.sh [new file with mode: 0644]
tools/testing/selftests/drivers/net/mlxsw/spectrum-2/resource_scale.sh
tools/testing/selftests/drivers/net/mlxsw/spectrum-2/rif_mac_profile_scale.sh [new file with mode: 0644]
tools/testing/selftests/drivers/net/mlxsw/spectrum/resource_scale.sh
tools/testing/selftests/drivers/net/mlxsw/spectrum/rif_mac_profile_scale.sh [new file with mode: 0644]

diff --git a/tools/testing/selftests/drivers/net/mlxsw/rif_mac_profile_scale.sh b/tools/testing/selftests/drivers/net/mlxsw/rif_mac_profile_scale.sh
new file mode 100644 (file)
index 0000000..71e7681
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# Test for RIF MAC profiles resource. The test adds VLAN netdevices according to
+# the maximum number of RIF MAC profiles, sets each of them with a random
+# MAC address, and checks that eventually the number of occupied RIF MAC
+# profiles equals the maximum number of RIF MAC profiles.
+
+
+RIF_MAC_PROFILE_NUM_NETIFS=2
+
+rif_mac_profiles_create()
+{
+       local count=$1; shift
+       local should_fail=$1; shift
+       local batch_file="$(mktemp)"
+
+       for ((i = 1; i <= count; i++)); do
+               vlan=$(( i*10 ))
+               m=$(( i*11 ))
+
+               cat >> $batch_file <<-EOF
+                       link add link $h1 name $h1.$vlan \
+                               address 00:$m:$m:$m:$m:$m type vlan id $vlan
+                       address add 192.0.$m.1/24 dev $h1.$vlan
+               EOF
+       done
+
+       ip -b $batch_file &> /dev/null
+       check_err_fail $should_fail $? "RIF creation"
+
+       rm -f $batch_file
+}
+
+rif_mac_profile_test()
+{
+       local count=$1; shift
+       local should_fail=$1; shift
+
+       rif_mac_profiles_create $count $should_fail
+
+       occ=$(devlink -j resource show $DEVLINK_DEV \
+             | jq '.[][][] | select(.name=="rif_mac_profiles") |.["occ"]')
+
+       [[ $occ -eq $count ]]
+       check_err_fail $should_fail $? "Attempt to use $count profiles (actual result $occ)"
+}
+
+rif_mac_profile_setup_prepare()
+{
+       h1=${NETIFS[p1]}
+       h2=${NETIFS[p2]}
+
+       # Disable IPv6 on the two interfaces to avoid IPv6 link-local addresses
+       # being generated and RIFs being created.
+       sysctl_set net.ipv6.conf.$h1.disable_ipv6 1
+       sysctl_set net.ipv6.conf.$h2.disable_ipv6 1
+
+       ip link set $h1 up
+       ip link set $h2 up
+}
+
+rif_mac_profile_cleanup()
+{
+       pre_cleanup
+
+       ip link set $h2 down
+       ip link set $h1 down
+
+       sysctl_restore net.ipv6.conf.$h2.disable_ipv6
+       sysctl_restore net.ipv6.conf.$h1.disable_ipv6
+}
index 02b7eea..e9f65bd 100755 (executable)
@@ -25,7 +25,7 @@ cleanup()
 
 trap cleanup EXIT
 
-ALL_TESTS="router tc_flower mirror_gre tc_police port"
+ALL_TESTS="router tc_flower mirror_gre tc_police port rif_mac_profile"
 for current_test in ${TESTS:-$ALL_TESTS}; do
        RET_FIN=0
        source ${current_test}_scale.sh
diff --git a/tools/testing/selftests/drivers/net/mlxsw/spectrum-2/rif_mac_profile_scale.sh b/tools/testing/selftests/drivers/net/mlxsw/spectrum-2/rif_mac_profile_scale.sh
new file mode 100644 (file)
index 0000000..303d7cb
--- /dev/null
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0
+source ../rif_mac_profile_scale.sh
+
+rif_mac_profile_get_target()
+{
+       local should_fail=$1
+       local target
+
+       target=$(devlink_resource_size_get rif_mac_profiles)
+
+       if ((! should_fail)); then
+               echo $target
+       else
+               echo $((target + 1))
+       fi
+}
index 685dfb3..bcb110e 100755 (executable)
@@ -22,7 +22,7 @@ cleanup()
 devlink_sp_read_kvd_defaults
 trap cleanup EXIT
 
-ALL_TESTS="router tc_flower mirror_gre tc_police port"
+ALL_TESTS="router tc_flower mirror_gre tc_police port rif_mac_profile"
 for current_test in ${TESTS:-$ALL_TESTS}; do
        RET_FIN=0
        source ${current_test}_scale.sh
diff --git a/tools/testing/selftests/drivers/net/mlxsw/spectrum/rif_mac_profile_scale.sh b/tools/testing/selftests/drivers/net/mlxsw/spectrum/rif_mac_profile_scale.sh
new file mode 100644 (file)
index 0000000..303d7cb
--- /dev/null
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0
+source ../rif_mac_profile_scale.sh
+
+rif_mac_profile_get_target()
+{
+       local should_fail=$1
+       local target
+
+       target=$(devlink_resource_size_get rif_mac_profiles)
+
+       if ((! should_fail)); then
+               echo $target
+       else
+               echo $((target + 1))
+       fi
+}