WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / net / forwarding / pedit_dsfield.sh
blob55eeacf592411bd905411efab7934f3a88b6b4aa
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 up type bridge vlan_filtering 1
64 ip link set dev $swp1 master br1
65 ip link set dev $swp1 up
66 ip link set dev $swp2 master br1
67 ip link set dev $swp2 up
69 tc qdisc add dev $swp1 clsact
70 tc qdisc add dev $swp2 clsact
73 switch_destroy()
75 tc qdisc del dev $swp2 clsact
76 tc qdisc del dev $swp1 clsact
78 ip link set dev $swp2 nomaster
79 ip link set dev $swp1 nomaster
80 ip link del dev br1
83 setup_prepare()
85 h1=${NETIFS[p1]}
86 swp1=${NETIFS[p2]}
88 swp2=${NETIFS[p3]}
89 h2=${NETIFS[p4]}
91 h2mac=$(mac_get $h2)
93 vrf_prepare
94 h1_create
95 h2_create
96 switch_create
99 cleanup()
101 pre_cleanup
103 switch_destroy
104 h2_destroy
105 h1_destroy
106 vrf_cleanup
109 ping_ipv4()
111 ping_test $h1 192.0.2.2
114 ping_ipv6()
116 ping6_test $h1 2001:db8:1::2
119 do_test_pedit_dsfield_common()
121 local pedit_locus=$1; shift
122 local pedit_action=$1; shift
123 local mz_flags=$1; shift
125 RET=0
127 # TOS 125: DSCP 31, ECN 1. Used for testing that the relevant part is
128 # overwritten when zero is selected.
129 $MZ $mz_flags $h1 -c 10 -d 20msec -p 100 \
130 -a own -b $h2mac -q -t tcp tos=0x7d,sp=54321,dp=12345
132 local pkts
133 pkts=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= 10" \
134 tc_rule_handle_stats_get "dev $h2 ingress" 101)
135 check_err $? "Expected to get 10 packets on test probe, but got $pkts."
137 pkts=$(tc_rule_handle_stats_get "$pedit_locus" 101)
138 ((pkts >= 10))
139 check_err $? "Expected to get 10 packets on pedit rule, but got $pkts."
141 log_test "$pedit_locus pedit $pedit_action"
144 do_test_pedit_dsfield()
146 local pedit_locus=$1; shift
147 local pedit_action=$1; shift
148 local match_prot=$1; shift
149 local match_flower=$1; shift
150 local mz_flags=$1; shift
151 local saddr=$1; shift
152 local daddr=$1; shift
154 tc filter add $pedit_locus handle 101 pref 1 \
155 flower action pedit ex munge $pedit_action
156 tc filter add dev $h2 ingress handle 101 pref 1 prot $match_prot \
157 flower skip_hw $match_flower action pass
159 do_test_pedit_dsfield_common "$pedit_locus" "$pedit_action" "$mz_flags"
161 tc filter del dev $h2 ingress pref 1
162 tc filter del $pedit_locus pref 1
165 do_test_ip_dsfield()
167 local locus=$1; shift
168 local dsfield
170 for dsfield in 0 1 2 3 128 252 253 254 255; do
171 do_test_pedit_dsfield "$locus" \
172 "ip dsfield set $dsfield" \
173 ip "ip_tos $dsfield" \
174 "-A 192.0.2.1 -B 192.0.2.2"
175 done
178 test_ip_dsfield()
180 do_test_ip_dsfield "dev $swp1 ingress"
181 do_test_ip_dsfield "dev $swp2 egress"
184 do_test_ip_dscp()
186 local locus=$1; shift
187 local dscp
189 for dscp in 0 1 2 3 32 61 62 63; do
190 do_test_pedit_dsfield "$locus" \
191 "ip dsfield set $((dscp << 2)) retain 0xfc" \
192 ip "ip_tos $(((dscp << 2) | 1))" \
193 "-A 192.0.2.1 -B 192.0.2.2"
194 done
197 test_ip_dscp()
199 do_test_ip_dscp "dev $swp1 ingress"
200 do_test_ip_dscp "dev $swp2 egress"
203 do_test_ip_ecn()
205 local locus=$1; shift
206 local ecn
208 for ecn in 0 1 2 3; do
209 do_test_pedit_dsfield "$locus" \
210 "ip dsfield set $ecn retain 0x03" \
211 ip "ip_tos $((124 | $ecn))" \
212 "-A 192.0.2.1 -B 192.0.2.2"
213 done
216 test_ip_ecn()
218 do_test_ip_ecn "dev $swp1 ingress"
219 do_test_ip_ecn "dev $swp2 egress"
222 do_test_ip_dscp_ecn()
224 local locus=$1; shift
226 tc filter add $locus handle 101 pref 1 \
227 flower action pedit ex munge ip dsfield set 124 retain 0xfc \
228 action pedit ex munge ip dsfield set 1 retain 0x03
229 tc filter add dev $h2 ingress handle 101 pref 1 prot ip \
230 flower skip_hw ip_tos 125 action pass
232 do_test_pedit_dsfield_common "$locus" "set DSCP + set ECN" \
233 "-A 192.0.2.1 -B 192.0.2.2"
235 tc filter del dev $h2 ingress pref 1
236 tc filter del $locus pref 1
239 test_ip_dscp_ecn()
241 do_test_ip_dscp_ecn "dev $swp1 ingress"
242 do_test_ip_dscp_ecn "dev $swp2 egress"
245 do_test_ip6_dsfield()
247 local locus=$1; shift
248 local dsfield
250 for dsfield in 0 1 2 3 128 252 253 254 255; do
251 do_test_pedit_dsfield "$locus" \
252 "ip6 traffic_class set $dsfield" \
253 ipv6 "ip_tos $dsfield" \
254 "-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
255 done
258 test_ip6_dsfield()
260 do_test_ip6_dsfield "dev $swp1 ingress"
261 do_test_ip6_dsfield "dev $swp2 egress"
264 do_test_ip6_dscp()
266 local locus=$1; shift
267 local dscp
269 for dscp in 0 1 2 3 32 61 62 63; do
270 do_test_pedit_dsfield "$locus" \
271 "ip6 traffic_class set $((dscp << 2)) retain 0xfc" \
272 ipv6 "ip_tos $(((dscp << 2) | 1))" \
273 "-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
274 done
277 test_ip6_dscp()
279 do_test_ip6_dscp "dev $swp1 ingress"
280 do_test_ip6_dscp "dev $swp2 egress"
283 do_test_ip6_ecn()
285 local locus=$1; shift
286 local ecn
288 for ecn in 0 1 2 3; do
289 do_test_pedit_dsfield "$locus" \
290 "ip6 traffic_class set $ecn retain 0x3" \
291 ipv6 "ip_tos $((124 | $ecn))" \
292 "-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
293 done
296 test_ip6_ecn()
298 do_test_ip6_ecn "dev $swp1 ingress"
299 do_test_ip6_ecn "dev $swp2 egress"
302 trap cleanup EXIT
304 setup_prepare
305 setup_wait
307 tests_run
309 exit $EXIT_STATUS