]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests: bonding: add test for LACP actor port priority
authorHangbin Liu <liuhangbin@gmail.com>
Tue, 2 Sep 2025 06:45:01 +0000 (06:45 +0000)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 9 Sep 2025 08:56:02 +0000 (10:56 +0200)
Add comprehensive selftest to verify:
- Per-port actor priority setting via ad_actor_port_prio
- Aggregator selection behavior with port_priority ad_select policy

Also move cmd_jq helper from forwarding/lib.sh to net/lib.sh for
broader reusability across network selftests.

Here is the result output
  # ./bond_lacp_prio.sh
  TEST: bond 802.3ad (ad_actor_port_prio setting)                     [ OK ]
  TEST: bond 802.3ad (ad_actor_port_prio select)                      [ OK ]
  TEST: bond 802.3ad (ad_actor_port_prio switch)                      [ OK ]

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Link: https://patch.msgid.link/20250902064501.360822-4-liuhangbin@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
tools/testing/selftests/drivers/net/bonding/Makefile
tools/testing/selftests/drivers/net/bonding/bond_lacp_prio.sh [new file with mode: 0755]
tools/testing/selftests/net/forwarding/lib.sh
tools/testing/selftests/net/lib.sh

index 44b98f17f8ff5713d987278f8446b6a4af7f125b..3462783ed3aca022e26c14e9f46b9cb46f05841e 100644 (file)
@@ -11,7 +11,8 @@ TEST_PROGS := \
        bond_options.sh \
        bond-eth-type-change.sh \
        bond_macvlan_ipvlan.sh \
-       bond_passive_lacp.sh
+       bond_passive_lacp.sh \
+       bond_lacp_prio.sh
 
 TEST_FILES := \
        lag_lib.sh \
