William Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 1 | #!/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 Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 12 | function 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 Starovoitov | a1c8270 | 2016-09-15 13:00:31 -0700 | [diff] [blame] | 18 | ip link set dev veth1 up mtu 1500 |
William Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 19 | ip addr add dev veth1 172.16.1.200/24 |
| 20 | } |
| 21 | |
| 22 | function 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 Tu | ef88f89 | 2017-08-25 09:21:29 -0700 | [diff] [blame] | 35 | function 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 Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 48 | function 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 | |
| 68 | function 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 Starovoitov | a1c8270 | 2016-09-15 13:00:31 -0700 | [diff] [blame] | 81 | function 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 Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 94 | function 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 | |
| 103 | function 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 Starovoitov | a1c8270 | 2016-09-15 13:00:31 -0700 | [diff] [blame] | 112 | cleanup |
William Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 113 | } |
| 114 | |
William Tu | ef88f89 | 2017-08-25 09:21:29 -0700 | [diff] [blame] | 115 | function 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 Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 127 | function 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 Starovoitov | a1c8270 | 2016-09-15 13:00:31 -0700 | [diff] [blame] | 136 | cleanup |
William Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | function 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 Starovoitov | a1c8270 | 2016-09-15 13:00:31 -0700 | [diff] [blame] | 148 | cleanup |
| 149 | } |
| 150 | |
| 151 | function 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 Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | function cleanup { |
Alexei Starovoitov | a1c8270 | 2016-09-15 13:00:31 -0700 | [diff] [blame] | 171 | set +ex |
| 172 | pkill iperf |
William Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 173 | ip netns delete at_ns0 |
| 174 | ip link del veth1 |
Alexei Starovoitov | a1c8270 | 2016-09-15 13:00:31 -0700 | [diff] [blame] | 175 | ip link del ipip11 |
| 176 | ip link del gretap11 |
William Tu | cc75f85 | 2017-07-31 14:40:50 -0700 | [diff] [blame] | 177 | ip link del vxlan11 |
Alexei Starovoitov | a1c8270 | 2016-09-15 13:00:31 -0700 | [diff] [blame] | 178 | ip link del geneve11 |
William Tu | ef88f89 | 2017-08-25 09:21:29 -0700 | [diff] [blame] | 179 | ip link del erspan11 |
Alexei Starovoitov | a1c8270 | 2016-09-15 13:00:31 -0700 | [diff] [blame] | 180 | pkill tcpdump |
| 181 | pkill cat |
| 182 | set -ex |
William Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 183 | } |
| 184 | |
William Tu | ef88f89 | 2017-08-25 09:21:29 -0700 | [diff] [blame] | 185 | trap cleanup 0 2 3 6 9 |
Alexei Starovoitov | a1c8270 | 2016-09-15 13:00:31 -0700 | [diff] [blame] | 186 | cleanup |
William Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 187 | echo "Testing GRE tunnel..." |
| 188 | test_gre |
William Tu | ef88f89 | 2017-08-25 09:21:29 -0700 | [diff] [blame] | 189 | echo "Testing ERSPAN tunnel..." |
| 190 | test_erspan |
William Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 191 | echo "Testing VXLAN tunnel..." |
| 192 | test_vxlan |
William Tu | 6afb1e2 | 2016-08-19 11:55:44 -0700 | [diff] [blame] | 193 | echo "Testing GENEVE tunnel..." |
| 194 | test_geneve |
Alexei Starovoitov | a1c8270 | 2016-09-15 13:00:31 -0700 | [diff] [blame] | 195 | echo "Testing IPIP tunnel..." |
| 196 | test_ipip |
| 197 | echo "*** PASS ***" |