Skip to content

Commit 481b56e

Browse files
liuhangbindavem330
authored andcommitted
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 <[email protected]> Signed-off-by: Hangbin Liu <[email protected]> Acked-by: Jonathan Toppins <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4598380 commit 481b56e

File tree

4 files changed

+354
-246
lines changed

4 files changed

+354
-246
lines changed

tools/testing/selftests/drivers/net/bonding/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ TEST_PROGS := \
88
dev_addr_lists.sh \
99
mode-1-recovery-updelay.sh \
1010
mode-2-recovery-updelay.sh \
11-
option_prio.sh \
11+
bond_options.sh \
1212
bond-eth-type-change.sh
1313

1414
TEST_FILES := \
1515
lag_lib.sh \
16+
bond_topo_3d1c.sh \
1617
net_forwarding_lib.sh
1718

1819
include ../../../lib.mk
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Test bonding options with mode 1,5,6
5+
6+
ALL_TESTS="
7+
prio
8+
"
9+
10+
REQUIRE_MZ=no
11+
NUM_NETIFS=0
12+
lib_dir=$(dirname "$0")
13+
source ${lib_dir}/net_forwarding_lib.sh
14+
source ${lib_dir}/bond_topo_3d1c.sh
15+
16+
skip_prio()
17+
{
18+
local skip=1
19+
20+
# check if iproute support prio option
21+
ip -n ${s_ns} link set eth0 type bond_slave prio 10
22+
[[ $? -ne 0 ]] && skip=0
23+
24+
# check if kernel support prio option
25+
ip -n ${s_ns} -d link show eth0 | grep -q "prio 10"
26+
[[ $? -ne 0 ]] && skip=0
27+
28+
return $skip
29+
}
30+
31+
skip_ns()
32+
{
33+
local skip=1
34+
35+
# check if iproute support ns_ip6_target option
36+
ip -n ${s_ns} link add bond1 type bond ns_ip6_target ${g_ip6}
37+
[[ $? -ne 0 ]] && skip=0
38+
39+
# check if kernel support ns_ip6_target option
40+
ip -n ${s_ns} -d link show bond1 | grep -q "ns_ip6_target ${g_ip6}"
41+
[[ $? -ne 0 ]] && skip=0
42+
43+
ip -n ${s_ns} link del bond1
44+
45+
return $skip
46+
}
47+
48+
active_slave=""
49+
check_active_slave()
50+
{
51+
local target_active_slave=$1
52+
active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")
53+
test "$active_slave" = "$target_active_slave"
54+
check_err $? "Current active slave is $active_slave but not $target_active_slave"
55+
}
56+
57+
58+
# Test bonding prio option
59+
prio_test()
60+
{
61+
local param="$1"
62+
RET=0
63+
64+
# create bond
65+
bond_reset "${param}"
66+
67+
# check bonding member prio value
68+
ip -n ${s_ns} link set eth0 type bond_slave prio 0
69+
ip -n ${s_ns} link set eth1 type bond_slave prio 10
70+
ip -n ${s_ns} link set eth2 type bond_slave prio 11
71+
cmd_jq "ip -n ${s_ns} -d -j link show eth0" \
72+
".[].linkinfo.info_slave_data | select (.prio == 0)" "-e" &> /dev/null
73+
check_err $? "eth0 prio is not 0"
74+
cmd_jq "ip -n ${s_ns} -d -j link show eth1" \
75+
".[].linkinfo.info_slave_data | select (.prio == 10)" "-e" &> /dev/null
76+
check_err $? "eth1 prio is not 10"
77+
cmd_jq "ip -n ${s_ns} -d -j link show eth2" \
78+
".[].linkinfo.info_slave_data | select (.prio == 11)" "-e" &> /dev/null
79+
check_err $? "eth2 prio is not 11"
80+
81+
bond_check_connection "setup"
82+
83+
# active slave should be the primary slave
84+
check_active_slave eth1
85+
86+
# active slave should be the higher prio slave
87+
ip -n ${s_ns} link set $active_slave down
88+
bond_check_connection "fail over"
89+
check_active_slave eth2
90+
91+
# when only 1 slave is up
92+
ip -n ${s_ns} link set $active_slave down
93+
bond_check_connection "only 1 slave up"
94+
check_active_slave eth0
95+
96+
# when a higher prio slave change to up
97+
ip -n ${s_ns} link set eth2 up
98+
bond_check_connection "higher prio slave up"
99+
case $primary_reselect in
100+
"0")
101+
check_active_slave "eth2"
102+
;;
103+
"1")
104+
check_active_slave "eth0"
105+
;;
106+
"2")
107+
check_active_slave "eth0"
108+
;;
109+
esac
110+
local pre_active_slave=$active_slave
111+
112+
# when the primary slave change to up
113+
ip -n ${s_ns} link set eth1 up
114+
bond_check_connection "primary slave up"
115+
case $primary_reselect in
116+
"0")
117+
check_active_slave "eth1"
118+
;;
119+
"1")
120+
check_active_slave "$pre_active_slave"
121+
;;
122+
"2")
123+
check_active_slave "$pre_active_slave"
124+
ip -n ${s_ns} link set $active_slave down
125+
bond_check_connection "pre_active slave down"
126+
check_active_slave "eth1"
127+
;;
128+
esac
129+
130+
# Test changing bond slave prio
131+
if [[ "$primary_reselect" == "0" ]];then
132+
ip -n ${s_ns} link set eth0 type bond_slave prio 1000000
133+
ip -n ${s_ns} link set eth1 type bond_slave prio 0
134+
ip -n ${s_ns} link set eth2 type bond_slave prio -50
135+
ip -n ${s_ns} -d link show eth0 | grep -q 'prio 1000000'
136+
check_err $? "eth0 prio is not 1000000"
137+
ip -n ${s_ns} -d link show eth1 | grep -q 'prio 0'
138+
check_err $? "eth1 prio is not 0"
139+
ip -n ${s_ns} -d link show eth2 | grep -q 'prio -50'
140+
check_err $? "eth3 prio is not -50"
141+
check_active_slave "eth1"
142+
143+
ip -n ${s_ns} link set $active_slave down
144+
bond_check_connection "change slave prio"
145+
check_active_slave "eth0"
146+
fi
147+
}
148+
149+
prio_miimon()
150+
{
151+
local primary_reselect
152+
local mode=$1
153+
154+
for primary_reselect in 0 1 2; do
155+
prio_test "mode $mode miimon 100 primary eth1 primary_reselect $primary_reselect"
156+
log_test "prio" "$mode miimon primary_reselect $primary_reselect"
157+
done
158+
}
159+
160+
prio_arp()
161+
{
162+
local primary_reselect
163+
local mode=$1
164+
165+
for primary_reselect in 0 1 2; do
166+
prio_test "mode active-backup arp_interval 100 arp_ip_target ${g_ip4} primary eth1 primary_reselect $primary_reselect"
167+
log_test "prio" "$mode arp_ip_target primary_reselect $primary_reselect"
168+
done
169+
}
170+
171+
prio_ns()
172+
{
173+
local primary_reselect
174+
local mode=$1
175+
176+
if skip_ns; then
177+
log_test_skip "prio ns" "Current iproute or kernel doesn't support bond option 'ns_ip6_target'."
178+
return 0
179+
fi
180+
181+
for primary_reselect in 0 1 2; do
182+
prio_test "mode active-backup arp_interval 100 ns_ip6_target ${g_ip6} primary eth1 primary_reselect $primary_reselect"
183+
log_test "prio" "$mode ns_ip6_target primary_reselect $primary_reselect"
184+
done
185+
}
186+
187+
prio()
188+
{
189+
local mode modes="active-backup balance-tlb balance-alb"
190+
191+
if skip_prio; then
192+
log_test_skip "prio" "Current iproute or kernel doesn't support bond option 'prio'."
193+
return 0
194+
fi
195+
196+
for mode in $modes; do
197+
prio_miimon $mode
198+
prio_arp $mode
199+
prio_ns $mode
200+
done
201+
}
202+
203+
trap cleanup EXIT
204+
205+
setup_prepare
206+
setup_wait
207+
tests_run
208+
209+
exit $EXIT_STATUS
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Topology for Bond mode 1,5,6 testing
5+
#
6+
# +-------------------------------------+
7+
# | bond0 |
8+
# | + | Server
9+
# | eth0 | eth1 eth2 | 192.0.2.1/24
10+
# | +-------------------+ | 2001:db8::1/24
11+
# | | | | |
12+
# +-------------------------------------+
13+
# | | |
14+
# +-------------------------------------+
15+
# | | | | |
16+
# | +---+---------+---------+---+ | Gateway
17+
# | | br0 | | 192.0.2.254/24
18+
# | +-------------+-------------+ | 2001:db8::254/24
19+
# | | |
20+
# +-------------------------------------+
21+
# |
22+
# +-------------------------------------+
23+
# | | | Client
24+
# | + | 192.0.2.10/24
25+
# | eth0 | 2001:db8::10/24
26+
# +-------------------------------------+
27+
28+
s_ns="s-$(mktemp -u XXXXXX)"
29+
c_ns="c-$(mktemp -u XXXXXX)"
30+
g_ns="g-$(mktemp -u XXXXXX)"
31+
s_ip4="192.0.2.1"
32+
c_ip4="192.0.2.10"
33+
g_ip4="192.0.2.254"
34+
s_ip6="2001:db8::1"
35+
c_ip6="2001:db8::10"
36+
g_ip6="2001:db8::254"
37+
38+
gateway_create()
39+
{
40+
ip netns add ${g_ns}
41+
ip -n ${g_ns} link add br0 type bridge
42+
ip -n ${g_ns} link set br0 up
43+
ip -n ${g_ns} addr add ${g_ip4}/24 dev br0
44+
ip -n ${g_ns} addr add ${g_ip6}/24 dev br0
45+
}
46+
47+
gateway_destroy()
48+
{
49+
ip -n ${g_ns} link del br0
50+
ip netns del ${g_ns}
51+
}
52+
53+
server_create()
54+
{
55+
ip netns add ${s_ns}
56+
ip -n ${s_ns} link add bond0 type bond mode active-backup miimon 100
57+
58+
for i in $(seq 0 2); do
59+
ip -n ${s_ns} link add eth${i} type veth peer name s${i} netns ${g_ns}
60+
61+
ip -n ${g_ns} link set s${i} up
62+
ip -n ${g_ns} link set s${i} master br0
63+
ip -n ${s_ns} link set eth${i} master bond0
64+
done
65+
66+
ip -n ${s_ns} link set bond0 up
67+
ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0
68+
ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0
69+
sleep 2
70+
}
71+
72+
# Reset bond with new mode and options
73+
bond_reset()
74+
{
75+
local param="$1"
76+
77+
ip -n ${s_ns} link set bond0 down
78+
ip -n ${s_ns} link del bond0
79+
80+
ip -n ${s_ns} link add bond0 type bond $param
81+
for i in $(seq 0 2); do
82+
ip -n ${s_ns} link set eth$i master bond0
83+
done
84+
85+
ip -n ${s_ns} link set bond0 up
86+
ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0
87+
ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0
88+
sleep 2
89+
}
90+
91+
server_destroy()
92+
{
93+
for i in $(seq 0 2); do
94+
ip -n ${s_ns} link del eth${i}
95+
done
96+
ip netns del ${s_ns}
97+
}
98+
99+
client_create()
100+
{
101+
ip netns add ${c_ns}
102+
ip -n ${c_ns} link add eth0 type veth peer name c0 netns ${g_ns}
103+
104+
ip -n ${g_ns} link set c0 up
105+
ip -n ${g_ns} link set c0 master br0
106+
107+
ip -n ${c_ns} link set eth0 up
108+
ip -n ${c_ns} addr add ${c_ip4}/24 dev eth0
109+
ip -n ${c_ns} addr add ${c_ip6}/24 dev eth0
110+
}
111+
112+
client_destroy()
113+
{
114+
ip -n ${c_ns} link del eth0
115+
ip netns del ${c_ns}
116+
}
117+
118+
setup_prepare()
119+
{
120+
gateway_create
121+
server_create
122+
client_create
123+
}
124+
125+
cleanup()
126+
{
127+
pre_cleanup
128+
129+
client_destroy
130+
server_destroy
131+
gateway_destroy
132+
}
133+
134+
bond_check_connection()
135+
{
136+
local msg=${1:-"check connection"}
137+
138+
sleep 2
139+
ip netns exec ${s_ns} ping ${c_ip4} -c5 -i 0.1 &>/dev/null
140+
check_err $? "${msg}: ping failed"
141+
ip netns exec ${s_ns} ping6 ${c_ip6} -c5 -i 0.1 &>/dev/null
142+
check_err $? "${msg}: ping6 failed"
143+
}

0 commit comments

Comments
 (0)