Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/tests/sys/netpfil/pf/altq.sh
39536 views
1
. $(atf_get_srcdir)/utils.subr
2
3
atf_test_case "hfsc" "cleanup"
4
hfsc_head()
5
{
6
atf_set descr 'Basic HFSC test'
7
atf_set require.user root
8
}
9
10
hfsc_body()
11
{
12
altq_init
13
is_altq_supported hfsc
14
15
epair=$(vnet_mkepair)
16
vnet_mkjail altq_hfsc ${epair}b
17
18
ifconfig ${epair}a 192.0.2.1/24 up
19
jexec altq_hfsc ifconfig ${epair}b 192.0.2.2/24 up
20
21
# Sanity check
22
atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2
23
24
jexec altq_hfsc pfctl -e
25
pft_set_rules altq_hfsc \
26
"altq on ${epair}b bandwidth 100b hfsc queue { default }" \
27
"queue default hfsc(default linkshare 80b)" \
28
"pass proto icmp "
29
30
# single ping succeeds just fine
31
atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
32
33
# "Saturate the link"
34
ping -i .1 -c 5 -s 1200 192.0.2.2
35
36
# We should now be hitting the limits and get this packet dropped.
37
atf_check -s exit:2 -o ignore ping -c 1 -s 1200 192.0.2.2
38
}
39
40
hfsc_cleanup()
41
{
42
altq_cleanup
43
}
44
45
atf_test_case "match" "cleanup"
46
match_head()
47
{
48
atf_set descr 'Basic match keyword test'
49
atf_set require.user root
50
}
51
52
match_body()
53
{
54
altq_init
55
is_altq_supported hfsc
56
57
epair=$(vnet_mkepair)
58
vnet_mkjail altq_match ${epair}b
59
60
ifconfig ${epair}a 192.0.2.1/24 up
61
jexec altq_match ifconfig ${epair}b 192.0.2.2/24 up
62
63
# Sanity check
64
atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2
65
66
jexec altq_match pfctl -e
67
pft_set_rules altq_match \
68
"altq on ${epair}b bandwidth 100000000b hfsc queue { default, slow }" \
69
"queue default hfsc(default linkshare 80000000b)" \
70
"queue slow hfsc(linkshare 80b upperlimit 80b)" \
71
"match proto icmp queue slow" \
72
"pass"
73
74
# single ping succeeds just fine
75
atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
76
77
# "Saturate the link"
78
ping -i .1 -c 5 -s 1200 192.0.2.2
79
80
# We should now be hitting the limits and get this packet dropped.
81
atf_check -s exit:2 -o ignore ping -c 1 -s 1200 192.0.2.2
82
}
83
84
match_cleanup()
85
{
86
altq_cleanup
87
}
88
89
atf_test_case "cbq_vlan" "cleanup"
90
cbq_vlan_head()
91
{
92
atf_set descr 'CBQ over VLAN test'
93
atf_set require.user root
94
}
95
96
cbq_vlan_body()
97
{
98
altq_init
99
is_altq_supported cbq
100
101
epair=$(vnet_mkepair)
102
vnet_mkjail altq_cbq_vlan ${epair}b
103
104
vlan=$(vnet_mkvlan)
105
ifconfig ${vlan} vlan 42 vlandev ${epair}a
106
ifconfig ${vlan} 192.0.2.1/24 up
107
ifconfig ${epair}a up
108
109
vlanj=$(jexec altq_cbq_vlan ifconfig vlan create)
110
echo ${vlanj} >> created_interfaces.lst
111
112
jexec altq_cbq_vlan ifconfig ${epair}b up
113
jexec altq_cbq_vlan ifconfig ${vlanj} vlan 42 vlandev ${epair}b
114
jexec altq_cbq_vlan ifconfig ${vlanj} 192.0.2.2/24 up
115
116
# Sanity check
117
atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2
118
119
jexec altq_cbq_vlan pfctl -e
120
pft_set_rules altq_cbq_vlan \
121
"altq on ${vlanj} bandwidth 14000b cbq queue { default }" \
122
"queue default bandwidth 14000b cbq(default) { slow } " \
123
"queue slow bandwidth 6000b cbq(borrow)" \
124
"match proto icmp queue slow" \
125
"match proto tcp queue default" \
126
"pass"
127
128
# single ping succeeds just fine
129
atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
130
131
# "Saturate the link"
132
ping -i .01 -c 50 -s 1200 192.0.2.2
133
134
# We should now be hitting the limits and get these packet dropped.
135
rcv=$(ping -i .1 -c 5 -s 1200 192.0.2.2 | tr "," "\n" | awk '/packets received/ { print $1; }')
136
echo "Received $rcv packets"
137
if [ ${rcv} -gt 1 ]
138
then
139
atf_fail "Received ${rcv} packets in a saturated link"
140
fi
141
}
142
143
cbq_vlan_cleanup()
144
{
145
altq_cleanup
146
}
147
148
atf_test_case "codel_bridge" "cleanup"
149
codel_bridge_head()
150
{
151
atf_set descr 'codel over if_bridge test'
152
atf_set require.user root
153
}
154
155
codel_bridge_body()
156
{
157
altq_init
158
is_altq_supported codel
159
vnet_init_bridge
160
161
epair=$(vnet_mkepair)
162
ifconfig ${epair}a 192.0.2.1/24 up
163
164
vnet_mkjail altq_codel_bridge ${epair}b
165
166
bridge=$(jexec altq_codel_bridge ifconfig bridge create)
167
jexec altq_codel_bridge ifconfig ${bridge} addm ${epair}b
168
jexec altq_codel_bridge ifconfig ${epair}b up
169
jexec altq_codel_bridge ifconfig ${bridge} 192.0.2.2/24 up
170
171
# Sanity check
172
atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2
173
174
jexec altq_codel_bridge pfctl -e
175
pft_set_rules altq_codel_bridge \
176
"altq on ${bridge} bandwidth 1000b codelq queue { slow }" \
177
"match queue slow" \
178
"pass"
179
180
# "Saturate the link"
181
ping -i .1 -c 5 -s 1200 192.0.2.2
182
183
# We should now be hitting the limits and get these packet dropped.
184
rcv=$(ping -i .1 -c 5 -s 1200 192.0.2.2 | tr "," "\n" | awk '/packets received/ { print $1; }')
185
echo "Received $rcv packets"
186
if [ ${rcv} -gt 1 ]
187
then
188
atf_fail "Received ${rcv} packets in a saturated link"
189
fi
190
}
191
192
codel_bridge_cleanup()
193
{
194
altq_cleanup
195
}
196
197
atf_test_case "prioritise" "cleanup"
198
prioritise_head()
199
{
200
atf_set descr "Test prioritising one type of traffic over the other"
201
atf_set require.user root
202
}
203
204
prioritise_body()
205
{
206
altq_init
207
is_altq_supported cbq
208
209
epair=$(vnet_mkepair)
210
vnet_mkjail altq_prioritise ${epair}b
211
212
ifconfig ${epair}a 192.0.2.1/24 up
213
jexec altq_prioritise ifconfig ${epair}b 192.0.2.2/24 up
214
215
jexec altq_prioritise /usr/sbin/inetd -p ${PWD}/inetd-altq.pid \
216
$(atf_get_srcdir)/../pf/echo_inetd.conf
217
218
# Sanity check
219
atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2
220
221
jexec altq_prioritise pfctl -e
222
pft_set_rules altq_prioritise \
223
"altq on ${epair}b bandwidth 6000b cbq queue { default, slow }" \
224
"queue default priority 7 cbq(default)" \
225
"queue slow priority 1 cbq" \
226
"match proto icmp queue slow" \
227
"match proto tcp queue default" \
228
"pass"
229
230
# single ping succeeds just fine
231
atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
232
233
# Unsaturated TCP succeeds
234
reply=$(echo "foo" | nc -w 5 -N 192.0.2.2 7)
235
if [ "$reply" != "foo" ];
236
then
237
atf_fail "Unsaturated echo failed"
238
fi
239
240
# "Saturate the link"
241
ping -i .01 -c 50 -s 1200 192.0.2.2
242
243
# We should now be hitting the limits and get these packet dropped.
244
rcv=$(ping -i .1 -c 5 -s 1200 192.0.2.2 | tr "," "\n" | awk '/packets received/ { print $1; }')
245
echo "Received $rcv packets"
246
if [ ${rcv} -gt 1 ]
247
then
248
atf_fail "Received ${rcv} packets in a saturated link"
249
fi
250
251
# TCP should still pass
252
for i in `seq 1 10`
253
do
254
reply=$(echo "foo_${i}" | nc -w 5 -N 192.0.2.2 7)
255
if [ "$reply" != "foo_${i}" ];
256
then
257
atf_fail "Prioritised echo failed ${i}"
258
fi
259
260
done
261
262
# Now reverse priority
263
pft_set_rules altq_prioritise \
264
"altq on ${epair}b bandwidth 6000b cbq queue { default, slow }" \
265
"queue default priority 7 cbq(default)" \
266
"queue slow priority 1 cbq" \
267
"match proto tcp queue slow" \
268
"match proto icmp queue default" \
269
"pass"
270
271
atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
272
ping -i .01 -c 50 -s 1200 192.0.2.2
273
for i in `seq 1 10`
274
do
275
reply=$(echo "foo_${i}" | nc -w 5 -N 192.0.2.2 7)
276
if [ "$reply" == "foo_${i}" ];
277
then
278
atf_fail "Unexpected echo success"
279
fi
280
281
done
282
}
283
284
prioritise_cleanup()
285
{
286
altq_cleanup
287
}
288
289
atf_test_case "codel_vlan" "cleanup"
290
codel_vlan_head()
291
{
292
atf_set descr 'Test double-pass through ALTQ with codel'
293
atf_set require.user root
294
}
295
296
codel_vlan_body()
297
{
298
altq_init
299
is_altq_supported priq
300
is_altq_supported codel
301
302
j=altq_vlan_codel
303
epair=$(vnet_mkepair)
304
305
vnet_mkjail ${j}a ${epair}a
306
va=$(jexec ${j}a ifconfig vlan create)
307
jexec ${j}a ifconfig ${epair}a up
308
jexec ${j}a ifconfig ${va} vlan 42 vlandev ${epair}a up
309
jexec ${j}a ifconfig ${va} inet 192.0.2.1/24
310
311
vnet_mkjail ${j}b ${epair}b
312
vb=$(jexec ${j}b ifconfig vlan create)
313
jexec ${j}b ifconfig ${epair}b up
314
jexec ${j}b ifconfig ${vb} vlan 42 vlandev ${epair}b up
315
jexec ${j}b ifconfig ${vb} inet 192.0.2.2/24
316
317
# Sanity check
318
atf_check -s exit:0 -o ignore \
319
jexec ${j}a ping -c 1 192.0.2.2
320
321
jexec ${j}a pfctl -e
322
pft_set_rules ${j}a \
323
"altq on ${epair}a priq bandwidth 10Mb queue { slow }" \
324
"queue slow priority 6 qlimit 50 priq ( default codel )" \
325
"altq on ${va} priq bandwidth 10Mb queue { vslow }" \
326
"queue vslow priority 6 qlimit 50 priq ( default codel )" \
327
"pass queue (slow)"
328
329
atf_check -s exit:0 -o ignore \
330
jexec ${j}a ping -c 1 192.0.2.2
331
}
332
333
codel_vlan_cleanup()
334
{
335
altq_cleanup
336
}
337
338
atf_init_test_cases()
339
{
340
atf_add_test_case "hfsc"
341
atf_add_test_case "match"
342
atf_add_test_case "cbq_vlan"
343
atf_add_test_case "codel_bridge"
344
atf_add_test_case "prioritise"
345
atf_add_test_case "codel_vlan"
346
}
347
348