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