xref: /freebsd/tests/sys/netinet6/frag6/frag6_19.sh (revision c697fb7f)
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
31frag6_19_check_stats() {
32
33	local jname ifname
34	jname=$1
35	ifname=$2
36
37	case "${jname}" in
38	"")	echo "ERROR: jname is empty"; return ;;
39	esac
40	case "${ifname}" in
41	"")	echo "ERROR: ifname is empty"; return ;;
42	esac
43
44	# Defaults are: IPV6_FRAGTTL  120 slowtimo ticks.
45	# pfslowtimo() is run at hz/2.  So this takes 60s.
46	# This is awefully long for a test case.
47	# The Python script has to wait for this already to get the ICMPv6
48	# hence we do not sleep here anymore.
49
50	#
51	# Check selection of global UDP stats.
52	#
53	cat <<EOF > ${HOME}/filter-${jname}.txt
54    <received-datagrams>0</received-datagrams>
55    <dropped-incomplete-headers>0</dropped-incomplete-headers>
56    <dropped-bad-data-length>0</dropped-bad-data-length>
57    <dropped-bad-checksum>0</dropped-bad-checksum>
58    <dropped-no-checksum>0</dropped-no-checksum>
59    <dropped-no-socket>0</dropped-no-socket>
60    <dropped-broadcast-multicast>0</dropped-broadcast-multicast>
61    <dropped-full-socket-buffer>0</dropped-full-socket-buffer>
62    <not-for-hashed-pcb>0</not-for-hashed-pcb>
63EOF
64	count=`jexec ${jname} netstat -s -p udp --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
65	rm -f ${HOME}/filter-${jname}.txt
66	case ${count} in
67	9)	;;
68	*)	jexec ${jname} netstat -s -p udp --libxo xml,pretty
69		atf_fail "Global UDP statistics do not match: ${count} != 9" ;;
70	esac
71
72
73	#
74	# Check selection of global IPv6 stats.
75	#
76	cat <<EOF > ${HOME}/filter-${jname}.txt
77    <dropped-below-minimum-size>0</dropped-below-minimum-size>
78    <dropped-short-packets>0</dropped-short-packets>
79    <dropped-bad-options>0</dropped-bad-options>
80    <dropped-bad-version>0</dropped-bad-version>
81    <received-fragments>127</received-fragments>
82    <dropped-fragment>0</dropped-fragment>
83    <dropped-fragment-after-timeout>0</dropped-fragment-after-timeout>
84    <dropped-fragments-overflow>0</dropped-fragments-overflow>
85    <atomic-fragments>0</atomic-fragments>
86    <reassembled-packets>0</reassembled-packets>
87    <forwarded-packets>0</forwarded-packets>
88    <packets-not-forwardable>0</packets-not-forwardable>
89    <sent-redirects>0</sent-redirects>
90    <send-packets-fabricated-header>0</send-packets-fabricated-header>
91    <discard-no-mbufs>0</discard-no-mbufs>
92    <discard-no-route>0</discard-no-route>
93    <sent-fragments>0</sent-fragments>
94    <fragments-created>0</fragments-created>
95    <discard-cannot-fragment>0</discard-cannot-fragment>
96    <discard-scope-violations>0</discard-scope-violations>
97EOF
98	count=`jexec ${jname} netstat -s -p ip6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
99	rm -f ${HOME}/filter-${jname}.txt
100	case ${count} in
101	20)	;;
102	*)	jexec ${jname} netstat -s -p ip6 --libxo xml,pretty
103		atf_fail "Global IPv6 statistics do not match: ${count} != 20" ;;
104	esac
105
106	#
107	# Check selection of global ICMPv6 stats.
108	# XXX-TODO check output histogram (just too hard to parse [no multi-line-grep])
109	#
110	cat <<EOF > ${HOME}/filter-${jname}.txt
111    <icmp6-calls>0</icmp6-calls>
112      <no-route>0</no-route>
113      <admin-prohibited>0</admin-prohibited>
114      <beyond-scope>0</beyond-scope>
115      <address-unreachable>0</address-unreachable>
116      <port-unreachable>0</port-unreachable>
117      <packet-too-big>0</packet-too-big>
118      <time-exceed-transmit>0</time-exceed-transmit>
119      <time-exceed-reassembly>0</time-exceed-reassembly>
120      <bad-header>0</bad-header>
121      <bad-next-header>0</bad-next-header>
122      <bad-option>0</bad-option>
123      <redirects>0</redirects>
124      <unknown>0</unknown>
125      <reflect>0</reflect>
126      <too-many-nd-options>0</too-many-nd-options>
127      <bad-nd-options>0</bad-nd-options>
128      <bad-neighbor-solicitation>0</bad-neighbor-solicitation>
129      <bad-neighbor-advertisement>0</bad-neighbor-advertisement>
130      <bad-router-solicitation>0</bad-router-solicitation>
131      <bad-router-advertisement>0</bad-router-advertisement>
132      <bad-redirect>0</bad-redirect>
133EOF
134	count=`jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
135	rm -f ${HOME}/filter-${jname}.txt
136	case ${count} in
137	22)	;;
138	*)	jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty
139		atf_fail "Global ICMPv6 statistics do not match: ${count} != 22" ;;
140	esac
141
142	#
143	# Check selection of interface IPv6 stats.
144	# XXX-BZ no reassembly failed stats.#
145	#
146	cat <<EOF > ${HOME}/filter-${jname}.txt
147    <dropped-invalid-header>0</dropped-invalid-header>
148    <dropped-mtu-exceeded>0</dropped-mtu-exceeded>
149    <dropped-no-route>0</dropped-no-route>
150    <dropped-invalid-destination>0</dropped-invalid-destination>
151    <dropped-unknown-protocol>0</dropped-unknown-protocol>
152    <dropped-truncated>0</dropped-truncated>
153    <sent-forwarded>0</sent-forwarded>
154    <discard-packets>0</discard-packets>
155    <discard-fragments>0</discard-fragments>
156    <fragments-failed>0</fragments-failed>
157    <fragments-created>0</fragments-created>
158    <reassembly-required>127</reassembly-required>
159    <reassembled-packets>0</reassembled-packets>
160    <reassembly-failed>0</reassembly-failed>
161EOF
162	count=`jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
163	rm -f ${HOME}/filter-${jname}.txt
164	case ${count} in
165	14)	;;
166	*)	jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty
167		atf_fail "Interface IPv6 statistics do not match: ${count} != 14" ;;
168	esac
169
170	#
171	# Check selection of interface ICMPv6 stats.
172	#
173	cat <<EOF > ${HOME}/filter-${jname}.txt
174    <received-errors>0</received-errors>
175    <received-destination-unreachable>0</received-destination-unreachable>
176    <received-admin-prohibited>0</received-admin-prohibited>
177    <received-time-exceeded>0</received-time-exceeded>
178    <received-bad-parameter>0</received-bad-parameter>
179    <received-packet-too-big>0</received-packet-too-big>
180    <received-echo-requests>0</received-echo-requests>
181    <received-echo-replies>0</received-echo-replies>
182    <received-router-solicitation>0</received-router-solicitation>
183    <received-router-advertisement>0</received-router-advertisement>
184    <sent-errors>0</sent-errors>
185    <sent-destination-unreachable>0</sent-destination-unreachable>
186    <sent-admin-prohibited>0</sent-admin-prohibited>
187    <sent-time-exceeded>0</sent-time-exceeded>
188    <sent-bad-parameter>0</sent-bad-parameter>
189    <sent-packet-too-big>0</sent-packet-too-big>
190    <sent-echo-requests>0</sent-echo-requests>
191    <sent-echo-replies>0</sent-echo-replies>
192    <sent-router-solicitation>0</sent-router-solicitation>
193    <sent-router-advertisement>0</sent-router-advertisement>
194    <sent-redirects>0</sent-redirects>
195EOF
196	count=`jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt`
197	rm -f ${HOME}/filter-${jname}.txt
198	case ${count} in
199	21)	;;
200	*)	jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty
201		atf_fail "Interface ICMPv6 statistics do not match: ${count} != 21" ;;
202	esac
203}
204
205atf_test_case "frag6_19" "cleanup"
206frag6_19_head() {
207	frag6_head 19
208}
209
210frag6_19_body() {
211	frag6_body 19 frag6_19_check_stats
212}
213
214frag6_19_cleanup() {
215	frag6_cleanup 19
216}
217
218atf_init_test_cases()
219{
220	atf_add_test_case "frag6_19"
221}
222