File Index
Files and directories
Sign in
FILE

bond_passive_lacp.sh

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh BASH
  1#!/bin/bash
  2# SPDX-License-Identifier: GPL-2.0
  3#
  4# Test if a bond interface works with lacp_active=off.
  5
  6# shellcheck disable=SC2034
  7REQUIRE_MZ=no
  8NUM_NETIFS=0
  9lib_dir=$(dirname "$0")
 10# shellcheck disable=SC1091
 11source "$lib_dir"/../../../net/forwarding/lib.sh
 12
 13# shellcheck disable=SC2317
 14check_port_state()
 15{
 16	local netns=$1
 17	local port=$2
 18	local state=$3
 19
 20	ip -n "${netns}" -d -j link show "$port" | \
 21		jq -e ".[].linkinfo.info_slave_data.ad_actor_oper_port_state_str | index(\"${state}\") != null" > /dev/null
 22}
 23
 24check_pkt_count()
 25{
 26	RET=0
 27	local ns="$1"
 28	local iface="$2"
 29
 30	# wait 65s, one per 30s
 31	slowwait_for_counter 65 2 tc_rule_handle_stats_get \
 32		"dev ${iface} egress" 101 ".packets" "-n ${ns}" &> /dev/null
 33}
 34
 35setup() {
 36	setup_ns c_ns s_ns
 37
 38	# shellcheck disable=SC2154
 39	ip -n "${c_ns}" link add eth0 type veth peer name eth0 netns "${s_ns}"
 40	ip -n "${c_ns}" link add eth1 type veth peer name eth1 netns "${s_ns}"
 41
 42	# Add tc filter to count the pkts
 43	tc -n "${c_ns}" qdisc add dev eth0 clsact
 44	tc -n "${c_ns}" filter add dev eth0 egress handle 101 protocol 0x8809 matchall action pass
 45	tc -n "${s_ns}" qdisc add dev eth1 clsact
 46	tc -n "${s_ns}" filter add dev eth1 egress handle 101 protocol 0x8809 matchall action pass
 47
 48	ip -n "${s_ns}" link add bond0 type bond mode 802.3ad lacp_active on lacp_rate fast
 49	ip -n "${s_ns}" link set eth0 master bond0
 50	ip -n "${s_ns}" link set eth1 master bond0
 51
 52	ip -n "${c_ns}" link add bond0 type bond mode 802.3ad lacp_active off lacp_rate fast
 53	ip -n "${c_ns}" link set eth0 master bond0
 54	ip -n "${c_ns}" link set eth1 master bond0
 55
 56}
 57
 58trap cleanup_all_ns EXIT
 59setup
 60
 61# The bond will send 2 lacpdu pkts during init time, let's wait at least 2s
 62# after interface up
 63ip -n "${c_ns}" link set bond0 up
 64sleep 2
 65
 66# 1. The passive side shouldn't send LACPDU.
 67check_pkt_count "${c_ns}" "eth0" && RET=1
 68log_test "802.3ad lacp_active off" "init port"
 69
 70ip -n "${s_ns}" link set bond0 up
 71# 2. The passive side should not have the 'active' flag.
 72RET=0
 73slowwait 2 check_port_state "${c_ns}" "eth0" "active" && RET=1
 74log_test "802.3ad lacp_active off" "port state active"
 75
 76# 3. The active side should have the 'active' flag.
 77RET=0
 78slowwait 2 check_port_state "${s_ns}" "eth0" "active" || RET=1
 79log_test "802.3ad lacp_active on" "port state active"
 80
 81# 4. Make sure the connection is not expired.
 82RET=0
 83slowwait 5 check_port_state "${s_ns}" "eth0" "distributing"
 84slowwait 10 check_port_state "${s_ns}" "eth0" "expired" && RET=1
 85log_test "bond 802.3ad lacp_active off" "port connection"
 86
 87# After testing, disconnect one port on each side to check the state.
 88ip -n "${s_ns}" link set eth0 nomaster
 89ip -n "${s_ns}" link set eth0 up
 90ip -n "${c_ns}" link set eth1 nomaster
 91ip -n "${c_ns}" link set eth1 up
 92# Due to Periodic Machine and Rx Machine state change, the bond will still
 93# send lacpdu pkts in a few seconds. sleep at lease 5s to make sure
 94# negotiation finished
 95sleep 5
 96
 97# 5. The active side should keep sending LACPDU.
 98check_pkt_count "${s_ns}" "eth1" || RET=1
 99log_test "bond 802.3ad lacp_active on" "port pkt after disconnect"
100
101# 6. The passive side shouldn't send LACPDU anymore.
102check_pkt_count "${c_ns}" "eth0" && RET=1
103log_test "bond 802.3ad lacp_active off" "port pkt after disconnect"
104
105exit "$EXIT_STATUS"
~/ Read-only file preview.