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 # +---------------------------------------------------------------------------+
38 lib_dir
=$
(dirname $0)/..
/..
/..
/net
/forwarding
41 source $lib_dir/lib.sh
47 # This is based on rt_tos2priority in include/net/route.h. Assuming 1:1
48 # mapping between priorities and TOS, it yields a new priority for a
49 # packet with ingress priority of $in.
50 local -a reprio
=(0 0 2 2 6 6 4 4)
67 simple_if_init
$h1 192.0.2.1/28
68 tc qdisc add dev
$h1 clsact
69 dscp_capture_install
$h1 0
70 ip route add vrf v
$h1 192.0.2.16/28 via
192.0.2.2
75 ip route del vrf v
$h1 192.0.2.16/28 via
192.0.2.2
76 dscp_capture_uninstall
$h1 0
77 tc qdisc del dev
$h1 clsact
78 simple_if_fini
$h1 192.0.2.1/28
83 simple_if_init
$h2 192.0.2.18/28
84 tc qdisc add dev
$h2 clsact
85 dscp_capture_install
$h2 0
86 ip route add vrf v
$h2 192.0.2.0/28 via
192.0.2.17
91 ip route del vrf v
$h2 192.0.2.0/28 via
192.0.2.17
92 dscp_capture_uninstall
$h2 0
93 tc qdisc del dev
$h2 clsact
94 simple_if_fini
$h2 192.0.2.18/28
102 for prio
in {0.
.7}; do
103 echo app
=$prio,5,$
((base
+ prio
))
109 simple_if_init
$swp1 192.0.2.2/28
110 __simple_if_init
$swp2 v
$swp1 192.0.2.17/28
112 tc qdisc add dev
$swp1 clsact
113 tc qdisc add dev
$swp2 clsact
115 lldptool
-T -i $swp1 -V APP $
(dscp_map
0) >/dev
/null
116 lldptool
-T -i $swp2 -V APP $
(dscp_map
0) >/dev
/null
117 lldpad_app_wait_set
$swp1
118 lldpad_app_wait_set
$swp2
123 lldptool
-T -i $swp2 -V APP
-d $
(dscp_map
0) >/dev
/null
124 lldptool
-T -i $swp1 -V APP
-d $
(dscp_map
0) >/dev
/null
127 tc qdisc del dev
$swp2 clsact
128 tc qdisc del dev
$swp1 clsact
130 __simple_if_fini
$swp2 192.0.2.17/28
131 simple_if_fini
$swp1 192.0.2.2/28
144 sysctl_set net.ipv4.ip_forward_update_priority
1
157 sysctl_restore net.ipv4.ip_forward_update_priority
164 ping_test
$h1 192.0.2.18
169 local vrf_name
=$1; shift
173 local reprio
=$1; shift
178 local prio2
=$
($reprio $prio) # ICMP Request egress prio
179 local prio3
=$
($reprio $prio2) # ICMP Response egress prio
181 local dscp
=$
((prio
<< 2)) # ICMP Request ingress DSCP
182 local dscp2=$((prio2 << 2)) # ICMP Request egress DSCP
183 local dscp3=$((prio3 << 2)) # ICMP Response egress DSCP
187 eval "local -A dev1_t0s=($(dscp_fetch_stats $dev1 0))"
188 eval "local -A dev2_t0s=($(dscp_fetch_stats $dev2 0))"
190 local ping_timeout=$((PING_TIMEOUT * 5))
191 ip vrf exec $vrf_name \
192 ${PING} -Q $dscp ${sip:+-I $sip} $dip \
193 -c 10 -i 0.5 -w $ping_timeout &> /dev/null
195 eval "local -A dev1_t1s=($(dscp_fetch_stats $dev1 0))"
196 eval "local -A dev2_t1s=($(dscp_fetch_stats $dev2 0))"
199 local dscpi=$((i << 2))
203 if ((i == prio2)); then
206 if ((i == prio3)); then
210 local delta=$((dev2_t1s[$i] - dev2_t0s[$i]))
212 check_err $? "DSCP $dscpi@$dev2: Expected to capture $expect2 packets, got $delta."
214 delta=$((dev1_t1s[$i] - dev1_t0s[$i]))
216 check_err $? "DSCP $dscpi@$dev1: Expected to capture $expect3 packets, got $delta."
219 log_test "DSCP rewrite: $dscp-(prio $prio2)-$dscp2-(prio $prio3)-$dscp3"
224 local update=$1; shift
225 local reprio=$1; shift
228 sysctl_restore net.ipv4.ip_forward_update_priority
229 sysctl_set net.ipv4.ip_forward_update_priority $update
231 for prio in {0..7}; do
232 dscp_ping_test v$h1 192.0.2.1 192.0.2.18 $prio $reprio $h1 $h2
238 echo "Test net.ipv4.ip_forward_update_priority=1"
239 __test_update 1 reprioritize
244 echo "Test net.ipv4.ip_forward_update_priority=0"
248 # Test that when DSCP is updated in pedit, the DSCP rewrite is turned off.
249 test_pedit_norewrite()
251 echo "Test no DSCP rewrite after DSCP is updated by pedit"
253 tc filter add dev $swp1 ingress handle 101 pref 1 prot ip flower \
254 action pedit ex munge ip dsfield set $((3 << 2)) retain 0xfc \
255 action skbedit priority 3
257 __test_update 0 three
259 tc filter del dev $swp1 ingress pref 1
262 # Test that when the last APP rule is removed, the prio->DSCP map is properly
263 # set to zeroes, and that the last APP rule does not stay active in the ASIC.
266 echo "Test that last removed DSCP rule is deconfigured correctly"
268 lldptool -T -i $swp2 -V APP -d $(dscp_map 0) >/dev/null
273 lldptool -T -i $swp2 -V APP $(dscp_map 0) >/dev/null
274 lldpad_app_wait_set $swp2