selftests: forwarding: Add PCP match and VLAN match tests
authorAmit Cohen <amitc@mellanox.com>
Thu, 28 Mar 2019 12:12:20 +0000 (12:12 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 29 Mar 2019 00:20:52 +0000 (17:20 -0700)
Send packets with VLAN and PCP set and check that TC flower filters can
match on these keys.

Signed-off-by: Amit Cohen <amitc@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/net/forwarding/tc_flower.sh

index 20d1077..29bcfa8 100755 (executable)
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \
-       match_src_ip_test match_ip_flags_test"
+       match_src_ip_test match_ip_flags_test match_pcp_test match_vlan_test"
 NUM_NETIFS=2
 source tc_common.sh
 source lib.sh
@@ -219,6 +219,63 @@ match_ip_flags_test()
        log_test "ip_flags match ($tcflags)"
 }
 
+match_pcp_test()
+{
+       RET=0
+
+       vlan_create $h2 85 v$h2 192.0.2.11/24
+
+       tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 101 \
+               flower vlan_prio 6 $tcflags dst_mac $h2mac action drop
+       tc filter add dev $h2 ingress protocol 802.1q pref 2 handle 102 \
+               flower vlan_prio 7 $tcflags dst_mac $h2mac action drop
+
+       $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 7:85 -t ip -q
+       $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 0:85 -t ip -q
+
+       tc_check_packets "dev $h2 ingress" 101 0
+       check_err $? "Matched on specified PCP when should not"
+
+       tc_check_packets "dev $h2 ingress" 102 1
+       check_err $? "Did not match on specified PCP"
+
+       tc filter del dev $h2 ingress protocol 802.1q pref 2 handle 102 flower
+       tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 101 flower
+
+       vlan_destroy $h2 85
+
+       log_test "PCP match ($tcflags)"
+}
+
+match_vlan_test()
+{
+       RET=0
+
+       vlan_create $h2 85 v$h2 192.0.2.11/24
+       vlan_create $h2 75 v$h2 192.0.2.10/24
+
+       tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 101 \
+               flower vlan_id 75 $tcflags action drop
+       tc filter add dev $h2 ingress protocol 802.1q pref 2 handle 102 \
+               flower vlan_id 85 $tcflags action drop
+
+       $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 0:85 -t ip -q
+
+       tc_check_packets "dev $h2 ingress" 101 0
+       check_err $? "Matched on specified VLAN when should not"
+
+       tc_check_packets "dev $h2 ingress" 102 1
+       check_err $? "Did not match on specified VLAN"
+
+       tc filter del dev $h2 ingress protocol 802.1q pref 2 handle 102 flower
+       tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 101 flower
+
+       vlan_destroy $h2 75
+       vlan_destroy $h2 85
+
+       log_test "VLAN match ($tcflags)"
+}
+
 setup_prepare()
 {
        h1=${NETIFS[p1]}