Path: blob/master/tools/testing/selftests/drivers/net/team/decoupled_enablement.sh
171056 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.023# These tests verify the decoupled RX and TX enablement of team driver member4# interfaces.5#6# Topology7#8# +---------------------+ NS19# | test_team1 |10# | | |11# | eth0 |12# | | |13# | | |14# +---------------------+15# |16# +---------------------+ NS217# | | |18# | | |19# | eth0 |20# | | |21# | test_team2 |22# +---------------------+2324export ALL_TESTS="25team_test_tx_enablement26team_test_rx_enablement27"2829test_dir="$(dirname "$0")"30# shellcheck disable=SC109131source "${test_dir}/../../../net/lib.sh"32# shellcheck disable=SC109133source "${test_dir}/team_lib.sh"3435NS1=""36NS2=""37export NODAD="nodad"38PREFIX_LENGTH="64"39NS1_IP="fd00::1"40NS2_IP="fd00::2"41NS1_IP4="192.168.0.1"42NS2_IP4="192.168.0.2"43MEMBERS=("eth0")44PING_COUNT=545PING_TIMEOUT_S=146PING_INTERVAL=0.14748while getopts "4" opt; do49case $opt in504)51echo "IPv4 mode selected."52export NODAD=53PREFIX_LENGTH="24"54NS1_IP="${NS1_IP4}"55NS2_IP="${NS2_IP4}"56;;57\?)58echo "Invalid option: -$OPTARG" >&259exit 160;;61esac62done6364# This has to be sourced after opts are gathered...65export REQUIRE_MZ=no66export NUM_NETIFS=067# shellcheck disable=SC109168source "${test_dir}/../../../net/forwarding/lib.sh"6970# Create the network namespaces, veth pair, and team devices in the specified71# mode.72# Globals:73# RET - Used by test infra, set by `check_err` functions.74# Arguments:75# mode - The team driver mode to use for the team devices.76environment_create()77{78trap cleanup_all_ns EXIT79setup_ns ns1 ns280NS1="${NS_LIST[0]}"81NS2="${NS_LIST[1]}"8283# Create the interfaces.84ip -n "${NS1}" link add eth0 type veth peer name eth0 netns "${NS2}"85ip -n "${NS1}" link add test_team1 type team86ip -n "${NS2}" link add test_team2 type team8788# Set up the receiving network namespace's team interface.89setup_team "${NS2}" test_team2 roundrobin "${NS2_IP}" \90"${PREFIX_LENGTH}" "${MEMBERS[@]}"91}9293# Set a particular option value for team or team port.94# Arguments:95# namespace - The namespace name that has the team.96# option_name - The option name to set.97# option_value - The value to set the option to.98# team_name - The name of team to set the option for.99# member_name - The (optional) optional name of the member port.100set_option_value()101{102local namespace="$1"103local option_name="$2"104local option_value="$3"105local team_name="$4"106local member_name="$5"107local port_flag="--port=${member_name}"108109ip netns exec "${namespace}" teamnl "${team_name}" setoption \110"${option_name}" "${option_value}" "${port_flag}"111return $?112}113114# Send some pings and return the ping command return value.115try_ping()116{117ip netns exec "${NS1}" ping -i "${PING_INTERVAL}" -c "${PING_COUNT}" \118"${NS2_IP}" -W "${PING_TIMEOUT_S}"119}120121# Checks tcpdump output from net/forwarding lib, and checks if there are any122# ICMP(4 or 6) packets.123# Arguments:124# interface - The interface name to search for.125# ip_address - The destination IP address (4 or 6) to search for.126did_interface_receive_icmp()127{128local interface="$1"129local ip_address="$2"130local packet_count131132packet_count=$(tcpdump_show "$interface" | grep -c \133"> ${ip_address}: ICMP")134echo "Packet count for ${interface} was ${packet_count}"135136if [[ "$packet_count" -gt 0 ]]; then137true138else139false140fi141}142143# Test JUST tx enablement with a given mode.144# Globals:145# RET - Used by test infra, set by `check_err` functions.146# Arguments:147# mode - The mode to set the team interfaces to.148team_test_mode_tx_enablement()149{150local mode="$1"151export RET=0152153# Set up the sender team with the correct mode.154setup_team "${NS1}" test_team1 "${mode}" "${NS1_IP}" \155"${PREFIX_LENGTH}" "${MEMBERS[@]}"156check_err $? "Failed to set up sender team"157158### Scenario 1: Member interface initially enabled.159# Expect ping to pass160try_ping161check_err $? "Ping failed when TX enabled"162163### Scenario 2: One tx-side interface disabled.164# Expect ping to fail.165set_option_value "${NS1}" tx_enabled false test_team1 eth0166check_err $? "Failed to disable TX"167tcpdump_start eth0 "${NS2}"168try_ping169check_fail $? "Ping succeeded when TX disabled"170tcpdump_stop eth0171# Expect no packets to be transmitted, since TX is disabled.172did_interface_receive_icmp eth0 "${NS2_IP}"173check_fail $? "eth0 IS transmitting when TX disabled"174tcpdump_cleanup eth0175176### Scenario 3: The interface has tx re-enabled.177# Expect ping to pass.178set_option_value "${NS1}" tx_enabled true test_team1 eth0179check_err $? "Failed to reenable TX"180try_ping181check_err $? "Ping failed when TX reenabled"182183log_test "TX failover of '${mode}' test"184}185186# Test JUST rx enablement with a given mode.187# Globals:188# RET - Used by test infra, set by `check_err` functions.189# Arguments:190# mode - The mode to set the team interfaces to.191team_test_mode_rx_enablement()192{193local mode="$1"194export RET=0195196# Set up the sender team with the correct mode.197setup_team "${NS1}" test_team1 "${mode}" "${NS1_IP}" \198"${PREFIX_LENGTH}" "${MEMBERS[@]}"199check_err $? "Failed to set up sender team"200201### Scenario 1: Member interface initially enabled.202# Expect ping to pass203try_ping204check_err $? "Ping failed when RX enabled"205206### Scenario 2: One rx-side interface disabled.207# Expect ping to fail.208set_option_value "${NS1}" rx_enabled false test_team1 eth0209check_err $? "Failed to disable RX"210tcpdump_start eth0 "${NS2}"211try_ping212check_fail $? "Ping succeeded when RX disabled"213tcpdump_stop eth0214# Expect packets to be transmitted, since only RX is disabled.215did_interface_receive_icmp eth0 "${NS2_IP}"216check_err $? "eth0 not transmitting when RX disabled"217tcpdump_cleanup eth0218219### Scenario 3: The interface has rx re-enabled.220# Expect ping to pass.221set_option_value "${NS1}" rx_enabled true test_team1 eth0222check_err $? "Failed to reenable RX"223try_ping224check_err $? "Ping failed when RX reenabled"225226log_test "RX failover of '${mode}' test"227}228229team_test_tx_enablement()230{231team_test_mode_tx_enablement broadcast232team_test_mode_tx_enablement roundrobin233team_test_mode_tx_enablement random234}235236team_test_rx_enablement()237{238team_test_mode_rx_enablement broadcast239team_test_mode_rx_enablement roundrobin240team_test_mode_rx_enablement random241}242243require_command teamnl244require_command tcpdump245require_command ping246environment_create247tests_run248exit "${EXIT_STATUS}"249250251