Skip to content

Commit c09bfd9

Browse files
Guillaume Naultdavem330
authored andcommitted
selftests: tc: Add generic mpls matching support for tc-flower
Add tests in tc_flower.sh for generic matching on MPLS Label Stack Entries. The label, tc, bos and ttl fields are tested for the first and second labels. For each field, the minimal and maximal values are tested (the former at depth 1 and the later at depth 2). There are also tests for matching the presence of a label stack entry at a given depth. In order to reduce the amount of code, all "lse" subcommands are tested in match_mpls_lse_test(). Action "continue" is used, so that test packets are evaluated by all filters. Then, we can verify if each filter matched the expected number of packets. Some versions of tc-flower produced invalid json output when dumping MPLS filters with depth > 1. Skip the test if tc isn't recent enough. Signed-off-by: Guillaume Nault <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 203ee5c commit c09bfd9

File tree

2 files changed

+162
-1
lines changed

2 files changed

+162
-1
lines changed

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,32 @@ check_tc_mpls_support()
5757
matchall
5858
}
5959

60+
# Old versions of tc produce invalid json output for mpls lse statistics
61+
check_tc_mpls_lse_stats()
62+
{
63+
local dev=$1; shift
64+
local ret;
65+
66+
tc filter add dev $dev ingress protocol mpls_uc pref 1 handle 1 \
67+
flower mpls lse depth 2 \
68+
action continue &> /dev/null
69+
70+
if [[ $? -ne 0 ]]; then
71+
echo "SKIP: iproute2 too old; tc-flower is missing extended MPLS support"
72+
return 1
73+
fi
74+
75+
tc -j filter show dev $dev ingress protocol mpls_uc | jq . &> /dev/null
76+
ret=$?
77+
tc filter del dev $dev ingress protocol mpls_uc pref 1 handle 1 \
78+
flower
79+
80+
if [[ $ret -ne 0 ]]; then
81+
echo "SKIP: iproute2 too old; tc-flower produces invalid json output for extended MPLS filters"
82+
return 1
83+
fi
84+
}
85+
6086
check_tc_shblock_support()
6187
{
6288
tc filter help 2>&1 | grep block &> /dev/null

tools/testing/selftests/net/forwarding/tc_flower.sh

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \
55
match_src_ip_test match_ip_flags_test match_pcp_test match_vlan_test \
66
match_ip_tos_test match_indev_test match_mpls_label_test \
7-
match_mpls_tc_test match_mpls_bos_test match_mpls_ttl_test"
7+
match_mpls_tc_test match_mpls_bos_test match_mpls_ttl_test \
8+
match_mpls_lse_test"
89
NUM_NETIFS=2
910
source tc_common.sh
1011
source lib.sh
@@ -504,6 +505,140 @@ match_mpls_ttl_test()
504505
log_test "mpls_ttl match ($tcflags)"
505506
}
506507

