xref: /freebsd/tests/sys/netpfil/pf/altq.sh (revision cd46399b9ccf04f6ec00a532e52c8b1edb007af7)
1. $(atf_get_srcdir)/utils.subr
2
3atf_test_case "hfsc" "cleanup"
4hfsc_head()
5{
6	atf_set descr 'Basic HFSC test'
7	atf_set require.user root
8}
9
10hfsc_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
40hfsc_cleanup()
41{
42	altq_cleanup
43}
44
45atf_test_case "match" "cleanup"
46match_head()
47{
48	atf_set descr 'Basic match keyword test'
49	atf_set require.user root
50}
51
52match_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
84match_cleanup()
85{
86	altq_cleanup
87}
88
89atf_test_case "cbq_vlan" "cleanup"
90cbq_vlan_head()
91{
92	atf_set descr 'CBQ over VLAN test'
93	atf_set require.user root
94}
95
96cbq_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
143cbq_vlan_cleanup()
144{
145	altq_cleanup
146}
147
148atf_test_case "prioritise" "cleanup"
149prioritise_head()
150{
151	atf_set descr "Test prioritising one type of traffic over the other"
152	atf_set require.user root
153}
154
155prioritise_body()
156{
157	altq_init
158	is_altq_supported cbq
159
160	epair=$(vnet_mkepair)
161	vnet_mkjail altq_prioritise ${epair}b
162
163	ifconfig ${epair}a 192.0.2.1/24 up
164	jexec altq_prioritise ifconfig ${epair}b 192.0.2.2/24 up
165
166	jexec altq_prioritise /usr/sbin/inetd -p inetd-altq.pid \
167	    $(atf_get_srcdir)/../pf/echo_inetd.conf
168
169	# Sanity check
170	atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2
171
172	jexec altq_prioritise pfctl -e
173	pft_set_rules altq_prioritise \
174		"altq on ${epair}b bandwidth 6000b cbq queue { default, slow }" \
175		"queue default priority 7 cbq(default)" \
176		"queue slow priority 1 cbq" \
177		"match proto icmp queue slow" \
178		"match proto tcp queue default" \
179		"pass"
180
181	# single ping succeeds just fine
182	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
183
184	# Unsaturated TCP succeeds
185	reply=$(echo "foo" | nc -w 5 -N 192.0.2.2 7)
186	if [ "$reply" != "foo" ];
187	then
188		atf_fail "Unsaturated echo failed"
189	fi
190
191	# "Saturate the link"
192	ping -i .01 -c 50 -s 1200 192.0.2.2
193
194	# We should now be hitting the limits and get these packet dropped.
195	rcv=$(ping -i .1 -c 5 -s 1200 192.0.2.2 | tr "," "\n" | awk '/packets received/ { print $1; }')
196	echo "Received $rcv packets"
197	if [ ${rcv} -gt 1 ]
198	then
199		atf_fail "Received ${rcv} packets in a saturated link"
200	fi
201
202	# TCP should still pass
203	for i in `seq 1 10`
204	do
205		reply=$(echo "foo_${i}" | nc -w 5 -N 192.0.2.2 7)
206		if [ "$reply" != "foo_${i}" ];
207		then
208			atf_fail "Prioritised echo failed ${i}"
209		fi
210
211	done
212
213	# Now reverse priority
214	pft_set_rules altq_prioritise \
215		"altq on ${epair}b bandwidth 6000b cbq queue { default, slow }" \
216		"queue default priority 7 cbq(default)" \
217		"queue slow priority 1 cbq" \
218		"match proto tcp queue slow" \
219		"match proto icmp queue default" \
220		"pass"
221
222	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
223	ping -i .01 -c 50 -s 1200 192.0.2.2
224	for i in `seq 1 10`
225	do
226		reply=$(echo "foo_${i}" | nc -w 5 -N 192.0.2.2 7)
227		if [ "$reply" == "foo_${i}" ];
228		then
229			atf_fail "Unexpected echo success"
230		fi
231
232	done
233}
234
235prioritise_cleanup()
236{
237	altq_cleanup
238}
239
240atf_init_test_cases()
241{
242	atf_add_test_case "hfsc"
243	atf_add_test_case "match"
244	atf_add_test_case "cbq_vlan"
245	atf_add_test_case "prioritise"
246}
247