blob: c32eebff5005d93e4f68c4882704e968587b3796 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Test bonding option prio
#
ALL_TESTS="
prio_arp_ip_target_test
prio_miimon_test
"
REQUIRE_MZ=no
REQUIRE_JQ=no
NUM_NETIFS=0
lib_dir=$(dirname "$0")
source "$lib_dir"/net_forwarding_lib.sh
destroy()
{
ip link del bond0 &>/dev/null
ip link del br0 &>/dev/null
ip link del veth0 &>/dev/null
ip link del veth1 &>/dev/null
ip link del veth2 &>/dev/null
ip netns del ns1 &>/dev/null
ip link del veth3 &>/dev/null
}
cleanup()
{
pre_cleanup
destroy
}
skip()
{
local skip=1
ip link add name bond0 type bond mode 1 miimon 100 &>/dev/null
ip link add name veth0 type veth peer name veth0_p
ip link set veth0 master bond0
# check if iproute support prio option
ip link set dev veth0 type bond_slave prio 10
[[ $? -ne 0 ]] && skip=0
# check if bonding support prio option
ip -d link show veth0 | grep -q "prio 10"
[[ $? -ne 0 ]] && skip=0
ip link del bond0 &>/dev/null
ip link del veth0
return $skip
}
active_slave=""
check_active_slave()
{
local target_active_slave=$1
active_slave="$(cat /sys/class/net/bond0/bonding/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 with mode=$mode monitor=$monitor
# and primary_reselect=$primary_reselect
prio_test()
{
RET=0
local monitor=$1
local mode=$2
local primary_reselect=$3
local bond_ip4="192.169.1.2"
local peer_ip4="192.169.1.1"
local bond_ip6="2009:0a:0b::02"
local peer_ip6="2009:0a:0b::01"
# create veths
ip link add name veth0 type veth peer name veth0_p
ip link add name veth1 type veth peer name veth1_p
ip link add name veth2 type veth peer name veth2_p
# create bond
if [[ "$monitor" == "miimon" ]];then
ip link add name bond0 type bond mode $mode miimon 100 primary veth1 primary_reselect $primary_reselect
elif [[ "$monitor" == "arp_ip_target" ]];then
ip link add name bond0 type bond mode $mode arp_interval 1000 arp_ip_target $peer_ip4 primary veth1 primary_reselect $primary_reselect
elif [[ "$monitor" == "ns_ip6_target" ]];then
ip link add name bond0 type bond mode $mode arp_interval 1000 ns_ip6_target $peer_ip6 primary veth1 primary_reselect $primary_reselect
fi
ip link set bond0 up
ip link set veth0 master bond0
ip link set veth1 master bond0
ip link set veth2 master bond0
# check bonding member prio value
ip link set dev veth0 type bond_slave prio 0
ip link set dev veth1 type bond_slave prio 10
ip link set dev veth2 type bond_slave prio 11
ip -d link show veth0 | grep -q 'prio 0'
check_err $? "veth0 prio is not 0"
ip -d link show veth1 | grep -q 'prio 10'
check_err $? "veth0 prio is not 10"
ip -d link show veth2 | grep -q 'prio 11'
check_err $? "veth0 prio is not 11"
ip link set veth0 up
ip link set veth1 up
ip link set veth2 up
ip link set veth0_p up
ip link set veth1_p up
ip link set veth2_p up
# prepare ping target
ip link add name br0 type bridge
ip link set br0 up
ip link set veth0_p master br0
ip link set veth1_p master br0
ip link set veth2_p master br0
ip link add name veth3 type veth peer name veth3_p
ip netns add ns1
ip link set veth3_p master br0 up
ip link set veth3 netns ns1 up
ip netns exec ns1 ip addr add $peer_ip4/24 dev veth3
ip netns exec ns1 ip addr add $peer_ip6/64 dev veth3
ip addr add $bond_ip4/24 dev bond0
ip addr add $bond_ip6/64 dev bond0
sleep 5
ping $peer_ip4 -c5 -I bond0 &>/dev/null
check_err $? "ping failed 1."
ping6 $peer_ip6 -c5 -I bond0 &>/dev/null
check_err $? "ping6 failed 1."
# active salve should be the primary slave
check_active_slave veth1
# active slave should be the higher prio slave
ip link set $active_slave down
ping $peer_ip4 -c5 -I bond0 &>/dev/null
check_err $? "ping failed 2."
check_active_slave veth2
# when only 1 slave is up
ip link set $active_slave down
ping $peer_ip4 -c5 -I bond0 &>/dev/null
check_err $? "ping failed 3."
check_active_slave veth0
# when a higher prio slave change to up
ip link set veth2 up
ping $peer_ip4 -c5 -I bond0 &>/dev/null
check_err $? "ping failed 4."
case $primary_reselect in
"0")
check_active_slave "veth2"
;;
"1")
check_active_slave "veth0"
;;
"2")
check_active_slave "veth0"
;;
esac
local pre_active_slave=$active_slave
# when the primary slave change to up
ip link set veth1 up
ping $peer_ip4 -c5 -I bond0 &>/dev/null
check_err $? "ping failed 5."
case $primary_reselect in
"0")
check_active_slave "veth1"
;;
"1")
check_active_slave "$pre_active_slave"
;;
"2")
check_active_slave "$pre_active_slave"
ip link set $active_slave down
ping $peer_ip4 -c5 -I bond0 &>/dev/null
check_err $? "ping failed 6."
check_active_slave "veth1"
;;
esac
# Test changing bond salve prio
if [[ "$primary_reselect" == "0" ]];then
ip link set dev veth0 type bond_slave prio 1000000
ip link set dev veth1 type bond_slave prio 0
ip link set dev veth2 type bond_slave prio -50
ip -d link show veth0 | grep -q 'prio 1000000'
check_err $? "veth0 prio is not 1000000"
ip -d link show veth1 | grep -q 'prio 0'
check_err $? "veth1 prio is not 0"
ip -d link show veth2 | grep -q 'prio -50'
check_err $? "veth3 prio is not -50"
check_active_slave "veth1"
ip link set $active_slave down
ping $peer_ip4 -c5 -I bond0 &>/dev/null
check_err $? "ping failed 7."
check_active_slave "veth0"
fi
cleanup
log_test "prio_test" "Test bonding option 'prio' with mode=$mode monitor=$monitor and primary_reselect=$primary_reselect"
}
prio_miimon_test()
{
local mode
local primary_reselect
for mode in 1 5 6; do
for primary_reselect in 0 1 2; do
prio_test "miimon" $mode $primary_reselect
done
done
}
prio_arp_ip_target_test()
{
local primary_reselect
for primary_reselect in 0 1 2; do
prio_test "arp_ip_target" 1 $primary_reselect
done
}
if skip;then
log_test_skip "option_prio.sh" "Current iproute doesn't support 'prio'."
exit 0
fi
trap cleanup EXIT
tests_run
exit "$EXIT_STATUS"
|