508+
match_mpls_lse_test()
509+
{
510+
local ethtype="88 47"; readonly ethtype
511+
local pkt
512+
513+
RET=0
514+
515+
check_tc_mpls_lse_stats $h2 || return 0
516+
517+
# Match on first LSE (minimal values for each field)
518+
tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
519+
flower $tcflags mpls lse depth 1 label 0 action continue
520+
tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
521+
flower $tcflags mpls lse depth 1 tc 0 action continue
522+
tc filter add dev $h2 ingress protocol mpls_uc pref 3 handle 103 \
523+
flower $tcflags mpls lse depth 1 bos 0 action continue
524+
tc filter add dev $h2 ingress protocol mpls_uc pref 4 handle 104 \
525+
flower $tcflags mpls lse depth 1 ttl 0 action continue
526+
527+
# Match on second LSE (maximal values for each field)
528+
tc filter add dev $h2 ingress protocol mpls_uc pref 5 handle 105 \
529+
flower $tcflags mpls lse depth 2 label 1048575 action continue
530+
tc filter add dev $h2 ingress protocol mpls_uc pref 6 handle 106 \
531+
flower $tcflags mpls lse depth 2 tc 7 action continue
532+
tc filter add dev $h2 ingress protocol mpls_uc pref 7 handle 107 \
533+
flower $tcflags mpls lse depth 2 bos 1 action continue
534+
tc filter add dev $h2 ingress protocol mpls_uc pref 8 handle 108 \
535+
flower $tcflags mpls lse depth 2 ttl 255 action continue
536+
537+
# Match on LSE depth
538+
tc filter add dev $h2 ingress protocol mpls_uc pref 9 handle 109 \
539+
flower $tcflags mpls lse depth 1 action continue
540+
tc filter add dev $h2 ingress protocol mpls_uc pref 10 handle 110 \
541+
flower $tcflags mpls lse depth 2 action continue
542+
tc filter add dev $h2 ingress protocol mpls_uc pref 11 handle 111 \
543+
flower $tcflags mpls lse depth 3 action continue
544+
545+
# Base packet, matched by all filters (except for stack depth 3)
546+
pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 7 1 255)"
547+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
548+
549+
# Make a variant of the above packet, with a non-matching value
550+
# for each LSE field
551+
552+
# Wrong label at depth 1
553+
pkt="$ethtype $(mpls_lse 1 0 0 0) $(mpls_lse 1048575 7 1 255)"
554+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
555+
556+
# Wrong TC at depth 1
557+
pkt="$ethtype $(mpls_lse 0 1 0 0) $(mpls_lse 1048575 7 1 255)"
558+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
559+
560+
# Wrong BOS at depth 1 (not adding a second LSE here since BOS is set
561+
# in the first label, so anything that'd follow wouldn't be considered)
562+
pkt="$ethtype $(mpls_lse 0 0 1 0)"
563+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
564+
565+
# Wrong TTL at depth 1
566+
pkt="$ethtype $(mpls_lse 0 0 0 1) $(mpls_lse 1048575 7 1 255)"
567+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
568+
569+
# Wrong label at depth 2
570+
pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048574 7 1 255)"
571+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
572+
573+
# Wrong TC at depth 2
574+
pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 6 1 255)"
575+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
576+
577+
# Wrong BOS at depth 2 (adding a third LSE here since BOS isn't set in
578+
# the second label)
579+
pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 7 0 255)"
580+
pkt="$pkt $(mpls_lse 0 0 1 255)"
581+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
582+
583+
# Wrong TTL at depth 2
584+
pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 7 1 254)"
585+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
586+
587+
# Filters working at depth 1 should match all packets but one
588+
589+
tc_check_packets "dev $h2 ingress" 101 8
590+
check_err $? "Did not match on correct filter"
591+
592+
tc_check_packets "dev $h2 ingress" 102 8
593+
check_err $? "Did not match on correct filter"
594+
595+
tc_check_packets "dev $h2 ingress" 103 8
596+
check_err $? "Did not match on correct filter"
597+
598+
tc_check_packets "dev $h2 ingress" 104 8
599+
check_err $? "Did not match on correct filter"
600+
601+
# Filters working at depth 2 should match all packets but two (because
602+
# of the test packet where the label stack depth is just one)
603+
604+
tc_check_packets "dev $h2 ingress" 105 7
605+
check_err $? "Did not match on correct filter"
606+
607+
tc_check_packets "dev $h2 ingress" 106 7
608+
check_err $? "Did not match on correct filter"
609+
610+
tc_check_packets "dev $h2 ingress" 107 7
611+
check_err $? "Did not match on correct filter"
612+
613+
tc_check_packets "dev $h2 ingress" 108 7
614+
check_err $? "Did not match on correct filter"
615+
616+
# Finally, verify the filters that only match on LSE depth
617+
618+
tc_check_packets "dev $h2 ingress" 109 9
619+
check_err $? "Did not match on correct filter"
620+
621+
tc_check_packets "dev $h2 ingress" 110 8
622+
check_err $? "Did not match on correct filter"
623+
624+
tc_check_packets "dev $h2 ingress" 111 1
625+
check_err $? "Did not match on correct filter"
626+
627+
tc filter del dev $h2 ingress protocol mpls_uc pref 11 handle 111 flower
628+
tc filter del dev $h2 ingress protocol mpls_uc pref 10 handle 110 flower
629+
tc filter del dev $h2 ingress protocol mpls_uc pref 9 handle 109 flower
630+
tc filter del dev $h2 ingress protocol mpls_uc pref 8 handle 108 flower
631+
tc filter del dev $h2 ingress protocol mpls_uc pref 7 handle 107 flower
632+
tc filter del dev $h2 ingress protocol mpls_uc pref 6 handle 106 flower
633+
tc filter del dev $h2 ingress protocol mpls_uc pref 5 handle 105 flower
634+
tc filter del dev $h2 ingress protocol mpls_uc pref 4 handle 104 flower
635+
tc filter del dev $h2 ingress protocol mpls_uc pref 3 handle 103 flower
636+
tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
637+
tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
638+
639+
log_test "mpls lse match ($tcflags)"
640+
}
641+
507642
setup_prepare()
508643
{
509644
h1=${NETIFS[p1]}

0 commit comments

Comments
 (0)