tools/testing/selftests/drivers/net/mlxsw/qos_dscp_router.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/mlxsw/qos_dscp_router.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/drivers/net/mlxsw/qos_dscp_router.sh
Extension
.sh
Size
6581 bytes
Lines
270
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

# Test for DSCP prioritization in the router.
#
# With ip_forward_update_priority disabled, the packets are expected to keep
# their DSCP (which in this test uses only values 0..7) intact as they are
# forwarded by the switch. That is verified at $h2. ICMP responses are formed
# with the same DSCP as the requests, and likewise pass through the switch
# intact, which is verified at $h1.
#
# With ip_forward_update_priority enabled, router reprioritizes the packets
# according to the table in reprioritize(). Thus, say, DSCP 7 maps to priority
# 4, which on egress maps back to DSCP 4. The response packet then gets
# reprioritized to 6, getting DSCP 6 on egress.
#
# +----------------------+                             +----------------------+
# | H1                   |                             |                   H2 |
# |    + $h1             |                             |            $h2 +     |
# |    | 192.0.2.1/28    |                             |  192.0.2.18/28 |     |
# +----|-----------------+                             +----------------|-----+
#      |                                                                |
# +----|----------------------------------------------------------------|-----+
# | SW |                                                                |     |
# |    + $swp1                                                    $swp2 +     |
# |      192.0.2.2/28                                     192.0.2.17/28       |
# |      APP=0,5,0 .. 7,5,7                          APP=0,5,0 .. 7,5,7       |
# +---------------------------------------------------------------------------+

ALL_TESTS="
	ping_ipv4
	test_update
	test_no_update
	test_pedit_norewrite
	test_dscp_leftover
"

lib_dir=$(dirname $0)/../../../net/forwarding

NUM_NETIFS=4
source $lib_dir/lib.sh

reprioritize()
{
	local in=$1; shift

	# This is based on rt_tos2priority in include/net/route.h. Assuming 1:1
	# mapping between priorities and TOS, it yields a new priority for a
	# packet with ingress priority of $in.
	local -a reprio=(0 0 2 2 6 6 4 4)

	echo ${reprio[$in]}
}

zero()
{
    echo 0
}

three()
{
    echo 3
}

h1_create()
{
	simple_if_init $h1 192.0.2.1/28
	tc qdisc add dev $h1 clsact
	dscp_capture_install $h1 0
	ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2

Annotation

Implementation Notes