brintos

brintos / linux-shallow public Read only

0
0
Text · 4.3 KiB · c51c834 Raw
254 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03# Copyright 2022 NXP4 5# The script is mostly generic, with the exception of the6# ethtool per-TC counter names ("rx_green_prio_${tc}")7 8WAIT_TIME=19NUM_NETIFS=410STABLE_MAC_ADDRS=yes11NETIF_CREATE=no12lib_dir=$(dirname $0)/../../../net/forwarding13source $lib_dir/tc_common.sh14source $lib_dir/lib.sh15 16require_command dcb17 18h1=${NETIFS[p1]}19swp1=${NETIFS[p2]}20swp2=${NETIFS[p3]}21h2=${NETIFS[p4]}22 23H1_IPV4="192.0.2.1"24H2_IPV4="192.0.2.2"25H1_IPV6="2001:db8:1::1"26H2_IPV6="2001:db8:1::2"27 28h1_create()29{30	simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/6431}32 33h1_destroy()34{35	simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/6436}37 38h2_create()39{40	simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/6441}42 43h2_destroy()44{45	simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/6446}47 48h1_vlan_create()49{50	local vid=$151 52	vlan_create $h1 $vid53	simple_if_init $h1.$vid $H1_IPV4/24 $H1_IPV6/6454	ip link set $h1.$vid type vlan \55		egress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 \56		ingress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:757}58 59h1_vlan_destroy()60{61	local vid=$162 63	simple_if_fini $h1.$vid $H1_IPV4/24 $H1_IPV6/6464	vlan_destroy $h1 $vid65}66 67h2_vlan_create()68{69	local vid=$170 71	vlan_create $h2 $vid72	simple_if_init $h2.$vid $H2_IPV4/24 $H2_IPV6/6473	ip link set $h2.$vid type vlan \74		egress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 \75		ingress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:776}77 78h2_vlan_destroy()79{80	local vid=$181 82	simple_if_fini $h2.$vid $H2_IPV4/24 $H2_IPV6/6483	vlan_destroy $h2 $vid84}85 86vlans_prepare()87{88	h1_vlan_create 10089	h2_vlan_create 10090 91	tc qdisc add dev ${h1}.100 clsact92	tc filter add dev ${h1}.100 egress protocol ipv4 \93		flower ip_proto icmp action skbedit priority 394	tc filter add dev ${h1}.100 egress protocol ipv6 \95		flower ip_proto icmpv6 action skbedit priority 396}97 98vlans_destroy()99{100	tc qdisc del dev ${h1}.100 clsact101 102	h1_vlan_destroy 100103	h2_vlan_destroy 100104}105 106switch_create()107{108	ip link set ${swp1} up109	ip link set ${swp2} up110 111	# Ports should trust VLAN PCP even with vlan_filtering=0112	ip link add br0 type bridge113	ip link set ${swp1} master br0114	ip link set ${swp2} master br0115	ip link set br0 up116}117 118switch_destroy()119{120	ip link del br0121}122 123setup_prepare()124{125	vrf_prepare126 127	h1_create128	h2_create129	switch_create130}131 132cleanup()133{134	pre_cleanup135 136	h2_destroy137	h1_destroy138	switch_destroy139 140	vrf_cleanup141}142 143dscp_cs_to_tos()144{145	local dscp_cs=$1146 147	# https://datatracker.ietf.org/doc/html/rfc2474148	# 4.2.2.1  The Class Selector Codepoints149	echo $((${dscp_cs} << 5))150}151 152run_test()153{154	local test_name=$1; shift155	local if_name=$1; shift156	local tc=$1; shift157	local tos=$1; shift158	local counter_name="rx_green_prio_${tc}"159	local ipv4_before160	local ipv4_after161	local ipv6_before162	local ipv6_after163 164	ipv4_before=$(ethtool_stats_get ${swp1} "${counter_name}")165	ping_do ${if_name} $H2_IPV4 "-Q ${tos}"166	ipv4_after=$(ethtool_stats_get ${swp1} "${counter_name}")167 168	if [ $((${ipv4_after} - ${ipv4_before})) -lt ${PING_COUNT} ]; then169		RET=1170	else171		RET=0172	fi173	log_test "IPv4 ${test_name}"174 175	ipv6_before=$(ethtool_stats_get ${swp1} "${counter_name}")176	ping_do ${if_name} $H2_IPV6 "-Q ${tos}"177	ipv6_after=$(ethtool_stats_get ${swp1} "${counter_name}")178 179	if [ $((${ipv6_after} - ${ipv6_before})) -lt ${PING_COUNT} ]; then180		RET=1181	else182		RET=0183	fi184	log_test "IPv6 ${test_name}"185}186 187port_default_prio_get()188{189	local if_name=$1190	local prio191 192	prio="$(dcb -j app show dev ${if_name} default-prio | \193		jq '.default_prio[]')"194	if [ -z "${prio}" ]; then195		prio=0196	fi197 198	echo ${prio}199}200 201test_port_default()202{203	local orig=$(port_default_prio_get ${swp1})204	local dmac=$(mac_get ${h2})205 206	dcb app replace dev ${swp1} default-prio 5207 208	run_test "Port-default QoS classification" ${h1} 5 0209 210	dcb app replace dev ${swp1} default-prio ${orig}211}212 213test_vlan_pcp()214{215	vlans_prepare216 217	run_test "Trusted VLAN PCP QoS classification" ${h1}.100 3 0218 219	vlans_destroy220}221 222test_ip_dscp()223{224	local port_default=$(port_default_prio_get ${swp1})225	local tos=$(dscp_cs_to_tos 4)226 227	dcb app add dev ${swp1} dscp-prio CS4:4228	run_test "Trusted DSCP QoS classification" ${h1} 4 ${tos}229	dcb app del dev ${swp1} dscp-prio CS4:4230 231	vlans_prepare232	run_test "Untrusted DSCP QoS classification follows VLAN PCP" \233		${h1}.100 3 ${tos}234	vlans_destroy235 236	run_test "Untrusted DSCP QoS classification follows port default" \237		${h1} ${port_default} ${tos}238}239 240trap cleanup EXIT241 242ALL_TESTS="243	test_port_default244	test_vlan_pcp245	test_ip_dscp246"247 248setup_prepare249setup_wait250 251tests_run252 253exit $EXIT_STATUS254