xref: /linux/tools/testing/selftests/drivers/net/mlxsw/port_range_scale.sh (revision 42874e4eb35bdfc54f8514685e50434098ba4f6c)
1# SPDX-License-Identifier: GPL-2.0
2
3PORT_RANGE_NUM_NETIFS=2
4
5port_range_h1_create()
6{
7	simple_if_init $h1
8}
9
10port_range_h1_destroy()
11{
12	simple_if_fini $h1
13}
14
15port_range_switch_create()
16{
17	simple_if_init $swp1
18	tc qdisc add dev $swp1 clsact
19}
20
21port_range_switch_destroy()
22{
23	tc qdisc del dev $swp1 clsact
24	simple_if_fini $swp1
25}
26
27port_range_rules_create()
28{
29	local count=$1; shift
30	local should_fail=$1; shift
31	local batch_file="$(mktemp)"
32
33	for ((i = 0; i < count; ++i)); do
34		cat >> $batch_file <<-EOF
35			filter add dev $swp1 ingress \
36				prot ipv4 \
37				pref 1000 \
38				flower skip_sw \
39				ip_proto udp dst_port 1-$((100 + i)) \
40				action pass
41		EOF
42	done
43
44	tc -b $batch_file
45	check_err_fail $should_fail $? "Rule insertion"
46
47	rm -f $batch_file
48}
49
50__port_range_test()
51{
52	local count=$1; shift
53	local should_fail=$1; shift
54
55	port_range_rules_create $count $should_fail
56
57	offload_count=$(tc -j filter show dev $swp1 ingress |
58			jq "[.[] | select(.options.in_hw == true)] | length")
59	((offload_count == count))
60	check_err_fail $should_fail $? "port range offload count"
61}
62
63port_range_test()
64{
65	local count=$1; shift
66	local should_fail=$1; shift
67
68	if ! tc_offload_check $PORT_RANGE_NUM_NETIFS; then
69		check_err 1 "Could not test offloaded functionality"
70		return
71	fi
72
73	__port_range_test $count $should_fail
74}
75
76port_range_setup_prepare()
77{
78	h1=${NETIFS[p1]}
79	swp1=${NETIFS[p2]}
80
81	vrf_prepare
82
83	port_range_h1_create
84	port_range_switch_create
85}
86
87port_range_cleanup()
88{
89	pre_cleanup
90
91	port_range_switch_destroy
92	port_range_h1_destroy
93
94	vrf_cleanup
95}
96