ip6gre_inner_v4_multipath.sh (7956B)
1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4# Test traffic distribution when there are multiple routes between an IPv6 5# GRE tunnel. The tunnel carries IPv4 traffic between multiple hosts. 6# Multiple routes are in the underlay network. With the default multipath 7# policy, SW2 will only look at the outer IP addresses, hence only a single 8# route would be used. 9# 10# +-------------------------+ 11# | H1 | 12# | $h1 + | 13# | 192.0.3.{2-62}/24 | | 14# +-------------------|-----+ 15# | 16# +-------------------|-------------------------+ 17# | SW1 | | 18# | $ol1 + | 19# | 192.0.3.1/24 | 20# | | 21# | + g1 (gre) | 22# | loc=2001:db8:40::1 | 23# | rem=2001:db8:40::2 --. | 24# | tos=inherit | | 25# | v | 26# | + $ul1 | 27# | | 2001:db8:80::1/64 | 28# +-------------------------|-------------------+ 29# | 30# +-------------------------|-------------------+ 31# | SW2 | | 32# | $ul21 + | 33# | 2001:db8:80::2/64 | 34# | | | 35# ! ________________|_____ | 36# | / \ | 37# | | | | 38# | + $ul22.111 (vlan) + $ul22.222 (vlan) | 39# | | 2001:db8:81::1/64 | 2001:db8:82::1/64 | 40# | | | | 41# +--|----------------------|-------------------+ 42# | | 43# +--|----------------------|-------------------+ 44# | | | | 45# | + $ul32.111 (vlan) + $ul32.222 (vlan) | 46# | | 2001:db8:81::2/64 | 2001:db8:82::2/64 | 47# | | | | 48# | \______________________/ | 49# | | | 50# | | | 51# | $ul31 + | 52# | 2001:db8:83::2/64 | SW3 | 53# +-------------------------|-------------------+ 54# | 55# +-------------------------|-------------------+ 56# | + $ul4 | 57# | ^ 2001:db8:83::1/64 | 58# | + g2 (gre) | | 59# | loc=2001:db8:40::2 | | 60# | rem=2001:db8:40::1 --' | 61# | tos=inherit | 62# | | 63# | $ol4 + | 64# | 192.0.4.1/24 | SW4 | 65# +--------------------|------------------------+ 66# | 67# +--------------------|---------+ 68# | | | 69# | $h2 + | 70# | 192.0.4.{2-62}/24 H2 | 71# +------------------------------+ 72 73ALL_TESTS=" 74 ping_ipv4 75 multipath_ipv4 76" 77 78NUM_NETIFS=10 79source lib.sh 80 81h1_create() 82{ 83 simple_if_init $h1 192.0.3.2/24 84 ip route add vrf v$h1 192.0.4.0/24 via 192.0.3.1 85} 86 87h1_destroy() 88{ 89 ip route del vrf v$h1 192.0.4.0/24 via 192.0.3.1 90 simple_if_fini $h1 192.0.3.2/24 91} 92 93sw1_create() 94{ 95 simple_if_init $ol1 192.0.3.1/24 96 __simple_if_init $ul1 v$ol1 2001:db8:80::1/64 97 98 tunnel_create g1 ip6gre 2001:db8:40::1 2001:db8:40::2 tos inherit dev v$ol1 99 __simple_if_init g1 v$ol1 2001:db8:40::1/128 100 ip -6 route add vrf v$ol1 2001:db8:40::2/128 via 2001:db8:80::2 101 102 ip route add vrf v$ol1 192.0.4.0/24 nexthop dev g1 103} 104 105sw1_destroy() 106{ 107 ip route del vrf v$ol1 192.0.4.0/24 108 109 ip -6 route del vrf v$ol1 2001:db8:40::2/128 110 __simple_if_fini g1 2001:db8:40::1/128 111 tunnel_destroy g1 112 113 __simple_if_fini $ul1 2001:db8:80::1/64 114 simple_if_fini $ol1 192.0.3.1/24 115} 116 117sw2_create() 118{ 119 simple_if_init $ul21 2001:db8:80::2/64 120 __simple_if_init $ul22 v$ul21 121 vlan_create $ul22 111 v$ul21 2001:db8:81::1/64 122 vlan_create $ul22 222 v$ul21 2001:db8:82::1/64 123 124 ip -6 route add vrf v$ul21 2001:db8:40::1/128 via 2001:db8:80::1 125 ip -6 route add vrf v$ul21 2001:db8:40::2/128 \ 126 nexthop via 2001:db8:81::2 \ 127 nexthop via 2001:db8:82::2 128} 129 130sw2_destroy() 131{ 132 ip -6 route del vrf v$ul21 2001:db8:40::2/128 133 ip -6 route del vrf v$ul21 2001:db8:40::1/128 134 135 vlan_destroy $ul22 222 136 vlan_destroy $ul22 111 137 __simple_if_fini $ul22 138 simple_if_fini $ul21 2001:db8:80::2/64 139} 140 141sw3_create() 142{ 143 simple_if_init $ul31 2001:db8:83::2/64 144 __simple_if_init $ul32 v$ul31 145 vlan_create $ul32 111 v$ul31 2001:db8:81::2/64 146 vlan_create $ul32 222 v$ul31 2001:db8:82::2/64 147 148 ip -6 route add vrf v$ul31 2001:db8:40::2/128 via 2001:db8:83::1 149 ip -6 route add vrf v$ul31 2001:db8:40::1/128 \ 150 nexthop via 2001:db8:81::1 \ 151 nexthop via 2001:db8:82::1 152 153 tc qdisc add dev $ul32 clsact 154 tc filter add dev $ul32 ingress pref 111 prot 802.1Q \ 155 flower vlan_id 111 action pass 156 tc filter add dev $ul32 ingress pref 222 prot 802.1Q \ 157 flower vlan_id 222 action pass 158} 159 160sw3_destroy() 161{ 162 tc qdisc del dev $ul32 clsact 163 164 ip -6 route del vrf v$ul31 2001:db8:40::1/128 165 ip -6 route del vrf v$ul31 2001:db8:40::2/128 166 167 vlan_destroy $ul32 222 168 vlan_destroy $ul32 111 169 __simple_if_fini $ul32 170 simple_if_fini $ul31 2001:Db8:83::2/64 171} 172 173sw4_create() 174{ 175 simple_if_init $ol4 192.0.4.1/24 176 __simple_if_init $ul4 v$ol4 2001:db8:83::1/64 177 178 tunnel_create g2 ip6gre 2001:db8:40::2 2001:db8:40::1 tos inherit dev v$ol4 179 __simple_if_init g2 v$ol4 2001:db8:40::2/128 180 ip -6 route add vrf v$ol4 2001:db8:40::1/128 via 2001:db8:83::2 181 182 ip route add vrf v$ol4 192.0.3.0/24 nexthop dev g2 183} 184 185sw4_destroy() 186{ 187 ip route del vrf v$ol4 192.0.3.0/24 188 189 ip -6 route del vrf v$ol4 2001:db8:40::1/128 190 __simple_if_fini g2 2001:db8:40::2/128 191 tunnel_destroy g2 192 193 __simple_if_fini $ul4 2001:db8:83::1/64 194 simple_if_fini $ol4 192.0.4.1/24 195} 196 197h2_create() 198{ 199 simple_if_init $h2 192.0.4.2/24 200 ip route add vrf v$h2 192.0.3.0/24 via 192.0.4.1 201} 202 203h2_destroy() 204{ 205 ip route del vrf v$h2 192.0.3.0/24 via 192.0.4.1 206 simple_if_fini $h2 192.0.4.2/24 207} 208 209setup_prepare() 210{ 211 h1=${NETIFS[p1]} 212 213 ol1=${NETIFS[p2]} 214 ul1=${NETIFS[p3]} 215 216 ul21=${NETIFS[p4]} 217 ul22=${NETIFS[p5]} 218 219 ul32=${NETIFS[p6]} 220 ul31=${NETIFS[p7]} 221 222 ul4=${NETIFS[p8]} 223 ol4=${NETIFS[p9]} 224 225 h2=${NETIFS[p10]} 226 227 vrf_prepare 228 h1_create 229 sw1_create 230 sw2_create 231 sw3_create 232 sw4_create 233 h2_create 234 235 forwarding_enable 236} 237 238cleanup() 239{ 240 pre_cleanup 241 242 forwarding_restore 243 244 h2_destroy 245 sw4_destroy 246 sw3_destroy 247 sw2_destroy 248 sw1_destroy 249 h1_destroy 250 vrf_cleanup 251} 252 253multipath4_test() 254{ 255 local what=$1; shift 256 local weight1=$1; shift 257 local weight2=$1; shift 258 259 sysctl_set net.ipv6.fib_multipath_hash_policy 2 260 ip route replace vrf v$ul21 2001:db8:40::2/128 \ 261 nexthop via 2001:db8:81::2 weight $weight1 \ 262 nexthop via 2001:db8:82::2 weight $weight2 263 264 local t0_111=$(tc_rule_stats_get $ul32 111 ingress) 265 local t0_222=$(tc_rule_stats_get $ul32 222 ingress) 266 267 ip vrf exec v$h1 \ 268 $MZ $h1 -q -p 64 -A "192.0.3.2-192.0.3.62" -B "192.0.4.2-192.0.4.62" \ 269 -d 1msec -c 50 -t udp "sp=1024,dp=1024" 270 sleep 1 271 272 local t1_111=$(tc_rule_stats_get $ul32 111 ingress) 273 local t1_222=$(tc_rule_stats_get $ul32 222 ingress) 274 275 local d111=$((t1_111 - t0_111)) 276 local d222=$((t1_222 - t0_222)) 277 multipath_eval "$what" $weight1 $weight2 $d111 $d222 278 279 ip route replace vrf v$ul21 2001:db8:40::2/128 \ 280 nexthop via 2001:db8:81::2 \ 281 nexthop via 2001:db8:82::2 282 sysctl_restore net.ipv6.fib_multipath_hash_policy 283} 284 285ping_ipv4() 286{ 287 ping_test $h1 192.0.4.2 288} 289 290multipath_ipv4() 291{ 292 log_info "Running IPv4 over GRE over IPv6 multipath tests" 293 multipath4_test "ECMP" 1 1 294 multipath4_test "Weighted MP 2:1" 2 1 295 multipath4_test "Weighted MP 11:45" 11 45 296} 297 298trap cleanup EXIT 299 300setup_prepare 301setup_wait 302tests_run 303 304exit $EXIT_STATUS