Path: blob/master/tools/testing/selftests/drivers/net/ocelot/basic_qos.sh
26298 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02# Copyright 2022 NXP34# The script is mostly generic, with the exception of the5# ethtool per-TC counter names ("rx_green_prio_${tc}")67WAIT_TIME=18NUM_NETIFS=49STABLE_MAC_ADDRS=yes10NETIF_CREATE=no11lib_dir=$(dirname $0)/../../../net/forwarding12source $lib_dir/tc_common.sh13source $lib_dir/lib.sh1415require_command dcb1617h1=${NETIFS[p1]}18swp1=${NETIFS[p2]}19swp2=${NETIFS[p3]}20h2=${NETIFS[p4]}2122H1_IPV4="192.0.2.1"23H2_IPV4="192.0.2.2"24H1_IPV6="2001:db8:1::1"25H2_IPV6="2001:db8:1::2"2627h1_create()28{29simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/6430}3132h1_destroy()33{34simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/6435}3637h2_create()38{39simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/6440}4142h2_destroy()43{44simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/6445}4647h1_vlan_create()48{49local vid=$15051vlan_create $h1 $vid52simple_if_init $h1.$vid $H1_IPV4/24 $H1_IPV6/6453ip link set $h1.$vid type vlan \54egress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 \55ingress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:756}5758h1_vlan_destroy()59{60local vid=$16162simple_if_fini $h1.$vid $H1_IPV4/24 $H1_IPV6/6463vlan_destroy $h1 $vid64}6566h2_vlan_create()67{68local vid=$16970vlan_create $h2 $vid71simple_if_init $h2.$vid $H2_IPV4/24 $H2_IPV6/6472ip link set $h2.$vid type vlan \73egress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 \74ingress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:775}7677h2_vlan_destroy()78{79local vid=$18081simple_if_fini $h2.$vid $H2_IPV4/24 $H2_IPV6/6482vlan_destroy $h2 $vid83}8485vlans_prepare()86{87h1_vlan_create 10088h2_vlan_create 1008990tc qdisc add dev ${h1}.100 clsact91tc filter add dev ${h1}.100 egress protocol ipv4 \92flower ip_proto icmp action skbedit priority 393tc filter add dev ${h1}.100 egress protocol ipv6 \94flower ip_proto icmpv6 action skbedit priority 395}9697vlans_destroy()98{99tc qdisc del dev ${h1}.100 clsact100101h1_vlan_destroy 100102h2_vlan_destroy 100103}104105switch_create()106{107ip link set ${swp1} up108ip link set ${swp2} up109110# Ports should trust VLAN PCP even with vlan_filtering=0111ip link add br0 type bridge112ip link set ${swp1} master br0113ip link set ${swp2} master br0114ip link set br0 up115}116117switch_destroy()118{119ip link del br0120}121122setup_prepare()123{124vrf_prepare125126h1_create127h2_create128switch_create129}130131cleanup()132{133pre_cleanup134135h2_destroy136h1_destroy137switch_destroy138139vrf_cleanup140}141142dscp_cs_to_tos()143{144local dscp_cs=$1145146# https://datatracker.ietf.org/doc/html/rfc2474147# 4.2.2.1 The Class Selector Codepoints148echo $((${dscp_cs} << 5))149}150151run_test()152{153local test_name=$1; shift154local if_name=$1; shift155local tc=$1; shift156local tos=$1; shift157local counter_name="rx_green_prio_${tc}"158local ipv4_before159local ipv4_after160local ipv6_before161local ipv6_after162163ipv4_before=$(ethtool_stats_get ${swp1} "${counter_name}")164ping_do ${if_name} $H2_IPV4 "-Q ${tos}"165ipv4_after=$(ethtool_stats_get ${swp1} "${counter_name}")166167if [ $((${ipv4_after} - ${ipv4_before})) -lt ${PING_COUNT} ]; then168RET=1169else170RET=0171fi172log_test "IPv4 ${test_name}"173174ipv6_before=$(ethtool_stats_get ${swp1} "${counter_name}")175ping_do ${if_name} $H2_IPV6 "-Q ${tos}"176ipv6_after=$(ethtool_stats_get ${swp1} "${counter_name}")177178if [ $((${ipv6_after} - ${ipv6_before})) -lt ${PING_COUNT} ]; then179RET=1180else181RET=0182fi183log_test "IPv6 ${test_name}"184}185186port_default_prio_get()187{188local if_name=$1189local prio190191prio="$(dcb -j app show dev ${if_name} default-prio | \192jq '.default_prio[]')"193if [ -z "${prio}" ]; then194prio=0195fi196197echo ${prio}198}199200test_port_default()201{202local orig=$(port_default_prio_get ${swp1})203local dmac=$(mac_get ${h2})204205dcb app replace dev ${swp1} default-prio 5206207run_test "Port-default QoS classification" ${h1} 5 0208209dcb app replace dev ${swp1} default-prio ${orig}210}211212test_vlan_pcp()213{214vlans_prepare215216run_test "Trusted VLAN PCP QoS classification" ${h1}.100 3 0217218vlans_destroy219}220221test_ip_dscp()222{223local port_default=$(port_default_prio_get ${swp1})224local tos=$(dscp_cs_to_tos 4)225226dcb app add dev ${swp1} dscp-prio CS4:4227run_test "Trusted DSCP QoS classification" ${h1} 4 ${tos}228dcb app del dev ${swp1} dscp-prio CS4:4229230vlans_prepare231run_test "Untrusted DSCP QoS classification follows VLAN PCP" \232${h1}.100 3 ${tos}233vlans_destroy234235run_test "Untrusted DSCP QoS classification follows port default" \236${h1} ${port_default} ${tos}237}238239trap cleanup EXIT240241ALL_TESTS="242test_port_default243test_vlan_pcp244test_ip_dscp245"246247setup_prepare248setup_wait249250tests_run251252exit $EXIT_STATUS253254255