diff --git a/tools/testing/selftests/drivers/net/bonding/bond_lacp_prio.sh b/tools/testing/selftests/drivers/net/bonding/bond_lacp_prio.sh
new file mode 100755 (executable)
index 0000000..a483d50
--- /dev/null
@@ -0,0 +1,108 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Testing if bond lacp per port priority works
+#
+#          Switch (s_ns)          Backup Switch (b_ns)
+#  +-------------------------+ +-------------------------+
+#  |          bond0          | |          bond0          |
+#  |            +            | |            +            |
+#  |      eth0  |  eth1      | |      eth0  |  eth1      |
+#  |        +---+---+        | |        +---+---+        |
+#  |        |       |        | |        |       |        |
+#  +-------------------------+ +-------------------------+
+#           |       |                   |       |
+#  +-----------------------------------------------------+
+#  |        |       |                   |       |        |
+#  |        +-------+---------+---------+-------+        |
+#  |      eth0     eth1       |       eth2     eth3      |
+#  |                          +                          |
+#  |                        bond0                        |
+#  +-----------------------------------------------------+
+#                        Client (c_ns)
+
+lib_dir=$(dirname "$0")
+# shellcheck disable=SC1091
+source "$lib_dir"/../../../net/lib.sh
+
+setup_links()
+{
+       # shellcheck disable=SC2154
+       ip -n "${c_ns}" link add eth0 type veth peer name eth0 netns "${s_ns}"
+       ip -n "${c_ns}" link add eth1 type veth peer name eth1 netns "${s_ns}"
+       # shellcheck disable=SC2154
+       ip -n "${c_ns}" link add eth2 type veth peer name eth0 netns "${b_ns}"
+       ip -n "${c_ns}" link add eth3 type veth peer name eth1 netns "${b_ns}"
+
+       ip -n "${c_ns}" link add bond0 type bond mode 802.3ad miimon 100 \
+               lacp_rate fast ad_select actor_port_prio
+       ip -n "${s_ns}" link add bond0 type bond mode 802.3ad miimon 100 \
+               lacp_rate fast
+       ip -n "${b_ns}" link add bond0 type bond mode 802.3ad miimon 100 \
+               lacp_rate fast
+
+       ip -n "${c_ns}" link set eth0 master bond0
+       ip -n "${c_ns}" link set eth1 master bond0
+       ip -n "${c_ns}" link set eth2 master bond0
+       ip -n "${c_ns}" link set eth3 master bond0
+       ip -n "${s_ns}" link set eth0 master bond0
+       ip -n "${s_ns}" link set eth1 master bond0
+       ip -n "${b_ns}" link set eth0 master bond0
+       ip -n "${b_ns}" link set eth1 master bond0
+
+       ip -n "${c_ns}" link set bond0 up
+       ip -n "${s_ns}" link set bond0 up
+       ip -n "${b_ns}" link set bond0 up
+}
+
+test_port_prio_setting()
+{
+       RET=0
+       ip -n "${c_ns}" link set eth0 type bond_slave actor_port_prio 1000
+       prio=$(cmd_jq "ip -n ${c_ns} -d -j link show eth0" \
+               ".[].linkinfo.info_slave_data.actor_port_prio")
+       [ "$prio" -ne 1000 ] && RET=1
+       ip -n "${c_ns}" link set eth2 type bond_slave actor_port_prio 10
+       prio=$(cmd_jq "ip -n ${c_ns} -d -j link show eth2" \
+               ".[].linkinfo.info_slave_data.actor_port_prio")
+       [ "$prio" -ne 10 ] && RET=1
+}
+
+test_agg_reselect()
+{
+       local bond_agg_id slave_agg_id
+       local expect_slave="$1"
+       RET=0
+
+       # Trigger link state change to reselect the aggregator
+       ip -n "${c_ns}" link set eth1 down
+       sleep 0.5
+       ip -n "${c_ns}" link set eth1 up
+       sleep 0.5
+
+       bond_agg_id=$(cmd_jq "ip -n ${c_ns} -d -j link show bond0" \
+               ".[].linkinfo.info_data.ad_info.aggregator")
+       slave_agg_id=$(cmd_jq "ip -n ${c_ns} -d -j link show $expect_slave" \
+               ".[].linkinfo.info_slave_data.ad_aggregator_id")
+       # shellcheck disable=SC2034
+       [ "${bond_agg_id}" -ne "${slave_agg_id}" ] && \
+               RET=1
+}
+
+trap cleanup_all_ns EXIT
+setup_ns c_ns s_ns b_ns
+setup_links
+
+test_port_prio_setting
+log_test "bond 802.3ad" "actor_port_prio setting"
+
+test_agg_reselect eth0
+log_test "bond 802.3ad" "actor_port_prio select"
+
+# Change the actor port prio and re-test
+ip -n "${c_ns}" link set eth0 type bond_slave actor_port_prio 10
+ip -n "${c_ns}" link set eth2 type bond_slave actor_port_prio 1000
+test_agg_reselect eth2
+log_test "bond 802.3ad" "actor_port_prio switch"
+
+exit "${EXIT_STATUS}"
index 890b3374dacdac5383956820658257cee49b1b4a..08121cb9dc2693eea3af2ed70676f04d909152ae 100644 (file)
@@ -571,30 +571,6 @@ wait_for_dev()
         fi
 }
 
-cmd_jq()
-{
-       local cmd=$1
-       local jq_exp=$2
-       local jq_opts=$3
-       local ret
-       local output
-
-       output="$($cmd)"
-       # it the command fails, return error right away
-       ret=$?
-       if [[ $ret -ne 0 ]]; then
-               return $ret
-       fi
-       output=$(echo $output | jq -r $jq_opts "$jq_exp")
-       ret=$?
-       if [[ $ret -ne 0 ]]; then
-               return $ret
-       fi
-       echo $output
-       # return success only in case of non-empty output
-       [ ! -z "$output" ]
-}
-
 pre_cleanup()
 {
        if [ "${PAUSE_ON_CLEANUP}" = "yes" ]; then
index c7add0dc4c6052bc10b1dc3c5c4ac24bbed13bfd..4dca6893aa8ab29d4ed8d6a261b1d61cddb3d7e9 100644 (file)
@@ -645,3 +645,27 @@ wait_local_port_listen()
                sleep 0.1
        done
 }
+
+cmd_jq()
+{
+       local cmd=$1
+       local jq_exp=$2
+       local jq_opts=$3
+       local ret
+       local output
+
+       output="$($cmd)"
+       # it the command fails, return error right away
+       ret=$?
+       if [[ $ret -ne 0 ]]; then
+               return $ret
+       fi
+       output=$(echo $output | jq -r $jq_opts "$jq_exp")
+       ret=$?
+       if [[ $ret -ne 0 ]]; then
+               return $ret
+       fi
+       echo $output
+       # return success only in case of non-empty output
+       [ ! -z "$output" ]
+}