xref: /freebsd/tests/sys/netinet6/frag6/frag6_16.sh (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1# $FreeBSD$
2#-
3# SPDX-License-Identifier: BSD-2-Clause
4#
5# Copyright (c) 2019 Netflix, Inc.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28
29. $(atf_get_srcdir)/frag6.subr
30
31
32frag6_16_check_stats() {
33
34	local jname ifname
35	jname=$1
36	ifname=$2
37
38	case "${jname}" in
39	"")	echo "ERROR: jname is empty"; return ;;
40	esac
41	case "${ifname}" in
42	"")	echo "ERROR: ifname is empty"; return ;;
43	esac
44
45	# Defaults are: IPV6_FRAGTTL  120 slowtimo ticks.
46	# pfslowtimo() is run at hz/2.  So this takes 60s.
47	# This is awefully long for a test case.
48	# The Python script has to wait for this already to get the ICMPv6
49	# hence we do not sleep here anymore.
50
51	nf=`jexec ${jname} sysctl -n net.inet6.ip6.frag6_nfragpackets`
52	case ${nf} in
53	0)	break ;;
54	*)	atf_fail "VNET frag6_nfragpackets not 0 but: ${nf}" ;;
55	esac
56	nf=`sysctl -n net.inet6.ip6.frag6_nfrags`
57	case ${nf} in
58	0)	break ;;
59	*)	atf_fail "Global frag6_nfrags not 0 but: ${nf}" ;;
60	esac
61
62	#
63	# Check selection of global UDP stats.
64	#
65	cat <<EOF > ${HOME}/filter-${jname}.txt
66    <received-datagrams>1</received-datagrams>
67    <dropped-incomplete-headers>0</dropped-incomplete-headers>
68    <dropped-bad-data-length>0</dropped-bad-data-length>
69    <dropped-bad-checksum>0</dropped-bad-checksum>
70    <dropped-no-checksum>0</dropped-no-checksum>
71    <dropped-no-socket>1</dropped-no-socket>
72    <dropped-broadcast-multicast>0</dropped-broadcast-multicast>
73    <dropped-full-socket-buffer>0</dropped-full-socket-buffer>
74    <not-for-hashed-pcb>0</not-for-hashed-pcb>
75EOF
76	count=`jexec ${jname} netstat -s -p udp --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
77	rm -f ${HOME}/filter-${jname}.txt
78	case ${count} in
79	9)	;;
80	*)	jexec ${jname} netstat -s -p udp --libxo xml,pretty
81		atf_fail "Global UDP statistics do not match: ${count} != 9" ;;
82	esac
83
84
85	#
86	# Check selection of global IPv6 stats.
87	#
88	cat <<EOF > ${HOME}/filter-${jname}.txt
89    <dropped-below-minimum-size>0</dropped-below-minimum-size>
90    <dropped-short-packets>0</dropped-short-packets>
91    <dropped-bad-options>0</dropped-bad-options>
92    <dropped-bad-version>0</dropped-bad-version>
93    <received-fragments>30</received-fragments>
94    <dropped-fragment>0</dropped-fragment>
95    <dropped-fragment-after-timeout>0</dropped-fragment-after-timeout>
96    <dropped-fragments-overflow>0</dropped-fragments-overflow>
97    <atomic-fragments>0</atomic-fragments>
98    <reassembled-packets>1</reassembled-packets>
99    <forwarded-packets>0</forwarded-packets>
100    <packets-not-forwardable>0</packets-not-forwardable>
101    <sent-redirects>0</sent-redirects>
102    <send-packets-fabricated-header>0</send-packets-fabricated-header>
103    <discard-no-mbufs>0</discard-no-mbufs>
104    <discard-no-route>0</discard-no-route>
105    <sent-fragments>0</sent-fragments>
106    <fragments-created>0</fragments-created>
107    <discard-cannot-fragment>0</discard-cannot-fragment>
108    <discard-scope-violations>0</discard-scope-violations>
109EOF
110	count=`jexec ${jname} netstat -s -p ip6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
111	rm -f ${HOME}/filter-${jname}.txt
112	case ${count} in
113	20)	;;
114	*)	jexec ${jname} netstat -s -p ip6 --libxo xml,pretty
115		atf_fail "Global IPv6 statistics do not match: ${count} != 20" ;;
116	esac
117
118	#
119	# Check selection of global ICMPv6 stats.
120	# XXX-TODO check output histogram (just too hard to parse [no multi-line-grep])
121	#
122	cat <<EOF > ${HOME}/filter-${jname}.txt
123    <icmp6-calls>1</icmp6-calls>
124      <no-route>0</no-route>
125      <admin-prohibited>0</admin-prohibited>
126      <beyond-scope>0</beyond-scope>
127      <address-unreachable>0</address-unreachable>
128      <port-unreachable>1</port-unreachable>
129      <packet-too-big>0</packet-too-big>
130      <time-exceed-transmit>0</time-exceed-transmit>
131      <time-exceed-reassembly>0</time-exceed-reassembly>
132      <bad-header>0</bad-header>
133      <bad-next-header>0</bad-next-header>
134      <bad-option>0</bad-option>
135      <redirects>0</redirects>
136      <unknown>0</unknown>
137      <reflect>0</reflect>
138      <too-many-nd-options>0</too-many-nd-options>
139      <bad-nd-options>0</bad-nd-options>
140      <bad-neighbor-solicitation>0</bad-neighbor-solicitation>
141      <bad-neighbor-advertisement>0</bad-neighbor-advertisement>
142      <bad-router-solicitation>0</bad-router-solicitation>
143      <bad-router-advertisement>0</bad-router-advertisement>
144      <bad-redirect>0</bad-redirect>
145EOF
146	count=`jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
147	rm -f ${HOME}/filter-${jname}.txt
148	case ${count} in
149	22)	;;
150	*)	jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty
151		atf_fail "Global ICMPv6 statistics do not match: ${count} != 22" ;;
152	esac
153
154	#
155	# Check selection of interface IPv6 stats.
156	# XXX-BZ no reassembly failed stats.#
157	#
158	cat <<EOF > ${HOME}/filter-${jname}.txt
159    <dropped-invalid-header>0</dropped-invalid-header>
160    <dropped-mtu-exceeded>0</dropped-mtu-exceeded>
161    <dropped-no-route>0</dropped-no-route>
162    <dropped-invalid-destination>0</dropped-invalid-destination>
163    <dropped-unknown-protocol>0</dropped-unknown-protocol>
164    <dropped-truncated>0</dropped-truncated>
165    <sent-forwarded>0</sent-forwarded>
166    <discard-packets>0</discard-packets>
167    <discard-fragments>0</discard-fragments>
168    <fragments-failed>0</fragments-failed>
169    <fragments-created>0</fragments-created>
170    <reassembly-required>30</reassembly-required>
171    <reassembled-packets>1</reassembled-packets>
172    <reassembly-failed>0</reassembly-failed>
173EOF
174	count=`jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
175	rm -f ${HOME}/filter-${jname}.txt
176	case ${count} in
177	14)	;;
178	*)	jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty
179		atf_fail "Interface IPv6 statistics do not match: ${count} != 14" ;;
180	esac
181
182	#
183	# Check selection of interface ICMPv6 stats.
184	#
185	cat <<EOF > ${HOME}/filter-${jname}.txt
186    <received-errors>0</received-errors>
187    <received-destination-unreachable>0</received-destination-unreachable>
188    <received-admin-prohibited>0</received-admin-prohibited>
189    <received-time-exceeded>0</received-time-exceeded>
190    <received-bad-parameter>0</received-bad-parameter>
191    <received-packet-too-big>0</received-packet-too-big>
192    <received-echo-requests>0</received-echo-requests>
193    <received-echo-replies>0</received-echo-replies>
194    <received-router-solicitation>0</received-router-solicitation>
195    <received-router-advertisement>0</received-router-advertisement>
196    <sent-errors>1</sent-errors>
197    <sent-destination-unreachable>1</sent-destination-unreachable>
198    <sent-admin-prohibited>0</sent-admin-prohibited>
199    <sent-time-exceeded>0</sent-time-exceeded>
200    <sent-bad-parameter>0</sent-bad-parameter>
201    <sent-packet-too-big>0</sent-packet-too-big>
202    <sent-echo-requests>0</sent-echo-requests>
203    <sent-echo-replies>0</sent-echo-replies>
204    <sent-router-solicitation>0</sent-router-solicitation>
205    <sent-router-advertisement>0</sent-router-advertisement>
206    <sent-redirects>0</sent-redirects>
207EOF
208	count=`jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
209	rm -f ${HOME}/filter-${jname}.txt
210	case ${count} in
211	21)	;;
212	*)	jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty
213		atf_fail "Interface ICMPv6 statistics do not match: ${count} != 21" ;;
214	esac
215}
216
217atf_test_case "frag6_16" "cleanup"
218frag6_16_head() {
219	frag6_head 16
220}
221
222frag6_16_body() {
223	frag6_body 16 frag6_16_check_stats
224}
225
226frag6_16_cleanup() {
227	frag6_cleanup 16
228}
229
230atf_init_test_cases()
231{
232	atf_add_test_case "frag6_16"
233}
234