Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # +-----------------------+                          +------------------------+
0005 # | H1 (vrf)              |                          | H2 (vrf)               |
0006 # |  + $h1.10             |                          |  + $h2.10              |
0007 # |  | 192.0.2.1/28       |                          |  | 192.0.2.2/28        |
0008 # |  |                    |                          |  |                     |
0009 # |  | + $h1.20           |                          |  | + $h2.20            |
0010 # |  \ | 198.51.100.1/24  |                          |  \ | 198.51.100.2/24   |
0011 # |   \|                  |                          |   \|                   |
0012 # |    + $h1              |                          |    + $h2               |
0013 # +----|------------------+                          +----|-------------------+
0014 #      |                                                  |
0015 # +----|--------------------------------------------------|-------------------+
0016 # | SW |                                                  |                   |
0017 # | +--|--------------------------------------------------|-----------------+ |
0018 # | |  + $swp1                   BR1 (802.1q)             + $swp2           | |
0019 # | |     vid 10                                             vid 10         | |
0020 # | |     vid 20                                             vid 20         | |
0021 # | |                                                                       | |
0022 # | |  + vx10 (vxlan)                        + vx20 (vxlan)                 | |
0023 # | |    local 192.0.2.17                      local 192.0.2.17             | |
0024 # | |    remote 192.0.2.34 192.0.2.50          remote 192.0.2.34 192.0.2.50 | |
0025 # | |    id 1000 dstport $VXPORT               id 2000 dstport $VXPORT      | |
0026 # | |    vid 10 pvid untagged                  vid 20 pvid untagged         | |
0027 # | +-----------------------------------------------------------------------+ |
0028 # |                                                                           |
0029 # |  192.0.2.32/28 via 192.0.2.18                                             |
0030 # |  192.0.2.48/28 via 192.0.2.18                                             |
0031 # |                                                                           |
0032 # |    + $rp1                                                                 |
0033 # |    | 192.0.2.17/28                                                        |
0034 # +----|----------------------------------------------------------------------+
0035 #      |
0036 # +----|--------------------------------------------------------+
0037 # |    |                                             VRP2 (vrf) |
0038 # |    + $rp2                                                   |
0039 # |      192.0.2.18/28                                          |
0040 # |                                                             |   (maybe) HW
0041 # =============================================================================
0042 # |                                                             |  (likely) SW
0043 # |    + v1 (veth)                             + v3 (veth)      |
0044 # |    | 192.0.2.33/28                         | 192.0.2.49/28  |
0045 # +----|---------------------------------------|----------------+
0046 #      |                                       |
0047 # +----|------------------------------+   +----|------------------------------+
0048 # |    + v2 (veth)        NS1 (netns) |   |    + v4 (veth)        NS2 (netns) |
0049 # |      192.0.2.34/28                |   |      192.0.2.50/28                |
0050 # |                                   |   |                                   |
0051 # |   192.0.2.16/28 via 192.0.2.33    |   |   192.0.2.16/28 via 192.0.2.49    |
0052 # |   192.0.2.50/32 via 192.0.2.33    |   |   192.0.2.34/32 via 192.0.2.49    |
0053 # |                                   |   |                                   |
0054 # | +-------------------------------+ |   | +-------------------------------+ |
0055 # | |                  BR2 (802.1q) | |   | |                  BR2 (802.1q) | |
0056 # | |  + vx10 (vxlan)               | |   | |  + vx10 (vxlan)               | |
0057 # | |    local 192.0.2.34           | |   | |    local 192.0.2.50           | |
0058 # | |    remote 192.0.2.17          | |   | |    remote 192.0.2.17          | |
0059 # | |    remote 192.0.2.50          | |   | |    remote 192.0.2.34          | |
0060 # | |    id 1000 dstport $VXPORT    | |   | |    id 1000 dstport $VXPORT    | |
0061 # | |    vid 10 pvid untagged       | |   | |    vid 10 pvid untagged       | |
0062 # | |                               | |   | |                               | |
0063 # | |  + vx20 (vxlan)               | |   | |  + vx20 (vxlan)               | |
0064 # | |    local 192.0.2.34           | |   | |    local 192.0.2.50           | |
0065 # | |    remote 192.0.2.17          | |   | |    remote 192.0.2.17          | |
0066 # | |    remote 192.0.2.50          | |   | |    remote 192.0.2.34          | |
0067 # | |    id 2000 dstport $VXPORT    | |   | |    id 2000 dstport $VXPORT    | |
0068 # | |    vid 20 pvid untagged       | |   | |    vid 20 pvid untagged       | |
0069 # | |                               | |   | |                               | |
0070 # | |  + w1 (veth)                  | |   | |  + w1 (veth)                  | |
0071 # | |  | vid 10                     | |   | |  | vid 10                     | |
0072 # | |  | vid 20                     | |   | |  | vid 20                     | |
0073 # | +--|----------------------------+ |   | +--|----------------------------+ |
0074 # |    |                              |   |    |                              |
0075 # | +--|----------------------------+ |   | +--|----------------------------+ |
0076 # | |  + w2 (veth)        VW2 (vrf) | |   | |  + w2 (veth)        VW2 (vrf) | |
0077 # | |  |\                           | |   | |  |\                           | |
0078 # | |  | + w2.10                    | |   | |  | + w2.10                    | |
0079 # | |  |   192.0.2.3/28             | |   | |  |   192.0.2.4/28             | |
0080 # | |  |                            | |   | |  |                            | |
0081 # | |  + w2.20                      | |   | |  + w2.20                      | |
0082 # | |    198.51.100.3/24            | |   | |    198.51.100.4/24            | |
0083 # | +-------------------------------+ |   | +-------------------------------+ |
0084 # +-----------------------------------+   +-----------------------------------+
0085 
0086 : ${VXPORT:=4789}
0087 export VXPORT
0088 
0089 : ${ALL_TESTS:="
0090         ping_ipv4
0091         test_flood
0092         test_unicast
0093         reapply_config
0094         ping_ipv4
0095         test_flood
0096         test_unicast
0097         test_learning
0098         test_pvid
0099     "}
0100 
0101 NUM_NETIFS=6
0102 source lib.sh
0103 
0104 h1_create()
0105 {
0106         simple_if_init $h1
0107         tc qdisc add dev $h1 clsact
0108         vlan_create $h1 10 v$h1 192.0.2.1/28
0109         vlan_create $h1 20 v$h1 198.51.100.1/24
0110 }
0111 
0112 h1_destroy()
0113 {
0114         vlan_destroy $h1 20
0115         vlan_destroy $h1 10
0116         tc qdisc del dev $h1 clsact
0117         simple_if_fini $h1
0118 }
0119 
0120 h2_create()
0121 {
0122         simple_if_init $h2
0123         tc qdisc add dev $h2 clsact
0124         vlan_create $h2 10 v$h2 192.0.2.2/28
0125         vlan_create $h2 20 v$h2 198.51.100.2/24
0126 }
0127 
0128 h2_destroy()
0129 {
0130         vlan_destroy $h2 20
0131         vlan_destroy $h2 10
0132         tc qdisc del dev $h2 clsact
0133         simple_if_fini $h2
0134 }
0135 
0136 rp1_set_addr()
0137 {
0138         ip address add dev $rp1 192.0.2.17/28
0139 
0140         ip route add 192.0.2.32/28 nexthop via 192.0.2.18
0141         ip route add 192.0.2.48/28 nexthop via 192.0.2.18
0142 }
0143 
0144 rp1_unset_addr()
0145 {
0146         ip route del 192.0.2.48/28 nexthop via 192.0.2.18
0147         ip route del 192.0.2.32/28 nexthop via 192.0.2.18
0148 
0149         ip address del dev $rp1 192.0.2.17/28
0150 }
0151 
0152 switch_create()
0153 {
0154         ip link add name br1 type bridge vlan_filtering 1 vlan_default_pvid 0 \
0155                 mcast_snooping 0
0156         # Make sure the bridge uses the MAC address of the local port and not
0157         # that of the VxLAN's device.
0158         ip link set dev br1 address $(mac_get $swp1)
0159         ip link set dev br1 up
0160 
0161         ip link set dev $rp1 up
0162         rp1_set_addr
0163 
0164         ip link add name vx10 type vxlan id 1000        \
0165                 local 192.0.2.17 dstport "$VXPORT"      \
0166                 nolearning noudpcsum tos inherit ttl 100
0167         ip link set dev vx10 up
0168 
0169         ip link set dev vx10 master br1
0170         bridge vlan add vid 10 dev vx10 pvid untagged
0171 
0172         ip link add name vx20 type vxlan id 2000        \
0173                 local 192.0.2.17 dstport "$VXPORT"      \
0174                 nolearning noudpcsum tos inherit ttl 100
0175         ip link set dev vx20 up
0176 
0177         ip link set dev vx20 master br1
0178         bridge vlan add vid 20 dev vx20 pvid untagged
0179 
0180         ip link set dev $swp1 master br1
0181         ip link set dev $swp1 up
0182         bridge vlan add vid 10 dev $swp1
0183         bridge vlan add vid 20 dev $swp1
0184 
0185         ip link set dev $swp2 master br1
0186         ip link set dev $swp2 up
0187         bridge vlan add vid 10 dev $swp2
0188         bridge vlan add vid 20 dev $swp2
0189 
0190         bridge fdb append dev vx10 00:00:00:00:00:00 dst 192.0.2.34 self
0191         bridge fdb append dev vx10 00:00:00:00:00:00 dst 192.0.2.50 self
0192 
0193         bridge fdb append dev vx20 00:00:00:00:00:00 dst 192.0.2.34 self
0194         bridge fdb append dev vx20 00:00:00:00:00:00 dst 192.0.2.50 self
0195 }
0196 
0197 switch_destroy()
0198 {
0199         bridge fdb del dev vx20 00:00:00:00:00:00 dst 192.0.2.50 self
0200         bridge fdb del dev vx20 00:00:00:00:00:00 dst 192.0.2.34 self
0201 
0202         bridge fdb del dev vx10 00:00:00:00:00:00 dst 192.0.2.50 self
0203         bridge fdb del dev vx10 00:00:00:00:00:00 dst 192.0.2.34 self
0204 
0205         bridge vlan del vid 20 dev $swp2
0206         bridge vlan del vid 10 dev $swp2
0207         ip link set dev $swp2 down
0208         ip link set dev $swp2 nomaster
0209 
0210         bridge vlan del vid 20 dev $swp1
0211         bridge vlan del vid 10 dev $swp1
0212         ip link set dev $swp1 down
0213         ip link set dev $swp1 nomaster
0214 
0215         bridge vlan del vid 20 dev vx20
0216         ip link set dev vx20 nomaster
0217 
0218         ip link set dev vx20 down
0219         ip link del dev vx20
0220 
0221         bridge vlan del vid 10 dev vx10
0222         ip link set dev vx10 nomaster
0223 
0224         ip link set dev vx10 down
0225         ip link del dev vx10
0226 
0227         rp1_unset_addr
0228         ip link set dev $rp1 down
0229 
0230         ip link set dev br1 down
0231         ip link del dev br1
0232 }
0233 
0234 vrp2_create()
0235 {
0236         simple_if_init $rp2 192.0.2.18/28
0237         __simple_if_init v1 v$rp2 192.0.2.33/28
0238         __simple_if_init v3 v$rp2 192.0.2.49/28
0239         tc qdisc add dev v1 clsact
0240 }
0241 
0242 vrp2_destroy()
0243 {
0244         tc qdisc del dev v1 clsact
0245         __simple_if_fini v3 192.0.2.49/28
0246         __simple_if_fini v1 192.0.2.33/28
0247         simple_if_fini $rp2 192.0.2.18/28
0248 }
0249 
0250 ns_init_common()
0251 {
0252         local in_if=$1; shift
0253         local in_addr=$1; shift
0254         local other_in_addr=$1; shift
0255         local nh_addr=$1; shift
0256         local host_addr1=$1; shift
0257         local host_addr2=$1; shift
0258 
0259         ip link set dev $in_if up
0260         ip address add dev $in_if $in_addr/28
0261         tc qdisc add dev $in_if clsact
0262 
0263         ip link add name br2 type bridge vlan_filtering 1 vlan_default_pvid 0
0264         ip link set dev br2 up
0265 
0266         ip link add name w1 type veth peer name w2
0267 
0268         ip link set dev w1 master br2
0269         ip link set dev w1 up
0270 
0271         bridge vlan add vid 10 dev w1
0272         bridge vlan add vid 20 dev w1
0273 
0274         ip link add name vx10 type vxlan id 1000 local $in_addr \
0275                 dstport "$VXPORT"
0276         ip link set dev vx10 up
0277         bridge fdb append dev vx10 00:00:00:00:00:00 dst 192.0.2.17 self
0278         bridge fdb append dev vx10 00:00:00:00:00:00 dst $other_in_addr self
0279 
0280         ip link set dev vx10 master br2
0281         tc qdisc add dev vx10 clsact
0282 
0283         bridge vlan add vid 10 dev vx10 pvid untagged
0284 
0285         ip link add name vx20 type vxlan id 2000 local $in_addr \
0286                 dstport "$VXPORT"
0287         ip link set dev vx20 up
0288         bridge fdb append dev vx20 00:00:00:00:00:00 dst 192.0.2.17 self
0289         bridge fdb append dev vx20 00:00:00:00:00:00 dst $other_in_addr self
0290 
0291         ip link set dev vx20 master br2
0292         tc qdisc add dev vx20 clsact
0293 
0294         bridge vlan add vid 20 dev vx20 pvid untagged
0295 
0296         simple_if_init w2
0297         vlan_create w2 10 vw2 $host_addr1/28
0298         vlan_create w2 20 vw2 $host_addr2/24
0299 
0300         ip route add 192.0.2.16/28 nexthop via $nh_addr
0301         ip route add $other_in_addr/32 nexthop via $nh_addr
0302 }
0303 export -f ns_init_common
0304 
0305 ns1_create()
0306 {
0307         ip netns add ns1
0308         ip link set dev v2 netns ns1
0309         in_ns ns1 \
0310               ns_init_common v2 192.0.2.34 192.0.2.50 192.0.2.33 192.0.2.3 \
0311               198.51.100.3
0312 }
0313 
0314 ns1_destroy()
0315 {
0316         ip netns exec ns1 ip link set dev v2 netns 1
0317         ip netns del ns1
0318 }
0319 
0320 ns2_create()
0321 {
0322         ip netns add ns2
0323         ip link set dev v4 netns ns2
0324         in_ns ns2 \
0325               ns_init_common v4 192.0.2.50 192.0.2.34 192.0.2.49 192.0.2.4 \
0326               198.51.100.4
0327 }
0328 
0329 ns2_destroy()
0330 {
0331         ip netns exec ns2 ip link set dev v4 netns 1
0332         ip netns del ns2
0333 }
0334 
0335 setup_prepare()
0336 {
0337         h1=${NETIFS[p1]}
0338         swp1=${NETIFS[p2]}
0339 
0340         swp2=${NETIFS[p3]}
0341         h2=${NETIFS[p4]}
0342 
0343         rp1=${NETIFS[p5]}
0344         rp2=${NETIFS[p6]}
0345 
0346         vrf_prepare
0347         forwarding_enable
0348 
0349         h1_create
0350         h2_create
0351         switch_create
0352 
0353         ip link add name v1 type veth peer name v2
0354         ip link add name v3 type veth peer name v4
0355         vrp2_create
0356         ns1_create
0357         ns2_create
0358 
0359         r1_mac=$(in_ns ns1 mac_get w2)
0360         r2_mac=$(in_ns ns2 mac_get w2)
0361         h2_mac=$(mac_get $h2)
0362 }
0363 
0364 cleanup()
0365 {
0366         pre_cleanup
0367 
0368         ns2_destroy
0369         ns1_destroy
0370         vrp2_destroy
0371         ip link del dev v3
0372         ip link del dev v1
0373 
0374         switch_destroy
0375         h2_destroy
0376         h1_destroy
0377 
0378         forwarding_restore
0379         vrf_cleanup
0380 }
0381 
0382 # For the first round of tests, vx10 and vx20 were the first devices to get
0383 # attached to the bridge, and that at the point that the local IP is already
0384 # configured. Try the other scenario of attaching these devices to a bridge
0385 # that already has local ports members, and only then assign the local IP.
0386 reapply_config()
0387 {
0388         log_info "Reapplying configuration"
0389 
0390         bridge fdb del dev vx20 00:00:00:00:00:00 dst 192.0.2.50 self
0391         bridge fdb del dev vx20 00:00:00:00:00:00 dst 192.0.2.34 self
0392 
0393         bridge fdb del dev vx10 00:00:00:00:00:00 dst 192.0.2.50 self
0394         bridge fdb del dev vx10 00:00:00:00:00:00 dst 192.0.2.34 self
0395 
0396         ip link set dev vx20 nomaster
0397         ip link set dev vx10 nomaster
0398 
0399         rp1_unset_addr
0400         sleep 5
0401 
0402         ip link set dev vx10 master br1
0403         bridge vlan add vid 10 dev vx10 pvid untagged
0404 
0405         ip link set dev vx20 master br1
0406         bridge vlan add vid 20 dev vx20 pvid untagged
0407 
0408         bridge fdb append dev vx10 00:00:00:00:00:00 dst 192.0.2.34 self
0409         bridge fdb append dev vx10 00:00:00:00:00:00 dst 192.0.2.50 self
0410 
0411         bridge fdb append dev vx20 00:00:00:00:00:00 dst 192.0.2.34 self
0412         bridge fdb append dev vx20 00:00:00:00:00:00 dst 192.0.2.50 self
0413 
0414         rp1_set_addr
0415         sleep 5
0416 }
0417 
0418 ping_ipv4()
0419 {
0420         ping_test $h1.10 192.0.2.2 ": local->local vid 10"
0421         ping_test $h1.20 198.51.100.2 ": local->local vid 20"
0422         ping_test $h1.10 192.0.2.3 ": local->remote 1 vid 10"
0423         ping_test $h1.10 192.0.2.4 ": local->remote 2 vid 10"
0424         ping_test $h1.20 198.51.100.3 ": local->remote 1 vid 20"
0425         ping_test $h1.20 198.51.100.4 ": local->remote 2 vid 20"
0426 }
0427 
0428 maybe_in_ns()
0429 {
0430         echo ${1:+in_ns} $1
0431 }
0432 
0433 __flood_counter_add_del()
0434 {
0435         local add_del=$1; shift
0436         local dev=$1; shift
0437         local ns=$1; shift
0438 
0439         # Putting the ICMP capture both to HW and to SW will end up
0440         # double-counting the packets that are trapped to slow path, such as for
0441         # the unicast test. Adding either skip_hw or skip_sw fixes this problem,
0442         # but with skip_hw, the flooded packets are not counted at all, because
0443         # those are dropped due to MAC address mismatch; and skip_sw is a no-go
0444         # for veth-based topologies.
0445         #
0446         # So try to install with skip_sw and fall back to skip_sw if that fails.
0447 
0448         $(maybe_in_ns $ns) __icmp_capture_add_del          \
0449                            $add_del 100 "" $dev skip_sw 2>/dev/null || \
0450         $(maybe_in_ns $ns) __icmp_capture_add_del          \
0451                            $add_del 100 "" $dev skip_hw
0452 }
0453 
0454 flood_counter_install()
0455 {
0456         __flood_counter_add_del add "$@"
0457 }
0458 
0459 flood_counter_uninstall()
0460 {
0461         __flood_counter_add_del del "$@"
0462 }
0463 
0464 flood_fetch_stat()
0465 {
0466         local dev=$1; shift
0467         local ns=$1; shift
0468 
0469         $(maybe_in_ns $ns) tc_rule_stats_get $dev 100 ingress
0470 }
0471 
0472 flood_fetch_stats()
0473 {
0474         local counters=("${@}")
0475         local counter
0476 
0477         for counter in "${counters[@]}"; do
0478                 flood_fetch_stat $counter
0479         done
0480 }
0481 
0482 vxlan_flood_test()
0483 {
0484         local mac=$1; shift
0485         local dst=$1; shift
0486         local vid=$1; shift
0487         local -a expects=("${@}")
0488 
0489         local -a counters=($h2 "vx10 ns1" "vx20 ns1" "vx10 ns2" "vx20 ns2")
0490         local counter
0491         local key
0492 
0493         # Packets reach the local host tagged whereas they reach the VxLAN
0494         # devices untagged. In order to be able to use the same filter for
0495         # all counters, make sure the packets also reach the local host
0496         # untagged
0497         bridge vlan add vid $vid dev $swp2 untagged
0498         for counter in "${counters[@]}"; do
0499                 flood_counter_install $counter
0500         done
0501 
0502         local -a t0s=($(flood_fetch_stats "${counters[@]}"))
0503         $MZ $h1 -Q $vid -c 10 -d 100msec -p 64 -b $mac -B $dst -t icmp -q
0504         sleep 1
0505         local -a t1s=($(flood_fetch_stats "${counters[@]}"))
0506 
0507         for key in ${!t0s[@]}; do
0508                 local delta=$((t1s[$key] - t0s[$key]))
0509                 local expect=${expects[$key]}
0510 
0511                 ((expect == delta))
0512                 check_err $? "${counters[$key]}: Expected to capture $expect packets, got $delta."
0513         done
0514 
0515         for counter in "${counters[@]}"; do
0516                 flood_counter_uninstall $counter
0517         done
0518         bridge vlan add vid $vid dev $swp2
0519 }
0520 
0521 __test_flood()
0522 {
0523         local mac=$1; shift
0524         local dst=$1; shift
0525         local vid=$1; shift
0526         local what=$1; shift
0527         local -a expects=("${@}")
0528 
0529         RET=0
0530 
0531         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0532 
0533         log_test "VXLAN: $what"
0534 }
0535 
0536 test_flood()
0537 {
0538         __test_flood de:ad:be:ef:13:37 192.0.2.100 10 "flood vlan 10" \
0539                 10 10 0 10 0
0540         __test_flood ca:fe:be:ef:13:37 198.51.100.100 20 "flood vlan 20" \
0541                 10 0 10 0 10
0542 }
0543 
0544 vxlan_fdb_add_del()
0545 {
0546         local add_del=$1; shift
0547         local vid=$1; shift
0548         local mac=$1; shift
0549         local dev=$1; shift
0550         local dst=$1; shift
0551 
0552         bridge fdb $add_del dev $dev $mac self static permanent \
0553                 ${dst:+dst} $dst 2>/dev/null
0554         bridge fdb $add_del dev $dev $mac master static vlan $vid 2>/dev/null
0555 }
0556 
0557 __test_unicast()
0558 {
0559         local mac=$1; shift
0560         local dst=$1; shift
0561         local hit_idx=$1; shift
0562         local vid=$1; shift
0563         local what=$1; shift
0564 
0565         RET=0
0566 
0567         local -a expects=(0 0 0 0 0)
0568         expects[$hit_idx]=10
0569 
0570         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0571 
0572         log_test "VXLAN: $what"
0573 }
0574 
0575 test_unicast()
0576 {
0577         local -a targets=("$h2_mac $h2"
0578                           "$r1_mac vx10 192.0.2.34"
0579                           "$r2_mac vx10 192.0.2.50")
0580         local target
0581 
0582         log_info "unicast vlan 10"
0583 
0584         for target in "${targets[@]}"; do
0585                 vxlan_fdb_add_del add 10 $target
0586         done
0587 
0588         __test_unicast $h2_mac 192.0.2.2 0 10 "local MAC unicast"
0589         __test_unicast $r1_mac 192.0.2.3 1 10 "remote MAC 1 unicast"
0590         __test_unicast $r2_mac 192.0.2.4 3 10 "remote MAC 2 unicast"
0591 
0592         for target in "${targets[@]}"; do
0593                 vxlan_fdb_add_del del 10 $target
0594         done
0595 
0596         log_info "unicast vlan 20"
0597 
0598         targets=("$h2_mac $h2" "$r1_mac vx20 192.0.2.34" \
0599                  "$r2_mac vx20 192.0.2.50")
0600 
0601         for target in "${targets[@]}"; do
0602                 vxlan_fdb_add_del add 20 $target
0603         done
0604 
0605         __test_unicast $h2_mac 198.51.100.2 0 20 "local MAC unicast"
0606         __test_unicast $r1_mac 198.51.100.3 2 20 "remote MAC 1 unicast"
0607         __test_unicast $r2_mac 198.51.100.4 4 20 "remote MAC 2 unicast"
0608 
0609         for target in "${targets[@]}"; do
0610                 vxlan_fdb_add_del del 20 $target
0611         done
0612 }
0613 
0614 test_pvid()
0615 {
0616         local -a expects=(0 0 0 0 0)
0617         local mac=de:ad:be:ef:13:37
0618         local dst=192.0.2.100
0619         local vid=10
0620 
0621         # Check that flooding works
0622         RET=0
0623 
0624         expects[0]=10; expects[1]=10; expects[3]=10
0625         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0626 
0627         log_test "VXLAN: flood before pvid off"
0628 
0629         # Toggle PVID off and test that flood to remote hosts does not work
0630         RET=0
0631 
0632         bridge vlan add vid 10 dev vx10
0633 
0634         expects[0]=10; expects[1]=0; expects[3]=0
0635         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0636 
0637         log_test "VXLAN: flood after pvid off"
0638 
0639         # Toggle PVID on and test that flood to remote hosts does work
0640         RET=0
0641 
0642         bridge vlan add vid 10 dev vx10 pvid untagged
0643 
0644         expects[0]=10; expects[1]=10; expects[3]=10
0645         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0646 
0647         log_test "VXLAN: flood after pvid on"
0648 
0649         # Add a new VLAN and test that it does not affect flooding
0650         RET=0
0651 
0652         bridge vlan add vid 30 dev vx10
0653 
0654         expects[0]=10; expects[1]=10; expects[3]=10
0655         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0656 
0657         bridge vlan del vid 30 dev vx10
0658 
0659         log_test "VXLAN: flood after vlan add"
0660 
0661         # Remove currently mapped VLAN and test that flood to remote hosts does
0662         # not work
0663         RET=0
0664 
0665         bridge vlan del vid 10 dev vx10
0666 
0667         expects[0]=10; expects[1]=0; expects[3]=0
0668         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0669 
0670         log_test "VXLAN: flood after vlan delete"
0671 
0672         # Re-add the VLAN and test that flood to remote hosts does work
0673         RET=0
0674 
0675         bridge vlan add vid 10 dev vx10 pvid untagged
0676 
0677         expects[0]=10; expects[1]=10; expects[3]=10
0678         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0679 
0680         log_test "VXLAN: flood after vlan re-add"
0681 }
0682 
0683 __test_learning()
0684 {
0685         local -a expects=(0 0 0 0 0)
0686         local mac=$1; shift
0687         local dst=$1; shift
0688         local vid=$1; shift
0689         local idx1=$1; shift
0690         local idx2=$1; shift
0691         local vx=vx$vid
0692 
0693         # Check that flooding works
0694         RET=0
0695 
0696         expects[0]=10; expects[$idx1]=10; expects[$idx2]=10
0697         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0698 
0699         log_test "VXLAN: flood before learning"
0700 
0701         # Send a packet with source mac set to $mac from host w2 and check that
0702         # a corresponding entry is created in the VxLAN device
0703         RET=0
0704 
0705         in_ns ns1 $MZ w2 -Q $vid -c 1 -p 64 -a $mac -b ff:ff:ff:ff:ff:ff \
0706                 -B $dst -t icmp -q
0707         sleep 1
0708 
0709         bridge fdb show brport $vx | grep $mac | grep -q self
0710         check_err $?
0711         bridge fdb show brport $vx | grep $mac | grep "vlan $vid" \
0712                 | grep -q -v self
0713         check_err $?
0714 
0715         log_test "VXLAN: show learned FDB entry"
0716 
0717         # Repeat first test and check that packets only reach host w2 in ns1
0718         RET=0
0719 
0720         expects[0]=0; expects[$idx1]=10; expects[$idx2]=0
0721         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0722 
0723         log_test "VXLAN: learned FDB entry"
0724 
0725         # Delete the learned FDB entry from the VxLAN and bridge devices and
0726         # check that packets are flooded
0727         RET=0
0728 
0729         bridge fdb del dev $vx $mac master self vlan $vid
0730         sleep 1
0731 
0732         expects[0]=10; expects[$idx1]=10; expects[$idx2]=10
0733         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0734 
0735         log_test "VXLAN: deletion of learned FDB entry"
0736 
0737         # Re-learn the first FDB entry and check that it is correctly aged-out
0738         RET=0
0739 
0740         in_ns ns1 $MZ w2 -Q $vid -c 1 -p 64 -a $mac -b ff:ff:ff:ff:ff:ff \
0741                 -B $dst -t icmp -q
0742         sleep 1
0743 
0744         bridge fdb show brport $vx | grep $mac | grep -q self
0745         check_err $?
0746         bridge fdb show brport $vx | grep $mac | grep "vlan $vid" \
0747                 | grep -q -v self
0748         check_err $?
0749 
0750         expects[0]=0; expects[$idx1]=10; expects[$idx2]=0
0751         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0752 
0753         sleep 20
0754 
0755         bridge fdb show brport $vx | grep $mac | grep -q self
0756         check_fail $?
0757         bridge fdb show brport $vx | grep $mac | grep "vlan $vid" \
0758                 | grep -q -v self
0759         check_fail $?
0760 
0761         expects[0]=10; expects[$idx1]=10; expects[$idx2]=10
0762         vxlan_flood_test $mac $dst $vid "${expects[@]}"
0763 
0764         log_test "VXLAN: Ageing of learned FDB entry"
0765 
0766         # Toggle learning on the bridge port and check that the bridge's FDB
0767         # is populated only when it should
0768         RET=0
0769 
0770         ip link set dev $vx type bridge_slave learning off
0771 
0772         in_ns ns1 $MZ w2 -Q $vid -c 1 -p 64 -a $mac -b ff:ff:ff:ff:ff:ff \
0773                 -B $dst -t icmp -q
0774         sleep 1
0775 
0776         bridge fdb show brport $vx | grep $mac | grep "vlan $vid" \
0777                 | grep -q -v self
0778         check_fail $?
0779 
0780         ip link set dev $vx type bridge_slave learning on
0781 
0782         in_ns ns1 $MZ w2 -Q $vid -c 1 -p 64 -a $mac -b ff:ff:ff:ff:ff:ff \
0783                 -B $dst -t icmp -q
0784         sleep 1
0785 
0786         bridge fdb show brport $vx | grep $mac | grep "vlan $vid" \
0787                 | grep -q -v self
0788         check_err $?
0789 
0790         log_test "VXLAN: learning toggling on bridge port"
0791 }
0792 
0793 test_learning()
0794 {
0795         local mac=de:ad:be:ef:13:37
0796         local dst=192.0.2.100
0797         local vid=10
0798 
0799         # Enable learning on the VxLAN devices and set ageing time to 10 seconds
0800         ip link set dev br1 type bridge ageing_time 1000
0801         ip link set dev vx10 type vxlan ageing 10
0802         ip link set dev vx10 type vxlan learning
0803         ip link set dev vx20 type vxlan ageing 10
0804         ip link set dev vx20 type vxlan learning
0805         reapply_config
0806 
0807         log_info "learning vlan 10"
0808 
0809         __test_learning $mac $dst $vid 1 3
0810 
0811         log_info "learning vlan 20"
0812 
0813         mac=ca:fe:be:ef:13:37
0814         dst=198.51.100.100
0815         vid=20
0816 
0817         __test_learning $mac $dst $vid 2 4
0818 
0819         # Restore previous settings
0820         ip link set dev vx20 type vxlan nolearning
0821         ip link set dev vx20 type vxlan ageing 300
0822         ip link set dev vx10 type vxlan nolearning
0823         ip link set dev vx10 type vxlan ageing 300
0824         ip link set dev br1 type bridge ageing_time 30000
0825         reapply_config
0826 }
0827 
0828 test_all()
0829 {
0830         log_info "Running tests with UDP port $VXPORT"
0831         tests_run
0832 }
0833 
0834 trap cleanup EXIT
0835 
0836 setup_prepare
0837 setup_wait
0838 test_all
0839 
0840 exit $EXIT_STATUS