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
0105
0106 ip route add vrf v$ol1 192.0.2.16/28 nhid 103
0107 ip route add vrf v$ol1 2001:db8:2::/64 nhid 103
0108 }
0109
0110 sw1_destroy()
0111 {
0112 ip route del vrf v$ol1 2001:db8:2::/64
0113 ip route del vrf v$ol1 192.0.2.16/28
0114
0115 ip nexthop del id 103
0116 ip -6 nexthop del id 102
0117 ip -6 nexthop del id 101
0118
0119 ip route del vrf v$ol1 192.0.2.82/32 via 192.0.2.146
0120 __simple_if_fini g1b 192.0.2.81/32
0121 tunnel_destroy g1b
0122
0123 ip route del vrf v$ol1 192.0.2.66/32 via 192.0.2.130
0124 __simple_if_fini g1a 192.0.2.65/32
0125 tunnel_destroy g1a
0126
0127 vlan_destroy $ul1 222
0128 vlan_destroy $ul1 111
0129 __simple_if_fini $ul1
0130 simple_if_fini $ol1 192.0.2.2/28 2001:db8:1::2/64
0131 }
0132
0133 sw2_create()
0134 {
0135 simple_if_init $ol2 192.0.2.17/28 2001:db8:2::1/64
0136 __simple_if_init $ul2 v$ol2
0137 vlan_create $ul2 111 v$ol2 192.0.2.130/28
0138 vlan_create $ul2 222 v$ol2 192.0.2.146/28
0139
0140 tunnel_create g2a gre 192.0.2.66 192.0.2.65 tos inherit dev v$ol2
0141 __simple_if_init g2a v$ol2 192.0.2.66/32
0142 ip route add vrf v$ol2 192.0.2.65/32 via 192.0.2.129
0143
0144 tunnel_create g2b gre 192.0.2.82 192.0.2.81 tos inherit dev v$ol2
0145 __simple_if_init g2b v$ol2 192.0.2.82/32
0146 ip route add vrf v$ol2 192.0.2.81/32 via 192.0.2.145
0147
0148 ip -6 nexthop add id 201 dev g2a
0149 ip -6 nexthop add id 202 dev g2b
0150 ip nexthop add id 203 group 201/202
0151
0152 ip route add vrf v$ol2 192.0.2.0/28 nhid 203
0153 ip route add vrf v$ol2 2001:db8:1::/64 nhid 203
0154
0155 tc qdisc add dev $ul2 clsact
0156 tc filter add dev $ul2 ingress pref 111 prot 802.1Q \
0157 flower vlan_id 111 action pass
0158 tc filter add dev $ul2 ingress pref 222 prot 802.1Q \
0159 flower vlan_id 222 action pass
0160 }
0161
0162 sw2_destroy()
0163 {
0164 tc qdisc del dev $ul2 clsact
0165
0166 ip route del vrf v$ol2 2001:db8:1::/64
0167 ip route del vrf v$ol2 192.0.2.0/28
0168
0169 ip nexthop del id 203
0170 ip -6 nexthop del id 202
0171 ip -6 nexthop del id 201
0172
0173 ip route del vrf v$ol2 192.0.2.81/32 via 192.0.2.145
0174 __simple_if_fini g2b 192.0.2.82/32
0175 tunnel_destroy g2b
0176
0177 ip route del vrf v$ol2 192.0.2.65/32 via 192.0.2.129
0178 __simple_if_fini g2a 192.0.2.66/32
0179 tunnel_destroy g2a
0180
0181 vlan_destroy $ul2 222
0182 vlan_destroy $ul2 111
0183 __simple_if_fini $ul2
0184 simple_if_fini $ol2 192.0.2.17/28 2001:db8:2::1/64
0185 }
0186
0187 h2_create()
0188 {
0189 simple_if_init $h2 192.0.2.18/28 2001:db8:2::2/64
0190 ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.17
0191 ip route add vrf v$h2 2001:db8:1::/64 via 2001:db8:2::1
0192 }
0193
0194 h2_destroy()
0195 {
0196 ip route del vrf v$h2 2001:db8:1::/64 via 2001:db8:2::1
0197 ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.17
0198 simple_if_fini $h2 192.0.2.18/28 2001:db8:2::2/64
0199 }
0200
0201 setup_prepare()
0202 {
0203 h1=${NETIFS[p1]}
0204 ol1=${NETIFS[p2]}
0205
0206 ul1=${NETIFS[p3]}
0207 ul2=${NETIFS[p4]}
0208
0209 ol2=${NETIFS[p5]}
0210 h2=${NETIFS[p6]}
0211
0212 vrf_prepare
0213 h1_create
0214 sw1_create
0215 sw2_create
0216 h2_create
0217
0218 forwarding_enable
0219 }
0220
0221 cleanup()
0222 {
0223 pre_cleanup
0224
0225 forwarding_restore
0226
0227 h2_destroy
0228 sw2_destroy
0229 sw1_destroy
0230 h1_destroy
0231 vrf_cleanup
0232 }
0233
0234 multipath4_test()
0235 {
0236 local what=$1; shift
0237 local weight1=$1; shift
0238 local weight2=$1; shift
0239
0240 sysctl_set net.ipv4.fib_multipath_hash_policy 1
0241 ip nexthop replace id 103 group 101,$weight1/102,$weight2
0242
0243 local t0_111=$(tc_rule_stats_get $ul2 111 ingress)
0244 local t0_222=$(tc_rule_stats_get $ul2 222 ingress)
0245
0246 ip vrf exec v$h1 \
0247 $MZ $h1 -q -p 64 -A 192.0.2.1 -B 192.0.2.18 \
0248 -d 1msec -t udp "sp=1024,dp=0-32768"
0249
0250 local t1_111=$(tc_rule_stats_get $ul2 111 ingress)
0251 local t1_222=$(tc_rule_stats_get $ul2 222 ingress)
0252
0253 local d111=$((t1_111 - t0_111))
0254 local d222=$((t1_222 - t0_222))
0255 multipath_eval "$what" $weight1 $weight2 $d111 $d222
0256
0257 ip nexthop replace id 103 group 101/102
0258 sysctl_restore net.ipv4.fib_multipath_hash_policy
0259 }
0260
0261 multipath6_test()
0262 {
0263 local what=$1; shift
0264 local weight1=$1; shift
0265 local weight2=$1; shift
0266
0267 sysctl_set net.ipv6.fib_multipath_hash_policy 0
0268 ip nexthop replace id 103 group 101,$weight1/102,$weight2
0269
0270 local t0_111=$(tc_rule_stats_get $ul2 111 ingress)
0271 local t0_222=$(tc_rule_stats_get $ul2 222 ingress)
0272
0273
0274 for ((i=0; i < 16384; ++i)); do
0275 ip vrf exec v$h1 $PING6 2001:db8:2::2 -F 0 -c 1 -q &> /dev/null
0276 done
0277
0278 local t1_111=$(tc_rule_stats_get $ul2 111 ingress)
0279 local t1_222=$(tc_rule_stats_get $ul2 222 ingress)
0280
0281 local d111=$((t1_111 - t0_111))
0282 local d222=$((t1_222 - t0_222))
0283 multipath_eval "$what" $weight1 $weight2 $d111 $d222
0284
0285 ip nexthop replace id 103 group 101/102
0286 sysctl_restore net.ipv6.fib_multipath_hash_policy
0287 }
0288
0289 multipath6_l4_test()
0290 {
0291 local what=$1; shift
0292 local weight1=$1; shift
0293 local weight2=$1; shift
0294
0295 sysctl_set net.ipv6.fib_multipath_hash_policy 1
0296 ip nexthop replace id 103 group 101,$weight1/102,$weight2
0297
0298 local t0_111=$(tc_rule_stats_get $ul2 111 ingress)
0299 local t0_222=$(tc_rule_stats_get $ul2 222 ingress)
0300
0301 ip vrf exec v$h1 \
0302 $MZ $h1 -6 -q -p 64 -A 2001:db8:1::1 -B 2001:db8:2::2 \
0303 -d 1msec -t udp "sp=1024,dp=0-32768"
0304
0305 local t1_111=$(tc_rule_stats_get $ul2 111 ingress)
0306 local t1_222=$(tc_rule_stats_get $ul2 222 ingress)
0307
0308 local d111=$((t1_111 - t0_111))
0309 local d222=$((t1_222 - t0_222))
0310 multipath_eval "$what" $weight1 $weight2 $d111 $d222
0311
0312 ip nexthop replace id 103 group 101/102
0313 sysctl_restore net.ipv6.fib_multipath_hash_policy
0314 }
0315
0316 ping_ipv4()
0317 {
0318 ping_test $h1 192.0.2.18
0319 }
0320
0321 ping_ipv6()
0322 {
0323 ping6_test $h1 2001:db8:2::2
0324 }
0325
0326 multipath_ipv4()
0327 {
0328 log_info "Running IPv4 multipath tests"
0329 multipath4_test "ECMP" 1 1
0330 multipath4_test "Weighted MP 2:1" 2 1
0331 multipath4_test "Weighted MP 11:45" 11 45
0332 }
0333
0334 multipath_ipv6()
0335 {
0336 log_info "Running IPv6 multipath tests"
0337 multipath6_test "ECMP" 1 1
0338 multipath6_test "Weighted MP 2:1" 2 1
0339 multipath6_test "Weighted MP 11:45" 11 45
0340 }
0341
0342 multipath_ipv6_l4()
0343 {
0344 log_info "Running IPv6 L4 hash multipath tests"
0345 multipath6_l4_test "ECMP" 1 1
0346 multipath6_l4_test "Weighted MP 2:1" 2 1
0347 multipath6_l4_test "Weighted MP 11:45" 11 45
0348 }
0349
0350 trap cleanup EXIT
0351
0352 setup_prepare
0353 setup_wait
0354 tests_run
0355
0356 exit $EXIT_STATUS