2 # SPDX-License-Identifier: GPL-2.0
4 # Test for DSCP prioritization in the router.
6 # With ip_forward_update_priority disabled, the packets are expected to keep
7 # their DSCP (which in this test uses only values 0..7) intact as they are
8 # forwarded by the switch. That is verified at $h2. ICMP responses are formed
9 # with the same DSCP as the requests, and likewise pass through the switch
10 # intact, which is verified at $h1.
12 # With ip_forward_update_priority enabled, router reprioritizes the packets
13 # according to the table in reprioritize(). Thus, say, DSCP 7 maps to priority
14 # 4, which on egress maps back to DSCP 4. The response packet then gets
15 # reprioritized to 6, getting DSCP 6 on egress.
17 # +----------------------+ +----------------------+
20 # | | 192.0.2.1/28 | | 192.0.2.18/28 | |
21 # +----|-----------------+ +----------------|-----+
23 # +----|----------------------------------------------------------------|-----+
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 # +---------------------------------------------------------------------------+
36 lib_dir=$(dirname $0)/../../../net/forwarding
39 source $lib_dir/lib.sh
45 # This is based on rt_tos2priority in include/net/route.h. Assuming 1:1
46 # mapping between priorities and TOS, it yields a new priority for a
47 # packet with ingress priority of $in.
48 local -a reprio=(0 0 2 2 6 6 4 4)
57 simple_if_init $h1 192.0.2.1/28
58 tc qdisc add dev $h1 clsact
59 dscp_capture_install $h1 0
60 ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2
65 ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.2
66 dscp_capture_uninstall $h1 0
67 tc qdisc del dev $h1 clsact
68 simple_if_fini $h1 192.0.2.1/28
73 simple_if_init $h2 192.0.2.18/28
74 tc qdisc add dev $h2 clsact
75 dscp_capture_install $h2 0
76 ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.17
81 ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.17
82 dscp_capture_uninstall $h2 0
83 tc qdisc del dev $h2 clsact
84 simple_if_fini $h2 192.0.2.18/28
91 for prio in {0..7}; do
92 echo app=$prio,5,$((base + prio))
98 simple_if_init $swp1 192.0.2.2/28
99 __simple_if_init $swp2 v$swp1 192.0.2.17/28
101 lldptool -T -i $swp1 -V APP $(dscp_map 0) >/dev/null
102 lldptool -T -i $swp2 -V APP $(dscp_map 0) >/dev/null
103 lldpad_app_wait_set $swp1
104 lldpad_app_wait_set $swp2
109 lldptool -T -i $swp2 -V APP -d $(dscp_map 0) >/dev/null
110 lldptool -T -i $swp1 -V APP -d $(dscp_map 0) >/dev/null
113 __simple_if_fini $swp2 192.0.2.17/28
114 simple_if_fini $swp1 192.0.2.2/28
127 sysctl_set net.ipv4.ip_forward_update_priority 1
140 sysctl_restore net.ipv4.ip_forward_update_priority
147 ping_test $h1 192.0.2.18
152 local vrf_name=$1; shift
156 local reprio=$1; shift
160 local prio2=$($reprio $prio) # ICMP Request egress prio
161 local prio3=$($reprio $prio2) # ICMP Response egress prio
163 local dscp=$((prio << 2)) # ICMP Request ingress DSCP
164 local dscp2=$((prio2 << 2)) # ICMP Request egress DSCP
165 local dscp3=$((prio3 << 2)) # ICMP Response egress DSCP
169 eval "local -A dev1_t0s=($(dscp_fetch_stats $dev1 0))"
170 eval "local -A dev2_t0s=($(dscp_fetch_stats $dev2 0))"
172 ip vrf exec $vrf_name \
173 ${PING} -Q $dscp ${sip:+-I $sip} $dip \
174 -c 10 -i 0.1 -w 2 &> /dev/null
176 eval "local -A dev1_t1s=($(dscp_fetch_stats $dev1 0))"
177 eval "local -A dev2_t1s=($(dscp_fetch_stats $dev2 0))"
180 local dscpi=$((i << 2))
184 if ((i == prio2)); then
187 if ((i == prio3)); then
191 local delta=$((dev2_t1s[$i] - dev2_t0s[$i]))
193 check_err $? "DSCP $dscpi@$dev2: Expected to capture $expect2 packets, got $delta."
195 delta=$((dev1_t1s[$i] - dev1_t0s[$i]))
197 check_err $? "DSCP $dscpi@$dev1: Expected to capture $expect3 packets, got $delta."
200 log_test "DSCP rewrite: $dscp-(prio $prio2)-$dscp2-(prio $prio3)-$dscp3"
205 local update=$1; shift
206 local reprio=$1; shift
208 sysctl_restore net.ipv4.ip_forward_update_priority
209 sysctl_set net.ipv4.ip_forward_update_priority $update
211 for prio in {0..7}; do
212 dscp_ping_test v$h1 192.0.2.1 192.0.2.18 $prio $reprio $h1 $h2
218 __test_update 1 reprioritize