xref: /minix/tests/net/if_bridge/t_bridge.sh (revision 0a6a1f1d)
1#	$NetBSD: t_bridge.sh,v 1.11 2015/08/07 00:50:12 ozaki-r 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
28inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_bridge -lrumpnet_shmif"
29inet6server="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 -lrumpnet_bridge -lrumpnet_shmif"
30
31SOCK1=unix://commsock1
32SOCK2=unix://commsock2
33SOCK3=unix://commsock3
34IP1=10.0.0.1
35IP2=10.0.0.2
36IP61=fc00::1
37IP62=fc00::2
38IPBR1=10.0.0.11
39IPBR2=10.0.0.12
40IP6BR1=fc00::11
41IP6BR2=fc00::12
42
43TIMEOUT=5
44
45atf_test_case basic cleanup
46atf_test_case basic6 cleanup
47atf_test_case rtable cleanup
48atf_test_case member_ip cleanup
49atf_test_case member_ip6 cleanup
50
51basic_head()
52{
53	atf_set "descr" "Does simple if_bridge tests"
54	atf_set "require.progs" "rump_server"
55}
56
57basic6_head()
58{
59	atf_set "descr" "Does simple if_bridge tests (IPv6)"
60	atf_set "require.progs" "rump_server"
61}
62
63rtable_head()
64{
65	atf_set "descr" "Tests route table operations of if_bridge"
66	atf_set "require.progs" "rump_server"
67}
68
69member_ip_head()
70{
71	atf_set "descr" "Tests if_bridge with members with an IP address"
72	atf_set "require.progs" "rump_server"
73}
74
75member_ip6_head()
76{
77	atf_set "descr" "Tests if_bridge with members with an IP address (IPv6)"
78	atf_set "require.progs" "rump_server"
79}
80
81setup_endpoint()
82{
83	sock=${1}
84	addr=${2}
85	bus=${3}
86	mode=${4}
87
88	export RUMP_SERVER=${sock}
89	atf_check -s exit:0 rump.ifconfig shmif0 create
90	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${bus}
91	if [ $mode = "ipv6" ]; then
92		atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
93	else
94		atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
95	fi
96
97	atf_check -s exit:0 rump.ifconfig shmif0 up
98	rump.ifconfig shmif0
99}
100
101test_endpoint()
102{
103	sock=${1}
104	addr=${2}
105	bus=${3}
106	mode=${4}
107
108	export RUMP_SERVER=${sock}
109	atf_check -s exit:0 -o match:shmif0 rump.ifconfig
110	if [ $mode = "ipv6" ]; then
111		atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${addr}
112	else
113		atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${addr}
114	fi
115}
116
117show_endpoint()
118{
119	sock=${1}
120
121	export RUMP_SERVER=${sock}
122	rump.ifconfig -v shmif0
123}
124
125test_setup()
126{
127	test_endpoint $SOCK1 $IP1 bus1 ipv4
128	test_endpoint $SOCK3 $IP2 bus2 ipv4
129
130	export RUMP_SERVER=$SOCK2
131	atf_check -s exit:0 -o match:shmif0 rump.ifconfig
132	atf_check -s exit:0 -o match:shmif1 rump.ifconfig
133}
134
135test_setup6()
136{
137	test_endpoint $SOCK1 $IP61 bus1 ipv6
138	test_endpoint $SOCK3 $IP62 bus2 ipv6
139
140	export RUMP_SERVER=$SOCK2
141	atf_check -s exit:0 -o match:shmif0 rump.ifconfig
142	atf_check -s exit:0 -o match:shmif1 rump.ifconfig
143}
144
145setup_bridge_server()
146{
147	export RUMP_SERVER=$SOCK2
148	atf_check -s exit:0 rump.ifconfig shmif0 create
149	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
150	atf_check -s exit:0 rump.ifconfig shmif0 up
151
152	atf_check -s exit:0 rump.ifconfig shmif1 create
153	atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus2
154	atf_check -s exit:0 rump.ifconfig shmif1 up
155}
156
157setup()
158{
159	atf_check -s exit:0 ${inetserver} $SOCK1
160	atf_check -s exit:0 ${inetserver} $SOCK2
161	atf_check -s exit:0 ${inetserver} $SOCK3
162
163	setup_endpoint $SOCK1 $IP1 bus1 ipv4
164	setup_endpoint $SOCK3 $IP2 bus2 ipv4
165	setup_bridge_server
166}
167
168setup6()
169{
170	atf_check -s exit:0 ${inet6server} $SOCK1
171	atf_check -s exit:0 ${inet6server} $SOCK2
172	atf_check -s exit:0 ${inet6server} $SOCK3
173
174	setup_endpoint $SOCK1 $IP61 bus1 ipv6
175	setup_endpoint $SOCK3 $IP62 bus2 ipv6
176	setup_bridge_server
177}
178
179setup_bridge()
180{
181	export RUMP_SERVER=$SOCK2
182	atf_check -s exit:0 rump.ifconfig bridge0 create
183	atf_check -s exit:0 rump.ifconfig bridge0 up
184
185	export LD_PRELOAD=/usr/lib/librumphijack.so
186	atf_check -s exit:0 /sbin/brconfig bridge0 add shmif0
187	atf_check -s exit:0 /sbin/brconfig bridge0 add shmif1
188	/sbin/brconfig bridge0
189	unset LD_PRELOAD
190	rump.ifconfig shmif0
191	rump.ifconfig shmif1
192}
193
194setup_member_ip()
195{
196	export RUMP_SERVER=$SOCK2
197	export LD_PRELOAD=/usr/lib/librumphijack.so
198	atf_check -s exit:0 rump.ifconfig shmif0 $IPBR1/24
199	atf_check -s exit:0 rump.ifconfig shmif1 $IPBR2/24
200	atf_check -s exit:0 rump.ifconfig -w 10
201	/sbin/brconfig bridge0
202	unset LD_PRELOAD
203	rump.ifconfig shmif0
204	rump.ifconfig shmif1
205}
206
207setup_member_ip6()
208{
209	export RUMP_SERVER=$SOCK2
210	export LD_PRELOAD=/usr/lib/librumphijack.so
211	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6BR1
212	atf_check -s exit:0 rump.ifconfig shmif1 inet6 $IP6BR2
213	atf_check -s exit:0 rump.ifconfig -w 10
214	/sbin/brconfig bridge0
215	unset LD_PRELOAD
216	rump.ifconfig shmif0
217	rump.ifconfig shmif1
218}
219
220teardown_bridge()
221{
222	export RUMP_SERVER=$SOCK2
223	export LD_PRELOAD=/usr/lib/librumphijack.so
224	/sbin/brconfig bridge0
225	atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif0
226	atf_check -s exit:0 /sbin/brconfig bridge0 delete shmif1
227	/sbin/brconfig bridge0
228	unset LD_PRELOAD
229	rump.ifconfig shmif0
230	rump.ifconfig shmif1
231}
232
233test_setup_bridge()
234{
235	export RUMP_SERVER=$SOCK2
236	export LD_PRELOAD=/usr/lib/librumphijack.so
237	atf_check -s exit:0 -o match:shmif0 /sbin/brconfig bridge0
238	atf_check -s exit:0 -o match:shmif1 /sbin/brconfig bridge0
239	/sbin/brconfig bridge0
240	unset LD_PRELOAD
241}
242
243cleanup()
244{
245	env RUMP_SERVER=$SOCK1 rump.halt
246	env RUMP_SERVER=$SOCK2 rump.halt
247	env RUMP_SERVER=$SOCK3 rump.halt
248}
249
250dump_bus()
251{
252	/usr/bin/shmif_dumpbus -p - bus1 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
253	/usr/bin/shmif_dumpbus -p - bus2 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
254}
255
256down_up_interfaces()
257{
258	export RUMP_SERVER=$SOCK1
259	rump.ifconfig shmif0 down
260	rump.ifconfig shmif0 up
261	export RUMP_SERVER=$SOCK3
262	rump.ifconfig shmif0 down
263	rump.ifconfig shmif0 up
264}
265
266test_ping_failure()
267{
268	export RUMP_SERVER=$SOCK1
269	atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2
270	export RUMP_SERVER=$SOCK3
271	atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1
272}
273
274test_ping_success()
275{
276	export RUMP_SERVER=$SOCK1
277	rump.ifconfig -v shmif0
278	atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP2
279	rump.ifconfig -v shmif0
280
281	export RUMP_SERVER=$SOCK3
282	rump.ifconfig -v shmif0
283	atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP1
284	rump.ifconfig -v shmif0
285}
286
287test_ping6_failure()
288{
289	export RUMP_SERVER=$SOCK1
290	atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP62
291	export RUMP_SERVER=$SOCK3
292	atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP61
293}
294
295test_ping6_success()
296{
297	export RUMP_SERVER=$SOCK1
298	rump.ifconfig -v shmif0
299	atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP62
300	rump.ifconfig -v shmif0
301
302	export RUMP_SERVER=$SOCK3
303	rump.ifconfig -v shmif0
304	atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP61
305	rump.ifconfig -v shmif0
306}
307
308test_ping_member()
309{
310	export RUMP_SERVER=$SOCK1
311	rump.ifconfig -v shmif0
312	atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1
313	rump.ifconfig -v shmif0
314	# Test for PR#48104
315	atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2
316	rump.ifconfig -v shmif0
317
318	export RUMP_SERVER=$SOCK3
319	rump.ifconfig -v shmif0
320	# Test for PR#48104
321	atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1
322	rump.ifconfig -v shmif0
323	atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2
324	rump.ifconfig -v shmif0
325}
326
327test_ping6_member()
328{
329	export RUMP_SERVER=$SOCK1
330	rump.ifconfig -v shmif0
331	atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1
332	rump.ifconfig -v shmif0
333	# Test for PR#48104
334	atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2
335	rump.ifconfig -v shmif0
336
337	export RUMP_SERVER=$SOCK3
338	rump.ifconfig -v shmif0
339	# Test for PR#48104
340	atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1
341	rump.ifconfig -v shmif0
342	atf_check -s exit:0 -o ignore rump.ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2
343	rump.ifconfig -v shmif0
344}
345
346get_number_of_caches()
347{
348	export RUMP_SERVER=$SOCK2
349	export LD_PRELOAD=/usr/lib/librumphijack.so
350	echo $(($(/sbin/brconfig bridge0 |grep -A 100 "Address cache" |wc -l) - 1))
351	unset LD_PRELOAD
352}
353
354test_brconfig_maxaddr()
355{
356	addr1= addr3= n=
357
358	# Get MAC addresses of the endpoints.
359	export RUMP_SERVER=$SOCK1
360	addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
361	export RUMP_SERVER=$SOCK3
362	addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
363	unset RUMP_SERVER
364
365	# Refill the MAC addresses of the endpoints.
366	export RUMP_SERVER=$SOCK1
367	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
368	export RUMP_SERVER=$SOCK2
369	export LD_PRELOAD=/usr/lib/librumphijack.so
370	/sbin/brconfig bridge0
371	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
372	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
373
374	# Check the default # of caches is 100
375	atf_check -s exit:0 -o match:"max cache: 100" /sbin/brconfig bridge0
376
377	# Test two MAC addresses are cached
378	n=$(get_number_of_caches)
379	atf_check_equal $n 2
380
381	# Limit # of caches to one
382	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 1
383	atf_check -s exit:0 -o match:"max cache: 1" /sbin/brconfig bridge0
384	/sbin/brconfig bridge0
385
386	# Test just one address is cached
387	n=$(get_number_of_caches)
388	atf_check_equal $n 1
389
390	# Increase # of caches to two
391	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 2
392	atf_check -s exit:0 -o match:"max cache: 2" /sbin/brconfig bridge0
393	unset LD_PRELOAD
394
395	# Test we can cache two addresses again
396	export RUMP_SERVER=$SOCK1
397	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
398	export RUMP_SERVER=$SOCK2
399	export LD_PRELOAD=/usr/lib/librumphijack.so
400	/sbin/brconfig bridge0
401	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
402	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
403	unset LD_PRELOAD
404}
405
406basic_body()
407{
408	setup
409	test_setup
410
411	# Enable once PR kern/49219 is fixed
412	#test_ping_failure
413
414	setup_bridge
415	sleep 1
416	test_setup_bridge
417	test_ping_success
418
419	teardown_bridge
420	test_ping_failure
421}
422
423basic6_body()
424{
425	setup6
426	test_setup6
427
428	test_ping6_failure
429
430	setup_bridge
431	sleep 1
432	test_setup_bridge
433	test_ping6_success
434
435	teardown_bridge
436	test_ping6_failure
437}
438
439rtable_body()
440{
441	addr1= addr3=
442
443	setup
444	setup_bridge
445
446	# Get MAC addresses of the endpoints.
447	export RUMP_SERVER=$SOCK1
448	addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
449	export RUMP_SERVER=$SOCK3
450	addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
451	unset RUMP_SERVER
452
453	# Confirm there is no MAC address caches.
454	export RUMP_SERVER=$SOCK2
455	export LD_PRELOAD=/usr/lib/librumphijack.so
456	/sbin/brconfig bridge0
457	atf_check -s exit:0 -o not-match:"$addr1" /sbin/brconfig bridge0
458	atf_check -s exit:0 -o not-match:"$addr3" /sbin/brconfig bridge0
459	unset LD_PRELOAD
460
461	# Make the bridge learn the MAC addresses of the endpoints.
462	export RUMP_SERVER=$SOCK1
463	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
464	unset RUMP_SERVER
465
466	# Tests the addresses are in the cache.
467	export RUMP_SERVER=$SOCK2
468	export LD_PRELOAD=/usr/lib/librumphijack.so
469	/sbin/brconfig bridge0
470	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
471	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
472
473	# Tests brconfig deladdr
474	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr1"
475	atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
476	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr3"
477	atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
478	unset LD_PRELOAD
479
480	# Refill the MAC addresses of the endpoints.
481	export RUMP_SERVER=$SOCK1
482	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
483	unset RUMP_SERVER
484	export RUMP_SERVER=$SOCK2
485	export LD_PRELOAD=/usr/lib/librumphijack.so
486	/sbin/brconfig bridge0
487	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
488	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
489
490	# Tests brconfig flush.
491	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 flush
492	atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
493	atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
494	unset LD_PRELOAD
495
496	# Tests brconfig timeout.
497	export RUMP_SERVER=$SOCK2
498	export LD_PRELOAD=/usr/lib/librumphijack.so
499	atf_check -s exit:0 -o match:"timeout: 1200" /sbin/brconfig bridge0
500	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 timeout 10
501	atf_check -s exit:0 -o match:"timeout: 10" /sbin/brconfig bridge0
502	unset LD_PRELOAD
503
504	# Tests brconfig maxaddr.
505	test_brconfig_maxaddr
506
507	# TODO: brconfig static/flushall/discover/learn
508	# TODO: cache expiration; it takes 5 minutes at least and we want to
509	#       wait here so long. Should we have a sysctl to change the period?
510}
511
512member_ip_body()
513{
514	setup
515	test_setup
516
517	# Enable once PR kern/49219 is fixed
518	#test_ping_failure
519
520	setup_bridge
521	sleep 1
522	test_setup_bridge
523	test_ping_success
524
525	setup_member_ip
526	test_ping_member
527
528	teardown_bridge
529	test_ping_failure
530}
531
532member_ip6_body()
533{
534	setup6
535	test_setup6
536
537	test_ping6_failure
538
539	setup_bridge
540	sleep 1
541	test_setup_bridge
542	test_ping6_success
543
544	setup_member_ip6
545	test_ping6_member
546
547	teardown_bridge
548	test_ping6_failure
549}
550
551basic_cleanup()
552{
553	dump_bus
554	cleanup
555}
556
557basic6_cleanup()
558{
559	dump_bus
560	cleanup
561}
562
563rtable_cleanup()
564{
565	dump_bus
566	cleanup
567}
568
569member_ip_cleanup()
570{
571	dump_bus
572	cleanup
573}
574
575member_ip6_cleanup()
576{
577	dump_bus
578	cleanup
579}
580
581atf_init_test_cases()
582{
583	atf_add_test_case basic
584	atf_add_test_case basic6
585	atf_add_test_case rtable
586	atf_add_test_case member_ip
587	atf_add_test_case member_ip6
588}
589