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