xref: /freebsd/tests/sys/netpfil/pf/altq.sh (revision b0fcf4d5222bfdbbc0e2af2b14f0d73704706aa0)
116b38333SKristof Provost. $(atf_get_srcdir)/utils.subr
216b38333SKristof Provost
316b38333SKristof Provostatf_test_case "hfsc" "cleanup"
416b38333SKristof Provosthfsc_head()
516b38333SKristof Provost{
616b38333SKristof Provost	atf_set descr 'Basic HFSC test'
716b38333SKristof Provost	atf_set require.user root
816b38333SKristof Provost}
916b38333SKristof Provost
1016b38333SKristof Provosthfsc_body()
1116b38333SKristof Provost{
1216b38333SKristof Provost	altq_init
1316b38333SKristof Provost	is_altq_supported hfsc
1416b38333SKristof Provost
1516b38333SKristof Provost	epair=$(vnet_mkepair)
1616b38333SKristof Provost	vnet_mkjail altq_hfsc ${epair}b
1716b38333SKristof Provost
1816b38333SKristof Provost	ifconfig ${epair}a 192.0.2.1/24 up
1916b38333SKristof Provost	jexec altq_hfsc ifconfig ${epair}b 192.0.2.2/24 up
2016b38333SKristof Provost
2116b38333SKristof Provost	# Sanity check
2216b38333SKristof Provost	atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2
2316b38333SKristof Provost
2416b38333SKristof Provost	jexec altq_hfsc pfctl -e
2516b38333SKristof Provost	pft_set_rules altq_hfsc \
2616b38333SKristof Provost	    "altq on ${epair}b bandwidth 100b hfsc queue { default }" \
2716b38333SKristof Provost	    "queue default hfsc(default linkshare 80b)" \
2816b38333SKristof Provost	    "pass proto icmp "
2916b38333SKristof Provost
3016b38333SKristof Provost	# single ping succeeds just fine
3116b38333SKristof Provost	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
3216b38333SKristof Provost
3316b38333SKristof Provost	# "Saturate the link"
3416b38333SKristof Provost	ping -i .1 -c 5 -s 1200 192.0.2.2
3516b38333SKristof Provost
3616b38333SKristof Provost	# We should now be hitting the limits and get this packet dropped.
3716b38333SKristof Provost	atf_check -s exit:2 -o ignore ping -c 1 -s 1200 192.0.2.2
3816b38333SKristof Provost}
3916b38333SKristof Provost
4016b38333SKristof Provosthfsc_cleanup()
4116b38333SKristof Provost{
4216b38333SKristof Provost	altq_cleanup
4316b38333SKristof Provost}
4416b38333SKristof Provost
45d363ebc7SKristof Provostatf_test_case "match" "cleanup"
46d363ebc7SKristof Provostmatch_head()
47d363ebc7SKristof Provost{
48d363ebc7SKristof Provost	atf_set descr 'Basic match keyword test'
49d363ebc7SKristof Provost	atf_set require.user root
50d363ebc7SKristof Provost}
51d363ebc7SKristof Provost
52d363ebc7SKristof Provostmatch_body()
53d363ebc7SKristof Provost{
54d363ebc7SKristof Provost	altq_init
55d363ebc7SKristof Provost	is_altq_supported hfsc
56d363ebc7SKristof Provost
57d363ebc7SKristof Provost	epair=$(vnet_mkepair)
58d363ebc7SKristof Provost	vnet_mkjail altq_match ${epair}b
59d363ebc7SKristof Provost
60d363ebc7SKristof Provost	ifconfig ${epair}a 192.0.2.1/24 up
61d363ebc7SKristof Provost	jexec altq_match ifconfig ${epair}b 192.0.2.2/24 up
62d363ebc7SKristof Provost
63d363ebc7SKristof Provost	# Sanity check
64d363ebc7SKristof Provost	atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2
65d363ebc7SKristof Provost
66d363ebc7SKristof Provost	jexec altq_match pfctl -e
67d363ebc7SKristof Provost	pft_set_rules altq_match \
68d363ebc7SKristof Provost	    "altq on ${epair}b bandwidth 100000000b hfsc queue { default, slow }" \
69d363ebc7SKristof Provost	    "queue default hfsc(default linkshare 80000000b)" \
70d363ebc7SKristof Provost	    "queue slow hfsc(linkshare 80b upperlimit 80b)" \
71d363ebc7SKristof Provost	    "match proto icmp queue slow" \
72d363ebc7SKristof Provost	    "pass"
73d363ebc7SKristof Provost
74d363ebc7SKristof Provost	# single ping succeeds just fine
75d363ebc7SKristof Provost	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
76d363ebc7SKristof Provost
77d363ebc7SKristof Provost	# "Saturate the link"
78d363ebc7SKristof Provost	ping -i .1 -c 5 -s 1200 192.0.2.2
79d363ebc7SKristof Provost
80d363ebc7SKristof Provost	# We should now be hitting the limits and get this packet dropped.
81d363ebc7SKristof Provost	atf_check -s exit:2 -o ignore ping -c 1 -s 1200 192.0.2.2
82d363ebc7SKristof Provost}
83d363ebc7SKristof Provost
84d363ebc7SKristof Provostmatch_cleanup()
85d363ebc7SKristof Provost{
86d363ebc7SKristof Provost	altq_cleanup
87d363ebc7SKristof Provost}
88d363ebc7SKristof Provost
89e62175dfSKristof Provostatf_test_case "cbq_vlan" "cleanup"
90e62175dfSKristof Provostcbq_vlan_head()
91e62175dfSKristof Provost{
92e62175dfSKristof Provost	atf_set descr 'CBQ over VLAN test'
93e62175dfSKristof Provost	atf_set require.user root
94e62175dfSKristof Provost}
95e62175dfSKristof Provost
96e62175dfSKristof Provostcbq_vlan_body()
97e62175dfSKristof Provost{
98e62175dfSKristof Provost	altq_init
99e62175dfSKristof Provost	is_altq_supported cbq
100e62175dfSKristof Provost
101e62175dfSKristof Provost	epair=$(vnet_mkepair)
102e62175dfSKristof Provost	vnet_mkjail altq_cbq_vlan ${epair}b
103e62175dfSKristof Provost
104e62175dfSKristof Provost	vlan=$(vnet_mkvlan)
105e62175dfSKristof Provost	ifconfig ${vlan} vlan 42 vlandev ${epair}a
106e62175dfSKristof Provost	ifconfig ${vlan} 192.0.2.1/24 up
107e62175dfSKristof Provost	ifconfig ${epair}a up
108e62175dfSKristof Provost
109e62175dfSKristof Provost	vlanj=$(jexec altq_cbq_vlan ifconfig vlan create)
110e62175dfSKristof Provost	echo ${vlanj} >> created_interfaces.lst
111e62175dfSKristof Provost
112e62175dfSKristof Provost	jexec altq_cbq_vlan ifconfig ${epair}b up
113e62175dfSKristof Provost	jexec altq_cbq_vlan ifconfig ${vlanj} vlan 42 vlandev ${epair}b
114e62175dfSKristof Provost	jexec altq_cbq_vlan ifconfig ${vlanj} 192.0.2.2/24 up
115e62175dfSKristof Provost
116e62175dfSKristof Provost	# Sanity check
117e62175dfSKristof Provost	atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2
118e62175dfSKristof Provost
119e62175dfSKristof Provost	jexec altq_cbq_vlan pfctl -e
120e62175dfSKristof Provost	pft_set_rules altq_cbq_vlan \
121e62175dfSKristof Provost		"altq on ${vlanj} bandwidth 14000b cbq queue { default }" \
122e62175dfSKristof Provost		"queue default bandwidth 14000b cbq(default) { slow } " \
123e62175dfSKristof Provost		"queue slow bandwidth 6000b cbq(borrow)" \
124e62175dfSKristof Provost		"match proto icmp queue slow" \
125e62175dfSKristof Provost		"match proto tcp queue default" \
126e62175dfSKristof Provost		"pass"
127e62175dfSKristof Provost
128e62175dfSKristof Provost	# single ping succeeds just fine
129e62175dfSKristof Provost	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
130e62175dfSKristof Provost
131e62175dfSKristof Provost	# "Saturate the link"
132e62175dfSKristof Provost	ping -i .01 -c 50 -s 1200 192.0.2.2
133e62175dfSKristof Provost
134e62175dfSKristof Provost	# We should now be hitting the limits and get these packet dropped.
135e62175dfSKristof Provost	rcv=$(ping -i .1 -c 5 -s 1200 192.0.2.2 | tr "," "\n" | awk '/packets received/ { print $1; }')
136e62175dfSKristof Provost	echo "Received $rcv packets"
137e62175dfSKristof Provost	if [ ${rcv} -gt 1 ]
138e62175dfSKristof Provost	then
139e62175dfSKristof Provost		atf_fail "Received ${rcv} packets in a saturated link"
140e62175dfSKristof Provost	fi
141e62175dfSKristof Provost}
142e62175dfSKristof Provost
143e62175dfSKristof Provostcbq_vlan_cleanup()
144e62175dfSKristof Provost{
145e62175dfSKristof Provost	altq_cleanup
146e62175dfSKristof Provost}
147e62175dfSKristof Provost
14806246369SKristof Provostatf_test_case "codel_bridge" "cleanup"
14906246369SKristof Provostcodel_bridge_head()
15006246369SKristof Provost{
15106246369SKristof Provost	atf_set descr 'codel over if_bridge test'
15206246369SKristof Provost	atf_set require.user root
15306246369SKristof Provost}
15406246369SKristof Provost
15506246369SKristof Provostcodel_bridge_body()
15606246369SKristof Provost{
15706246369SKristof Provost	altq_init
15806246369SKristof Provost	is_altq_supported codel
159480ad405SKristof Provost	vnet_init_bridge
16006246369SKristof Provost
16106246369SKristof Provost	epair=$(vnet_mkepair)
16206246369SKristof Provost	ifconfig ${epair}a 192.0.2.1/24 up
16306246369SKristof Provost
16406246369SKristof Provost	vnet_mkjail altq_codel_bridge ${epair}b
16506246369SKristof Provost
16606246369SKristof Provost	bridge=$(jexec altq_codel_bridge ifconfig bridge create)
16706246369SKristof Provost	jexec altq_codel_bridge ifconfig ${bridge} addm ${epair}b
16806246369SKristof Provost	jexec altq_codel_bridge ifconfig ${epair}b up
16906246369SKristof Provost	jexec altq_codel_bridge ifconfig ${bridge} 192.0.2.2/24 up
17006246369SKristof Provost
17106246369SKristof Provost	# Sanity check
17206246369SKristof Provost	atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2
17306246369SKristof Provost
17406246369SKristof Provost	jexec altq_codel_bridge pfctl -e
17506246369SKristof Provost	pft_set_rules altq_codel_bridge \
17606246369SKristof Provost		"altq on ${bridge} bandwidth 1000b codelq queue { slow }" \
17706246369SKristof Provost		"match queue slow" \
17806246369SKristof Provost		"pass"
17906246369SKristof Provost
18006246369SKristof Provost	# "Saturate the link"
18106246369SKristof Provost	ping -i .1 -c 5 -s 1200 192.0.2.2
18206246369SKristof Provost
18306246369SKristof Provost	# We should now be hitting the limits and get these packet dropped.
18406246369SKristof Provost	rcv=$(ping -i .1 -c 5 -s 1200 192.0.2.2 | tr "," "\n" | awk '/packets received/ { print $1; }')
18506246369SKristof Provost	echo "Received $rcv packets"
18606246369SKristof Provost	if [ ${rcv} -gt 1 ]
18706246369SKristof Provost	then
18806246369SKristof Provost		atf_fail "Received ${rcv} packets in a saturated link"
18906246369SKristof Provost	fi
19006246369SKristof Provost}
19106246369SKristof Provost
19206246369SKristof Provostcodel_bridge_cleanup()
19306246369SKristof Provost{
19406246369SKristof Provost	altq_cleanup
19506246369SKristof Provost}
19606246369SKristof Provost
197cd46399bSKristof Provostatf_test_case "prioritise" "cleanup"
198cd46399bSKristof Provostprioritise_head()
199cd46399bSKristof Provost{
200cd46399bSKristof Provost	atf_set descr "Test prioritising one type of traffic over the other"
201cd46399bSKristof Provost	atf_set require.user root
202cd46399bSKristof Provost}
203cd46399bSKristof Provost
204cd46399bSKristof Provostprioritise_body()
205cd46399bSKristof Provost{
206cd46399bSKristof Provost	altq_init
207cd46399bSKristof Provost	is_altq_supported cbq
208cd46399bSKristof Provost
209cd46399bSKristof Provost	epair=$(vnet_mkepair)
210cd46399bSKristof Provost	vnet_mkjail altq_prioritise ${epair}b
211cd46399bSKristof Provost
212cd46399bSKristof Provost	ifconfig ${epair}a 192.0.2.1/24 up
213cd46399bSKristof Provost	jexec altq_prioritise ifconfig ${epair}b 192.0.2.2/24 up
214cd46399bSKristof Provost
215*b0fcf4d5SKristof Provost	jexec altq_prioritise /usr/sbin/inetd -p ${PWD}/inetd-altq.pid \
216cd46399bSKristof Provost	    $(atf_get_srcdir)/../pf/echo_inetd.conf
217cd46399bSKristof Provost
218cd46399bSKristof Provost	# Sanity check
219cd46399bSKristof Provost	atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2
220cd46399bSKristof Provost
221cd46399bSKristof Provost	jexec altq_prioritise pfctl -e
222cd46399bSKristof Provost	pft_set_rules altq_prioritise \
223cd46399bSKristof Provost		"altq on ${epair}b bandwidth 6000b cbq queue { default, slow }" \
224cd46399bSKristof Provost		"queue default priority 7 cbq(default)" \
225cd46399bSKristof Provost		"queue slow priority 1 cbq" \
226cd46399bSKristof Provost		"match proto icmp queue slow" \
227cd46399bSKristof Provost		"match proto tcp queue default" \
228cd46399bSKristof Provost		"pass"
229cd46399bSKristof Provost
230cd46399bSKristof Provost	# single ping succeeds just fine
231cd46399bSKristof Provost	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
232cd46399bSKristof Provost
233cd46399bSKristof Provost	# Unsaturated TCP succeeds
234cd46399bSKristof Provost	reply=$(echo "foo" | nc -w 5 -N 192.0.2.2 7)
235cd46399bSKristof Provost	if [ "$reply" != "foo" ];
236cd46399bSKristof Provost	then
237cd46399bSKristof Provost		atf_fail "Unsaturated echo failed"
238cd46399bSKristof Provost	fi
239cd46399bSKristof Provost
240cd46399bSKristof Provost	# "Saturate the link"
241cd46399bSKristof Provost	ping -i .01 -c 50 -s 1200 192.0.2.2
242cd46399bSKristof Provost
243cd46399bSKristof Provost	# We should now be hitting the limits and get these packet dropped.
244cd46399bSKristof Provost	rcv=$(ping -i .1 -c 5 -s 1200 192.0.2.2 | tr "," "\n" | awk '/packets received/ { print $1; }')
245cd46399bSKristof Provost	echo "Received $rcv packets"
246cd46399bSKristof Provost	if [ ${rcv} -gt 1 ]
247cd46399bSKristof Provost	then
248cd46399bSKristof Provost		atf_fail "Received ${rcv} packets in a saturated link"
249cd46399bSKristof Provost	fi
250cd46399bSKristof Provost
251cd46399bSKristof Provost	# TCP should still pass
252cd46399bSKristof Provost	for i in `seq 1 10`
253cd46399bSKristof Provost	do
254cd46399bSKristof Provost		reply=$(echo "foo_${i}" | nc -w 5 -N 192.0.2.2 7)
255cd46399bSKristof Provost		if [ "$reply" != "foo_${i}" ];
256cd46399bSKristof Provost		then
257cd46399bSKristof Provost			atf_fail "Prioritised echo failed ${i}"
258cd46399bSKristof Provost		fi
259cd46399bSKristof Provost
260cd46399bSKristof Provost	done
261cd46399bSKristof Provost
262cd46399bSKristof Provost	# Now reverse priority
263cd46399bSKristof Provost	pft_set_rules altq_prioritise \
264cd46399bSKristof Provost		"altq on ${epair}b bandwidth 6000b cbq queue { default, slow }" \
265cd46399bSKristof Provost		"queue default priority 7 cbq(default)" \
266cd46399bSKristof Provost		"queue slow priority 1 cbq" \
267cd46399bSKristof Provost		"match proto tcp queue slow" \
268cd46399bSKristof Provost		"match proto icmp queue default" \
269cd46399bSKristof Provost		"pass"
270cd46399bSKristof Provost
271cd46399bSKristof Provost	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
272cd46399bSKristof Provost	ping -i .01 -c 50 -s 1200 192.0.2.2
273cd46399bSKristof Provost	for i in `seq 1 10`
274cd46399bSKristof Provost	do
275cd46399bSKristof Provost		reply=$(echo "foo_${i}" | nc -w 5 -N 192.0.2.2 7)
276cd46399bSKristof Provost		if [ "$reply" == "foo_${i}" ];
277cd46399bSKristof Provost		then
278cd46399bSKristof Provost			atf_fail "Unexpected echo success"
279cd46399bSKristof Provost		fi
280cd46399bSKristof Provost
281cd46399bSKristof Provost	done
282cd46399bSKristof Provost}
283cd46399bSKristof Provost
284cd46399bSKristof Provostprioritise_cleanup()
285cd46399bSKristof Provost{
286cd46399bSKristof Provost	altq_cleanup
287cd46399bSKristof Provost}
288cd46399bSKristof Provost
289e8423423SKristof Provostatf_test_case "codel_vlan" "cleanup"
290e8423423SKristof Provostcodel_vlan_head()
291e8423423SKristof Provost{
292e8423423SKristof Provost	atf_set descr 'Test double-pass through ALTQ with codel'
293e8423423SKristof Provost	atf_set require.user root
294e8423423SKristof Provost}
295e8423423SKristof Provost
296e8423423SKristof Provostcodel_vlan_body()
297e8423423SKristof Provost{
298e8423423SKristof Provost	altq_init
299e8423423SKristof Provost	is_altq_supported priq
300e8423423SKristof Provost	is_altq_supported codel
301e8423423SKristof Provost
302e8423423SKristof Provost	j=altq_vlan_codel
303e8423423SKristof Provost	epair=$(vnet_mkepair)
304e8423423SKristof Provost
305e8423423SKristof Provost	vnet_mkjail ${j}a ${epair}a
306e8423423SKristof Provost	va=$(jexec ${j}a ifconfig vlan create)
307e8423423SKristof Provost	jexec ${j}a ifconfig ${epair}a up
308e8423423SKristof Provost	jexec ${j}a ifconfig ${va} vlan 42 vlandev ${epair}a up
309e8423423SKristof Provost	jexec ${j}a ifconfig ${va} inet 192.0.2.1/24
310e8423423SKristof Provost
311e8423423SKristof Provost	vnet_mkjail ${j}b ${epair}b
312e8423423SKristof Provost	vb=$(jexec ${j}b ifconfig vlan create)
313e8423423SKristof Provost	jexec ${j}b ifconfig ${epair}b up
314e8423423SKristof Provost	jexec ${j}b ifconfig ${vb} vlan 42 vlandev ${epair}b up
315e8423423SKristof Provost	jexec ${j}b ifconfig ${vb} inet 192.0.2.2/24
316e8423423SKristof Provost
317e8423423SKristof Provost	# Sanity check
318e8423423SKristof Provost	atf_check -s exit:0 -o ignore \
319e8423423SKristof Provost	    jexec ${j}a ping -c 1 192.0.2.2
320e8423423SKristof Provost
321e8423423SKristof Provost	jexec ${j}a pfctl -e
322e8423423SKristof Provost	pft_set_rules ${j}a \
323e8423423SKristof Provost		"altq on ${epair}a priq bandwidth 10Mb queue { slow }" \
324e8423423SKristof Provost		"queue slow priority 6 qlimit 50 priq ( default codel )" \
325e8423423SKristof Provost		"altq on ${va} priq bandwidth 10Mb queue { vslow }" \
326e8423423SKristof Provost		"queue vslow priority 6 qlimit 50 priq ( default codel )" \
327e8423423SKristof Provost		"pass queue (slow)"
328e8423423SKristof Provost
329e8423423SKristof Provost	atf_check -s exit:0 -o ignore \
330e8423423SKristof Provost	    jexec ${j}a ping -c 1 192.0.2.2
331e8423423SKristof Provost}
332e8423423SKristof Provost
333e8423423SKristof Provostcodel_vlan_cleanup()
334e8423423SKristof Provost{
335e8423423SKristof Provost	altq_cleanup
336e8423423SKristof Provost}
337e8423423SKristof Provost
33816b38333SKristof Provostatf_init_test_cases()
33916b38333SKristof Provost{
34016b38333SKristof Provost	atf_add_test_case "hfsc"
341d363ebc7SKristof Provost	atf_add_test_case "match"
342e62175dfSKristof Provost	atf_add_test_case "cbq_vlan"
34306246369SKristof Provost	atf_add_test_case "codel_bridge"
344cd46399bSKristof Provost	atf_add_test_case "prioritise"
345e8423423SKristof Provost	atf_add_test_case "codel_vlan"
34616b38333SKristof Provost}
347