0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 ALL_TESTS="
0063 ping_ipv4
0064 ping_ipv6
0065 multipath_ipv4
0066 multipath_ipv6
0067 multipath_ipv6_l4
0068 "
0069
0070 NUM_NETIFS=6
0071 source lib.sh
0072
0073 h1_create()
0074 {
0075 simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
0076 ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2
0077 ip route add vrf v$h1 2001:db8:2::/64 via 2001:db8:1::2
0078 }
0079
0080 h1_destroy()
0081 {
0082 ip route del vrf v$h1 2001:db8:2::/64 via 2001:db8:1::2
0083 ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.2
0084 simple_if_fini $h1 192.0.2.1/28
0085 }
0086
0087 sw1_create()
0088 {
0089 simple_if_init $ol1 192.0.2.2/28 2001:db8:1::2/64
0090 __simple_if_init $ul1 v$ol1
0091 vlan_create $ul1 111 v$ol1 192.0.2.129/28
0092 vlan_create $ul1 222 v$ol1 192.0.2.145/28
0093
0094 tunnel_create g1a gre 192.0.2.65 192.0.2.66 tos inherit dev v$ol1
0095 __simple_if_init g1a v$ol1 192.0.2.65/32
0096 ip route add vrf v$ol1 192.0.2.66/32 via 192.0.2.130
0097
0098 tunnel_create g1b gre 192.0.2.81 192.0.2.82 tos inherit dev v$ol1
0099 __simple_if_init g1b v$ol1 192.0.2.81/32
0100 ip route add vrf v$ol1 192.0.2.82/32 via 192.0.2.146
0101
0102 ip -6 nexthop add id 101 dev g1a
0103 ip -6 nexthop add id 102 dev g1b
0104 ip nexthop add id 103 group 101/102 type resilient buckets 512 \
0105 idle_timer 0
0106
0107 ip route add vrf v$ol1 192.0.2.16/28 nhid 103
0108 ip route add vrf v$ol1 2001:db8:2::/64 nhid 103
0109 }
0110
0111 sw1_destroy()
0112 {
0113 ip route del vrf v$ol1 2001:db8:2::/64
0114 ip route del vrf v$ol1 192.0.2.16/28
0115
0116 ip nexthop del id 103
0117 ip -6 nexthop del id 102
0118 ip -6 nexthop del id 101
0119
0120 ip route del vrf v$ol1 192.0.2.82/32 via 192.0.2.146
0121 __simple_if_fini g1b 192.0.2.81/32
0122 tunnel_destroy g1b
0123
0124 ip route del vrf v$ol1 192.0.2.66/32 via 192.0.2.130
0125 __simple_if_fini g1a 192.0.2.65/32
0126 tunnel_destroy g1a
0127
0128 vlan_destroy $ul1 222
0129 vlan_destroy $ul1 111
0130 __simple_if_fini $ul1
0131 simple_if_fini $ol1 192.0.2.2/28 2001:db8:1::2/64
0132 }
0133
0134 sw2_create()
0135 {
0136 simple_if_init $ol2 192.0.2.17/28 2001:db8:2::1/64
0137 __simple_if_init $ul2 v$ol2
0138 vlan_create $ul2 111 v$ol2 192.0.2.130/28
0139 vlan_create $ul2 222 v$ol2 192.0.2.146/28
0140
0141 tunnel_create g2a gre 192.0.2.66 192.0.2.65 tos inherit dev v$ol2
0142 __simple_if_init g2a v$ol2 192.0.2.66/32
0143 ip route add vrf v$ol2 192.0.2.65/32 via 192.0.2.129
0144
0145 tunnel_create g2b gre 192.0.2.82 192.0.2.81 tos inherit dev v$ol2
0146 __simple_if_init g2b v$ol2 192.0.2.82/32
0147 ip route add vrf v$ol2 192.0.2.81/32 via 192.0.2.145
0148
0149 ip -6 nexthop add id 201 dev g2a
0150 ip -6 nexthop add id 202 dev g2b
0151 ip nexthop add id 203 group 201/202 type resilient buckets 512 \
0152 idle_timer 0
0153
0154 ip route add vrf v$ol2 192.0.2.0/28 nhid 203
0155 ip route add vrf v$ol2 2001:db8:1::/64 nhid 203
0156
0157 tc qdisc add dev $ul2 clsact
0158 tc filter add dev $ul2 ingress pref 111 prot 802.1Q \
0159 flower vlan_id 111 action pass
0160 tc filter add dev $ul2 ingress pref 222 prot 802.1Q \
0161 flower vlan_id 222 action pass
0162 }
0163
0164 sw2_destroy()
0165 {
0166 tc qdisc del dev $ul2 clsact
0167
0168 ip route del vrf v$ol2 2001:db8:1::/64
0169 ip route del vrf v$ol2 192.0.2.0/28
0170
0171 ip nexthop del id 203
0172 ip -6 nexthop del id 202
0173 ip -6 nexthop del id 201
0174
0175 ip route del vrf v$ol2 192.0.2.81/32 via 192.0.2.145
0176 __simple_if_fini g2b 192.0.2.82/32
0177 tunnel_destroy g2b
0178
0179 ip route del vrf v$ol2 192.0.2.65/32 via 192.0.2.129
0180 __simple_if_fini g2a 192.0.2.66/32
0181 tunnel_destroy g2a
0182
0183 vlan_destroy $ul2 222
0184 vlan_destroy $ul2 111
0185 __simple_if_fini $ul2
0186 simple_if_fini $ol2 192.0.2.17/28 2001:db8:2::1/64
0187 }
0188
0189 h2_create()
0190 {
0191 simple_if_init $h2 192.0.2.18/28 2001:db8:2::2/64
0192 ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.17
0193 ip route add vrf v$h2 2001:db8:1::/64 via 2001:db8:2::1
0194 }
0195
0196 h2_destroy()
0197 {
0198 ip route del vrf v$h2 2001:db8:1::/64 via 2001:db8:2::1
0199 ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.17
0200 simple_if_fini $h2 192.0.2.18/28 2001:db8:2::2/64
0201 }
0202
0203 setup_prepare()
0204 {
0205 h1=${NETIFS[p1]}
0206 ol1=${NETIFS[p2]}
0207
0208 ul1=${NETIFS[p3]}
0209 ul2=${NETIFS[p4]}
0210
0211 ol2=${NETIFS[p5]}
0212 h2=${NETIFS[p6]}
0213
0214 vrf_prepare
0215 h1_create
0216 sw1_create
0217 sw2_create
0218 h2_create
0219
0220 forwarding_enable
0221 }
0222
0223 cleanup()
0224 {
0225 pre_cleanup
0226
0227 forwarding_restore
0228
0229 h2_destroy
0230 sw2_destroy
0231 sw1_destroy
0232 h1_destroy
0233 vrf_cleanup
0234 }
0235
0236 multipath4_test()
0237 {
0238 local what=$1; shift
0239 local weight1=$1; shift
0240 local weight2=$1; shift
0241
0242 sysctl_set net.ipv4.fib_multipath_hash_policy 1
0243 ip nexthop replace id 103 group 101,$weight1/102,$weight2 \
0244 type resilient
0245
0246 local t0_111=$(tc_rule_stats_get $ul2 111 ingress)
0247 local t0_222=$(tc_rule_stats_get $ul2 222 ingress)
0248
0249 ip vrf exec v$h1 \
0250 $MZ $h1 -q -p 64 -A 192.0.2.1 -B 192.0.2.18 \
0251 -d 1msec -t udp "sp=1024,dp=0-32768"
0252
0253 local t1_111=$(tc_rule_stats_get $ul2 111 ingress)
0254 local t1_222=$(tc_rule_stats_get $ul2 222 ingress)
0255
0256 local d111=$((t1_111 - t0_111))
0257 local d222=$((t1_222 - t0_222))
0258 multipath_eval "$what" $weight1 $weight2 $d111 $d222
0259
0260 ip nexthop replace id 103 group 101/102 type resilient
0261 sysctl_restore net.ipv4.fib_multipath_hash_policy
0262 }
0263
0264 multipath6_test()
0265 {
0266 local what=$1; shift
0267 local weight1=$1; shift
0268 local weight2=$1; shift
0269
0270 sysctl_set net.ipv6.fib_multipath_hash_policy 0
0271 ip nexthop replace id 103 group 101,$weight1/102,$weight2 \
0272 type resilient
0273
0274 local t0_111=$(tc_rule_stats_get $ul2 111 ingress)
0275 local t0_222=$(tc_rule_stats_get $ul2 222 ingress)
0276
0277
0278 for ((i=0; i < 16384; ++i)); do
0279 ip vrf exec v$h1 $PING6 2001:db8:2::2 -F 0 -c 1 -q &> /dev/null
0280 done
0281
0282 local t1_111=$(tc_rule_stats_get $ul2 111 ingress)
0283 local t1_222=$(tc_rule_stats_get $ul2 222 ingress)
0284
0285 local d111=$((t1_111 - t0_111))
0286 local d222=$((t1_222 - t0_222))
0287 multipath_eval "$what" $weight1 $weight2 $d111 $d222
0288
0289 ip nexthop replace id 103 group 101/102 type resilient
0290 sysctl_restore net.ipv6.fib_multipath_hash_policy
0291 }
0292
0293 multipath6_l4_test()
0294 {
0295 local what=$1; shift
0296 local weight1=$1; shift
0297 local weight2=$1; shift
0298
0299 sysctl_set net.ipv6.fib_multipath_hash_policy 1
0300 ip nexthop replace id 103 group 101,$weight1/102,$weight2 \
0301 type resilient
0302
0303 local t0_111=$(tc_rule_stats_get $ul2 111 ingress)
0304 local t0_222=$(tc_rule_stats_get $ul2 222 ingress)
0305
0306 ip vrf exec v$h1 \
0307 $MZ $h1 -6 -q -p 64 -A 2001:db8:1::1 -B 2001:db8:2::2 \
0308 -d 1msec -t udp "sp=1024,dp=0-32768"
0309
0310 local t1_111=$(tc_rule_stats_get $ul2 111 ingress)
0311 local t1_222=$(tc_rule_stats_get $ul2 222 ingress)
0312
0313 local d111=$((t1_111 - t0_111))
0314 local d222=$((t1_222 - t0_222))
0315 multipath_eval "$what" $weight1 $weight2 $d111 $d222
0316
0317 ip nexthop replace id 103 group 101/102 type resilient
0318 sysctl_restore net.ipv6.fib_multipath_hash_policy
0319 }
0320
0321 ping_ipv4()
0322 {
0323 ping_test $h1 192.0.2.18
0324 }
0325
0326 ping_ipv6()
0327 {
0328 ping6_test $h1 2001:db8:2::2
0329 }
0330
0331 multipath_ipv4()
0332 {
0333 log_info "Running IPv4 multipath tests"
0334 multipath4_test "ECMP" 1 1
0335 multipath4_test "Weighted MP 2:1" 2 1
0336 multipath4_test "Weighted MP 11:45" 11 45
0337 }
0338
0339 multipath_ipv6()
0340 {
0341 log_info "Running IPv6 multipath tests"
0342 multipath6_test "ECMP" 1 1
0343 multipath6_test "Weighted MP 2:1" 2 1
0344 multipath6_test "Weighted MP 11:45" 11 45
0345 }
0346
0347 multipath_ipv6_l4()
0348 {
0349 log_info "Running IPv6 L4 hash multipath tests"
0350 multipath6_l4_test "ECMP" 1 1
0351 multipath6_l4_test "Weighted MP 2:1" 2 1
0352 multipath6_l4_test "Weighted MP 11:45" 11 45
0353 }
0354
0355 trap cleanup EXIT
0356
0357 setup_prepare
0358 setup_wait
0359 tests_run
0360
0361 exit $EXIT_STATUS