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 local ping_timeout=$((PING_TIMEOUT * 5))
173 ip vrf exec $vrf_name \
174 ${PING} -Q $dscp ${sip:+-I $sip} $dip \
175 -c 10 -i 0.5 -w $ping_timeout &> /dev/null
177 eval "local -A dev1_t1s=($(dscp_fetch_stats $dev1 0))"
178 eval "local -A dev2_t1s=($(dscp_fetch_stats $dev2 0))"
181 local dscpi=$((i << 2))
185 if ((i == prio2)); then
188 if ((i == prio3)); then
192 local delta=$((dev2_t1s[$i] - dev2_t0s[$i]))
194 check_err $? "DSCP $dscpi@$dev2: Expected to capture $expect2 packets, got $delta."
196 delta=$((dev1_t1s[$i] - dev1_t0s[$i]))
198 check_err $? "DSCP $dscpi@$dev1: Expected to capture $expect3 packets, got $delta."
201 log_test "DSCP rewrite: $dscp-(prio $prio2)-$dscp2-(prio $prio3)-$dscp3"
206 local update=$1; shift
207 local reprio=$1; shift
209 sysctl_restore net.ipv4.ip_forward_update_priority
210 sysctl_set net.ipv4.ip_forward_update_priority $update
212 for prio in {0..7}; do
213 dscp_ping_test v$h1 192.0.2.1 192.0.2.18 $prio $reprio $h1 $h2
219 __test_update 1 reprioritize