Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/testing/selftests/drivers/net/team/transmit_failover.sh
171056 views
1
#!/bin/bash
2
# SPDX-License-Identifier: GPL-2.0
3
4
# These tests verify the basic failover capability of the team driver via the
5
# `enabled` team driver option across different team driver modes. This does not
6
# rely on teamd, and instead just uses teamnl to set the `enabled` option
7
# directly.
8
#
9
# Topology:
10
#
11
# +-------------------------+ NS1
12
# | test_team1 |
13
# | + |
14
# | eth0 | eth1 |
15
# | +---+---+ |
16
# | | | |
17
# +-------------------------+
18
# | |
19
# +-------------------------+ NS2
20
# | | | |
21
# | +-------+ |
22
# | eth0 | eth1 |
23
# | + |
24
# | test_team2 |
25
# +-------------------------+
26
27
export ALL_TESTS="team_test_failover"
28
29
test_dir="$(dirname "$0")"
30
# shellcheck disable=SC1091
31
source "${test_dir}/../../../net/lib.sh"
32
# shellcheck disable=SC1091
33
source "${test_dir}/team_lib.sh"
34
35
NS1=""
36
NS2=""
37
export NODAD="nodad"
38
PREFIX_LENGTH="64"
39
NS1_IP="fd00::1"
40
NS2_IP="fd00::2"
41
NS1_IP4="192.168.0.1"
42
NS2_IP4="192.168.0.2"
43
MEMBERS=("eth0" "eth1")
44
45
while getopts "4" opt; do
46
case $opt in
47
4)
48
echo "IPv4 mode selected."
49
export NODAD=
50
PREFIX_LENGTH="24"
51
NS1_IP="${NS1_IP4}"
52
NS2_IP="${NS2_IP4}"
53
;;
54
\?)
55
echo "Invalid option: -$OPTARG" >&2
56
exit 1
57
;;
58
esac
59
done
60
61
# Create the network namespaces, veth pair, and team devices in the specified
62
# mode.
63
# Globals:
64
# RET - Used by test infra, set by `check_err` functions.
65
# Arguments:
66
# mode - The team driver mode to use for the team devices.
67
environment_create()
68
{
69
trap cleanup_all_ns EXIT
70
setup_ns ns1 ns2
71
NS1="${NS_LIST[0]}"
72
NS2="${NS_LIST[1]}"
73
74
# Create the interfaces.
75
ip -n "${NS1}" link add eth0 type veth peer name eth0 netns "${NS2}"
76
ip -n "${NS1}" link add eth1 type veth peer name eth1 netns "${NS2}"
77
ip -n "${NS1}" link add test_team1 type team
78
ip -n "${NS2}" link add test_team2 type team
79
80
# Set up the receiving network namespace's team interface.
81
setup_team "${NS2}" test_team2 roundrobin "${NS2_IP}" \
82
"${PREFIX_LENGTH}" "${MEMBERS[@]}"
83
}
84
85
86
# Check that failover works for a specific team driver mode.
87
# Globals:
88
# RET - Used by test infra, set by `check_err` functions.
89
# Arguments:
90
# mode - The mode to set the team interfaces to.
91
team_test_mode_failover()
92
{
93
local mode="$1"
94
export RET=0
95
96
# Set up the sender team with the correct mode.
97
setup_team "${NS1}" test_team1 "${mode}" "${NS1_IP}" \
98
"${PREFIX_LENGTH}" "${MEMBERS[@]}"
99
check_err $? "Failed to set up sender team"
100
101
start_listening_and_sending
102
103
### Scenario 1: All interfaces initially enabled.
104
save_tcpdump_outputs "${NS2}" "${MEMBERS[@]}"
105
did_interface_receive eth0 "${NS2_IP}"
106
check_err $? "eth0 not transmitting when both links enabled"
107
did_interface_receive eth1 "${NS2_IP}"
108
check_err $? "eth1 not transmitting when both links enabled"
109
clear_tcpdump_outputs "${MEMBERS[@]}"
110
111
### Scenario 2: One tx-side interface disabled.
112
ip netns exec "${NS1}" teamnl test_team1 setoption enabled false \
113
--port=eth1
114
slowwait 2 bash -c "ip netns exec ${NS1} teamnl test_team1 getoption \
115
enabled --port=eth1 | grep -q false"
116
117
save_tcpdump_outputs "${NS2}" "${MEMBERS[@]}"
118
did_interface_receive eth0 "${NS2_IP}"
119
check_err $? "eth0 not transmitting when enabled"
120
did_interface_receive eth1 "${NS2_IP}"
121
check_fail $? "eth1 IS transmitting when disabled"
122
clear_tcpdump_outputs "${MEMBERS[@]}"
123
124
### Scenario 3: The interface is re-enabled.
125
ip netns exec "${NS1}" teamnl test_team1 setoption enabled true \
126
--port=eth1
127
slowwait 2 bash -c "ip netns exec ${NS1} teamnl test_team1 getoption \
128
enabled --port=eth1 | grep -q true"
129
130
save_tcpdump_outputs "${NS2}" "${MEMBERS[@]}"
131
did_interface_receive eth0 "${NS2_IP}"
132
check_err $? "eth0 not transmitting when both links enabled"
133
did_interface_receive eth1 "${NS2_IP}"
134
check_err $? "eth1 not transmitting when both links enabled"
135
clear_tcpdump_outputs "${MEMBERS[@]}"
136
137
log_test "Failover of '${mode}' test"
138
139
# Clean up
140
stop_sending_and_listening
141
}
142
143
team_test_failover()
144
{
145
team_test_mode_failover broadcast
146
team_test_mode_failover roundrobin
147
team_test_mode_failover random
148
# Don't test `activebackup` or `loadbalance` modes, since they are too
149
# complicated for just setting `enabled` to work. They use more than
150
# the `enabled` option for transmit.
151
}
152
153
require_command teamnl
154
require_command iperf3
155
require_command tcpdump
156
environment_create
157
tests_run
158
exit "${EXIT_STATUS}"
159
160