summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/drivers/net/mlxsw/mirror_gre_scale.sh
blob: d43093310e23a2c4aef536382d4d47fcc25acca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# SPDX-License-Identifier: GPL-2.0

# Test offloading a number of mirrors-to-gretap. The test creates a number of
# tunnels. Then it adds one flower mirror for each of the tunnels, matching a
# given host IP. Then it generates traffic at each of the host IPs and checks
# that the traffic has been mirrored at the appropriate tunnel.
#
#   +--------------------------+                   +--------------------------+
#   | H1                       |                   |                       H2 |
#   |     + $h1                |                   |                $h2 +     |
#   |     | 2001:db8:1:X::1/64 |                   | 2001:db8:1:X::2/64 |     |
#   +-----|--------------------+                   +--------------------|-----+
#         |                                                             |
#   +-----|-------------------------------------------------------------|-----+
#   | SW  o--> mirrors                                                  |     |
#   | +---|-------------------------------------------------------------|---+ |
#   | |   + $swp1                    BR                           $swp2 +   | |
#   | +---------------------------------------------------------------------+ |
#   |                                                                         |
#   |     + $swp3                          + gt6-<X> (ip6gretap)              |
#   |     | 2001:db8:2:X::1/64             : loc=2001:db8:2:X::1              |
#   |     |                                : rem=2001:db8:2:X::2              |
#   |     |                                : ttl=100                          |
#   |     |                                : tos=inherit                      |
#   |     |                                :                                  |
#   +-----|--------------------------------:----------------------------------+
#         |                                :
#   +-----|--------------------------------:----------------------------------+
#   | H3  + $h3                            + h3-gt6-<X> (ip6gretap)           |
#   |       2001:db8:2:X::2/64               loc=2001:db8:2:X::2              |
#   |                                        rem=2001:db8:2:X::1              |
#   |                                        ttl=100                          |
#   |                                        tos=inherit                      |
#   |                                                                         |
#   +-------------------------------------------------------------------------+

source ../../../../net/forwarding/mirror_lib.sh

MIRROR_NUM_NETIFS=6

mirror_gre_ipv6_addr()
{
	local net=$1; shift
	local num=$1; shift

	printf "2001:db8:%x:%x" $net $num
}

mirror_gre_tunnels_create()
{
	local count=$1; shift
	local should_fail=$1; shift

	MIRROR_GRE_BATCH_FILE="$(mktemp)"
	for ((i=0; i < count; ++i)); do
		local match_dip=$(mirror_gre_ipv6_addr 1 $i)::2
		local htun=h3-gt6-$i
		local tun=gt6-$i

		((mirror_gre_tunnels++))

		ip address add dev $h1 $(mirror_gre_ipv6_addr 1 $i)::1/64
		ip address add dev $h2 $(mirror_gre_ipv6_addr 1 $i)::2/64

		ip address add dev $swp3 $(mirror_gre_ipv6_addr 2 $i)::1/64
		ip address add dev $h3 $(mirror_gre_ipv6_addr 2 $i)::2/64

		tunnel_create $tun ip6gretap \
			      $(mirror_gre_ipv6_addr 2 $i)::1 \
			      $(mirror_gre_ipv6_addr 2 $i)::2 \
			      ttl 100 tos inherit allow-localremote

		tunnel_create $htun ip6gretap \
			      $(mirror_gre_ipv6_addr 2 $i)::2 \
			      $(mirror_gre_ipv6_addr 2 $i)::1
		ip link set $htun vrf v$h3
		matchall_sink_create $htun

		cat >> $MIRROR_GRE_BATCH_FILE <<-EOF
			filter add dev $swp1 ingress pref 1000 \
				protocol ipv6 \
				flower skip_sw dst_ip $match_dip \
				action mirred egress mirror dev $tun
		EOF
	done

	tc -b $MIRROR_GRE_BATCH_FILE
	check_err_fail $should_fail $? "Mirror rule insertion"
}

mirror_gre_tunnels_destroy()
{
	local count=$1; shift

	for ((i=0; i < count; ++i)); do
		local htun=h3-gt6-$i
		local tun=gt6-$i

		ip address del dev $h3 $(mirror_gre_ipv6_addr 2 $i)::2/64
		ip address del dev $swp3 $(mirror_gre_ipv6_addr 2 $i)::1/64

		ip address del dev $h2 $(mirror_gre_ipv6_addr 1 $i)::2/64
		ip address del dev $h1 $(mirror_gre_ipv6_addr 1 $i)::1/64

		tunnel_destroy $htun
		tunnel_destroy $tun
	done
}

mirror_gre_test()
{
	local count=$1; shift
	local should_fail=$1; shift

	mirror_gre_tunnels_create $count $should_fail
	if ((should_fail)); then
	    return
	fi

	sleep 5

	for ((i = 0; i < count; ++i)); do
		local sip=$(mirror_gre_ipv6_addr 1 $i)::1
		local dip=$(mirror_gre_ipv6_addr 1 $i)::2
		local htun=h3-gt6-$i
		local message

		icmp6_capture_install $htun
		mirror_test v$h1 $sip $dip $htun 100 10
		icmp6_capture_uninstall $htun
	done
}

mirror_gre_setup_prepare()
{
	h1=${NETIFS[p1]}
	swp1=${NETIFS[p2]}

	swp2=${NETIFS[p3]}
	h2=${NETIFS[p4]}

	swp3=${NETIFS[p5]}
	h3=${NETIFS[p6]}

	mirror_gre_tunnels=0

	vrf_prepare

	simple_if_init $h1
	simple_if_init $h2
	simple_if_init $h3

	ip link add name br1 type bridge vlan_filtering 1
	ip link set dev br1 addrgenmode none
	ip link set dev br1 up

	ip link set dev $swp1 master br1
	ip link set dev $swp1 up
	tc qdisc add dev $swp1 clsact

	ip link set dev $swp2 master br1
	ip link set dev $swp2 up

	ip link set dev $swp3 up
}

mirror_gre_cleanup()
{
	mirror_gre_tunnels_destroy $mirror_gre_tunnels

	ip link set dev $swp3 down

	ip link set dev $swp2 down

	tc qdisc del dev $swp1 clsact
	ip link set dev $swp1 down

	ip link del dev br1

	simple_if_fini $h3
	simple_if_fini $h2
	simple_if_fini $h1

	vrf_cleanup
}