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 ALL_TESTS="
0059 ping_ipv4
0060 multipath_ipv4
0061 "
0062
0063 NUM_NETIFS=6
0064 source lib.sh
0065
0066 h1_create()
0067 {
0068 simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
0069 ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2
0070 }
0071
0072 h1_destroy()
0073 {
0074 ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.2
0075 simple_if_fini $h1 192.0.2.1/28
0076 }
0077
0078 sw1_create()
0079 {
0080 simple_if_init $ol1 192.0.2.2/28
0081 __simple_if_init $ul1 v$ol1
0082 vlan_create $ul1 111 v$ol1 192.0.2.129/28
0083 vlan_create $ul1 222 v$ol1 192.0.2.145/28
0084
0085 tunnel_create g1a gre 192.0.2.65 192.0.2.66 tos inherit dev v$ol1
0086 __simple_if_init g1a v$ol1 192.0.2.65/32
0087 ip route add vrf v$ol1 192.0.2.66/32 via 192.0.2.130
0088
0089 tunnel_create g1b gre 192.0.2.81 192.0.2.82 tos inherit dev v$ol1
0090 __simple_if_init g1b v$ol1 192.0.2.81/32
0091 ip route add vrf v$ol1 192.0.2.82/32 via 192.0.2.146
0092
0093 ip route add vrf v$ol1 192.0.2.16/28 \
0094 nexthop dev g1a \
0095 nexthop dev g1b
0096 }
0097
0098 sw1_destroy()
0099 {
0100 ip route del vrf v$ol1 192.0.2.16/28
0101
0102 ip route del vrf v$ol1 192.0.2.82/32 via 192.0.2.146
0103 __simple_if_fini g1b 192.0.2.81/32
0104 tunnel_destroy g1b
0105
0106 ip route del vrf v$ol1 192.0.2.66/32 via 192.0.2.130
0107 __simple_if_fini g1a 192.0.2.65/32
0108 tunnel_destroy g1a
0109
0110 vlan_destroy $ul1 222
0111 vlan_destroy $ul1 111
0112 __simple_if_fini $ul1
0113 simple_if_fini $ol1 192.0.2.2/28
0114 }
0115
0116 sw2_create()
0117 {
0118 simple_if_init $ol2 192.0.2.17/28
0119 __simple_if_init $ul2 v$ol2
0120 vlan_create $ul2 111 v$ol2 192.0.2.130/28
0121 vlan_create $ul2 222 v$ol2 192.0.2.146/28
0122
0123 tunnel_create g2a gre 192.0.2.66 192.0.2.65 tos inherit dev v$ol2
0124 __simple_if_init g2a v$ol2 192.0.2.66/32
0125 ip route add vrf v$ol2 192.0.2.65/32 via 192.0.2.129
0126
0127 tunnel_create g2b gre 192.0.2.82 192.0.2.81 tos inherit dev v$ol2
0128 __simple_if_init g2b v$ol2 192.0.2.82/32
0129 ip route add vrf v$ol2 192.0.2.81/32 via 192.0.2.145
0130
0131 ip route add vrf v$ol2 192.0.2.0/28 \
0132 nexthop dev g2a \
0133 nexthop dev g2b
0134
0135 tc qdisc add dev $ul2 clsact
0136 tc filter add dev $ul2 ingress pref 111 prot 802.1Q \
0137 flower vlan_id 111 action pass
0138 tc filter add dev $ul2 ingress pref 222 prot 802.1Q \
0139 flower vlan_id 222 action pass
0140 }
0141
0142 sw2_destroy()
0143 {
0144 tc qdisc del dev $ul2 clsact
0145
0146 ip route del vrf v$ol2 192.0.2.0/28
0147
0148 ip route del vrf v$ol2 192.0.2.81/32 via 192.0.2.145
0149 __simple_if_fini g2b 192.0.2.82/32
0150 tunnel_destroy g2b
0151
0152 ip route del vrf v$ol2 192.0.2.65/32 via 192.0.2.129
0153 __simple_if_fini g2a 192.0.2.66/32
0154 tunnel_destroy g2a
0155
0156 vlan_destroy $ul2 222
0157 vlan_destroy $ul2 111
0158 __simple_if_fini $ul2
0159 simple_if_fini $ol2 192.0.2.17/28
0160 }
0161
0162 h2_create()
0163 {
0164 simple_if_init $h2 192.0.2.18/28
0165 ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.17
0166 }
0167
0168 h2_destroy()
0169 {
0170 ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.17
0171 simple_if_fini $h2 192.0.2.18/28
0172 }
0173
0174 setup_prepare()
0175 {
0176 h1=${NETIFS[p1]}
0177 ol1=${NETIFS[p2]}
0178
0179 ul1=${NETIFS[p3]}
0180 ul2=${NETIFS[p4]}
0181
0182 ol2=${NETIFS[p5]}
0183 h2=${NETIFS[p6]}
0184
0185 vrf_prepare
0186 h1_create
0187 sw1_create
0188 sw2_create
0189 h2_create
0190
0191 forwarding_enable
0192 }
0193
0194 cleanup()
0195 {
0196 pre_cleanup
0197
0198 forwarding_restore
0199
0200 h2_destroy
0201 sw2_destroy
0202 sw1_destroy
0203 h1_destroy
0204 vrf_cleanup
0205 }
0206
0207 multipath4_test()
0208 {
0209 local what=$1; shift
0210 local weight1=$1; shift
0211 local weight2=$1; shift
0212
0213 sysctl_set net.ipv4.fib_multipath_hash_policy 1
0214 ip route replace vrf v$ol1 192.0.2.16/28 \
0215 nexthop dev g1a weight $weight1 \
0216 nexthop dev g1b weight $weight2
0217
0218 local t0_111=$(tc_rule_stats_get $ul2 111 ingress)
0219 local t0_222=$(tc_rule_stats_get $ul2 222 ingress)
0220
0221 ip vrf exec v$h1 \
0222 $MZ $h1 -q -p 64 -A 192.0.2.1 -B 192.0.2.18 \
0223 -d 1msec -t udp "sp=1024,dp=0-32768"
0224
0225 local t1_111=$(tc_rule_stats_get $ul2 111 ingress)
0226 local t1_222=$(tc_rule_stats_get $ul2 222 ingress)
0227
0228 local d111=$((t1_111 - t0_111))
0229 local d222=$((t1_222 - t0_222))
0230 multipath_eval "$what" $weight1 $weight2 $d111 $d222
0231
0232 ip route replace vrf v$ol1 192.0.2.16/28 \
0233 nexthop dev g1a \
0234 nexthop dev g1b
0235 sysctl_restore net.ipv4.fib_multipath_hash_policy
0236 }
0237
0238 ping_ipv4()
0239 {
0240 ping_test $h1 192.0.2.18
0241 }
0242
0243 multipath_ipv4()
0244 {
0245 log_info "Running IPv4 multipath tests"
0246 multipath4_test "ECMP" 1 1
0247 multipath4_test "Weighted MP 2:1" 2 1
0248 multipath4_test "Weighted MP 11:45" 11 45
0249 }
0250
0251 trap cleanup EXIT
0252
0253 setup_prepare
0254 setup_wait
0255 tests_run
0256
0257 exit $EXIT_STATUS