blob: 410052d9fc37088ccce56123dc746d56957d9124 [file] [log] [blame]
William Tu6afb1e22016-08-19 11:55:44 -07001#!/bin/bash
2# In Namespace 0 (at_ns0) using native tunnel
3# Overlay IP: 10.1.1.100
4# local 192.16.1.100 remote 192.16.1.200
5# veth0 IP: 172.16.1.100, tunnel dev <type>00
6
7# Out of Namespace using BPF set/get on lwtunnel
8# Overlay IP: 10.1.1.200
9# local 172.16.1.200 remote 172.16.1.100
10# veth1 IP: 172.16.1.200, tunnel dev <type>11
11
William Tu6afb1e22016-08-19 11:55:44 -070012function config_device {
13 ip netns add at_ns0
14 ip link add veth0 type veth peer name veth1
15 ip link set veth0 netns at_ns0
16 ip netns exec at_ns0 ip addr add 172.16.1.100/24 dev veth0
17 ip netns exec at_ns0 ip link set dev veth0 up
Alexei Starovoitova1c82702016-09-15 13:00:31 -070018 ip link set dev veth1 up mtu 1500
William Tu6afb1e22016-08-19 11:55:44 -070019 ip addr add dev veth1 172.16.1.200/24
20}
21
22function add_gre_tunnel {
23 # in namespace
24 ip netns exec at_ns0 \
25 ip link add dev $DEV_NS type $TYPE key 2 local 172.16.1.100 remote 172.16.1.200
26 ip netns exec at_ns0 ip link set dev $DEV_NS up
27 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
28
29 # out of namespace
30 ip link add dev $DEV type $TYPE key 2 external
31 ip link set dev $DEV up
32 ip addr add dev $DEV 10.1.1.200/24
33}
34
William Tuef88f892017-08-25 09:21:29 -070035function add_erspan_tunnel {
36 # in namespace
37 ip netns exec at_ns0 \
38 ip link add dev $DEV_NS type $TYPE seq key 2 local 172.16.1.100 remote 172.16.1.200 erspan 123
39 ip netns exec at_ns0 ip link set dev $DEV_NS up
40 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
41
42 # out of namespace
43 ip link add dev $DEV type $TYPE external
44 ip link set dev $DEV up
45 ip addr add dev $DEV 10.1.1.200/24
46}
47
William Tu6afb1e22016-08-19 11:55:44 -070048function add_vxlan_tunnel {
49 # Set static ARP entry here because iptables set-mark works
50 # on L3 packet, as a result not applying to ARP packets,
51 # causing errors at get_tunnel_{key/opt}.
52
53 # in namespace
54 ip netns exec at_ns0 \
55 ip link add dev $DEV_NS type $TYPE id 2 dstport 4789 gbp remote 172.16.1.200
56 ip netns exec at_ns0 ip link set dev $DEV_NS address 52:54:00:d9:01:00 up
57 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
58 ip netns exec at_ns0 arp -s 10.1.1.200 52:54:00:d9:02:00
59 ip netns exec at_ns0 iptables -A OUTPUT -j MARK --set-mark 0x800FF
60
61 # out of namespace
62 ip link add dev $DEV type $TYPE external gbp dstport 4789
63 ip link set dev $DEV address 52:54:00:d9:02:00 up
64 ip addr add dev $DEV 10.1.1.200/24
65 arp -s 10.1.1.100 52:54:00:d9:01:00
66}
67
68function add_geneve_tunnel {
69 # in namespace
70 ip netns exec at_ns0 \
71 ip link add dev $DEV_NS type $TYPE id 2 dstport 6081 remote 172.16.1.200
72 ip netns exec at_ns0 ip link set dev $DEV_NS up
73 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
74
75 # out of namespace
76 ip link add dev $DEV type $TYPE dstport 6081 external
77 ip link set dev $DEV up
78 ip addr add dev $DEV 10.1.1.200/24
79}
80
Alexei Starovoitova1c82702016-09-15 13:00:31 -070081function add_ipip_tunnel {
82 # in namespace
83 ip netns exec at_ns0 \
84 ip link add dev $DEV_NS type $TYPE local 172.16.1.100 remote 172.16.1.200
85 ip netns exec at_ns0 ip link set dev $DEV_NS up
86 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
87
88 # out of namespace
89 ip link add dev $DEV type $TYPE external
90 ip link set dev $DEV up
91 ip addr add dev $DEV 10.1.1.200/24
92}
93
William Tu6afb1e22016-08-19 11:55:44 -070094function attach_bpf {
95 DEV=$1
96 SET_TUNNEL=$2
97 GET_TUNNEL=$3
98 tc qdisc add dev $DEV clsact
99 tc filter add dev $DEV egress bpf da obj tcbpf2_kern.o sec $SET_TUNNEL
100 tc filter add dev $DEV ingress bpf da obj tcbpf2_kern.o sec $GET_TUNNEL
101}
102
103function test_gre {
104 TYPE=gretap
105 DEV_NS=gretap00
106 DEV=gretap11
107 config_device
108 add_gre_tunnel
109 attach_bpf $DEV gre_set_tunnel gre_get_tunnel
110 ping -c 1 10.1.1.100
111 ip netns exec at_ns0 ping -c 1 10.1.1.200
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700112 cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700113}
114
William Tuef88f892017-08-25 09:21:29 -0700115function test_erspan {
116 TYPE=erspan
117 DEV_NS=erspan00
118 DEV=erspan11
119 config_device
120 add_erspan_tunnel
121 attach_bpf $DEV erspan_set_tunnel erspan_get_tunnel
122 ping -c 1 10.1.1.100
123 ip netns exec at_ns0 ping -c 1 10.1.1.200
124 cleanup
125}
126
William Tu6afb1e22016-08-19 11:55:44 -0700127function test_vxlan {
128 TYPE=vxlan
129 DEV_NS=vxlan00
130 DEV=vxlan11
131 config_device
132 add_vxlan_tunnel
133 attach_bpf $DEV vxlan_set_tunnel vxlan_get_tunnel
134 ping -c 1 10.1.1.100
135 ip netns exec at_ns0 ping -c 1 10.1.1.200
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700136 cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700137}
138
139function test_geneve {
140 TYPE=geneve
141 DEV_NS=geneve00
142 DEV=geneve11
143 config_device
144 add_geneve_tunnel
145 attach_bpf $DEV geneve_set_tunnel geneve_get_tunnel
146 ping -c 1 10.1.1.100
147 ip netns exec at_ns0 ping -c 1 10.1.1.200
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700148 cleanup
149}
150
151function test_ipip {
152 TYPE=ipip
153 DEV_NS=ipip00
154 DEV=ipip11
155 config_device
156 tcpdump -nei veth1 &
157 cat /sys/kernel/debug/tracing/trace_pipe &
158 add_ipip_tunnel
159 ethtool -K veth1 gso off gro off rx off tx off
160 ip link set dev veth1 mtu 1500
161 attach_bpf $DEV ipip_set_tunnel ipip_get_tunnel
162 ping -c 1 10.1.1.100
163 ip netns exec at_ns0 ping -c 1 10.1.1.200
164 ip netns exec at_ns0 iperf -sD -p 5200 > /dev/null
165 sleep 0.2
166 iperf -c 10.1.1.100 -n 5k -p 5200
167 cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700168}
169
170function cleanup {
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700171 set +ex
172 pkill iperf
William Tu6afb1e22016-08-19 11:55:44 -0700173 ip netns delete at_ns0
174 ip link del veth1
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700175 ip link del ipip11
176 ip link del gretap11
William Tucc75f852017-07-31 14:40:50 -0700177 ip link del vxlan11
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700178 ip link del geneve11
William Tuef88f892017-08-25 09:21:29 -0700179 ip link del erspan11
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700180 pkill tcpdump
181 pkill cat
182 set -ex
William Tu6afb1e22016-08-19 11:55:44 -0700183}
184
William Tuef88f892017-08-25 09:21:29 -0700185trap cleanup 0 2 3 6 9
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700186cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700187echo "Testing GRE tunnel..."
188test_gre
William Tuef88f892017-08-25 09:21:29 -0700189echo "Testing ERSPAN tunnel..."
190test_erspan
William Tu6afb1e22016-08-19 11:55:44 -0700191echo "Testing VXLAN tunnel..."
192test_vxlan
William Tu6afb1e22016-08-19 11:55:44 -0700193echo "Testing GENEVE tunnel..."
194test_geneve
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700195echo "Testing IPIP tunnel..."
196test_ipip
197echo "*** PASS ***"