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
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
12 function config_device
{
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
18 ip link
set dev veth1 up mtu
1500
19 ip addr add dev veth1
172.16.1.200/24
22 function add_gre_tunnel
{
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
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
35 function add_vxlan_tunnel
{
36 # Set static ARP entry here because iptables set-mark works
37 # on L3 packet, as a result not applying to ARP packets,
38 # causing errors at get_tunnel_{key/opt}.
41 ip netns
exec at_ns0 \
42 ip link add dev
$DEV_NS type $TYPE id
2 dstport
4789 gbp remote
172.16.1.200
43 ip netns
exec at_ns0 ip link
set dev
$DEV_NS address
52:54:00:d9
:01:00 up
44 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
45 ip netns
exec at_ns0 arp
-s 10.1.1.200 52:54:00:d9
:02:00
46 ip netns
exec at_ns0 iptables
-A OUTPUT
-j MARK
--set-mark 0x800FF
49 ip link add dev
$DEV type $TYPE external gbp dstport
4789
50 ip link
set dev
$DEV address
52:54:00:d9
:02:00 up
51 ip addr add dev
$DEV 10.1.1.200/24
52 arp
-s 10.1.1.100 52:54:00:d9
:01:00
55 function add_geneve_tunnel
{
57 ip netns
exec at_ns0 \
58 ip link add dev
$DEV_NS type $TYPE id
2 dstport
6081 remote
172.16.1.200
59 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
60 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
63 ip link add dev
$DEV type $TYPE dstport
6081 external
64 ip link
set dev
$DEV up
65 ip addr add dev
$DEV 10.1.1.200/24
68 function add_ipip_tunnel
{
70 ip netns
exec at_ns0 \
71 ip link add dev
$DEV_NS type $TYPE local 172.16.1.100 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
76 ip link add dev
$DEV type $TYPE external
77 ip link
set dev
$DEV up
78 ip addr add dev
$DEV 10.1.1.200/24
85 tc qdisc add dev
$DEV clsact
86 tc filter add dev
$DEV egress bpf da obj tcbpf2_kern.o sec
$SET_TUNNEL
87 tc filter add dev
$DEV ingress bpf da obj tcbpf2_kern.o sec
$GET_TUNNEL
96 attach_bpf
$DEV gre_set_tunnel gre_get_tunnel
98 ip netns
exec at_ns0
ping -c 1 10.1.1.200
102 function test_vxlan
{
108 attach_bpf
$DEV vxlan_set_tunnel vxlan_get_tunnel
110 ip netns
exec at_ns0
ping -c 1 10.1.1.200
114 function test_geneve
{
120 attach_bpf
$DEV geneve_set_tunnel geneve_get_tunnel
122 ip netns
exec at_ns0
ping -c 1 10.1.1.200
132 cat /sys
/kernel
/debug
/tracing
/trace_pipe
&
134 ethtool
-K veth1 gso off gro off rx off tx off
135 ip link
set dev veth1 mtu
1500
136 attach_bpf
$DEV ipip_set_tunnel ipip_get_tunnel
138 ip netns
exec at_ns0
ping -c 1 10.1.1.200
139 ip netns
exec at_ns0 iperf
-sD -p 5200 > /dev
/null
141 iperf
-c 10.1.1.100 -n 5k
-p 5200
148 ip netns delete at_ns0
159 echo "Testing GRE tunnel..."
161 echo "Testing VXLAN tunnel..."
163 echo "Testing GENEVE tunnel..."
165 echo "Testing IPIP tunnel..."