|
| 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 |
| 7 | +REQUIRE_MZ=no |
| 8 | +NUM_NETIFS=0 |
| 9 | +lib_dir=$(dirname "$0") |
| 10 | +# shellcheck disable=SC1091 |
| 11 | +source "$lib_dir"/../../../net/forwarding/lib.sh |
| 12 | + |
| 13 | +# shellcheck disable=SC2317 |
| 14 | +check_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 | + |
| 24 | +check_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 | + |
| 35 | +setup() { |
| 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 | + |
| 58 | +trap cleanup_all_ns EXIT |
| 59 | +setup |
| 60 | + |
| 61 | +# The bond will send 2 lacpdu pkts during init time, let's wait at least 2s |
| 62 | +# after interface up |
| 63 | +ip -n "${c_ns}" link set bond0 up |
| 64 | +sleep 2 |
| 65 | + |
| 66 | +# 1. The passive side shouldn't send LACPDU. |
| 67 | +check_pkt_count "${c_ns}" "eth0" && RET=1 |
| 68 | +log_test "802.3ad lacp_active off" "init port" |
| 69 | + |
| 70 | +ip -n "${s_ns}" link set bond0 up |
| 71 | +# 2. The passive side should not have the 'active' flag. |
| 72 | +RET=0 |
| 73 | +slowwait 2 check_port_state "${c_ns}" "eth0" "active" && RET=1 |
| 74 | +log_test "802.3ad lacp_active off" "port state active" |
| 75 | + |
| 76 | +# 3. The active side should have the 'active' flag. |
| 77 | +RET=0 |
| 78 | +slowwait 2 check_port_state "${s_ns}" "eth0" "active" || RET=1 |
| 79 | +log_test "802.3ad lacp_active on" "port state active" |
| 80 | + |
| 81 | +# 4. Make sure the connection is not expired. |
| 82 | +RET=0 |
| 83 | +slowwait 5 check_port_state "${s_ns}" "eth0" "distributing" |
| 84 | +slowwait 10 check_port_state "${s_ns}" "eth0" "expired" && RET=1 |
| 85 | +log_test "bond 802.3ad lacp_active off" "port connection" |
| 86 | + |
| 87 | +# After testing, disconnect one port on each side to check the state. |
| 88 | +ip -n "${s_ns}" link set eth0 nomaster |
| 89 | +ip -n "${s_ns}" link set eth0 up |
| 90 | +ip -n "${c_ns}" link set eth1 nomaster |
| 91 | +ip -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 |
| 95 | +sleep 5 |
| 96 | + |
| 97 | +# 5. The active side should keep sending LACPDU. |
| 98 | +check_pkt_count "${s_ns}" "eth1" || RET=1 |
| 99 | +log_test "bond 802.3ad lacp_active on" "port pkt after disconnect" |
| 100 | + |
| 101 | +# 6. The passive side shouldn't send LACPDU anymore. |
| 102 | +check_pkt_count "${c_ns}" "eth0" && RET=1 |
| 103 | +log_test "bond 802.3ad lacp_active off" "port pkt after disconnect" |
| 104 | + |
| 105 | +exit "$EXIT_STATUS" |
0 commit comments