t_bridge.sh revision 1.16.2.1 1 # $NetBSD: t_bridge.sh,v 1.16.2.1 2017/04/21 16:54:12 bouyer Exp $
2 #
3 # Copyright (c) 2014 The NetBSD Foundation, 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
28 SOCK1=unix://commsock1
29 SOCK2=unix://commsock2
30 SOCK3=unix://commsock3
31 IP1=10.0.0.1
32 IP2=10.0.0.2
33 IP61=fc00::1
34 IP62=fc00::2
35 IPBR1=10.0.0.11
36 IPBR2=10.0.0.12
37 IP6BR1=fc00::11
38 IP6BR2=fc00::12
39
40 DEBUG=${DEBUG:-false}
41 TIMEOUT=5
42
43 atf_test_case bridge_ipv4 cleanup
44 atf_test_case bridge_ipv6 cleanup
45 atf_test_case bridge_member_ipv4 cleanup
46 atf_test_case bridge_member_ipv6 cleanup
47
48 bridge_ipv4_head()
49 {
50 atf_set "descr" "Does simple if_bridge tests"
51 atf_set "require.progs" "rump_server"
52 }
53
54 bridge_ipv6_head()
55 {
56 atf_set "descr" "Does simple if_bridge tests (IPv6)"
57 atf_set "require.progs" "rump_server"
58 }
59
60 bridge_member_ipv4_head()
61 {
62 atf_set "descr" "Tests if_bridge with members with an IP address"
63 atf_set "require.progs" "rump_server"
64 }
65
66 bridge_member_ipv6_head()
67 {
68 atf_set "descr" "Tests if_bridge with members with an IP address (IPv6)"
69 atf_set "require.progs" "rump_server"
70 }
71
72 setup_endpoint()
73 {
74 sock=${1}
75 addr=${2}
76 bus=${3}
77 mode=${4}
78
79 rump_server_add_iface $sock shmif0 $bus
80 export RUMP_SERVER=${sock}
81 if [ $mode = "ipv6" ]; then
82 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
83 else
84 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
85 fi
86
87 atf_check -s exit:0 rump.ifconfig shmif0 up
88 $DEBUG && rump.ifconfig shmif0
89 }
90
91 test_endpoint()
92 {
93 sock=${1}
94 addr=${2}
95 bus=${3}
96 mode=${4}
97
98 export RUMP_SERVER=${sock}
99 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
100 if [ $mode = "ipv6" ]; then
101 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${addr}
102 else
103 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${addr}
104 fi
105 }
106
107 test_setup()
108 {
109 test_endpoint $SOCK1 $IP1 bus1 ipv4
110 test_endpoint $SOCK3 $IP2 bus2 ipv4
111
112 export RUMP_SERVER=$SOCK2
113 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
114 atf_check -s exit:0 -o match:shmif1 rump.ifconfig
115 }
116
117 test_setup6()
118 {
119 test_endpoint $SOCK1 $IP61 bus1 ipv6
120 test_endpoint $SOCK3 $IP62 bus2 ipv6
121
122 export RUMP_SERVER=$SOCK2
123 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
124 atf_check -s exit:0 -o match:shmif1 rump.ifconfig
125 }
126
127 setup_bridge_server()
128 {
129
130 rump_server_add_iface $SOCK2 shmif0 bus1
131 rump_server_add_iface $SOCK2 shmif1 bus2
132 export RUMP_SERVER=$SOCK2
133 atf_check -s exit:0 rump.ifconfig shmif0 up
134 atf_check -s exit:0 rump.ifconfig shmif1 up
135 }
136
137 setup()
138 {
139
140 rump_server_start $SOCK1 bridge
141 rump_server_start $SOCK2 bridge
142 rump_server_start $SOCK3 bridge
143
144 setup_endpoint $SOCK1 $IP1 bus1 ipv4
145 setup_endpoint $SOCK3 $IP2 bus2 ipv4
146 setup_bridge_server
147 }
148
149 setup6()
150 {
151
152 rump_server_start $SOCK1 netinet6 bridge
153 rump_server_start $SOCK2 netinet6 bridge
154 rump_server_start $SOCK3 netinet6 bridge
155
156 setup_endpoint $SOCK1 $IP61 bus1 ipv6
157 setup_endpoint $SOCK3 $IP62 bus2 ipv6
158 setup_bridge_server
159 }
160
161 setup_bridge()
162 {
163 export RUMP_SERVER=$SOCK2
164 atf_check -s exit:0 rump.ifconfig bridge0 create
165 atf_check -s exit:0 rump.ifconfig bridge0 up
166
167 export LD_PRELOAD=/usr/lib/librumphijack.so
168 atf_check -s exit:0 /sbin/brconfig bridge0 add shmif0
169 atf_check -s exit:0 /sbin/brconfig bridge0 add shmif1
170 /sbin/brconfig bridge0
171 unset LD_PRELOAD
172 rump.ifconfig shmif0
173 rump.ifconfig shmif1
174 }
175
176 setup_member_ip()
177 {
178 export RUMP_SERVER=$SOCK2
179 export LD_PRELOAD=/usr/lib/librumphijack.so
180 atf_check -s exit:0 rump.ifconfig shmif0 $IPBR1/24
181 atf_check -s exit:0 rump.ifconfig shmif1 $IPBR2/24
182 atf_check -s exit:0 rump.ifconfig -w 10
183 /sbin/brconfig bridge0
184 unset LD_PRELOAD
185 rump.ifconfig shmif0
186 rump.ifconfig shmif1
187 }
188
189 setup_member_ip6()
190 {
191 export RUMP_SERVER=$SOCK2
192 export LD_PRELOAD=/usr/lib/librumphijack.so
193 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6BR1
194 atf_check -s exit:0 rump.ifconfig shmif1 inet6 $IP6BR2
195 atf_check -s exit:0 rump.ifconfig -w 10
196 /sbin/brconfig bridge0
197 unset LD_PRELOAD
198 rump.ifconfig shmif0
199 rump.ifconfig shmif1
200 }
201
202 teardown_bridge()
203 {
204 export RUMP_SERVER=$SOCK2
205 export LD_PRELOAD=/usr/lib/librumphijack.so
206 /sbin/brconfig bridge0
207 atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif0
208 atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif1
209 /sbin/brconfig bridge0
210 unset LD_PRELOAD
211 rump.ifconfig shmif0
212 rump.ifconfig shmif1
213 }
214
215 test_setup_bridge()
216 {
217 export RUMP_SERVER=$SOCK2
218 export LD_PRELOAD=/usr/lib/librumphijack.so
219 atf_check -s exit:0 -o match:shmif0 /sbin/brconfig bridge0
220 atf_check -s exit:0 -o match:shmif1 /sbin/brconfig bridge0
221 /sbin/brconfig bridge0
222 unset LD_PRELOAD
223 }
224
225 down_up_interfaces()
226 {
227 export RUMP_SERVER=$SOCK1
228 rump.ifconfig shmif0 down
229 rump.ifconfig shmif0 up
230 export RUMP_SERVER=$SOCK3
231 rump.ifconfig shmif0 down
232 rump.ifconfig shmif0 up
233 }
234
235 test_ping_failure()
236 {
237 export RUMP_SERVER=$SOCK1
238 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2
239 export RUMP_SERVER=$SOCK3
240 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1
241 }
242
243 test_ping_success()
244 {
245 export RUMP_SERVER=$SOCK1
246 rump.ifconfig -v shmif0
247 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2
248 rump.ifconfig -v shmif0
249
250 export RUMP_SERVER=$SOCK3
251 rump.ifconfig -v shmif0
252 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1
253 rump.ifconfig -v shmif0
254 }
255
256 test_ping6_failure()
257 {
258 export RUMP_SERVER=$SOCK1
259 atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP62
260 export RUMP_SERVER=$SOCK3
261 atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP61
262 }
263
264 test_ping6_success()
265 {
266 export RUMP_SERVER=$SOCK1
267 rump.ifconfig -v shmif0
268 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP62
269 rump.ifconfig -v shmif0
270
271 export RUMP_SERVER=$SOCK3
272 rump.ifconfig -v shmif0
273 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP61
274 rump.ifconfig -v shmif0
275 }
276
277 test_ping_member()
278 {
279 export RUMP_SERVER=$SOCK1
280 rump.ifconfig -v shmif0
281 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1
282 rump.ifconfig -v shmif0
283 # Test for PR#48104
284 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2
285 rump.ifconfig -v shmif0
286
287 export RUMP_SERVER=$SOCK3
288 rump.ifconfig -v shmif0
289 # Test for PR#48104
290 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1
291 rump.ifconfig -v shmif0
292 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2
293 rump.ifconfig -v shmif0
294 }
295
296 test_ping6_member()
297 {
298 export RUMP_SERVER=$SOCK1
299 rump.ifconfig -v shmif0
300 atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1
301 rump.ifconfig -v shmif0
302 # Test for PR#48104
303 atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2
304 rump.ifconfig -v shmif0
305
306 export RUMP_SERVER=$SOCK3
307 rump.ifconfig -v shmif0
308 # Test for PR#48104
309 atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1
310 rump.ifconfig -v shmif0
311 atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2
312 rump.ifconfig -v shmif0
313 }
314
315 bridge_ipv4_body()
316 {
317 setup
318 test_setup
319
320 # Enable once PR kern/49219 is fixed
321 #test_ping_failure
322
323 setup_bridge
324 sleep 1
325 test_setup_bridge
326 test_ping_success
327
328 teardown_bridge
329 test_ping_failure
330
331 rump_server_destroy_ifaces
332 }
333
334 bridge_ipv6_body()
335 {
336 setup6
337 test_setup6
338
339 test_ping6_failure
340
341 setup_bridge
342 sleep 1
343 test_setup_bridge
344 test_ping6_success
345
346 teardown_bridge
347 test_ping6_failure
348
349 rump_server_destroy_ifaces
350 }
351
352 bridge_member_ipv4_body()
353 {
354 setup
355 test_setup
356
357 # Enable once PR kern/49219 is fixed
358 #test_ping_failure
359
360 setup_bridge
361 sleep 1
362 test_setup_bridge
363 test_ping_success
364
365 setup_member_ip
366 test_ping_member
367
368 teardown_bridge
369 test_ping_failure
370
371 rump_server_destroy_ifaces
372 }
373
374 bridge_member_ipv6_body()
375 {
376 setup6
377 test_setup6
378
379 test_ping6_failure
380
381 setup_bridge
382 sleep 1
383 test_setup_bridge
384 test_ping6_success
385
386 setup_member_ip6
387 test_ping6_member
388
389 teardown_bridge
390 test_ping6_failure
391
392 rump_server_destroy_ifaces
393 }
394
395 bridge_ipv4_cleanup()
396 {
397
398 $DEBUG && dump
399 cleanup
400 }
401
402 bridge_ipv6_cleanup()
403 {
404
405 $DEBUG && dump
406 cleanup
407 }
408
409 bridge_member_ipv4_cleanup()
410 {
411
412 $DEBUG && dump
413 cleanup
414 }
415
416 bridge_member_ipv6_cleanup()
417 {
418
419 $DEBUG && dump
420 cleanup
421 }
422
423 atf_init_test_cases()
424 {
425 atf_add_test_case bridge_ipv4
426 atf_add_test_case bridge_ipv6
427 atf_add_test_case bridge_member_ipv4
428 atf_add_test_case bridge_member_ipv6
429 }
430