brintos

brintos / linux-shallow public Read only

0
0
Text · 4.1 KiB · 914c63d Raw
183 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# Test for DSCP prioritization and rewrite. Packets ingress $swp1 with a DSCP5# tag and are prioritized according to the map at $swp1. They egress $swp2 and6# the DSCP value is updated to match the map at that interface. The updated DSCP7# tag is verified at $h2.8#9# ICMP responses are produced with the same DSCP tag that arrived at $h2. They10# go through prioritization at $swp2 and DSCP retagging at $swp1. The tag is11# verified at $h1--it should match the original tag.12#13# +----------------------+                             +----------------------+14# | H1                   |                             |                   H2 |15# |    + $h1             |                             |            $h2 +     |16# |    | 192.0.2.1/28    |                             |   192.0.2.2/28 |     |17# +----|-----------------+                             +----------------|-----+18#      |                                                                |19# +----|----------------------------------------------------------------|-----+20# | SW |                                                                |     |21# |  +-|----------------------------------------------------------------|-+   |22# |  | + $swp1                       BR                           $swp2 + |   |23# |  |   dcb dscp-prio 10:0...17:7            dcb dscp-prio 20:0...27:7   |   |24# |  +--------------------------------------------------------------------+   |25# +---------------------------------------------------------------------------+26 27ALL_TESTS="28	ping_ipv429	test_dscp30"31 32lib_dir=$(dirname $0)/../../../net/forwarding33 34NUM_NETIFS=435source $lib_dir/lib.sh36 37h1_create()38{39	simple_if_init $h1 192.0.2.1/2840	tc qdisc add dev $h1 clsact41	dscp_capture_install $h1 1042}43 44h1_destroy()45{46	dscp_capture_uninstall $h1 1047	tc qdisc del dev $h1 clsact48	simple_if_fini $h1 192.0.2.1/2849}50 51h2_create()52{53	simple_if_init $h2 192.0.2.2/2854	tc qdisc add dev $h2 clsact55	dscp_capture_install $h2 2056}57 58h2_destroy()59{60	dscp_capture_uninstall $h2 2061	tc qdisc del dev $h2 clsact62	simple_if_fini $h2 192.0.2.2/2863}64 65switch_create()66{67	ip link add name br1 type bridge vlan_filtering 168	ip link set dev br1 addrgenmode none69	ip link set dev br1 up70	ip link set dev $swp1 master br171	ip link set dev $swp1 up72	ip link set dev $swp2 master br173	ip link set dev $swp2 up74 75	dcb app add dev $swp1 dscp-prio 10:0 11:1 12:2 13:3 14:4 15:5 16:6 17:776	dcb app add dev $swp2 dscp-prio 20:0 21:1 22:2 23:3 24:4 25:5 26:6 27:777}78 79switch_destroy()80{81	dcb app del dev $swp2 dscp-prio 20:0 21:1 22:2 23:3 24:4 25:5 26:6 27:782	dcb app del dev $swp1 dscp-prio 10:0 11:1 12:2 13:3 14:4 15:5 16:6 17:783 84	ip link set dev $swp2 down85	ip link set dev $swp2 nomaster86	ip link set dev $swp1 down87	ip link set dev $swp1 nomaster88	ip link del dev br189}90 91setup_prepare()92{93	h1=${NETIFS[p1]}94	swp1=${NETIFS[p2]}95 96	swp2=${NETIFS[p3]}97	h2=${NETIFS[p4]}98 99	vrf_prepare100 101	h1_create102	h2_create103	switch_create104}105 106cleanup()107{108	pre_cleanup109 110	switch_destroy111	h2_destroy112	h1_destroy113 114	vrf_cleanup115}116 117ping_ipv4()118{119	ping_test $h1 192.0.2.2120}121 122dscp_ping_test()123{124	local vrf_name=$1; shift125	local sip=$1; shift126	local dip=$1; shift127	local prio=$1; shift128	local dev_10=$1; shift129	local dev_20=$1; shift130	local key131 132	local dscp_10=$(((prio + 10) << 2))133	local dscp_20=$(((prio + 20) << 2))134 135	RET=0136 137	local -A t0s138	eval "t0s=($(dscp_fetch_stats $dev_10 10)139		   $(dscp_fetch_stats $dev_20 20))"140 141	local ping_timeout=$((PING_TIMEOUT * 5))142	ip vrf exec $vrf_name \143	   ${PING} -Q $dscp_10 ${sip:+-I $sip} $dip \144		   -c 10 -i 0.5 -w $ping_timeout &> /dev/null145 146	local -A t1s147	eval "t1s=($(dscp_fetch_stats $dev_10 10)148		   $(dscp_fetch_stats $dev_20 20))"149 150	for key in ${!t0s[@]}; do151		local expect152		if ((key == prio+10 || key == prio+20)); then153			expect=10154		else155			expect=0156		fi157 158		local delta=$((t1s[$key] - t0s[$key]))159		((expect == delta))160		check_err $? "DSCP $key: Expected to capture $expect packets, got $delta."161	done162 163	log_test "DSCP rewrite: $dscp_10-(prio $prio)-$dscp_20"164}165 166test_dscp()167{168	local prio169 170	for prio in {0..7}; do171		dscp_ping_test v$h1 192.0.2.1 192.0.2.2 $prio $h1 $h2172	done173}174 175trap cleanup EXIT176 177setup_prepare178setup_wait179 180tests_run181 182exit $EXIT_STATUS183