File Index
Files and directories
Sign in
FILE

bridge_activity_notify.sh

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/net/forwarding/bridge_activity_notify.sh BASH
  1#!/bin/bash
  2# SPDX-License-Identifier: GPL-2.0
  3
  4# +-----------------------+                          +------------------------+
  5# | H1 (vrf)              |                          | H2 (vrf)               |
  6# | 192.0.2.1/28          |                          | 192.0.2.2/28           |
  7# |    + $h1              |                          |    + $h2               |
  8# +----|------------------+                          +----|-------------------+
  9#      |                                                  |
 10# +----|--------------------------------------------------|-------------------+
 11# | SW |                                                  |                   |
 12# | +--|--------------------------------------------------|-----------------+ |
 13# | |  + $swp1                   BR1 (802.1d)             + $swp2           | |
 14# | |                                                                       | |
 15# | +-----------------------------------------------------------------------+ |
 16# +---------------------------------------------------------------------------+
 17
 18ALL_TESTS="
 19	new_inactive_test
 20	existing_active_test
 21	norefresh_test
 22"
 23
 24NUM_NETIFS=4
 25source lib.sh
 26
 27h1_create()
 28{
 29	adf_simple_if_init "$h1" 192.0.2.1/28
 30}
 31
 32h2_create()
 33{
 34	adf_simple_if_init "$h2" 192.0.2.2/28
 35}
 36
 37switch_create()
 38{
 39	adf_ip_link_add br1 type bridge vlan_filtering 0 mcast_snooping 0 \
 40		ageing_time "$LOW_AGEING_TIME"
 41	adf_ip_link_set_up br1
 42
 43	adf_ip_link_set_master "$swp1" br1
 44	adf_ip_link_set_up "$swp1"
 45
 46	adf_ip_link_set_master "$swp2" br1
 47	adf_ip_link_set_up "$swp2"
 48}
 49
 50setup_prepare()
 51{
 52	h1=${NETIFS[p1]}
 53	swp1=${NETIFS[p2]}
 54
 55	swp2=${NETIFS[p3]}
 56	h2=${NETIFS[p4]}
 57
 58	adf_vrf_prepare
 59
 60	h1_create
 61	h2_create
 62	switch_create
 63}
 64
 65fdb_active_wait()
 66{
 67	local mac=$1; shift
 68
 69	bridge -d fdb get "$mac" br br1 | grep -q -v "inactive"
 70}
 71
 72fdb_inactive_wait()
 73{
 74	local mac=$1; shift
 75
 76	bridge -d fdb get "$mac" br br1 | grep -q "inactive"
 77}
 78
 79new_inactive_test()
 80{
 81	local mac="00:11:22:33:44:55"
 82
 83	# Add a new FDB entry as static and inactive and check that it
 84	# becomes active upon traffic.
 85	RET=0
 86
 87	bridge fdb add "$mac" dev "$swp1" master static activity_notify inactive
 88	bridge -d fdb get "$mac" br br1 | grep -q "inactive"
 89	check_err $? "FDB entry not present as \"inactive\" when should"
 90
 91	$MZ "$h1" -c 1 -p 64 -a "$mac" -b bcast -t ip -q
 92
 93	busywait "$BUSYWAIT_TIMEOUT" fdb_active_wait "$mac"
 94	check_err $? "FDB entry present as \"inactive\" when should not"
 95
 96	log_test "Transition from inactive to active"
 97
 98	bridge fdb del "$mac" dev "$swp1" master
 99}
100
101existing_active_test()
102{
103	local mac="00:11:22:33:44:55"
104	local ageing_time
105
106	# Enable activity notifications on an existing dynamic FDB entry and
107	# check that it becomes inactive after the ageing time passed.
108	RET=0
109
110	bridge fdb add "$mac" dev "$swp1" master dynamic
111	bridge fdb replace "$mac" dev "$swp1" master static activity_notify norefresh
112
113	bridge -d fdb get "$mac" br br1 | grep -q "activity_notify"
114	check_err $? "FDB entry not present as \"activity_notify\" when should"
115
116	bridge -d fdb get "$mac" br br1 | grep -q "inactive"
117	check_fail $? "FDB entry present as \"inactive\" when should not"
118
119	ageing_time=$(bridge_ageing_time_get br1)
120	slowwait $((ageing_time * 2)) fdb_inactive_wait "$mac"
121	check_err $? "FDB entry not present as \"inactive\" when should"
122
123	log_test "Transition from active to inactive"
124
125	bridge fdb del "$mac" dev "$swp1" master
126}
127
128norefresh_test()
129{
130	local mac="00:11:22:33:44:55"
131	local updated_time
132
133	# Check that the "updated" time is reset when replacing an FDB entry
134	# without the "norefresh" keyword and that it is not reset when
135	# replacing with the "norefresh" keyword.
136	RET=0
137
138	bridge fdb add "$mac" dev "$swp1" master static
139	sleep 1
140
141	bridge fdb replace "$mac" dev "$swp1" master static activity_notify
142	updated_time=$(bridge -d -s -j fdb get "$mac" br br1 | jq '.[]["updated"]')
143	if [[ $updated_time -ne 0 ]]; then
144		check_err 1 "\"updated\" time was not reset when should"
145	fi
146
147	sleep 1
148	bridge fdb replace "$mac" dev "$swp1" master static norefresh
149	updated_time=$(bridge -d -s -j fdb get "$mac" br br1 | jq '.[]["updated"]')
150	if [[ $updated_time -eq 0 ]]; then
151		check_err 1 "\"updated\" time was reset when should not"
152	fi
153
154	log_test "Resetting of \"updated\" time"
155
156	bridge fdb del "$mac" dev "$swp1" master
157}
158
159if ! bridge fdb help 2>&1 | grep -q "activity_notify"; then
160	echo "SKIP: iproute2 too old, missing bridge FDB activity notification control"
161	exit "$ksft_skip"
162fi
163
164trap cleanup EXIT
165
166setup_prepare
167setup_wait
168tests_run
169
170exit "$EXIT_STATUS"
~/ Read-only file preview.