Test that with coupled control disabled, a port only advertises the Collecting bit after a notification about its Rx state change was emitted. Use a slow LACP rate on the partner so that the port only transmits periodic LACPDUs every 30 seconds and is therefore not rate limited when entering COLLECTING state. Output without "bonding: 3ad: Advertise Collecting only after collection is enabled": # ./bond_lacp_independent_control.sh TEST: Receive in COLLECTING state [ OK ] TEST: Notifications in COLLECTING state [ OK ] TEST: Collecting advertised after notification [FAIL] Collecting bit advertised before notification TEST: Ping in DISTRIBUTING state [ OK ] Output with the fix: # ./bond_lacp_independent_control.sh TEST: Receive in COLLECTING state [ OK ] TEST: Notifications in COLLECTING state [ OK ] TEST: Collecting advertised after notification [ OK ] TEST: Ping in DISTRIBUTING state [ OK ] Reviewed-by: Petr Machata Signed-off-by: Ido Schimmel --- Notes: The test compares a user space timestamp (ip monitor) with a kernel timestamp (tcpdump). This cannot hide a bug since a delay in ip can only make the notification appear later. A false failure requires ip to stall for longer than the gap between the notification and the LACPDU, which is at least one state machine tick (100 ms). Did not observe such a failure with normal or debug kernels. .../bonding/bond_lacp_independent_control.sh | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/net/bonding/bond_lacp_independent_control.sh b/tools/testing/selftests/drivers/net/bonding/bond_lacp_independent_control.sh index a2b83b581e40..b86f39f31d0c 100755 --- a/tools/testing/selftests/drivers/net/bonding/bond_lacp_independent_control.sh +++ b/tools/testing/selftests/drivers/net/bonding/bond_lacp_independent_control.sh @@ -4,7 +4,7 @@ # +-------------------------+ +-------------------------+ # | H1 (vrf) | | H2 (vrf) | # | + bond1 (802.3ad) | | + bond2 (802.3ad) | -# | | coupled_control off | | | | +# | | coupled_control off | | | lacp_rate slow | # | | 192.0.2.1/28 | | | 192.0.2.2/28 | # | | | | | | # | + $h1 | | + $h2 | @@ -16,6 +16,7 @@ ALL_TESTS=" collecting collecting_notify + collecting_advertise distributing " NUM_NETIFS=2 @@ -24,6 +25,8 @@ lib_dir=$(dirname "$0") # shellcheck disable=SC1091 source "$lib_dir"/../../../net/forwarding/lib.sh +require_command tcpdump + lacp_state_get() { local dev=$1; shift @@ -75,7 +78,9 @@ h1_create() h2_create() { - adf_ip_link_add bond2 type bond mode 802.3ad lacp_rate fast + # Slow rate makes $h1 transmit periodic LACPDUs every 30 seconds, so + # that it is not rate limited when entering COLLECTING state. + adf_ip_link_add bond2 type bond mode 802.3ad lacp_rate slow adf_ip_link_set_master "$h2" bond2 adf_simple_if_init bond2 192.0.2.2/28 } @@ -162,6 +167,50 @@ collecting_notify() log_test "Notifications in COLLECTING state" } +collecting_advertise() +{ + local lacpdu_ts notify_ts tmp_dir + + RET=0 + + partner_state_clear 0x18 + defer tc filter del dev "$h1" ingress pref 1 handle 101 flower + lacp_state_wait "$h1" 0x0f + check_err $? "Port did not reach ATTACHED state" + + tmp_dir=$(mktemp -d) + defer rm -rf "$tmp_dir" + ip -ts -o -d monitor link dev "$h1" > "$tmp_dir"/notify & + defer kill_process $! + # Capture transmitted LACPDUs with the Collecting (0x10) bit set in + # the actor state. + tcpdump -tt -n -l -p -Q out -i "$h1" \ + "ether proto 0x8809 and ether[32] & 0x10 != 0" \ + > "$tmp_dir"/lacpdu 2> /dev/null & + defer kill_process $! + sleep 1 + + partner_state_clear 0x10 + lacp_state_wait "$h1" 0x1f + check_err $? "Port did not reach COLLECTING state" + + slowwait "$WAIT_TIMEOUT" grep -qw \ + "ad_actor_oper_port_state $((0x1f))" "$tmp_dir"/notify + check_err $? "No notification upon entering COLLECTING state" + + slowwait "$WAIT_TIMEOUT" grep -q . "$tmp_dir"/lacpdu + check_err $? "Collecting bit not advertised" + + notify_ts=$(grep -m1 -w "ad_actor_oper_port_state $((0x1f))" \ + "$tmp_dir"/notify | sed 's/^\[\([^]]*\)\].*/\1/') + notify_ts=$(date -d "$notify_ts" +%s%6N) + lacpdu_ts=$(head -n1 "$tmp_dir"/lacpdu | cut -d' ' -f1 | tr -d .) + ((lacpdu_ts > notify_ts)) + check_err $? "Collecting bit advertised before notification" + + log_test "Collecting advertised after notification" +} + distributing() { RET=0 -- 2.56.0