diff options
author | Ido Schimmel <idosch@mellanox.com> | 2018-02-28 05:25:07 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-02-28 12:25:47 -0500 |
commit | d4deb01467ec9ed33fe0f4b4fa4632c94f2dd8c9 (patch) | |
tree | a3949869df5d1e7945a4a5ea1f3608fdf45ed908 | |
parent | 73bae6736b6b577b52fbba2d4b71a5a3e9920fb5 (diff) |
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 <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rwxr-xr-x | tools/testing/selftests/net/forwarding/bridge_vlan_aware.sh | 5 | ||||
-rw-r--r-- | tools/testing/selftests/net/forwarding/lib.sh | 92 |
2 files changed, 96 insertions, 1 deletions
diff --git a/tools/testing/selftests/net/forwarding/bridge_vlan_aware.sh b/tools/testing/selftests/net/forwarding/bridge_vlan_aware.sh index e6faa9548460..1ba119f28963 100755 --- a/tools/testing/selftests/net/forwarding/bridge_vlan_aware.sh +++ b/tools/testing/selftests/net/forwarding/bridge_vlan_aware.sh | |||
@@ -26,7 +26,9 @@ h2_destroy() | |||
26 | 26 | ||
27 | switch_create() | 27 | switch_create() |
28 | { | 28 | { |
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 | ||
30 | 32 | ||
31 | ip link set dev $swp1 master br0 | 33 | ip link set dev $swp1 master br0 |
32 | ip link set dev $swp2 master br0 | 34 | ip link set dev $swp2 master br0 |
@@ -79,5 +81,6 @@ setup_wait | |||
79 | 81 | ||
80 | ping_test $h1 192.0.2.2 | 82 | ping_test $h1 192.0.2.2 |
81 | ping6_test $h1 2001:db8:1::2 | 83 | ping6_test $h1 2001:db8:1::2 |
84 | learning_test "br0" $swp1 $h1 $h2 | ||
82 | 85 | ||
83 | exit $EXIT_STATUS | 86 | exit $EXIT_STATUS |
diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index ff6550e9ddaf..21af63e860dc 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh | |||
@@ -7,6 +7,7 @@ | |||
7 | # Can be overridden by the configuration file. | 7 | # Can be overridden by the configuration file. |
8 | PING=${PING:=ping} | 8 | PING=${PING:=ping} |
9 | PING6=${PING6:=ping6} | 9 | PING6=${PING6:=ping6} |
10 | MZ=${MZ:=mausezahn} | ||
10 | WAIT_TIME=${WAIT_TIME:=5} | 11 | WAIT_TIME=${WAIT_TIME:=5} |
11 | PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} | 12 | PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} |
12 | PAUSE_ON_CLEANUP=${PAUSE_ON_CLEANUP:=no} | 13 | PAUSE_ON_CLEANUP=${PAUSE_ON_CLEANUP:=no} |
@@ -34,6 +35,11 @@ if [[ ! -x "$(command -v jq)" ]]; then | |||
34 | exit 0 | 35 | exit 0 |
35 | fi | 36 | fi |
36 | 37 | ||
38 | if [[ ! -x "$(command -v $MZ)" ]]; then | ||
39 | echo "SKIP: $MZ not installed" | ||
40 | exit 0 | ||
41 | fi | ||
42 | |||
37 | if [[ ! -v NUM_NETIFS ]]; then | 43 | if [[ ! -v NUM_NETIFS ]]; then |
38 | echo "SKIP: importer does not define \"NUM_NETIFS\"" | 44 | echo "SKIP: importer does not define \"NUM_NETIFS\"" |
39 | exit 0 | 45 | exit 0 |
@@ -250,6 +256,17 @@ master_name_get() | |||
250 | ip -j link show dev $if_name | jq -r '.[]["master"]' | 256 | ip -j link show dev $if_name | jq -r '.[]["master"]' |
251 | } | 257 | } |
252 | 258 | ||
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 | |||
253 | ############################################################################## | 270 | ############################################################################## |
254 | # Tests | 271 | # Tests |
255 | 272 | ||
@@ -280,3 +297,78 @@ ping6_test() | |||
280 | check_err $? | 297 | check_err $? |
281 | log_test "ping6" | 298 | log_test "ping6" |
282 | } | 299 | } |
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 | } | ||