xref: /freebsd-src/tests/sys/net/if_clone_test.sh (revision 6ee181b9d5f00cfe337419370ba4590d939cce84)
14b40bdbdSAlan Somers#
24b40bdbdSAlan Somers#  Copyright (c) 2014 Spectra Logic Corporation
34b40bdbdSAlan Somers#  All rights reserved.
44b40bdbdSAlan Somers#
54b40bdbdSAlan Somers#  Redistribution and use in source and binary forms, with or without
64b40bdbdSAlan Somers#  modification, are permitted provided that the following conditions
74b40bdbdSAlan Somers#  are met:
84b40bdbdSAlan Somers#  1. Redistributions of source code must retain the above copyright
94b40bdbdSAlan Somers#     notice, this list of conditions, and the following disclaimer,
104b40bdbdSAlan Somers#     without modification.
114b40bdbdSAlan Somers#  2. Redistributions in binary form must reproduce at minimum a disclaimer
124b40bdbdSAlan Somers#     substantially similar to the "NO WARRANTY" disclaimer below
134b40bdbdSAlan Somers#     ("Disclaimer") and any redistribution must be conditioned upon
144b40bdbdSAlan Somers#     including a substantially similar Disclaimer requirement for further
154b40bdbdSAlan Somers#     binary redistribution.
164b40bdbdSAlan Somers#
174b40bdbdSAlan Somers#  NO WARRANTY
184b40bdbdSAlan Somers#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
194b40bdbdSAlan Somers#  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
204b40bdbdSAlan Somers#  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
214b40bdbdSAlan Somers#  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
224b40bdbdSAlan Somers#  HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
234b40bdbdSAlan Somers#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
244b40bdbdSAlan Somers#  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
254b40bdbdSAlan Somers#  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
264b40bdbdSAlan Somers#  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
274b40bdbdSAlan Somers#  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
284b40bdbdSAlan Somers#  POSSIBILITY OF SUCH DAMAGES.
294b40bdbdSAlan Somers#
304b40bdbdSAlan Somers#  Authors: Alan Somers         (Spectra Logic Corporation)
314b40bdbdSAlan Somers#
324b40bdbdSAlan Somers
334b40bdbdSAlan Somers# Outline:
344b40bdbdSAlan Somers# For each cloned interface type, do three tests
354b40bdbdSAlan Somers# 1) Create and destroy it
364b40bdbdSAlan Somers# 2) Create, up, and destroy it
374b40bdbdSAlan Somers# 3) Create, disable IPv6 auto address assignment, up, and destroy it
384b40bdbdSAlan Somers
394b40bdbdSAlan SomersTESTLEN=10	# seconds
404b40bdbdSAlan Somers
4138edd595SAlan Somersatf_test_case epair_stress cleanup
4238edd595SAlan Somersepair_stress_head()
4338edd595SAlan Somers{
4438edd595SAlan Somers	atf_set "descr" "Simultaneously create and destroy an epair(4)"
4538edd595SAlan Somers	atf_set "require.user" "root"
4638edd595SAlan Somers}
4738edd595SAlan Somersepair_stress_body()
4838edd595SAlan Somers{
4938edd595SAlan Somers	do_stress "epair"
5038edd595SAlan Somers}
5138edd595SAlan Somersepair_stress_cleanup()
5238edd595SAlan Somers{
5338edd595SAlan Somers	cleanup_ifaces
5438edd595SAlan Somers}
5538edd595SAlan Somers
5638edd595SAlan Somersatf_test_case epair_up_stress cleanup
5738edd595SAlan Somersepair_up_stress_head()
5838edd595SAlan Somers{
5938edd595SAlan Somers	atf_set "descr" "Simultaneously up and detroy an epair(4)"
6038edd595SAlan Somers	atf_set "require.user" "root"
6138edd595SAlan Somers}
6238edd595SAlan Somersepair_up_stress_body()
6338edd595SAlan Somers{
6438edd595SAlan Somers	do_up_stress "epair" "" ""
6538edd595SAlan Somers}
6638edd595SAlan Somersepair_up_stress_cleanup()
6738edd595SAlan Somers{
6838edd595SAlan Somers	cleanup_ifaces
6938edd595SAlan Somers}
7038edd595SAlan Somers
71*868bf821SKristof Provostatf_test_case epair_destroy_race cleanup
72*868bf821SKristof Provostepair_destroy_race_head()
73*868bf821SKristof Provost{
74*868bf821SKristof Provost	atf_set "descr" "Race if_detach() and if_vmove()"
75*868bf821SKristof Provost	atf_set "require.user" "root"
76*868bf821SKristof Provost}
77*868bf821SKristof Provostepair_destroy_race_body()
78*868bf821SKristof Provost{
79*868bf821SKristof Provost	for i in `seq 1 10`
80*868bf821SKristof Provost	do
81*868bf821SKristof Provost		epair_a=$(ifconfig epair create)
82*868bf821SKristof Provost		echo $epair_a >> devices_to_cleanup
83*868bf821SKristof Provost		epair_b=${epair_a%a}b
84*868bf821SKristof Provost
85*868bf821SKristof Provost		jail -c vnet name="epair_destroy" nopersist path=/ \
86*868bf821SKristof Provost		  host.hostname="epair_destroy" vnet.interface="$epair_b" \
87*868bf821SKristof Provost		  command=sh -c "ifconfig $epair_b 192.0.2.1/24; sleep 0.1"&
88*868bf821SKristof Provost		pid=$!
89*868bf821SKristof Provost		ifconfig "$epair_a" destroy
90*868bf821SKristof Provost		wait $pid
91*868bf821SKristof Provost	done
92*868bf821SKristof Provost	true
93*868bf821SKristof Provost}
94*868bf821SKristof Provostepair_destroy_race_cleanup()
95*868bf821SKristof Provost{
96*868bf821SKristof Provost	cleanup_ifaces
97*868bf821SKristof Provost}
98*868bf821SKristof Provost
9938edd595SAlan Somersatf_test_case epair_ipv6_up_stress cleanup
10038edd595SAlan Somersepair_ipv6_up_stress_head()
10138edd595SAlan Somers{
10238edd595SAlan Somers	atf_set "descr" "Simultaneously up and destroy an epair(4) with IPv6"
10338edd595SAlan Somers	atf_set "require.user" "root"
10438edd595SAlan Somers}
10538edd595SAlan Somersepair_ipv6_up_stress_body()
10638edd595SAlan Somers{
10738edd595SAlan Somers	do_up_stress "epair" "6" ""
10838edd595SAlan Somers}
10938edd595SAlan Somersepair_ipv6_up_stress_cleanup()
11038edd595SAlan Somers{
11138edd595SAlan Somers	cleanup_ifaces
11238edd595SAlan Somers}
11338edd595SAlan Somers
1144b40bdbdSAlan Somersatf_test_case faith_stress cleanup
1154b40bdbdSAlan Somersfaith_stress_head()
1164b40bdbdSAlan Somers{
1174b40bdbdSAlan Somers	atf_set "descr" "Simultaneously create and destroy a faith(4)"
1184b40bdbdSAlan Somers	atf_set "require.user" "root"
1194b40bdbdSAlan Somers}
1204b40bdbdSAlan Somersfaith_stress_body()
1214b40bdbdSAlan Somers{
1224b40bdbdSAlan Somers	do_stress "faith"
1234b40bdbdSAlan Somers}
1244b40bdbdSAlan Somersfaith_stress_cleanup()
1254b40bdbdSAlan Somers{
1264b40bdbdSAlan Somers	cleanup_ifaces
1274b40bdbdSAlan Somers}
1284b40bdbdSAlan Somers
1294b40bdbdSAlan Somersatf_test_case faith_up_stress cleanup
1304b40bdbdSAlan Somersfaith_up_stress_head()
1314b40bdbdSAlan Somers{
1324b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a faith(4)"
1334b40bdbdSAlan Somers	atf_set "require.user" "root"
1344b40bdbdSAlan Somers}
1354b40bdbdSAlan Somersfaith_up_stress_body()
1364b40bdbdSAlan Somers{
1374b40bdbdSAlan Somers	do_up_stress "faith" "" ""
1384b40bdbdSAlan Somers}
1394b40bdbdSAlan Somersfaith_up_stress_cleanup()
1404b40bdbdSAlan Somers{
1414b40bdbdSAlan Somers	cleanup_ifaces
1424b40bdbdSAlan Somers}
1434b40bdbdSAlan Somers
1444b40bdbdSAlan Somersatf_test_case faith_ipv6_up_stress cleanup
1454b40bdbdSAlan Somersfaith_ipv6_up_stress_head()
1464b40bdbdSAlan Somers{
1474b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a faith(4) with IPv6"
1484b40bdbdSAlan Somers	atf_set "require.user" "root"
1494b40bdbdSAlan Somers}
1504b40bdbdSAlan Somersfaith_ipv6_up_stress_body()
1514b40bdbdSAlan Somers{
1524b40bdbdSAlan Somers	do_up_stress "faith" "6" ""
1534b40bdbdSAlan Somers}
1544b40bdbdSAlan Somersfaith_ipv6_up_stress_cleanup()
1554b40bdbdSAlan Somers{
1564b40bdbdSAlan Somers	cleanup_ifaces
1574b40bdbdSAlan Somers}
1584b40bdbdSAlan Somers
1594b40bdbdSAlan Somersatf_test_case gif_stress cleanup
1604b40bdbdSAlan Somersgif_stress_head()
1614b40bdbdSAlan Somers{
1624b40bdbdSAlan Somers	atf_set "descr" "Simultaneously create and destroy a gif(4)"
1634b40bdbdSAlan Somers	atf_set "require.user" "root"
1644b40bdbdSAlan Somers}
1654b40bdbdSAlan Somersgif_stress_body()
1664b40bdbdSAlan Somers{
1674b40bdbdSAlan Somers	do_stress "gif"
1684b40bdbdSAlan Somers}
1694b40bdbdSAlan Somersgif_stress_cleanup()
1704b40bdbdSAlan Somers{
1714b40bdbdSAlan Somers	cleanup_ifaces
1724b40bdbdSAlan Somers}
1734b40bdbdSAlan Somers
1744b40bdbdSAlan Somersatf_test_case gif_up_stress cleanup
1754b40bdbdSAlan Somersgif_up_stress_head()
1764b40bdbdSAlan Somers{
1774b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a gif(4)"
1784b40bdbdSAlan Somers	atf_set "require.user" "root"
1794b40bdbdSAlan Somers}
1804b40bdbdSAlan Somersgif_up_stress_body()
1814b40bdbdSAlan Somers{
1824b40bdbdSAlan Somers	do_up_stress "gif" "" "p2p"
1834b40bdbdSAlan Somers}
1844b40bdbdSAlan Somersgif_up_stress_cleanup()
1854b40bdbdSAlan Somers{
1864b40bdbdSAlan Somers	cleanup_ifaces
1874b40bdbdSAlan Somers}
1884b40bdbdSAlan Somers
1894b40bdbdSAlan Somersatf_test_case gif_ipv6_up_stress cleanup
1904b40bdbdSAlan Somersgif_ipv6_up_stress_head()
1914b40bdbdSAlan Somers{
1924b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a gif(4) with IPv6"
1934b40bdbdSAlan Somers	atf_set "require.user" "root"
1944b40bdbdSAlan Somers}
1954b40bdbdSAlan Somersgif_ipv6_up_stress_body()
1964b40bdbdSAlan Somers{
1974b40bdbdSAlan Somers	do_up_stress "gif" "6" "p2p"
1984b40bdbdSAlan Somers}
1994b40bdbdSAlan Somersgif_ipv6_up_stress_cleanup()
2004b40bdbdSAlan Somers{
2014b40bdbdSAlan Somers	cleanup_ifaces
2024b40bdbdSAlan Somers}
2034b40bdbdSAlan Somers
2044b40bdbdSAlan Somersatf_test_case lo_stress cleanup
2054b40bdbdSAlan Somerslo_stress_head()
2064b40bdbdSAlan Somers{
2074b40bdbdSAlan Somers	atf_set "descr" "Simultaneously create and destroy an lo(4)"
2084b40bdbdSAlan Somers	atf_set "require.user" "root"
2094b40bdbdSAlan Somers}
2104b40bdbdSAlan Somerslo_stress_body()
2114b40bdbdSAlan Somers{
2124b40bdbdSAlan Somers	do_stress "lo"
2134b40bdbdSAlan Somers}
2144b40bdbdSAlan Somerslo_stress_cleanup()
2154b40bdbdSAlan Somers{
2164b40bdbdSAlan Somers	cleanup_ifaces
2174b40bdbdSAlan Somers}
2184b40bdbdSAlan Somers
2194b40bdbdSAlan Somersatf_test_case lo_up_stress cleanup
2204b40bdbdSAlan Somerslo_up_stress_head()
2214b40bdbdSAlan Somers{
2224b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy an lo(4)"
2234b40bdbdSAlan Somers	atf_set "require.user" "root"
2244b40bdbdSAlan Somers}
2254b40bdbdSAlan Somerslo_up_stress_body()
2264b40bdbdSAlan Somers{
2274b40bdbdSAlan Somers	do_up_stress "lo" "" ""
2284b40bdbdSAlan Somers}
2294b40bdbdSAlan Somerslo_up_stress_cleanup()
2304b40bdbdSAlan Somers{
2314b40bdbdSAlan Somers	cleanup_ifaces
2324b40bdbdSAlan Somers}
2334b40bdbdSAlan Somers
2344b40bdbdSAlan Somersatf_test_case lo_ipv6_up_stress cleanup
2354b40bdbdSAlan Somerslo_ipv6_up_stress_head()
2364b40bdbdSAlan Somers{
2374b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy an lo(4) with IPv6"
2384b40bdbdSAlan Somers	atf_set "require.user" "root"
2394b40bdbdSAlan Somers}
2404b40bdbdSAlan Somerslo_ipv6_up_stress_body()
2414b40bdbdSAlan Somers{
2424b40bdbdSAlan Somers	do_up_stress "lo" "6" ""
2434b40bdbdSAlan Somers}
2444b40bdbdSAlan Somerslo_ipv6_up_stress_cleanup()
2454b40bdbdSAlan Somers{
2464b40bdbdSAlan Somers	cleanup_ifaces
2474b40bdbdSAlan Somers}
2484b40bdbdSAlan Somers
2494b40bdbdSAlan Somersatf_test_case tap_stress cleanup
2504b40bdbdSAlan Somerstap_stress_head()
2514b40bdbdSAlan Somers{
2524b40bdbdSAlan Somers	atf_set "descr" "Simultaneously create and destroy a tap(4)"
2534b40bdbdSAlan Somers	atf_set "require.user" "root"
2544b40bdbdSAlan Somers}
2554b40bdbdSAlan Somerstap_stress_body()
2564b40bdbdSAlan Somers{
2574b40bdbdSAlan Somers	do_stress "tap"
2584b40bdbdSAlan Somers}
2594b40bdbdSAlan Somerstap_stress_cleanup()
2604b40bdbdSAlan Somers{
2614b40bdbdSAlan Somers	cleanup_ifaces
2624b40bdbdSAlan Somers}
2634b40bdbdSAlan Somers
2644b40bdbdSAlan Somersatf_test_case tap_up_stress cleanup
2654b40bdbdSAlan Somerstap_up_stress_head()
2664b40bdbdSAlan Somers{
2674b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a tap(4)"
2684b40bdbdSAlan Somers	atf_set "require.user" "root"
2694b40bdbdSAlan Somers}
2704b40bdbdSAlan Somerstap_up_stress_body()
2714b40bdbdSAlan Somers{
2724b40bdbdSAlan Somers	do_up_stress "tap" "" ""
2734b40bdbdSAlan Somers}
2744b40bdbdSAlan Somerstap_up_stress_cleanup()
2754b40bdbdSAlan Somers{
2764b40bdbdSAlan Somers	cleanup_ifaces
2774b40bdbdSAlan Somers}
2784b40bdbdSAlan Somers
2794b40bdbdSAlan Somersatf_test_case tap_ipv6_up_stress cleanup
2804b40bdbdSAlan Somerstap_ipv6_up_stress_head()
2814b40bdbdSAlan Somers{
2824b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a tap(4) with IPv6"
2834b40bdbdSAlan Somers	atf_set "require.user" "root"
2844b40bdbdSAlan Somers}
2854b40bdbdSAlan Somerstap_ipv6_up_stress_body()
2864b40bdbdSAlan Somers{
2874b40bdbdSAlan Somers	do_up_stress "tap" "6" ""
2884b40bdbdSAlan Somers}
2894b40bdbdSAlan Somerstap_ipv6_up_stress_cleanup()
2904b40bdbdSAlan Somers{
2914b40bdbdSAlan Somers	cleanup_ifaces
2924b40bdbdSAlan Somers}
2934b40bdbdSAlan Somers
2944b40bdbdSAlan Somersatf_test_case tun_stress cleanup
2954b40bdbdSAlan Somerstun_stress_head()
2964b40bdbdSAlan Somers{
2974b40bdbdSAlan Somers	atf_set "descr" "Simultaneously create and destroy a tun(4)"
2984b40bdbdSAlan Somers	atf_set "require.user" "root"
2994b40bdbdSAlan Somers}
3004b40bdbdSAlan Somerstun_stress_body()
3014b40bdbdSAlan Somers{
3024b40bdbdSAlan Somers	do_stress "tun"
3034b40bdbdSAlan Somers}
3044b40bdbdSAlan Somerstun_stress_cleanup()
3054b40bdbdSAlan Somers{
3064b40bdbdSAlan Somers	cleanup_ifaces
3074b40bdbdSAlan Somers}
3084b40bdbdSAlan Somers
3094b40bdbdSAlan Somersatf_test_case tun_up_stress cleanup
3104b40bdbdSAlan Somerstun_up_stress_head()
3114b40bdbdSAlan Somers{
3124b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a tun(4)"
3134b40bdbdSAlan Somers	atf_set "require.user" "root"
3144b40bdbdSAlan Somers}
3154b40bdbdSAlan Somerstun_up_stress_body()
3164b40bdbdSAlan Somers{
3174b40bdbdSAlan Somers	do_up_stress "tun" "" "p2p"
3184b40bdbdSAlan Somers}
3194b40bdbdSAlan Somerstun_up_stress_cleanup()
3204b40bdbdSAlan Somers{
3214b40bdbdSAlan Somers	cleanup_ifaces
3224b40bdbdSAlan Somers}
3234b40bdbdSAlan Somers
3244b40bdbdSAlan Somersatf_test_case tun_ipv6_up_stress cleanup
3254b40bdbdSAlan Somerstun_ipv6_up_stress_head()
3264b40bdbdSAlan Somers{
3274b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a tun(4) with IPv6"
3284b40bdbdSAlan Somers	atf_set "require.user" "root"
3294b40bdbdSAlan Somers}
3304b40bdbdSAlan Somerstun_ipv6_up_stress_body()
3314b40bdbdSAlan Somers{
3324b40bdbdSAlan Somers	do_up_stress "tun" "6" "p2p"
3334b40bdbdSAlan Somers}
3344b40bdbdSAlan Somerstun_ipv6_up_stress_cleanup()
3354b40bdbdSAlan Somers{
3364b40bdbdSAlan Somers	cleanup_ifaces
3374b40bdbdSAlan Somers}
3384b40bdbdSAlan Somers
3394b40bdbdSAlan Somersatf_test_case vlan_stress cleanup
3404b40bdbdSAlan Somersvlan_stress_head()
3414b40bdbdSAlan Somers{
3424b40bdbdSAlan Somers	atf_set "descr" "Simultaneously create and destroy a vlan(4)"
3434b40bdbdSAlan Somers	atf_set "require.user" "root"
3444b40bdbdSAlan Somers}
3454b40bdbdSAlan Somersvlan_stress_body()
3464b40bdbdSAlan Somers{
3474b40bdbdSAlan Somers	do_stress "vlan"
3484b40bdbdSAlan Somers}
3494b40bdbdSAlan Somersvlan_stress_cleanup()
3504b40bdbdSAlan Somers{
3514b40bdbdSAlan Somers	cleanup_ifaces
3524b40bdbdSAlan Somers}
3534b40bdbdSAlan Somers
3544b40bdbdSAlan Somersatf_test_case vlan_up_stress cleanup
3554b40bdbdSAlan Somersvlan_up_stress_head()
3564b40bdbdSAlan Somers{
3574b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a vlan(4)"
3584b40bdbdSAlan Somers	atf_set "require.user" "root"
3594b40bdbdSAlan Somers}
3604b40bdbdSAlan Somersvlan_up_stress_body()
3614b40bdbdSAlan Somers{
3624b40bdbdSAlan Somers	do_up_stress "vlan" "" ""
3634b40bdbdSAlan Somers}
3644b40bdbdSAlan Somersvlan_up_stress_cleanup()
3654b40bdbdSAlan Somers{
3664b40bdbdSAlan Somers	cleanup_ifaces
3674b40bdbdSAlan Somers}
3684b40bdbdSAlan Somers
3694b40bdbdSAlan Somersatf_test_case vlan_ipv6_up_stress cleanup
3704b40bdbdSAlan Somersvlan_ipv6_up_stress_head()
3714b40bdbdSAlan Somers{
3724b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a vlan(4) with IPv6"
3734b40bdbdSAlan Somers	atf_set "require.user" "root"
3744b40bdbdSAlan Somers}
3754b40bdbdSAlan Somersvlan_ipv6_up_stress_body()
3764b40bdbdSAlan Somers{
3774b40bdbdSAlan Somers	do_up_stress "vlan" "6" ""
3784b40bdbdSAlan Somers}
3794b40bdbdSAlan Somersvlan_ipv6_up_stress_cleanup()
3804b40bdbdSAlan Somers{
3814b40bdbdSAlan Somers	cleanup_ifaces
3824b40bdbdSAlan Somers}
3834b40bdbdSAlan Somers
3844b40bdbdSAlan Somersatf_test_case vmnet_stress cleanup
3854b40bdbdSAlan Somersvmnet_stress_head()
3864b40bdbdSAlan Somers{
3874b40bdbdSAlan Somers	atf_set "descr" "Simultaneously create and destroy a vmnet(4)"
3884b40bdbdSAlan Somers	atf_set "require.user" "root"
3894b40bdbdSAlan Somers}
3904b40bdbdSAlan Somersvmnet_stress_body()
3914b40bdbdSAlan Somers{
3924b40bdbdSAlan Somers	do_stress "vmnet"
3934b40bdbdSAlan Somers}
3944b40bdbdSAlan Somersvmnet_stress_cleanup()
3954b40bdbdSAlan Somers{
3964b40bdbdSAlan Somers	cleanup_ifaces
3974b40bdbdSAlan Somers}
3984b40bdbdSAlan Somers
3994b40bdbdSAlan Somersatf_test_case vmnet_up_stress cleanup
4004b40bdbdSAlan Somersvmnet_up_stress_head()
4014b40bdbdSAlan Somers{
4024b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a vmnet(4)"
4034b40bdbdSAlan Somers	atf_set "require.user" "root"
4044b40bdbdSAlan Somers}
4054b40bdbdSAlan Somersvmnet_up_stress_body()
4064b40bdbdSAlan Somers{
4074b40bdbdSAlan Somers	do_up_stress "vmnet" "" ""
4084b40bdbdSAlan Somers}
4094b40bdbdSAlan Somersvmnet_up_stress_cleanup()
4104b40bdbdSAlan Somers{
4114b40bdbdSAlan Somers	cleanup_ifaces
4124b40bdbdSAlan Somers}
4134b40bdbdSAlan Somers
4144b40bdbdSAlan Somersatf_test_case vmnet_ipv6_up_stress cleanup
4154b40bdbdSAlan Somersvmnet_ipv6_up_stress_head()
4164b40bdbdSAlan Somers{
4174b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a vmnet(4) with IPv6"
4184b40bdbdSAlan Somers	atf_set "require.user" "root"
4194b40bdbdSAlan Somers}
4204b40bdbdSAlan Somersvmnet_ipv6_up_stress_body()
4214b40bdbdSAlan Somers{
4224b40bdbdSAlan Somers	do_up_stress "vmnet" "6" ""
4234b40bdbdSAlan Somers}
4244b40bdbdSAlan Somersvmnet_ipv6_up_stress_cleanup()
4254b40bdbdSAlan Somers{
4264b40bdbdSAlan Somers	cleanup_ifaces
4274b40bdbdSAlan Somers}
4284b40bdbdSAlan Somers
4294b40bdbdSAlan Somersatf_init_test_cases()
4304b40bdbdSAlan Somers{
43138edd595SAlan Somers	atf_add_test_case epair_ipv6_up_stress
43238edd595SAlan Somers	atf_add_test_case epair_stress
43338edd595SAlan Somers	atf_add_test_case epair_up_stress
434*868bf821SKristof Provost	atf_add_test_case epair_destroy_race
4354b40bdbdSAlan Somers	atf_add_test_case faith_ipv6_up_stress
4364b40bdbdSAlan Somers	atf_add_test_case faith_stress
4374b40bdbdSAlan Somers	atf_add_test_case faith_up_stress
4384b40bdbdSAlan Somers	atf_add_test_case gif_ipv6_up_stress
4394b40bdbdSAlan Somers	atf_add_test_case gif_stress
4404b40bdbdSAlan Somers	atf_add_test_case gif_up_stress
4414b40bdbdSAlan Somers	# Don't test lagg; it has its own test program
4424b40bdbdSAlan Somers	atf_add_test_case lo_ipv6_up_stress
4434b40bdbdSAlan Somers	atf_add_test_case lo_stress
4444b40bdbdSAlan Somers	atf_add_test_case lo_up_stress
4454b40bdbdSAlan Somers	atf_add_test_case tap_ipv6_up_stress
4464b40bdbdSAlan Somers	atf_add_test_case tap_stress
4474b40bdbdSAlan Somers	atf_add_test_case tap_up_stress
4484b40bdbdSAlan Somers	atf_add_test_case tun_ipv6_up_stress
4494b40bdbdSAlan Somers	atf_add_test_case tun_stress
4504b40bdbdSAlan Somers	atf_add_test_case tun_up_stress
4514b40bdbdSAlan Somers	atf_add_test_case vlan_ipv6_up_stress
4524b40bdbdSAlan Somers	atf_add_test_case vlan_stress
4534b40bdbdSAlan Somers	atf_add_test_case vlan_up_stress
4544b40bdbdSAlan Somers	atf_add_test_case vmnet_ipv6_up_stress
4554b40bdbdSAlan Somers	atf_add_test_case vmnet_stress
4564b40bdbdSAlan Somers	atf_add_test_case vmnet_up_stress
4574b40bdbdSAlan Somers}
4584b40bdbdSAlan Somers
4594b40bdbdSAlan Somersdo_stress()
4604b40bdbdSAlan Somers{
46138edd595SAlan Somers	local IFACE CREATOR_PID DESTROYER_PID
4624b40bdbdSAlan Somers
4634b40bdbdSAlan Somers	IFACE=`get_iface $1`
4644b40bdbdSAlan Somers
4654b40bdbdSAlan Somers	# First thread: create the interface
4664b40bdbdSAlan Somers	while true; do
46738edd595SAlan Somers		ifconfig ${IFACE%a} create 2>/dev/null && \
4684b40bdbdSAlan Somers			echo -n . >> creator_count.txt
4694b40bdbdSAlan Somers	done &
4704b40bdbdSAlan Somers	CREATOR_PID=$!
4714b40bdbdSAlan Somers
4724b40bdbdSAlan Somers	# Second thread: destroy the lagg
4734b40bdbdSAlan Somers	while true; do
4744b40bdbdSAlan Somers		ifconfig $IFACE destroy 2>/dev/null && \
4754b40bdbdSAlan Somers			echo -n . >> destroyer_count.txt
4764b40bdbdSAlan Somers	done &
4774b40bdbdSAlan Somers	DESTROYER_PID=$!
4784b40bdbdSAlan Somers
4794b40bdbdSAlan Somers	sleep ${TESTLEN}
4804b40bdbdSAlan Somers	kill $CREATOR_PID
4814b40bdbdSAlan Somers	kill $DESTROYER_PID
48238edd595SAlan Somers	echo "Created ${IFACE%a} `stat -f %z creator_count.txt` times."
4834b40bdbdSAlan Somers	echo "Destroyed it `stat -f %z destroyer_count.txt` times."
4844b40bdbdSAlan Somers}
4854b40bdbdSAlan Somers
4864b40bdbdSAlan Somers# Implement the up stress tests
4874b40bdbdSAlan Somers# Parameters
4884b40bdbdSAlan Somers# $1	Interface class, etc "lo" or "tap"
4894b40bdbdSAlan Somers# $2	"6" to enable IPv6 auto address assignment, anything else otherwise
4904b40bdbdSAlan Somers# $3	p2p for point to point interfaces, anything else for normal interfaces
4914b40bdbdSAlan Somersdo_up_stress()
4924b40bdbdSAlan Somers{
49338edd595SAlan Somers	local ADDR DSTADDR MASK MEAN_SLEEP_SECONDS MAX_SLEEP_USECS \
49438edd595SAlan Somers	    IFACE IPV6 P2P SRCDIR LOOP_PID ipv6_cmd up_cmd
4954b40bdbdSAlan Somers
4964b40bdbdSAlan Somers	# Configure the interface to use an RFC5737 nonrouteable addresses
4974b40bdbdSAlan Somers	ADDR="192.0.2.2"
4984b40bdbdSAlan Somers	DSTADDR="192.0.2.3"
4994b40bdbdSAlan Somers	MASK="24"
5004b40bdbdSAlan Somers	# ifconfig takes about 10ms to run.  To increase race coverage,
5014b40bdbdSAlan Somers	# randomly delay the two commands relative to each other by 5ms either
5024b40bdbdSAlan Somers	# way.
5034b40bdbdSAlan Somers	MEAN_SLEEP_SECONDS=.005
5044b40bdbdSAlan Somers	MAX_SLEEP_USECS=10000
5054b40bdbdSAlan Somers
5064b40bdbdSAlan Somers	IFACE=`get_iface $1`
5074b40bdbdSAlan Somers	IPV6=$2
5084b40bdbdSAlan Somers	P2P=$3
5094b40bdbdSAlan Somers
5104b40bdbdSAlan Somers	SRCDIR=$( atf_get_srcdir )
5114b40bdbdSAlan Somers	if [ "$IPV6" = 6 ]; then
5124b40bdbdSAlan Somers		ipv6_cmd="true"
5134b40bdbdSAlan Somers	else
5144b40bdbdSAlan Somers		ipv6_cmd="ifconfig $IFACE inet6 ifdisabled"
5154b40bdbdSAlan Somers	fi
5164b40bdbdSAlan Somers	if [ "$P2P" = "p2p" ]; then
5174b40bdbdSAlan Somers		up_cmd="ifconfig $IFACE up ${ADDR}/${MASK} ${DSTADDR}"
5184b40bdbdSAlan Somers	else
5194b40bdbdSAlan Somers		up_cmd="ifconfig $IFACE up ${ADDR}/${MASK}"
5204b40bdbdSAlan Somers	fi
5214b40bdbdSAlan Somers	while true; do
5224b40bdbdSAlan Somers		eval "$ipv6_cmd"
5234b40bdbdSAlan Somers		{ sleep ${MEAN_SLEEP_SECONDS} && \
5244b40bdbdSAlan Somers			eval "$up_cmd" 2> /dev/null &&
5254b40bdbdSAlan Somers			echo -n . >> up_count.txt ; } &
5264b40bdbdSAlan Somers		{ ${SRCDIR}/randsleep ${MAX_SLEEP_USECS} && \
5274b40bdbdSAlan Somers			ifconfig $IFACE destroy &&
5284b40bdbdSAlan Somers			echo -n . >> destroy_count.txt ; } &
5294b40bdbdSAlan Somers		wait
53038edd595SAlan Somers		ifconfig ${IFACE%a} create
5314b40bdbdSAlan Somers	done &
5324b40bdbdSAlan Somers	LOOP_PID=$!
5334b40bdbdSAlan Somers
5344b40bdbdSAlan Somers	sleep ${TESTLEN}
5354b40bdbdSAlan Somers	kill $LOOP_PID
5364b40bdbdSAlan Somers	echo "Upped ${IFACE} `stat -f %z up_count.txt` times."
5374b40bdbdSAlan Somers	echo "Destroyed it `stat -f %z destroy_count.txt` times."
5384b40bdbdSAlan Somers}
5394b40bdbdSAlan Somers
5404b40bdbdSAlan Somers# Creates a new cloned interface, registers it for cleanup, and echoes it
5414b40bdbdSAlan Somers# params: $1	Interface class name (tap, gif, etc)
5424b40bdbdSAlan Somersget_iface()
5434b40bdbdSAlan Somers{
5444b40bdbdSAlan Somers	local CLASS DEV N
5454b40bdbdSAlan Somers
5464b40bdbdSAlan Somers	CLASS=$1
5474b40bdbdSAlan Somers	N=0
5484b40bdbdSAlan Somers	while ! ifconfig ${CLASS}${N} create > /dev/null 2>&1; do
5494b40bdbdSAlan Somers		if [ "$N" -ge 8 ]; then
5504b40bdbdSAlan Somers			atf_skip "Could not create a ${CLASS} interface"
5514b40bdbdSAlan Somers		else
5524b40bdbdSAlan Somers			N=$(($N + 1))
5534b40bdbdSAlan Somers		fi
5544b40bdbdSAlan Somers	done
55538edd595SAlan Somers	if [ ${CLASS} = "epair" ]; then
55638edd595SAlan Somers		DEV=${CLASS}${N}a
55738edd595SAlan Somers	else
55838edd595SAlan Somers		DEV=${CLASS}${N}
55938edd595SAlan Somers	fi
5604b40bdbdSAlan Somers	# Record the device so we can clean it up later
5614b40bdbdSAlan Somers	echo ${DEV} >> "devices_to_cleanup"
5624b40bdbdSAlan Somers	echo ${DEV}
5634b40bdbdSAlan Somers}
5644b40bdbdSAlan Somers
5654b40bdbdSAlan Somers
5664b40bdbdSAlan Somerscleanup_ifaces()
5674b40bdbdSAlan Somers{
5684b40bdbdSAlan Somers	local DEV
5694b40bdbdSAlan Somers
5704b40bdbdSAlan Somers	for DEV in `cat "devices_to_cleanup"`; do
5714b40bdbdSAlan Somers		ifconfig ${DEV} destroy
5724b40bdbdSAlan Somers	done
5734b40bdbdSAlan Somers	true
5744b40bdbdSAlan Somers}
575