xref: /linux/tools/testing/selftests/drivers/net/hw/hw_stats_l3_gre.sh (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# Test L3 stats on IP-in-IP GRE tunnel without key.
5
6# This test uses flat topology for IP tunneling tests. See ipip_lib.sh for more
7# details.
8
9ALL_TESTS="
10	ping_ipv4
11	test_stats_rx
12	test_stats_tx
13"
14NUM_NETIFS=6
15lib_dir=$(dirname "$0")
16source "$lib_dir"/../../../net/forwarding/lib.sh
17source "$lib_dir"/../../../net/forwarding/ipip_lib.sh
18source "$lib_dir"/../../../net/forwarding/tc_common.sh
19
20setup_prepare()
21{
22	h1=${NETIFS[p1]}
23	ol1=${NETIFS[p2]}
24
25	ul1=${NETIFS[p3]}
26	ul2=${NETIFS[p4]}
27
28	ol2=${NETIFS[p5]}
29	h2=${NETIFS[p6]}
30
31	ol1mac=$(mac_get $ol1)
32
33	forwarding_enable
34	vrf_prepare
35	h1_create
36	h2_create
37	sw1_flat_create gre $ol1 $ul1
38	sw2_flat_create gre $ol2 $ul2
39	ip stats set dev g1a l3_stats on
40	ip stats set dev g2a l3_stats on
41}
42
43cleanup()
44{
45	pre_cleanup
46
47	ip stats set dev g1a l3_stats off
48	ip stats set dev g2a l3_stats off
49
50	sw2_flat_destroy $ol2 $ul2
51	sw1_flat_destroy $ol1 $ul1
52	h2_destroy
53	h1_destroy
54
55	vrf_cleanup
56	forwarding_restore
57}
58
59ping_ipv4()
60{
61	RET=0
62
63	ping_test $h1 192.0.2.18 " gre flat"
64}
65
66send_packets_ipv4()
67{
68	# Send 21 packets instead of 20, because the first one might trap and go
69	# through the SW datapath, which might not bump the HW counter.
70	$MZ $h1 -c 21 -d 20msec -p 100 \
71	    -a own -b $ol1mac -A 192.0.2.1 -B 192.0.2.18 \
72	    -q -t udp sp=54321,dp=12345
73}
74
75test_stats()
76{
77	local dev=$1; shift
78	local dir=$1; shift
79
80	local a
81	local b
82
83	RET=0
84
85	a=$(hw_stats_get l3_stats $dev $dir packets)
86	send_packets_ipv4
87	b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \
88		     hw_stats_get l3_stats $dev $dir packets)
89	check_err $? "Traffic not reflected in the counter: $a -> $b"
90
91	log_test "Test $dir packets: $prot"
92}
93
94test_stats_tx()
95{
96	test_stats g1a tx
97}
98
99test_stats_rx()
100{
101	test_stats g2a rx
102}
103
104trap cleanup EXIT
105
106setup_prepare
107setup_wait
108
109tests_run
110
111exit $EXIT_STATUS
112