1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4ALL_TESTS="ping_ipv4 ping_ipv6 learning flooding vlan_deletion extern_learn"
5NUM_NETIFS=4
6CHECK_TC="yes"
7source lib.sh
8
9h1_create()
10{
11	simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
12}
13
14h1_destroy()
15{
16	simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
17}
18
19h2_create()
20{
21	simple_if_init $h2 192.0.2.2/24 2001:db8:1::2/64
22}
23
24h2_destroy()
25{
26	simple_if_fini $h2 192.0.2.2/24 2001:db8:1::2/64
27}
28
29switch_create()
30{
31	# 10 Seconds ageing time.
32	ip link add dev br0 type bridge vlan_filtering 1 ageing_time 1000 \
33		mcast_snooping 0
34
35	ip link set dev $swp1 master br0
36	ip link set dev $swp2 master br0
37
38	ip link set dev br0 up
39	ip link set dev $swp1 up
40	ip link set dev $swp2 up
41}
42
43switch_destroy()
44{
45	ip link set dev $swp2 down
46	ip link set dev $swp1 down
47
48	ip link del dev br0
49}
50
51setup_prepare()
52{
53	h1=${NETIFS[p1]}
54	swp1=${NETIFS[p2]}
55
56	swp2=${NETIFS[p3]}
57	h2=${NETIFS[p4]}
58
59	vrf_prepare
60
61	h1_create
62	h2_create
63
64	switch_create
65}
66
67cleanup()
68{
69	pre_cleanup
70
71	switch_destroy
72
73	h2_destroy
74	h1_destroy
75
76	vrf_cleanup
77}
78
79ping_ipv4()
80{
81	ping_test $h1 192.0.2.2
82}
83
84ping_ipv6()
85{
86	ping6_test $h1 2001:db8:1::2
87}
88
89learning()
90{
91	learning_test "br0" $swp1 $h1 $h2
92}
93
94flooding()
95{
96	flood_test $swp2 $h1 $h2
97}
98
99vlan_deletion()
100{
101	# Test that the deletion of a VLAN on a bridge port does not affect
102	# the PVID VLAN
103	log_info "Add and delete a VLAN on bridge port $swp1"
104
105	bridge vlan add vid 10 dev $swp1
106	bridge vlan del vid 10 dev $swp1
107
108	ping_ipv4
109	ping_ipv6
110}
111
112extern_learn()
113{
114	local mac=de:ad:be:ef:13:37
115	local ageing_time
116
117	# Test that externally learned FDB entries can roam, but not age out
118	RET=0
119
120	bridge fdb add de:ad:be:ef:13:37 dev $swp1 master extern_learn vlan 1
121
122	bridge fdb show brport $swp1 | grep -q de:ad:be:ef:13:37
123	check_err $? "Did not find FDB entry when should"
124
125	# Wait for 10 seconds after the ageing time to make sure the FDB entry
126	# was not aged out
127	ageing_time=$(bridge_ageing_time_get br0)
128	sleep $((ageing_time + 10))
129
130	bridge fdb show brport $swp1 | grep -q de:ad:be:ef:13:37
131	check_err $? "FDB entry was aged out when should not"
132
133	$MZ $h2 -c 1 -p 64 -a $mac -t ip -q
134
135	bridge fdb show brport $swp2 | grep -q de:ad:be:ef:13:37
136	check_err $? "FDB entry did not roam when should"
137
138	log_test "Externally learned FDB entry - ageing & roaming"
139
140	bridge fdb del de:ad:be:ef:13:37 dev $swp2 master vlan 1 &> /dev/null
141	bridge fdb del de:ad:be:ef:13:37 dev $swp1 master vlan 1 &> /dev/null
142}
143
144trap cleanup EXIT
145
146setup_prepare
147setup_wait
148
149tests_run
150
151exit $EXIT_STATUS
152