blob: 64fbd211d907b071c7e5d1566e51d94ca89f8c99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# This test sends traffic from H1 to H2. Either on ingress of $swp1, or on
# egress of $swp2, the traffic is acted upon by a pedit action. An ingress
# filter installed on $h2 verifies that the packet looks like expected.
#
# +----------------------+ +----------------------+
# | H1 | | H2 |
# | + $h1 | | $h2 + |
# | | 192.0.2.1/28 | | 192.0.2.2/28 | |
# +----|-----------------+ +----------------|-----+
# | |
# +----|----------------------------------------------------------------|-----+
# | SW | | |
# | +-|----------------------------------------------------------------|-+ |
# | | + $swp1 BR $swp2 + | |
# | +--------------------------------------------------------------------+ |
# +---------------------------------------------------------------------------+
ALL_TESTS="
ping_ipv4
ping_ipv6
test_ip_dsfield
test_ip_dscp
test_ip_ecn
test_ip_dscp_ecn
test_ip6_dsfield
test_ip6_dscp
test_ip6_ecn
"
NUM_NETIFS=4
source lib.sh
source tc_common.sh
: ${HIT_TIMEOUT:=2000} # ms
h1_create()
{
simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
}
h1_destroy()
{
simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/64
}
h2_create()
{
simple_if_init $h2 192.0.2.2/28 2001:db8:1::2/64
tc qdisc add dev $h2 clsact
}
h2_destroy()
{
tc qdisc del dev $h2 clsact
simple_if_fini $h2 192.0.2.2/28 2001:db8:1::2/64
}
switch_create()
{
ip link add name br1 up type bridge vlan_filtering 1
ip link set dev $swp1 master br1
ip link set dev $swp1 up
ip link set dev $swp2 master br1
ip link set dev $swp2 up
tc qdisc add dev $swp1 clsact
tc qdisc add dev $swp2 clsact
}
switch_destroy()
{
tc qdisc del dev $swp2 clsact
tc qdisc del dev $swp1 clsact
ip link set dev $swp2 down
ip link set dev $swp2 nomaster
ip link set dev $swp1 down
ip link set dev $swp1 nomaster
ip link del dev br1
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
h2mac=$(mac_get $h2)
vrf_prepare
h1_create
h2_create
switch_create
}
cleanup()
{
pre_cleanup
switch_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
ping_ipv4()
{
ping_test $h1 192.0.2.2
}
ping_ipv6()
{
ping6_test $h1 2001:db8:1::2
}
do_test_pedit_dsfield_common()
{
local pedit_locus=$1; shift
local pedit_action=$1; shift
local mz_flags=$1; shift
RET=0
# TOS 125: DSCP 31, ECN 1. Used for testing that the relevant part is
# overwritten when zero is selected.
$MZ $mz_flags $h1 -c 10 -d 20msec -p 100 \
-a own -b $h2mac -q -t tcp tos=0x7d,sp=54321,dp=12345
local pkts
pkts=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= 10" \
tc_rule_handle_stats_get "dev $h2 ingress" 101)
check_err $? "Expected to get 10 packets on test probe, but got $pkts."
pkts=$(tc_rule_handle_stats_get "$pedit_locus" 101)
((pkts >= 10))
check_err $? "Expected to get 10 packets on pedit rule, but got $pkts."
log_test "$pedit_locus pedit $pedit_action"
}
do_test_pedit_dsfield()
{
local pedit_locus=$1; shift
local pedit_action=$1; shift
local match_prot=$1; shift
local match_flower=$1; shift
local mz_flags=$1; shift
local saddr=$1; shift
local daddr=$1; shift
tc filter add $pedit_locus handle 101 pref 1 \
flower action pedit ex munge $pedit_action
tc filter add dev $h2 ingress handle 101 pref 1 prot $match_prot \
flower skip_hw $match_flower action pass
do_test_pedit_dsfield_common "$pedit_locus" "$pedit_action" "$mz_flags"
tc filter del dev $h2 ingress pref 1
tc filter del $pedit_locus pref 1
}
do_test_ip_dsfield()
{
local locus=$1; shift
local dsfield
for dsfield in 0 1 2 3 128 252 253 254 255; do
do_test_pedit_dsfield "$locus" \
"ip dsfield set $dsfield" \
ip "ip_tos $dsfield" \
"-A 192.0.2.1 -B 192.0.2.2"
done
}
test_ip_dsfield()
{
do_test_ip_dsfield "dev $swp1 ingress"
do_test_ip_dsfield "dev $swp2 egress"
}
do_test_ip_dscp()
{
local locus=$1; shift
local dscp
for dscp in 0 1 2 3 32 61 62 63; do
do_test_pedit_dsfield "$locus" \
"ip dsfield set $((dscp << 2)) retain 0xfc" \
ip "ip_tos $(((dscp << 2) | 1))" \
"-A 192.0.2.1 -B 192.0.2.2"
done
}
test_ip_dscp()
{
do_test_ip_dscp "dev $swp1 ingress"
do_test_ip_dscp "dev $swp2 egress"
}
do_test_ip_ecn()
{
local locus=$1; shift
local ecn
for ecn in 0 1 2 3; do
do_test_pedit_dsfield "$locus" \
"ip dsfield set $ecn retain 0x03" \
ip "ip_tos $((124 | $ecn))" \
"-A 192.0.2.1 -B 192.0.2.2"
done
}
test_ip_ecn()
{
do_test_ip_ecn "dev $swp1 ingress"
do_test_ip_ecn "dev $swp2 egress"
}
do_test_ip_dscp_ecn()
{
local locus=$1; shift
tc filter add $locus handle 101 pref 1 \
flower action pedit ex munge ip dsfield set 124 retain 0xfc \
action pedit ex munge ip dsfield set 1 retain 0x03
tc filter add dev $h2 ingress handle 101 pref 1 prot ip \
flower skip_hw ip_tos 125 action pass
do_test_pedit_dsfield_common "$locus" "set DSCP + set ECN" \
"-A 192.0.2.1 -B 192.0.2.2"
tc filter del dev $h2 ingress pref 1
tc filter del $locus pref 1
}
test_ip_dscp_ecn()
{
do_test_ip_dscp_ecn "dev $swp1 ingress"
do_test_ip_dscp_ecn "dev $swp2 egress"
}
do_test_ip6_dsfield()
{
local locus=$1; shift
local dsfield
for dsfield in 0 1 2 3 128 252 253 254 255; do
do_test_pedit_dsfield "$locus" \
"ip6 traffic_class set $dsfield" \
ipv6 "ip_tos $dsfield" \
"-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
done
}
test_ip6_dsfield()
{
do_test_ip6_dsfield "dev $swp1 ingress"
do_test_ip6_dsfield "dev $swp2 egress"
}
do_test_ip6_dscp()
{
local locus=$1; shift
local dscp
for dscp in 0 1 2 3 32 61 62 63; do
do_test_pedit_dsfield "$locus" \
"ip6 traffic_class set $((dscp << 2)) retain 0xfc" \
ipv6 "ip_tos $(((dscp << 2) | 1))" \
"-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
done
}
test_ip6_dscp()
{
do_test_ip6_dscp "dev $swp1 ingress"
do_test_ip6_dscp "dev $swp2 egress"
}
do_test_ip6_ecn()
{
local locus=$1; shift
local ecn
for ecn in 0 1 2 3; do
do_test_pedit_dsfield "$locus" \
"ip6 traffic_class set $ecn retain 0x3" \
ipv6 "ip_tos $((124 | $ecn))" \
"-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
done
}
test_ip6_ecn()
{
do_test_ip6_ecn "dev $swp1 ingress"
do_test_ip6_ecn "dev $swp2 egress"
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
exit $EXIT_STATUS
|