blob: 43ce049996eeb5b4d81394705861a3f11715d3b4 [file] [log] [blame]
William Tu6afb1e22016-08-19 11:55:44 -07001#!/bin/bash
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01002# SPDX-License-Identifier: GPL-2.0
William Tu6afb1e22016-08-19 11:55:44 -07003# In Namespace 0 (at_ns0) using native tunnel
4# Overlay IP: 10.1.1.100
5# local 192.16.1.100 remote 192.16.1.200
6# veth0 IP: 172.16.1.100, tunnel dev <type>00
7
8# Out of Namespace using BPF set/get on lwtunnel
9# Overlay IP: 10.1.1.200
10# local 172.16.1.200 remote 172.16.1.100
11# veth1 IP: 172.16.1.200, tunnel dev <type>11
12
William Tu6afb1e22016-08-19 11:55:44 -070013function config_device {
14 ip netns add at_ns0
15 ip link add veth0 type veth peer name veth1
16 ip link set veth0 netns at_ns0
17 ip netns exec at_ns0 ip addr add 172.16.1.100/24 dev veth0
18 ip netns exec at_ns0 ip link set dev veth0 up
Alexei Starovoitova1c82702016-09-15 13:00:31 -070019 ip link set dev veth1 up mtu 1500
William Tu6afb1e22016-08-19 11:55:44 -070020 ip addr add dev veth1 172.16.1.200/24
21}
22
23function add_gre_tunnel {
24 # in namespace
25 ip netns exec at_ns0 \
26 ip link add dev $DEV_NS type $TYPE key 2 local 172.16.1.100 remote 172.16.1.200
27 ip netns exec at_ns0 ip link set dev $DEV_NS up
28 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
29
30 # out of namespace
31 ip link add dev $DEV type $TYPE key 2 external
32 ip link set dev $DEV up
33 ip addr add dev $DEV 10.1.1.200/24
34}
35
William Tu56ddd302017-12-01 15:26:10 -080036function add_ip6gretap_tunnel {
37
38 # assign ipv6 address
39 ip netns exec at_ns0 ip addr add ::11/96 dev veth0
40 ip netns exec at_ns0 ip link set dev veth0 up
41 ip addr add dev veth1 ::22/96
42 ip link set dev veth1 up
43
44 # in namespace
45 ip netns exec at_ns0 \
46 ip link add dev $DEV_NS type $TYPE flowlabel 0xbcdef key 2 \
47 local ::11 remote ::22
48
49 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
50 ip netns exec at_ns0 ip addr add dev $DEV_NS fc80::100/96
51 ip netns exec at_ns0 ip link set dev $DEV_NS up
52
53 # out of namespace
54 ip link add dev $DEV type $TYPE external
55 ip addr add dev $DEV 10.1.1.200/24
56 ip addr add dev $DEV fc80::200/24
57 ip link set dev $DEV up
58}
59
William Tuef88f892017-08-25 09:21:29 -070060function add_erspan_tunnel {
61 # in namespace
William Tuac80c2a2017-12-13 16:38:58 -080062 if [ "$1" == "v1" ]; then
63 ip netns exec at_ns0 \
64 ip link add dev $DEV_NS type $TYPE seq key 2 \
65 local 172.16.1.100 remote 172.16.1.200 \
66 erspan_ver 1 erspan 123
67 else
68 ip netns exec at_ns0 \
69 ip link add dev $DEV_NS type $TYPE seq key 2 \
70 local 172.16.1.100 remote 172.16.1.200 \
William Tu9c33ca42018-02-05 13:35:36 -080071 erspan_ver 2 erspan_dir egress erspan_hwid 3
William Tuac80c2a2017-12-13 16:38:58 -080072 fi
William Tuef88f892017-08-25 09:21:29 -070073 ip netns exec at_ns0 ip link set dev $DEV_NS up
74 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
75
76 # out of namespace
77 ip link add dev $DEV type $TYPE external
78 ip link set dev $DEV up
79 ip addr add dev $DEV 10.1.1.200/24
80}
81
William Tud37e3bb2017-12-05 15:15:45 -080082function add_ip6erspan_tunnel {
83
84 # assign ipv6 address
85 ip netns exec at_ns0 ip addr add ::11/96 dev veth0
86 ip netns exec at_ns0 ip link set dev veth0 up
87 ip addr add dev veth1 ::22/96
88 ip link set dev veth1 up
89
90 # in namespace
William Tuac80c2a2017-12-13 16:38:58 -080091 if [ "$1" == "v1" ]; then
92 ip netns exec at_ns0 \
93 ip link add dev $DEV_NS type $TYPE seq key 2 \
94 local ::11 remote ::22 \
95 erspan_ver 1 erspan 123
96 else
97 ip netns exec at_ns0 \
98 ip link add dev $DEV_NS type $TYPE seq key 2 \
99 local ::11 remote ::22 \
William Tu9c33ca42018-02-05 13:35:36 -0800100 erspan_ver 2 erspan_dir egress erspan_hwid 7
William Tuac80c2a2017-12-13 16:38:58 -0800101 fi
William Tud37e3bb2017-12-05 15:15:45 -0800102 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
103 ip netns exec at_ns0 ip link set dev $DEV_NS up
104
105 # out of namespace
106 ip link add dev $DEV type $TYPE external
107 ip addr add dev $DEV 10.1.1.200/24
108 ip link set dev $DEV up
109}
110
William Tu6afb1e22016-08-19 11:55:44 -0700111function add_vxlan_tunnel {
112 # Set static ARP entry here because iptables set-mark works
113 # on L3 packet, as a result not applying to ARP packets,
114 # causing errors at get_tunnel_{key/opt}.
115
116 # in namespace
117 ip netns exec at_ns0 \
118 ip link add dev $DEV_NS type $TYPE id 2 dstport 4789 gbp remote 172.16.1.200
119 ip netns exec at_ns0 ip link set dev $DEV_NS address 52:54:00:d9:01:00 up
120 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
121 ip netns exec at_ns0 arp -s 10.1.1.200 52:54:00:d9:02:00
122 ip netns exec at_ns0 iptables -A OUTPUT -j MARK --set-mark 0x800FF
123
124 # out of namespace
125 ip link add dev $DEV type $TYPE external gbp dstport 4789
126 ip link set dev $DEV address 52:54:00:d9:02:00 up
127 ip addr add dev $DEV 10.1.1.200/24
128 arp -s 10.1.1.100 52:54:00:d9:01:00
129}
130
131function add_geneve_tunnel {
132 # in namespace
133 ip netns exec at_ns0 \
134 ip link add dev $DEV_NS type $TYPE id 2 dstport 6081 remote 172.16.1.200
135 ip netns exec at_ns0 ip link set dev $DEV_NS up
136 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
137
138 # out of namespace
139 ip link add dev $DEV type $TYPE dstport 6081 external
140 ip link set dev $DEV up
141 ip addr add dev $DEV 10.1.1.200/24
142}
143
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700144function add_ipip_tunnel {
145 # in namespace
146 ip netns exec at_ns0 \
147 ip link add dev $DEV_NS type $TYPE local 172.16.1.100 remote 172.16.1.200
148 ip netns exec at_ns0 ip link set dev $DEV_NS up
149 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
150
151 # out of namespace
152 ip link add dev $DEV type $TYPE external
153 ip link set dev $DEV up
154 ip addr add dev $DEV 10.1.1.200/24
155}
156
William Tu6afb1e22016-08-19 11:55:44 -0700157function attach_bpf {
158 DEV=$1
159 SET_TUNNEL=$2
160 GET_TUNNEL=$3
161 tc qdisc add dev $DEV clsact
162 tc filter add dev $DEV egress bpf da obj tcbpf2_kern.o sec $SET_TUNNEL
163 tc filter add dev $DEV ingress bpf da obj tcbpf2_kern.o sec $GET_TUNNEL
164}
165
166function test_gre {
167 TYPE=gretap
168 DEV_NS=gretap00
169 DEV=gretap11
170 config_device
171 add_gre_tunnel
172 attach_bpf $DEV gre_set_tunnel gre_get_tunnel
173 ping -c 1 10.1.1.100
174 ip netns exec at_ns0 ping -c 1 10.1.1.200
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700175 cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700176}
177
William Tu56ddd302017-12-01 15:26:10 -0800178function test_ip6gre {
179 TYPE=ip6gre
180 DEV_NS=ip6gre00
181 DEV=ip6gre11
182 config_device
183 # reuse the ip6gretap function
184 add_ip6gretap_tunnel
185 attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
186 # underlay
187 ping6 -c 4 ::11
188 # overlay: ipv4 over ipv6
189 ip netns exec at_ns0 ping -c 1 10.1.1.200
190 ping -c 1 10.1.1.100
191 # overlay: ipv6 over ipv6
192 ip netns exec at_ns0 ping6 -c 1 fc80::200
193 cleanup
194}
195
196function test_ip6gretap {
197 TYPE=ip6gretap
198 DEV_NS=ip6gretap00
199 DEV=ip6gretap11
200 config_device
201 add_ip6gretap_tunnel
202 attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
203 # underlay
204 ping6 -c 4 ::11
205 # overlay: ipv4 over ipv6
206 ip netns exec at_ns0 ping -i .2 -c 1 10.1.1.200
207 ping -c 1 10.1.1.100
208 # overlay: ipv6 over ipv6
209 ip netns exec at_ns0 ping6 -c 1 fc80::200
210 cleanup
211}
212
William Tuef88f892017-08-25 09:21:29 -0700213function test_erspan {
214 TYPE=erspan
215 DEV_NS=erspan00
216 DEV=erspan11
217 config_device
William Tuac80c2a2017-12-13 16:38:58 -0800218 add_erspan_tunnel $1
William Tuef88f892017-08-25 09:21:29 -0700219 attach_bpf $DEV erspan_set_tunnel erspan_get_tunnel
220 ping -c 1 10.1.1.100
221 ip netns exec at_ns0 ping -c 1 10.1.1.200
222 cleanup
223}
224
William Tud37e3bb2017-12-05 15:15:45 -0800225function test_ip6erspan {
226 TYPE=ip6erspan
227 DEV_NS=ip6erspan00
228 DEV=ip6erspan11
229 config_device
William Tuac80c2a2017-12-13 16:38:58 -0800230 add_ip6erspan_tunnel $1
William Tud37e3bb2017-12-05 15:15:45 -0800231 attach_bpf $DEV ip4ip6erspan_set_tunnel ip4ip6erspan_get_tunnel
232 ping6 -c 3 ::11
233 ip netns exec at_ns0 ping -c 1 10.1.1.200
234 cleanup
235}
236
William Tu6afb1e22016-08-19 11:55:44 -0700237function test_vxlan {
238 TYPE=vxlan
239 DEV_NS=vxlan00
240 DEV=vxlan11
241 config_device
242 add_vxlan_tunnel
243 attach_bpf $DEV vxlan_set_tunnel vxlan_get_tunnel
244 ping -c 1 10.1.1.100
245 ip netns exec at_ns0 ping -c 1 10.1.1.200
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700246 cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700247}
248
249function test_geneve {
250 TYPE=geneve
251 DEV_NS=geneve00
252 DEV=geneve11
253 config_device
254 add_geneve_tunnel
255 attach_bpf $DEV geneve_set_tunnel geneve_get_tunnel
256 ping -c 1 10.1.1.100
257 ip netns exec at_ns0 ping -c 1 10.1.1.200
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700258 cleanup
259}
260
261function test_ipip {
262 TYPE=ipip
263 DEV_NS=ipip00
264 DEV=ipip11
265 config_device
266 tcpdump -nei veth1 &
267 cat /sys/kernel/debug/tracing/trace_pipe &
268 add_ipip_tunnel
269 ethtool -K veth1 gso off gro off rx off tx off
270 ip link set dev veth1 mtu 1500
271 attach_bpf $DEV ipip_set_tunnel ipip_get_tunnel
272 ping -c 1 10.1.1.100
273 ip netns exec at_ns0 ping -c 1 10.1.1.200
274 ip netns exec at_ns0 iperf -sD -p 5200 > /dev/null
275 sleep 0.2
276 iperf -c 10.1.1.100 -n 5k -p 5200
277 cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700278}
279
280function cleanup {
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700281 set +ex
282 pkill iperf
William Tu6afb1e22016-08-19 11:55:44 -0700283 ip netns delete at_ns0
284 ip link del veth1
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700285 ip link del ipip11
286 ip link del gretap11
William Tu56ddd302017-12-01 15:26:10 -0800287 ip link del ip6gre11
288 ip link del ip6gretap11
William Tucc75f852017-07-31 14:40:50 -0700289 ip link del vxlan11
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700290 ip link del geneve11
William Tuef88f892017-08-25 09:21:29 -0700291 ip link del erspan11
William Tud37e3bb2017-12-05 15:15:45 -0800292 ip link del ip6erspan11
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700293 pkill tcpdump
294 pkill cat
295 set -ex
William Tu6afb1e22016-08-19 11:55:44 -0700296}
297
William Tuef88f892017-08-25 09:21:29 -0700298trap cleanup 0 2 3 6 9
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700299cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700300echo "Testing GRE tunnel..."
301test_gre
William Tu56ddd302017-12-01 15:26:10 -0800302echo "Testing IP6GRE tunnel..."
303test_ip6gre
304echo "Testing IP6GRETAP tunnel..."
305test_ip6gretap
William Tuef88f892017-08-25 09:21:29 -0700306echo "Testing ERSPAN tunnel..."
William Tuac80c2a2017-12-13 16:38:58 -0800307test_erspan v1
308test_erspan v2
William Tud37e3bb2017-12-05 15:15:45 -0800309echo "Testing IP6ERSPAN tunnel..."
William Tuac80c2a2017-12-13 16:38:58 -0800310test_ip6erspan v1
311test_ip6erspan v2
William Tu6afb1e22016-08-19 11:55:44 -0700312echo "Testing VXLAN tunnel..."
313test_vxlan
William Tu6afb1e22016-08-19 11:55:44 -0700314echo "Testing GENEVE tunnel..."
315test_geneve
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700316echo "Testing IPIP tunnel..."
317test_ipip
318echo "*** PASS ***"