xref: /openbmc/linux/tools/testing/selftests/net/forwarding/tc_shblocks.sh (revision 0898782247ae533d1f4e47a06bc5d4870931b284)
14908e24bSJiri Pirko#!/bin/bash
24908e24bSJiri Pirko# SPDX-License-Identifier: GPL-2.0
34908e24bSJiri Pirko
4*dcc5e1f9SJiri PirkoALL_TESTS="shared_block_test match_indev_test"
54908e24bSJiri PirkoNUM_NETIFS=4
64908e24bSJiri Pirkosource tc_common.sh
7198979beSDavid Ahernsource lib.sh
84908e24bSJiri Pirko
94908e24bSJiri Pirkotcflags="skip_hw"
104908e24bSJiri Pirko
114908e24bSJiri Pirkoh1_create()
124908e24bSJiri Pirko{
134908e24bSJiri Pirko	simple_if_init $h1 192.0.2.1/24
144908e24bSJiri Pirko}
154908e24bSJiri Pirko
164908e24bSJiri Pirkoh1_destroy()
174908e24bSJiri Pirko{
184908e24bSJiri Pirko	simple_if_fini $h1 192.0.2.1/24
194908e24bSJiri Pirko}
204908e24bSJiri Pirko
214908e24bSJiri Pirkoh2_create()
224908e24bSJiri Pirko{
234908e24bSJiri Pirko	simple_if_init $h2 192.0.2.1/24
244908e24bSJiri Pirko}
254908e24bSJiri Pirko
264908e24bSJiri Pirkoh2_destroy()
274908e24bSJiri Pirko{
284908e24bSJiri Pirko	simple_if_fini $h2 192.0.2.1/24
294908e24bSJiri Pirko}
304908e24bSJiri Pirko
314908e24bSJiri Pirkoswitch_create()
324908e24bSJiri Pirko{
334908e24bSJiri Pirko	simple_if_init $swp1 192.0.2.2/24
344908e24bSJiri Pirko	tc qdisc add dev $swp1 ingress_block 22 egress_block 23 clsact
354908e24bSJiri Pirko
364908e24bSJiri Pirko	simple_if_init $swp2 192.0.2.2/24
374908e24bSJiri Pirko	tc qdisc add dev $swp2 ingress_block 22 egress_block 23 clsact
384908e24bSJiri Pirko}
394908e24bSJiri Pirko
404908e24bSJiri Pirkoswitch_destroy()
414908e24bSJiri Pirko{
424908e24bSJiri Pirko	tc qdisc del dev $swp2 clsact
434908e24bSJiri Pirko	simple_if_fini $swp2 192.0.2.2/24
444908e24bSJiri Pirko
454908e24bSJiri Pirko	tc qdisc del dev $swp1 clsact
464908e24bSJiri Pirko	simple_if_fini $swp1 192.0.2.2/24
474908e24bSJiri Pirko}
484908e24bSJiri Pirko
494908e24bSJiri Pirkoshared_block_test()
504908e24bSJiri Pirko{
514908e24bSJiri Pirko	RET=0
524908e24bSJiri Pirko
534908e24bSJiri Pirko	tc filter add block 22 protocol ip pref 1 handle 101 flower \
544908e24bSJiri Pirko		$tcflags dst_ip 192.0.2.2 action drop
554908e24bSJiri Pirko
564908e24bSJiri Pirko	$MZ $h1 -c 1 -p 64 -a $h1mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
574908e24bSJiri Pirko		-t ip -q
584908e24bSJiri Pirko
594908e24bSJiri Pirko	tc_check_packets "block 22" 101 1
604908e24bSJiri Pirko	check_err $? "Did not match first incoming packet on a block"
614908e24bSJiri Pirko
624908e24bSJiri Pirko	$MZ $h2 -c 1 -p 64 -a $h2mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
634908e24bSJiri Pirko		-t ip -q
644908e24bSJiri Pirko
654908e24bSJiri Pirko	tc_check_packets "block 22" 101 2
664908e24bSJiri Pirko	check_err $? "Did not match second incoming packet on a block"
674908e24bSJiri Pirko
684908e24bSJiri Pirko	tc filter del block 22 protocol ip pref 1 handle 101 flower
694908e24bSJiri Pirko
704908e24bSJiri Pirko	log_test "shared block ($tcflags)"
714908e24bSJiri Pirko}
724908e24bSJiri Pirko
73*dcc5e1f9SJiri Pirkomatch_indev_test()
74*dcc5e1f9SJiri Pirko{
75*dcc5e1f9SJiri Pirko	RET=0
76*dcc5e1f9SJiri Pirko
77*dcc5e1f9SJiri Pirko	tc filter add block 22 protocol ip pref 1 handle 101 flower \
78*dcc5e1f9SJiri Pirko		$tcflags indev $swp1 dst_mac $swmac action drop
79*dcc5e1f9SJiri Pirko	tc filter add block 22 protocol ip pref 2 handle 102 flower \
80*dcc5e1f9SJiri Pirko		$tcflags indev $swp2 dst_mac $swmac action drop
81*dcc5e1f9SJiri Pirko
82*dcc5e1f9SJiri Pirko	$MZ $h1 -c 1 -p 64 -a $h1mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
83*dcc5e1f9SJiri Pirko		-t ip -q
84*dcc5e1f9SJiri Pirko
85*dcc5e1f9SJiri Pirko	tc_check_packets "block 22" 101 1
86*dcc5e1f9SJiri Pirko	check_err $? "Did not match first incoming packet on a block"
87*dcc5e1f9SJiri Pirko
88*dcc5e1f9SJiri Pirko	$MZ $h2 -c 1 -p 64 -a $h2mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \
89*dcc5e1f9SJiri Pirko		-t ip -q
90*dcc5e1f9SJiri Pirko
91*dcc5e1f9SJiri Pirko	tc_check_packets "block 22" 102 1
92*dcc5e1f9SJiri Pirko	check_err $? "Did not match second incoming packet on a block"
93*dcc5e1f9SJiri Pirko
94*dcc5e1f9SJiri Pirko	tc filter del block 22 protocol ip pref 1 handle 101 flower
95*dcc5e1f9SJiri Pirko	tc filter del block 22 protocol ip pref 2 handle 102 flower
96*dcc5e1f9SJiri Pirko
97*dcc5e1f9SJiri Pirko	log_test "indev match ($tcflags)"
98*dcc5e1f9SJiri Pirko}
99*dcc5e1f9SJiri Pirko
1004908e24bSJiri Pirkosetup_prepare()
1014908e24bSJiri Pirko{
1024908e24bSJiri Pirko	h1=${NETIFS[p1]}
1034908e24bSJiri Pirko	swp1=${NETIFS[p2]}
1044908e24bSJiri Pirko
1054908e24bSJiri Pirko	swp2=${NETIFS[p3]}
1064908e24bSJiri Pirko	h2=${NETIFS[p4]}
1074908e24bSJiri Pirko
1084908e24bSJiri Pirko	h1mac=$(mac_get $h1)
1094908e24bSJiri Pirko	h2mac=$(mac_get $h2)
1104908e24bSJiri Pirko
1114908e24bSJiri Pirko	swmac=$(mac_get $swp1)
1124908e24bSJiri Pirko	swp2origmac=$(mac_get $swp2)
1134908e24bSJiri Pirko	ip link set $swp2 address $swmac
1144908e24bSJiri Pirko
1154908e24bSJiri Pirko	vrf_prepare
1164908e24bSJiri Pirko
1174908e24bSJiri Pirko	h1_create
1184908e24bSJiri Pirko	h2_create
1194908e24bSJiri Pirko	switch_create
1204908e24bSJiri Pirko}
1214908e24bSJiri Pirko
1224908e24bSJiri Pirkocleanup()
1234908e24bSJiri Pirko{
1244908e24bSJiri Pirko	pre_cleanup
1254908e24bSJiri Pirko
1264908e24bSJiri Pirko	switch_destroy
1274908e24bSJiri Pirko	h2_destroy
1284908e24bSJiri Pirko	h1_destroy
1294908e24bSJiri Pirko
1304908e24bSJiri Pirko	vrf_cleanup
1314908e24bSJiri Pirko
1324908e24bSJiri Pirko	ip link set $swp2 address $swp2origmac
1334908e24bSJiri Pirko}
1344908e24bSJiri Pirko
1357f333cbfSJiri Pirkocheck_tc_shblock_support
1367f333cbfSJiri Pirko
1374908e24bSJiri Pirkotrap cleanup EXIT
1384908e24bSJiri Pirko
1394908e24bSJiri Pirkosetup_prepare
1404908e24bSJiri Pirkosetup_wait
1414908e24bSJiri Pirko
1420eb8053cSIdo Schimmeltests_run
1434908e24bSJiri Pirko
1444908e24bSJiri Pirkotc_offload_check
1454908e24bSJiri Pirkoif [[ $? -ne 0 ]]; then
1464908e24bSJiri Pirko	log_info "Could not test offloaded functionality"
1474908e24bSJiri Pirkoelse
1484908e24bSJiri Pirko	tcflags="skip_sw"
1490eb8053cSIdo Schimmel	tests_run
1504908e24bSJiri Pirkofi
1514908e24bSJiri Pirko
1524908e24bSJiri Pirkoexit $EXIT_STATUS
153