Path: blob/master/tools/testing/selftests/drivers/net/team/transmit_failover.sh
171056 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.023# These tests verify the basic failover capability of the team driver via the4# `enabled` team driver option across different team driver modes. This does not5# rely on teamd, and instead just uses teamnl to set the `enabled` option6# directly.7#8# Topology:9#10# +-------------------------+ NS111# | test_team1 |12# | + |13# | eth0 | eth1 |14# | +---+---+ |15# | | | |16# +-------------------------+17# | |18# +-------------------------+ NS219# | | | |20# | +-------+ |21# | eth0 | eth1 |22# | + |23# | test_team2 |24# +-------------------------+2526export ALL_TESTS="team_test_failover"2728test_dir="$(dirname "$0")"29# shellcheck disable=SC109130source "${test_dir}/../../../net/lib.sh"31# shellcheck disable=SC109132source "${test_dir}/team_lib.sh"3334NS1=""35NS2=""36export NODAD="nodad"37PREFIX_LENGTH="64"38NS1_IP="fd00::1"39NS2_IP="fd00::2"40NS1_IP4="192.168.0.1"41NS2_IP4="192.168.0.2"42MEMBERS=("eth0" "eth1")4344while getopts "4" opt; do45case $opt in464)47echo "IPv4 mode selected."48export NODAD=49PREFIX_LENGTH="24"50NS1_IP="${NS1_IP4}"51NS2_IP="${NS2_IP4}"52;;53\?)54echo "Invalid option: -$OPTARG" >&255exit 156;;57esac58done5960# Create the network namespaces, veth pair, and team devices in the specified61# mode.62# Globals:63# RET - Used by test infra, set by `check_err` functions.64# Arguments:65# mode - The team driver mode to use for the team devices.66environment_create()67{68trap cleanup_all_ns EXIT69setup_ns ns1 ns270NS1="${NS_LIST[0]}"71NS2="${NS_LIST[1]}"7273# Create the interfaces.74ip -n "${NS1}" link add eth0 type veth peer name eth0 netns "${NS2}"75ip -n "${NS1}" link add eth1 type veth peer name eth1 netns "${NS2}"76ip -n "${NS1}" link add test_team1 type team77ip -n "${NS2}" link add test_team2 type team7879# Set up the receiving network namespace's team interface.80setup_team "${NS2}" test_team2 roundrobin "${NS2_IP}" \81"${PREFIX_LENGTH}" "${MEMBERS[@]}"82}838485# Check that failover works for a specific team driver mode.86# Globals:87# RET - Used by test infra, set by `check_err` functions.88# Arguments:89# mode - The mode to set the team interfaces to.90team_test_mode_failover()91{92local mode="$1"93export RET=09495# Set up the sender team with the correct mode.96setup_team "${NS1}" test_team1 "${mode}" "${NS1_IP}" \97"${PREFIX_LENGTH}" "${MEMBERS[@]}"98check_err $? "Failed to set up sender team"99100start_listening_and_sending101102### Scenario 1: All interfaces initially enabled.103save_tcpdump_outputs "${NS2}" "${MEMBERS[@]}"104did_interface_receive eth0 "${NS2_IP}"105check_err $? "eth0 not transmitting when both links enabled"106did_interface_receive eth1 "${NS2_IP}"107check_err $? "eth1 not transmitting when both links enabled"108clear_tcpdump_outputs "${MEMBERS[@]}"109110### Scenario 2: One tx-side interface disabled.111ip netns exec "${NS1}" teamnl test_team1 setoption enabled false \112--port=eth1113slowwait 2 bash -c "ip netns exec ${NS1} teamnl test_team1 getoption \114enabled --port=eth1 | grep -q false"115116save_tcpdump_outputs "${NS2}" "${MEMBERS[@]}"117did_interface_receive eth0 "${NS2_IP}"118check_err $? "eth0 not transmitting when enabled"119did_interface_receive eth1 "${NS2_IP}"120check_fail $? "eth1 IS transmitting when disabled"121clear_tcpdump_outputs "${MEMBERS[@]}"122123### Scenario 3: The interface is re-enabled.124ip netns exec "${NS1}" teamnl test_team1 setoption enabled true \125--port=eth1126slowwait 2 bash -c "ip netns exec ${NS1} teamnl test_team1 getoption \127enabled --port=eth1 | grep -q true"128129save_tcpdump_outputs "${NS2}" "${MEMBERS[@]}"130did_interface_receive eth0 "${NS2_IP}"131check_err $? "eth0 not transmitting when both links enabled"132did_interface_receive eth1 "${NS2_IP}"133check_err $? "eth1 not transmitting when both links enabled"134clear_tcpdump_outputs "${MEMBERS[@]}"135136log_test "Failover of '${mode}' test"137138# Clean up139stop_sending_and_listening140}141142team_test_failover()143{144team_test_mode_failover broadcast145team_test_mode_failover roundrobin146team_test_mode_failover random147# Don't test `activebackup` or `loadbalance` modes, since they are too148# complicated for just setting `enabled` to work. They use more than149# the `enabled` option for transmit.150}151152require_command teamnl153require_command iperf3154require_command tcpdump155environment_create156tests_run157exit "${EXIT_STATUS}"158159160