brintos

brintos / linux-shallow public Read only

0
0
Text · 6.4 KiB · f6c23f8 Raw
270 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# Test for DSCP prioritization in the router.5#6# With ip_forward_update_priority disabled, the packets are expected to keep7# their DSCP (which in this test uses only values 0..7) intact as they are8# forwarded by the switch. That is verified at $h2. ICMP responses are formed9# with the same DSCP as the requests, and likewise pass through the switch10# intact, which is verified at $h1.11#12# With ip_forward_update_priority enabled, router reprioritizes the packets13# according to the table in reprioritize(). Thus, say, DSCP 7 maps to priority14# 4, which on egress maps back to DSCP 4. The response packet then gets15# reprioritized to 6, getting DSCP 6 on egress.16#17# +----------------------+                             +----------------------+18# | H1                   |                             |                   H2 |19# |    + $h1             |                             |            $h2 +     |20# |    | 192.0.2.1/28    |                             |  192.0.2.18/28 |     |21# +----|-----------------+                             +----------------|-----+22#      |                                                                |23# +----|----------------------------------------------------------------|-----+24# | SW |                                                                |     |25# |    + $swp1                                                    $swp2 +     |26# |      192.0.2.2/28                                     192.0.2.17/28       |27# |      APP=0,5,0 .. 7,5,7                          APP=0,5,0 .. 7,5,7       |28# +---------------------------------------------------------------------------+29 30ALL_TESTS="31	ping_ipv432	test_update33	test_no_update34	test_pedit_norewrite35	test_dscp_leftover36"37 38lib_dir=$(dirname $0)/../../../net/forwarding39 40NUM_NETIFS=441source $lib_dir/lib.sh42 43reprioritize()44{45	local in=$1; shift46 47	# This is based on rt_tos2priority in include/net/route.h. Assuming 1:148	# mapping between priorities and TOS, it yields a new priority for a49	# packet with ingress priority of $in.50	local -a reprio=(0 0 2 2 6 6 4 4)51 52	echo ${reprio[$in]}53}54 55zero()56{57    echo 058}59 60three()61{62    echo 363}64 65h1_create()66{67	simple_if_init $h1 192.0.2.1/2868	tc qdisc add dev $h1 clsact69	dscp_capture_install $h1 070	ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.271}72 73h1_destroy()74{75	ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.276	dscp_capture_uninstall $h1 077	tc qdisc del dev $h1 clsact78	simple_if_fini $h1 192.0.2.1/2879}80 81h2_create()82{83	simple_if_init $h2 192.0.2.18/2884	tc qdisc add dev $h2 clsact85	dscp_capture_install $h2 086	ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.1787}88 89h2_destroy()90{91	ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.1792	dscp_capture_uninstall $h2 093	tc qdisc del dev $h2 clsact94	simple_if_fini $h2 192.0.2.18/2895}96 97switch_create()98{99	simple_if_init $swp1 192.0.2.2/28100	__simple_if_init $swp2 v$swp1 192.0.2.17/28101 102	tc qdisc add dev $swp1 clsact103	tc qdisc add dev $swp2 clsact104 105	dcb app add dev $swp1 dscp-prio 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7106	dcb app add dev $swp2 dscp-prio 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7107}108 109switch_destroy()110{111	dcb app del dev $swp2 dscp-prio 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7112	dcb app del dev $swp1 dscp-prio 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7113 114	tc qdisc del dev $swp2 clsact115	tc qdisc del dev $swp1 clsact116 117	__simple_if_fini $swp2 192.0.2.17/28118	simple_if_fini $swp1 192.0.2.2/28119}120 121setup_prepare()122{123	h1=${NETIFS[p1]}124	swp1=${NETIFS[p2]}125 126	swp2=${NETIFS[p3]}127	h2=${NETIFS[p4]}128 129	vrf_prepare130 131	sysctl_set net.ipv4.ip_forward_update_priority 1132	h1_create133	h2_create134	switch_create135}136 137cleanup()138{139	pre_cleanup140 141	switch_destroy142	h2_destroy143	h1_destroy144	sysctl_restore net.ipv4.ip_forward_update_priority145 146	vrf_cleanup147}148 149ping_ipv4()150{151	ping_test $h1 192.0.2.18152}153 154dscp_ping_test()155{156	local vrf_name=$1; shift157	local sip=$1; shift158	local dip=$1; shift159	local prio=$1; shift160	local reprio=$1; shift161	local dev1=$1; shift162	local dev2=$1; shift163	local i164 165	local prio2=$($reprio $prio)   # ICMP Request egress prio166	local prio3=$($reprio $prio2)  # ICMP Response egress prio167 168	local dscp=$((prio << 2))     # ICMP Request ingress DSCP169	local dscp2=$((prio2 << 2))   # ICMP Request egress DSCP170	local dscp3=$((prio3 << 2))   # ICMP Response egress DSCP171 172	RET=0173 174	eval "local -A dev1_t0s=($(dscp_fetch_stats $dev1 0))"175	eval "local -A dev2_t0s=($(dscp_fetch_stats $dev2 0))"176 177	local ping_timeout=$((PING_TIMEOUT * 5))178	ip vrf exec $vrf_name \179	   ${PING} -Q $dscp ${sip:+-I $sip} $dip \180		   -c 10 -i 0.5 -w $ping_timeout &> /dev/null181 182	eval "local -A dev1_t1s=($(dscp_fetch_stats $dev1 0))"183	eval "local -A dev2_t1s=($(dscp_fetch_stats $dev2 0))"184 185	for i in {0..7}; do186		local dscpi=$((i << 2))187		local expect2=0188		local expect3=0189 190		if ((i == prio2)); then191			expect2=10192		fi193		if ((i == prio3)); then194			expect3=10195		fi196 197		local delta=$((dev2_t1s[$i] - dev2_t0s[$i]))198		((expect2 == delta))199		check_err $? "DSCP $dscpi@$dev2: Expected to capture $expect2 packets, got $delta."200 201		delta=$((dev1_t1s[$i] - dev1_t0s[$i]))202		((expect3 == delta))203		check_err $? "DSCP $dscpi@$dev1: Expected to capture $expect3 packets, got $delta."204	done205 206	log_test "DSCP rewrite: $dscp-(prio $prio2)-$dscp2-(prio $prio3)-$dscp3"207}208 209__test_update()210{211	local update=$1; shift212	local reprio=$1; shift213	local prio214 215	sysctl_restore net.ipv4.ip_forward_update_priority216	sysctl_set net.ipv4.ip_forward_update_priority $update217 218	for prio in {0..7}; do219		dscp_ping_test v$h1 192.0.2.1 192.0.2.18 $prio $reprio $h1 $h2220	done221}222 223test_update()224{225	echo "Test net.ipv4.ip_forward_update_priority=1"226	__test_update 1 reprioritize227}228 229test_no_update()230{231	echo "Test net.ipv4.ip_forward_update_priority=0"232	__test_update 0 echo233}234 235# Test that when DSCP is updated in pedit, the DSCP rewrite is turned off.236test_pedit_norewrite()237{238	echo "Test no DSCP rewrite after DSCP is updated by pedit"239 240	tc filter add dev $swp1 ingress handle 101 pref 1 prot ip flower \241	    action pedit ex munge ip dsfield set $((3 << 2)) retain 0xfc \242	    action skbedit priority 3243 244	__test_update 0 three245 246	tc filter del dev $swp1 ingress pref 1247}248 249# Test that when the last APP rule is removed, the prio->DSCP map is properly250# set to zeroes, and that the last APP rule does not stay active in the ASIC.251test_dscp_leftover()252{253	echo "Test that last removed DSCP rule is deconfigured correctly"254 255	dcb app del dev $swp2 dscp-prio 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7256 257	__test_update 0 zero258 259	dcb app add dev $swp2 dscp-prio 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7260}261 262trap cleanup EXIT263 264setup_prepare265setup_wait266 267tests_run268 269exit $EXIT_STATUS270