-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests: bonding: re-format bond option tests
To improve the testing process for bond options, A new bond topology lib is added to our testing setup. The current option_prio.sh file will be renamed to bond_options.sh so that all bonding options can be tested here. Specifically, for priority testing, we will run all tests using modes 1, 5, and 6. These changes will help us streamline the testing process and ensure that our bond options are rigorously evaluated. Acked-by: Jay Vosburgh <jay.vosburgh@canonical.com> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Acked-by: Jonathan Toppins <jtoppins@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Hangbin Liu
authored and
David S. Miller
committed
Apr 7, 2023
1 parent
4598380
commit 481b56e
Showing
4 changed files
with
354 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
209 changes: 209 additions & 0 deletions
209
tools/testing/selftests/drivers/net/bonding/bond_options.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: GPL-2.0 | ||
# | ||
# Test bonding options with mode 1,5,6 | ||
|
||
ALL_TESTS=" | ||
prio | ||
" | ||
|
||
REQUIRE_MZ=no | ||
NUM_NETIFS=0 | ||
lib_dir=$(dirname "$0") | ||
source ${lib_dir}/net_forwarding_lib.sh | ||
source ${lib_dir}/bond_topo_3d1c.sh | ||
|
||
skip_prio() | ||
{ | ||
local skip=1 | ||
|
||
# check if iproute support prio option | ||
ip -n ${s_ns} link set eth0 type bond_slave prio 10 | ||
[[ $? -ne 0 ]] && skip=0 | ||
|
||
# check if kernel support prio option | ||
ip -n ${s_ns} -d link show eth0 | grep -q "prio 10" | ||
[[ $? -ne 0 ]] && skip=0 | ||
|
||
return $skip | ||
} | ||
|
||
skip_ns() | ||
{ | ||
local skip=1 | ||
|
||
# check if iproute support ns_ip6_target option | ||
ip -n ${s_ns} link add bond1 type bond ns_ip6_target ${g_ip6} | ||
[[ $? -ne 0 ]] && skip=0 | ||
|
||
# check if kernel support ns_ip6_target option | ||
ip -n ${s_ns} -d link show bond1 | grep -q "ns_ip6_target ${g_ip6}" | ||
[[ $? -ne 0 ]] && skip=0 | ||
|
||
ip -n ${s_ns} link del bond1 | ||
|
||
return $skip | ||
} | ||
|
||
active_slave="" | ||
check_active_slave() | ||
{ | ||
local target_active_slave=$1 | ||
active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave") | ||
test "$active_slave" = "$target_active_slave" | ||
check_err $? "Current active slave is $active_slave but not $target_active_slave" | ||
} | ||
|
||
|
||
# Test bonding prio option | ||
prio_test() | ||
{ | ||
local param="$1" | ||
RET=0 | ||
|
||
# create bond | ||
bond_reset "${param}" | ||
|
||
# check bonding member prio value | ||
ip -n ${s_ns} link set eth0 type bond_slave prio 0 | ||
ip -n ${s_ns} link set eth1 type bond_slave prio 10 | ||
ip -n ${s_ns} link set eth2 type bond_slave prio 11 | ||
cmd_jq "ip -n ${s_ns} -d -j link show eth0" \ | ||
".[].linkinfo.info_slave_data | select (.prio == 0)" "-e" &> /dev/null | ||
check_err $? "eth0 prio is not 0" | ||
cmd_jq "ip -n ${s_ns} -d -j link show eth1" \ | ||
".[].linkinfo.info_slave_data | select (.prio == 10)" "-e" &> /dev/null | ||
check_err $? "eth1 prio is not 10" | ||
cmd_jq "ip -n ${s_ns} -d -j link show eth2" \ | ||
".[].linkinfo.info_slave_data | select (.prio == 11)" "-e" &> /dev/null | ||
check_err $? "eth2 prio is not 11" | ||
|
||
bond_check_connection "setup" | ||
|
||
# active slave should be the primary slave | ||
check_active_slave eth1 | ||
|
||
# active slave should be the higher prio slave | ||
ip -n ${s_ns} link set $active_slave down | ||
bond_check_connection "fail over" | ||
check_active_slave eth2 | ||
|
||
# when only 1 slave is up | ||
ip -n ${s_ns} link set $active_slave down | ||
bond_check_connection "only 1 slave up" | ||
check_active_slave eth0 | ||
|
||
# when a higher prio slave change to up | ||
ip -n ${s_ns} link set eth2 up | ||
bond_check_connection "higher prio slave up" | ||
case $primary_reselect in | ||
"0") | ||
check_active_slave "eth2" | ||
;; | ||
"1") | ||
check_active_slave "eth0" | ||
;; | ||
"2") | ||
check_active_slave "eth0" | ||
;; | ||
esac | ||
local pre_active_slave=$active_slave | ||
|
||
# when the primary slave change to up | ||
ip -n ${s_ns} link set eth1 up | ||
bond_check_connection "primary slave up" | ||
case $primary_reselect in | ||
"0") | ||
check_active_slave "eth1" | ||
;; | ||
"1") | ||
check_active_slave "$pre_active_slave" | ||
;; | ||
"2") | ||
check_active_slave "$pre_active_slave" | ||
ip -n ${s_ns} link set $active_slave down | ||
bond_check_connection "pre_active slave down" | ||
check_active_slave "eth1" | ||
;; | ||
esac | ||
|
||
# Test changing bond slave prio | ||
if [[ "$primary_reselect" == "0" ]];then | ||
ip -n ${s_ns} link set eth0 type bond_slave prio 1000000 | ||
ip -n ${s_ns} link set eth1 type bond_slave prio 0 | ||
ip -n ${s_ns} link set eth2 type bond_slave prio -50 | ||
ip -n ${s_ns} -d link show eth0 | grep -q 'prio 1000000' | ||
check_err $? "eth0 prio is not 1000000" | ||
ip -n ${s_ns} -d link show eth1 | grep -q 'prio 0' | ||
check_err $? "eth1 prio is not 0" | ||
ip -n ${s_ns} -d link show eth2 | grep -q 'prio -50' | ||
check_err $? "eth3 prio is not -50" | ||
check_active_slave "eth1" | ||
|
||
ip -n ${s_ns} link set $active_slave down | ||
bond_check_connection "change slave prio" | ||
check_active_slave "eth0" | ||
fi | ||
} | ||
|
||
prio_miimon() | ||
{ | ||
local primary_reselect | ||
local mode=$1 | ||
|
||
for primary_reselect in 0 1 2; do | ||
prio_test "mode $mode miimon 100 primary eth1 primary_reselect $primary_reselect" | ||
log_test "prio" "$mode miimon primary_reselect $primary_reselect" | ||
done | ||
} | ||
|
||
prio_arp() | ||
{ | ||
local primary_reselect | ||
local mode=$1 | ||
|
||
for primary_reselect in 0 1 2; do | ||
prio_test "mode active-backup arp_interval 100 arp_ip_target ${g_ip4} primary eth1 primary_reselect $primary_reselect" | ||
log_test "prio" "$mode arp_ip_target primary_reselect $primary_reselect" | ||
done | ||
} | ||
|
||
prio_ns() | ||
{ | ||
local primary_reselect | ||
local mode=$1 | ||
|
||
if skip_ns; then | ||
log_test_skip "prio ns" "Current iproute or kernel doesn't support bond option 'ns_ip6_target'." | ||
return 0 | ||
fi | ||
|
||
for primary_reselect in 0 1 2; do | ||
prio_test "mode active-backup arp_interval 100 ns_ip6_target ${g_ip6} primary eth1 primary_reselect $primary_reselect" | ||
log_test "prio" "$mode ns_ip6_target primary_reselect $primary_reselect" | ||
done | ||
} | ||
|
||
prio() | ||
{ | ||
local mode modes="active-backup balance-tlb balance-alb" | ||
|
||
if skip_prio; then | ||
log_test_skip "prio" "Current iproute or kernel doesn't support bond option 'prio'." | ||
return 0 | ||
fi | ||
|
||
for mode in $modes; do | ||
prio_miimon $mode | ||
prio_arp $mode | ||
prio_ns $mode | ||
done | ||
} | ||
|
||
trap cleanup EXIT | ||
|
||
setup_prepare | ||
setup_wait | ||
tests_run | ||
|
||
exit $EXIT_STATUS |
143 changes: 143 additions & 0 deletions
143
tools/testing/selftests/drivers/net/bonding/bond_topo_3d1c.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: GPL-2.0 | ||
# | ||
# Topology for Bond mode 1,5,6 testing | ||
# | ||
# +-------------------------------------+ | ||
# | bond0 | | ||
# | + | Server | ||
# | eth0 | eth1 eth2 | 192.0.2.1/24 | ||
# | +-------------------+ | 2001:db8::1/24 | ||
# | | | | | | ||
# +-------------------------------------+ | ||
# | | | | ||
# +-------------------------------------+ | ||
# | | | | | | ||
# | +---+---------+---------+---+ | Gateway | ||
# | | br0 | | 192.0.2.254/24 | ||
# | +-------------+-------------+ | 2001:db8::254/24 | ||
# | | | | ||
# +-------------------------------------+ | ||
# | | ||
# +-------------------------------------+ | ||
# | | | Client | ||
# | + | 192.0.2.10/24 | ||
# | eth0 | 2001:db8::10/24 | ||
# +-------------------------------------+ | ||
|
||
s_ns="s-$(mktemp -u XXXXXX)" | ||
c_ns="c-$(mktemp -u XXXXXX)" | ||
g_ns="g-$(mktemp -u XXXXXX)" | ||
s_ip4="192.0.2.1" | ||
c_ip4="192.0.2.10" | ||
g_ip4="192.0.2.254" | ||
s_ip6="2001:db8::1" | ||
c_ip6="2001:db8::10" | ||
g_ip6="2001:db8::254" | ||
|
||
gateway_create() | ||
{ | ||
ip netns add ${g_ns} | ||
ip -n ${g_ns} link add br0 type bridge | ||
ip -n ${g_ns} link set br0 up | ||
ip -n ${g_ns} addr add ${g_ip4}/24 dev br0 | ||
ip -n ${g_ns} addr add ${g_ip6}/24 dev br0 | ||
} | ||
|
||
gateway_destroy() | ||
{ | ||
ip -n ${g_ns} link del br0 | ||
ip netns del ${g_ns} | ||
} | ||
|
||
server_create() | ||
{ | ||
ip netns add ${s_ns} | ||
ip -n ${s_ns} link add bond0 type bond mode active-backup miimon 100 | ||
|
||
for i in $(seq 0 2); do | ||
ip -n ${s_ns} link add eth${i} type veth peer name s${i} netns ${g_ns} | ||
|
||
ip -n ${g_ns} link set s${i} up | ||
ip -n ${g_ns} link set s${i} master br0 | ||
ip -n ${s_ns} link set eth${i} master bond0 | ||
done | ||
|
||
ip -n ${s_ns} link set bond0 up | ||
ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0 | ||
ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0 | ||
sleep 2 | ||
} | ||
|
||
# Reset bond with new mode and options | ||
bond_reset() | ||
{ | ||
local param="$1" | ||
|
||
ip -n ${s_ns} link set bond0 down | ||
ip -n ${s_ns} link del bond0 | ||
|
||
ip -n ${s_ns} link add bond0 type bond $param | ||
for i in $(seq 0 2); do | ||
ip -n ${s_ns} link set eth$i master bond0 | ||
done | ||
|
||
ip -n ${s_ns} link set bond0 up | ||
ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0 | ||
ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0 | ||
sleep 2 | ||
} | ||
|
||
server_destroy() | ||
{ | ||
for i in $(seq 0 2); do | ||
ip -n ${s_ns} link del eth${i} | ||
done | ||
ip netns del ${s_ns} | ||
} | ||
|
||
client_create() | ||
{ | ||
ip netns add ${c_ns} | ||
ip -n ${c_ns} link add eth0 type veth peer name c0 netns ${g_ns} | ||
|
||
ip -n ${g_ns} link set c0 up | ||
ip -n ${g_ns} link set c0 master br0 | ||
|
||
ip -n ${c_ns} link set eth0 up | ||
ip -n ${c_ns} addr add ${c_ip4}/24 dev eth0 | ||
ip -n ${c_ns} addr add ${c_ip6}/24 dev eth0 | ||
} | ||
|
||
client_destroy() | ||
{ | ||
ip -n ${c_ns} link del eth0 | ||
ip netns del ${c_ns} | ||
} | ||
|
||
setup_prepare() | ||
{ | ||
gateway_create | ||
server_create | ||
client_create | ||
} | ||
|
||
cleanup() | ||
{ | ||
pre_cleanup | ||
|
||
client_destroy | ||
server_destroy | ||
gateway_destroy | ||
} | ||
|
||
bond_check_connection() | ||
{ | ||
local msg=${1:-"check connection"} | ||
|
||
sleep 2 | ||
ip netns exec ${s_ns} ping ${c_ip4} -c5 -i 0.1 &>/dev/null | ||
check_err $? "${msg}: ping failed" | ||
ip netns exec ${s_ns} ping6 ${c_ip6} -c5 -i 0.1 &>/dev/null | ||
check_err $? "${msg}: ping6 failed" | ||
} |
Oops, something went wrong.