drm/atomic-helper: document drm_atomic_helper_check() restrictions
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / pedit_dsfield.sh
blobaf008fbf2725eb706963670a8faf8ffb6b6fc2be
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # This test sends traffic from H1 to H2. Either on ingress of $swp1, or on
5 # egress of $swp2, the traffic is acted upon by a pedit action. An ingress
6 # filter installed on $h2 verifies that the packet looks like expected.
8 # +----------------------+ +----------------------+
9 # | H1 | | H2 |
10 # | + $h1 | | $h2 + |
11 # | | 192.0.2.1/28 | | 192.0.2.2/28 | |
12 # +----|-----------------+ +----------------|-----+
13 # | |
14 # +----|----------------------------------------------------------------|-----+
15 # | SW | | |
16 # | +-|----------------------------------------------------------------|-+ |
17 # | | + $swp1 BR $swp2 + | |
18 # | +--------------------------------------------------------------------+ |
19 # +---------------------------------------------------------------------------+
21 ALL_TESTS="
22 ping_ipv4
23 ping_ipv6
24 test_ip_dsfield
25 test_ip_dscp
26 test_ip_ecn
27 test_ip_dscp_ecn
28 test_ip6_dsfield
29 test_ip6_dscp
30 test_ip6_ecn
33 NUM_NETIFS=4
34 source lib.sh
35 source tc_common.sh
37 : ${HIT_TIMEOUT:=2000} # ms
39 h1_create()
41 simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
44 h1_destroy()
46 simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/64
49 h2_create()
51 simple_if_init $h2 192.0.2.2/28 2001:db8:1::2/64
52 tc qdisc add dev $h2 clsact
55 h2_destroy()
57 tc qdisc del dev $h2 clsact
58 simple_if_fini $h2 192.0.2.2/28 2001:db8:1::2/64
61 switch_create()
63 ip link add name br1 type bridge vlan_filtering 1
64 ip link set dev br1 addrgenmode none
65 ip link set dev br1 up
66 ip link set dev $swp1 master br1
67 ip link set dev $swp1 up
68 ip link set dev $swp2 master br1
69 ip link set dev $swp2 up
71 tc qdisc add dev $swp1 clsact
72 tc qdisc add dev $swp2 clsact
75 switch_destroy()
77 tc qdisc del dev $swp2 clsact
78 tc qdisc del dev $swp1 clsact
80 ip link set dev $swp2 down
81 ip link set dev $swp2 nomaster
82 ip link set dev $swp1 down
83 ip link set dev $swp1 nomaster
84 ip link del dev br1
87 setup_prepare()
89 h1=${NETIFS[p1]}
90 swp1=${NETIFS[p2]}
92 swp2=${NETIFS[p3]}
93 h2=${NETIFS[p4]}
95 h2mac=$(mac_get $h2)
97 vrf_prepare
98 h1_create
99 h2_create
100 switch_create
103 cleanup()
105 pre_cleanup
107 switch_destroy
108 h2_destroy
109 h1_destroy
110 vrf_cleanup
113 ping_ipv4()
115 ping_test $h1 192.0.2.2
118 ping_ipv6()
120 ping6_test $h1 2001:db8:1::2
123 do_test_pedit_dsfield_common()
125 local pedit_locus=$1; shift
126 local pedit_action=$1; shift
127 local mz_flags=$1; shift
129 RET=0
131 # TOS 125: DSCP 31, ECN 1. Used for testing that the relevant part is
132 # overwritten when zero is selected.
133 $MZ $mz_flags $h1 -c 10 -d 20msec -p 100 \
134 -a own -b $h2mac -q -t tcp tos=0x7d,sp=54321,dp=12345
136 local pkts
137 pkts=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= 10" \
138 tc_rule_handle_stats_get "dev $h2 ingress" 101)
139 check_err $? "Expected to get 10 packets on test probe, but got $pkts."
141 pkts=$(tc_rule_handle_stats_get "$pedit_locus" 101)
142 ((pkts >= 10))
143 check_err $? "Expected to get 10 packets on pedit rule, but got $pkts."
145 log_test "$pedit_locus pedit $pedit_action"
148 do_test_pedit_dsfield()
150 local pedit_locus=$1; shift
151 local pedit_action=$1; shift
152 local match_prot=$1; shift
153 local match_flower=$1; shift
154 local mz_flags=$1; shift
155 local saddr=$1; shift
156 local daddr=$1; shift
158 tc filter add $pedit_locus handle 101 pref 1 \
159 flower action pedit ex munge $pedit_action
160 tc filter add dev $h2 ingress handle 101 pref 1 prot $match_prot \
161 flower skip_hw $match_flower action pass
163 do_test_pedit_dsfield_common "$pedit_locus" "$pedit_action" "$mz_flags"
165 tc filter del dev $h2 ingress pref 1
166 tc filter del $pedit_locus pref 1
169 do_test_ip_dsfield()
171 local locus=$1; shift
172 local dsfield
174 for dsfield in 0 1 2 3 128 252 253 254 255; do
175 do_test_pedit_dsfield "$locus" \
176 "ip dsfield set $dsfield" \
177 ip "ip_tos $dsfield" \
178 "-A 192.0.2.1 -B 192.0.2.2"
179 done
182 test_ip_dsfield()
184 do_test_ip_dsfield "dev $swp1 ingress"
185 do_test_ip_dsfield "dev $swp2 egress"
188 do_test_ip_dscp()
190 local locus=$1; shift
191 local dscp
193 for dscp in 0 1 2 3 32 61 62 63; do
194 do_test_pedit_dsfield "$locus" \
195 "ip dsfield set $((dscp << 2)) retain 0xfc" \
196 ip "ip_tos $(((dscp << 2) | 1))" \
197 "-A 192.0.2.1 -B 192.0.2.2"
198 done
201 test_ip_dscp()
203 do_test_ip_dscp "dev $swp1 ingress"
204 do_test_ip_dscp "dev $swp2 egress"
207 do_test_ip_ecn()
209 local locus=$1; shift
210 local ecn
212 for ecn in 0 1 2 3; do
213 do_test_pedit_dsfield "$locus" \
214 "ip dsfield set $ecn retain 0x03" \
215 ip "ip_tos $((124 | $ecn))" \
216 "-A 192.0.2.1 -B 192.0.2.2"
217 done
220 test_ip_ecn()
222 do_test_ip_ecn "dev $swp1 ingress"
223 do_test_ip_ecn "dev $swp2 egress"
226 do_test_ip_dscp_ecn()
228 local locus=$1; shift
230 tc filter add $locus handle 101 pref 1 \
231 flower action pedit ex munge ip dsfield set 124 retain 0xfc \
232 action pedit ex munge ip dsfield set 1 retain 0x03
233 tc filter add dev $h2 ingress handle 101 pref 1 prot ip \
234 flower skip_hw ip_tos 125 action pass
236 do_test_pedit_dsfield_common "$locus" "set DSCP + set ECN" \
237 "-A 192.0.2.1 -B 192.0.2.2"
239 tc filter del dev $h2 ingress pref 1
240 tc filter del $locus pref 1
243 test_ip_dscp_ecn()
245 do_test_ip_dscp_ecn "dev $swp1 ingress"
246 do_test_ip_dscp_ecn "dev $swp2 egress"
249 do_test_ip6_dsfield()
251 local locus=$1; shift
252 local dsfield
254 for dsfield in 0 1 2 3 128 252 253 254 255; do
255 do_test_pedit_dsfield "$locus" \
256 "ip6 traffic_class set $dsfield" \
257 ipv6 "ip_tos $dsfield" \
258 "-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
259 done
262 test_ip6_dsfield()
264 do_test_ip6_dsfield "dev $swp1 ingress"
265 do_test_ip6_dsfield "dev $swp2 egress"
268 do_test_ip6_dscp()
270 local locus=$1; shift
271 local dscp
273 for dscp in 0 1 2 3 32 61 62 63; do
274 do_test_pedit_dsfield "$locus" \
275 "ip6 traffic_class set $((dscp << 2)) retain 0xfc" \
276 ipv6 "ip_tos $(((dscp << 2) | 1))" \
277 "-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
278 done
281 test_ip6_dscp()
283 do_test_ip6_dscp "dev $swp1 ingress"
284 do_test_ip6_dscp "dev $swp2 egress"
287 do_test_ip6_ecn()
289 local locus=$1; shift
290 local ecn
292 for ecn in 0 1 2 3; do
293 do_test_pedit_dsfield "$locus" \
294 "ip6 traffic_class set $ecn retain 0x3" \
295 ipv6 "ip_tos $((124 | $ecn))" \
296 "-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
297 done
300 test_ip6_ecn()
302 do_test_ip6_ecn "dev $swp1 ingress"
303 do_test_ip6_ecn "dev $swp2 egress"
306 trap cleanup EXIT
308 setup_prepare
309 setup_wait
311 tests_run
313 exit $EXIT_STATUS