t_tap.sh revision 1.5
1#	$NetBSD: t_tap.sh,v 1.5 2016/11/24 09:03:53 ozaki-r Exp $
2#
3# Copyright (c) 2016 Internet Initiative Japan Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26#
27
28RUMP_FLAGS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6"
29RUMP_FLAGS="$RUMP_FLAGS -lrumpnet_shmif -lrumpnet_tap -lrumpnet_bridge -lrumpdev"
30
31SOCK_LOCAL=unix://commsock1
32SOCK_REMOTE=unix://commsock2
33BUS=bus1
34IP4_LOCAL=10.0.0.1
35IP4_TAP=10.0.0.2
36IP4_REMOTE=10.0.0.3
37IP6_LOCAL=fc00::1
38IP6_TAP=fc00::2
39IP6_REMOTE=fc00::3
40
41DEBUG=${DEBUG:-false}
42TIMEOUT=1
43
44atf_test_case tap_create_destroy cleanup
45tap_create_destroy_head()
46{
47
48	atf_set "descr" "tests of creation and deletion of tap interface"
49	atf_set "require.progs" "rump_server"
50}
51
52tap_create_destroy_body()
53{
54
55	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL}
56
57	export RUMP_SERVER=${SOCK_LOCAL}
58
59	# Create and destroy (no address)
60	atf_check -s exit:0 rump.ifconfig tap0 create
61	atf_check -s exit:0 rump.ifconfig tap0 destroy
62
63	# Create and destroy (with an IPv4 address)
64	atf_check -s exit:0 rump.ifconfig tap0 create
65	atf_check -s exit:0 rump.ifconfig tap0 $IP4_TAP
66	atf_check -s exit:0 rump.ifconfig tap0 up
67	atf_check -s exit:0 rump.ifconfig tap0 destroy
68
69	# Create and destroy (with an IPv6 address)
70	atf_check -s exit:0 rump.ifconfig tap0 create
71	atf_check -s exit:0 rump.ifconfig tap0 inet6 $IP6_TAP
72	atf_check -s exit:0 rump.ifconfig tap0 up
73	atf_check -s exit:0 rump.ifconfig tap0 destroy
74}
75
76tap_create_destroy_cleanup()
77{
78
79	RUMP_SERVER=${SOCK_LOCAL} rump.halt
80}
81
82atf_test_case tap_stand_alone cleanup
83tap_create_destroy_head()
84{
85
86	atf_set "descr" "tests of alone tap interface"
87	atf_set "require.progs" "rump_server"
88}
89
90tap_stand_alone_body()
91{
92	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL}
93	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_REMOTE}
94
95	export RUMP_SERVER=${SOCK_LOCAL}
96
97	atf_check -s exit:0 rump.ifconfig shmif0 create
98	atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
99	atf_check -s exit:0 rump.ifconfig shmif0 $IP4_LOCAL
100	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6_LOCAL
101	atf_check -s exit:0 rump.ifconfig shmif0 up
102	atf_check -s exit:0 rump.ifconfig tap0 create
103	atf_check -s exit:0 rump.ifconfig tap0 $IP4_TAP
104	atf_check -s exit:0 rump.ifconfig tap0 inet6 $IP6_TAP
105	atf_check -s exit:0 rump.ifconfig tap0 up
106	atf_check -s exit:0 rump.ifconfig -w 10
107
108	export RUMP_SERVER=${SOCK_REMOTE}
109
110	atf_check -s exit:0 rump.ifconfig shmif0 create
111	atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
112	atf_check -s exit:0 rump.ifconfig shmif0 $IP4_REMOTE
113	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6_REMOTE
114	atf_check -s exit:0 rump.ifconfig shmif0 up
115	atf_check -s exit:0 rump.ifconfig -w 10
116
117	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_LOCAL
118	# Cannot reach to an alone tap
119	atf_check -s not-exit:0 -o ignore -e ignore \
120	    rump.ping -n -w $TIMEOUT -c 1 $IP4_TAP
121
122	atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_LOCAL
123	# Cannot reach to an alone tap
124	atf_check -s not-exit:0 -o ignore -e ignore \
125	    rump.ping6 -n -X $TIMEOUT -c 1 $IP6_TAP
126}
127
128tap_stand_alone_cleanup()
129{
130
131	RUMP_SERVER=${SOCK_LOCAL} rump.halt
132	RUMP_SERVER=${SOCK_REMOTE} rump.halt
133}
134
135atf_test_case tap_bridged cleanup
136tap_bridged_head()
137{
138
139	atf_set "descr" "tests of alone tap interface"
140	atf_set "require.progs" "rump_server"
141}
142
143tap_bridged_body()
144{
145	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL}
146	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_REMOTE}
147
148	export RUMP_SERVER=${SOCK_LOCAL}
149
150	atf_check -s exit:0 rump.ifconfig shmif0 create
151	atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
152	atf_check -s exit:0 rump.ifconfig shmif0 $IP4_LOCAL
153	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6_LOCAL
154	atf_check -s exit:0 rump.ifconfig shmif0 up
155	atf_check -s exit:0 rump.ifconfig tap0 create
156	atf_check -s exit:0 rump.ifconfig tap0 $IP4_TAP
157	atf_check -s exit:0 rump.ifconfig tap0 inet6 $IP6_TAP
158	atf_check -s exit:0 rump.ifconfig tap0 up
159	atf_check -s exit:0 rump.ifconfig -w 10
160
161	atf_check -s exit:0 rump.ifconfig bridge0 create
162	atf_check -s exit:0 rump.ifconfig bridge0 up
163	export LD_PRELOAD=/usr/lib/librumphijack.so
164	atf_check -s exit:0 brconfig bridge0 add shmif0
165	atf_check -s exit:0 brconfig bridge0 add tap0
166	unset LD_PRELOAD
167
168	export RUMP_SERVER=${SOCK_REMOTE}
169
170	atf_check -s exit:0 rump.ifconfig shmif0 create
171	atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
172	atf_check -s exit:0 rump.ifconfig shmif0 $IP4_REMOTE
173	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6_REMOTE
174	atf_check -s exit:0 rump.ifconfig shmif0 up
175	atf_check -s exit:0 rump.ifconfig -w 10
176
177	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_LOCAL
178	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_TAP
179
180	atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_LOCAL
181	atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_TAP
182}
183
184tap_bridged_cleanup()
185{
186
187	RUMP_SERVER=${SOCK_LOCAL} rump.halt
188	RUMP_SERVER=${SOCK_REMOTE} rump.halt
189}
190
191atf_init_test_cases()
192{
193
194	atf_add_test_case tap_create_destroy
195	atf_add_test_case tap_stand_alone
196	atf_add_test_case tap_bridged
197}
198