Skip to content

Commit d4deb01

Browse files
idoschdavem330
authored andcommitted
selftests: forwarding: Add a test for FDB learning
Send a packet with a specific destination MAC, make sure it was learned on the ingress port and then aged-out. Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 73bae67 commit d4deb01

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

tools/testing/selftests/net/forwarding/bridge_vlan_aware.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ h2_destroy()
2626

2727
switch_create()
2828
{
29-
ip link add dev br0 type bridge vlan_filtering 1 mcast_snooping 0
29+
# 10 Seconds ageing time.
30+
ip link add dev br0 type bridge vlan_filtering 1 ageing_time 1000 \
31+
mcast_snooping 0
3032

3133
ip link set dev $swp1 master br0
3234
ip link set dev $swp2 master br0
@@ -79,5 +81,6 @@ setup_wait
7981

8082
ping_test $h1 192.0.2.2
8183
ping6_test $h1 2001:db8:1::2
84+
learning_test "br0" $swp1 $h1 $h2
8285

8386
exit $EXIT_STATUS

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Can be overridden by the configuration file.
88
PING=${PING:=ping}
99
PING6=${PING6:=ping6}
10+
MZ=${MZ:=mausezahn}
1011
WAIT_TIME=${WAIT_TIME:=5}
1112
PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
1213
PAUSE_ON_CLEANUP=${PAUSE_ON_CLEANUP:=no}
@@ -34,6 +35,11 @@ if [[ ! -x "$(command -v jq)" ]]; then
3435
exit 0
3536
fi
3637

38+
if [[ ! -x "$(command -v $MZ)" ]]; then
39+
echo "SKIP: $MZ not installed"
40+
exit 0
41+
fi
42+
3743
if [[ ! -v NUM_NETIFS ]]; then
3844
echo "SKIP: importer does not define \"NUM_NETIFS\""
3945
exit 0
@@ -250,6 +256,17 @@ master_name_get()
250256
ip -j link show dev $if_name | jq -r '.[]["master"]'
251257
}
252258

259+
bridge_ageing_time_get()
260+
{
261+
local bridge=$1
262+
local ageing_time
263+
264+
# Need to divide by 100 to convert to seconds.
265+
ageing_time=$(ip -j -d link show dev $bridge \
266+
| jq '.[]["linkinfo"]["info_data"]["ageing_time"]')
267+
echo $((ageing_time / 100))
268+
}
269+
253270
##############################################################################
254271
# Tests
255272

@@ -280,3 +297,78 @@ ping6_test()
280297
check_err $?
281298
log_test "ping6"
282299
}
300+
301+
learning_test()
302+
{
303+
local bridge=$1
304+
local br_port1=$2 # Connected to `host1_if`.
305+
local host1_if=$3
306+
local host2_if=$4
307+
local mac=de:ad:be:ef:13:37
308+
local ageing_time
309+
310+
RET=0
311+
312+
bridge -j fdb show br $bridge brport $br_port1 \
313+
| jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null
314+
check_fail $? "Found FDB record when should not"
315+
316+
# Disable unknown unicast flooding on `br_port1` to make sure
317+
# packets are only forwarded through the port after a matching
318+
# FDB entry was installed.
319+
bridge link set dev $br_port1 flood off
320+
321+
tc qdisc add dev $host1_if ingress
322+
tc filter add dev $host1_if ingress protocol ip pref 1 handle 101 \
323+
flower dst_mac $mac action drop
324+
325+
$MZ $host2_if -c 1 -p 64 -b $mac -t ip -q
326+
sleep 1
327+
328+
tc -j -s filter show dev $host1_if ingress \
329+
| jq -e ".[] | select(.options.handle == 101) \
330+
| select(.options.actions[0].stats.packets == 1)" &> /dev/null
331+
check_fail $? "Packet reached second host when should not"
332+
333+
$MZ $host1_if -c 1 -p 64 -a $mac -t ip -q
334+
sleep 1
335+
336+
bridge -j fdb show br $bridge brport $br_port1 \
337+
| jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null
338+
check_err $? "Did not find FDB record when should"
339+
340+
$MZ $host2_if -c 1 -p 64 -b $mac -t ip -q
341+
sleep 1
342+
343+
tc -j -s filter show dev $host1_if ingress \
344+
| jq -e ".[] | select(.options.handle == 101) \
345+
| select(.options.actions[0].stats.packets == 1)" &> /dev/null
346+
check_err $? "Packet did not reach second host when should"
347+
348+
# Wait for 10 seconds after the ageing time to make sure FDB
349+
# record was aged-out.
350+
ageing_time=$(bridge_ageing_time_get $bridge)
351+
sleep $((ageing_time + 10))
352+
353+
bridge -j fdb show br $bridge brport $br_port1 \
354+
| jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null
355+
check_fail $? "Found FDB record when should not"
356+
357+
bridge link set dev $br_port1 learning off
358+
359+
$MZ $host1_if -c 1 -p 64 -a $mac -t ip -q
360+
sleep 1
361+
362+
bridge -j fdb show br $bridge brport $br_port1 \
363+
| jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null
364+
check_fail $? "Found FDB record when should not"
365+
366+
bridge link set dev $br_port1 learning on
367+
368+
tc filter del dev $host1_if ingress protocol ip pref 1 handle 101 flower
369+
tc qdisc del dev $host1_if ingress
370+
371+
bridge link set dev $br_port1 flood on
372+
373+
log_test "FDB learning"
374+
}

0 commit comments

Comments
 (0)