summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/net/forwarding/bridge_activity_notify.sh
blob: 522a5b1b046c6623558e051cad581902c073b146 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

# +-----------------------+                          +------------------------+
# | H1 (vrf)              |                          | H2 (vrf)               |
# | 192.0.2.1/28          |                          | 192.0.2.2/28           |
# |    + $h1              |                          |    + $h2               |
# +----|------------------+                          +----|-------------------+
#      |                                                  |
# +----|--------------------------------------------------|-------------------+
# | SW |                                                  |                   |
# | +--|--------------------------------------------------|-----------------+ |
# | |  + $swp1                   BR1 (802.1d)             + $swp2           | |
# | |                                                                       | |
# | +-----------------------------------------------------------------------+ |
# +---------------------------------------------------------------------------+

ALL_TESTS="
	new_inactive_test
	existing_active_test
	norefresh_test
"

NUM_NETIFS=4
source lib.sh

h1_create()
{
	adf_simple_if_init "$h1" 192.0.2.1/28
}

h2_create()
{
	adf_simple_if_init "$h2" 192.0.2.2/28
}

switch_create()
{
	adf_ip_link_add br1 type bridge vlan_filtering 0 mcast_snooping 0 \
		ageing_time "$LOW_AGEING_TIME"
	adf_ip_link_set_up br1

	adf_ip_link_set_master "$swp1" br1
	adf_ip_link_set_up "$swp1"

	adf_ip_link_set_master "$swp2" br1
	adf_ip_link_set_up "$swp2"
}

setup_prepare()
{
	h1=${NETIFS[p1]}
	swp1=${NETIFS[p2]}

	swp2=${NETIFS[p3]}
	h2=${NETIFS[p4]}

	adf_vrf_prepare

	h1_create
	h2_create
	switch_create
}

fdb_active_wait()
{
	local mac=$1; shift

	bridge -d fdb get "$mac" br br1 | grep -q -v "inactive"
}

fdb_inactive_wait()
{
	local mac=$1; shift

	bridge -d fdb get "$mac" br br1 | grep -q "inactive"
}

new_inactive_test()
{
	local mac="00:11:22:33:44:55"

	# Add a new FDB entry as static and inactive and check that it
	# becomes active upon traffic.
	RET=0

	bridge fdb add "$mac" dev "$swp1" master static activity_notify inactive
	bridge -d fdb get "$mac" br br1 | grep -q "inactive"
	check_err $? "FDB entry not present as \"inactive\" when should"

	$MZ "$h1" -c 1 -p 64 -a "$mac" -b bcast -t ip -q

	busywait "$BUSYWAIT_TIMEOUT" fdb_active_wait "$mac"
	check_err $? "FDB entry present as \"inactive\" when should not"

	log_test "Transition from inactive to active"

	bridge fdb del "$mac" dev "$swp1" master
}

existing_active_test()
{
	local mac="00:11:22:33:44:55"
	local ageing_time

	# Enable activity notifications on an existing dynamic FDB entry and
	# check that it becomes inactive after the ageing time passed.
	RET=0

	bridge fdb add "$mac" dev "$swp1" master dynamic
	bridge fdb replace "$mac" dev "$swp1" master static activity_notify norefresh

	bridge -d fdb get "$mac" br br1 | grep -q "activity_notify"
	check_err $? "FDB entry not present as \"activity_notify\" when should"

	bridge -d fdb get "$mac" br br1 | grep -q "inactive"
	check_fail $? "FDB entry present as \"inactive\" when should not"

	ageing_time=$(bridge_ageing_time_get br1)
	slowwait $((ageing_time * 2)) fdb_inactive_wait "$mac"
	check_err $? "FDB entry not present as \"inactive\" when should"

	log_test "Transition from active to inactive"

	bridge fdb del "$mac" dev "$swp1" master
}

norefresh_test()
{
	local mac="00:11:22:33:44:55"
	local updated_time

	# Check that the "updated" time is reset when replacing an FDB entry
	# without the "norefresh" keyword and that it is not reset when
	# replacing with the "norefresh" keyword.
	RET=0

	bridge fdb add "$mac" dev "$swp1" master static
	sleep 1

	bridge fdb replace "$mac" dev "$swp1" master static activity_notify
	updated_time=$(bridge -d -s -j fdb get "$mac" br br1 | jq '.[]["updated"]')
	if [[ $updated_time -ne 0 ]]; then
		check_err 1 "\"updated\" time was not reset when should"
	fi

	sleep 1
	bridge fdb replace "$mac" dev "$swp1" master static norefresh
	updated_time=$(bridge -d -s -j fdb get "$mac" br br1 | jq '.[]["updated"]')
	if [[ $updated_time -eq 0 ]]; then
		check_err 1 "\"updated\" time was reset when should not"
	fi

	log_test "Resetting of \"updated\" time"

	bridge fdb del "$mac" dev "$swp1" master
}

if ! bridge fdb help 2>&1 | grep -q "activity_notify"; then
	echo "SKIP: iproute2 too old, missing bridge FDB activity notification control"
	exit "$ksft_skip"
fi

trap cleanup EXIT

setup_prepare
setup_wait
tests_run

exit "$EXIT_STATUS"