t_bridge.sh revision 1.8
1#	$NetBSD: t_bridge.sh,v 1.8 2015/06/09 00:39:53 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
48
49basic_head()
50{
51	atf_set "descr" "Does simple if_bridge tests"
52	atf_set "require.progs" "rump_server"
53}
54
55basic6_head()
56{
57	atf_set "descr" "Does simple if_bridge tests (IPv6)"
58	atf_set "require.progs" "rump_server"
59}
60
61rtable_head()
62{
63	atf_set "descr" "Tests route table operations of if_bridge"
64	atf_set "require.progs" "rump_server"
65}
66
67member_ip_head()
68{
69	atf_set "descr" "Tests if_bridge with members with an IP address"
70	atf_set "require.progs" "rump_server"
71}
72
73member_ip6_head()
74{
75	atf_set "descr" "Tests if_bridge with members with an IP address (IPv6)"
76	atf_set "require.progs" "rump_server"
77}
78
79setup_endpoint()
80{
81	sock=${1}
82	addr=${2}
83	bus=${3}
84	mode=${4}
85
86	export RUMP_SERVER=${sock}
87	atf_check -s exit:0 rump.ifconfig shmif0 create
88	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${bus}
89	if [ $mode = "ipv6" ]; then
90		atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
91	else
92		atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
93	fi
94
95	atf_check -s exit:0 rump.ifconfig shmif0 up
96	rump.ifconfig shmif0
97}
98
99test_endpoint()
100{
101	sock=${1}
102	addr=${2}
103	bus=${3}
104	mode=${4}
105
106	export RUMP_SERVER=${sock}
107	atf_check -s exit:0 -o match:shmif0 rump.ifconfig
108	if [ $mode = "ipv6" ]; then
109		export LD_PRELOAD=/usr/lib/librumphijack.so
110		atf_check -s exit:0 -o ignore ping6 -n -c 1 -X $TIMEOUT ${addr}
111		unset LD_PRELOAD
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 LD_PRELOAD=/usr/lib/librumphijack.so
290	export RUMP_SERVER=$SOCK1
291	atf_check -s not-exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP62
292	export RUMP_SERVER=$SOCK3
293	atf_check -s not-exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP61
294	unset LD_PRELOAD
295}
296
297test_ping6_success()
298{
299	export RUMP_SERVER=$SOCK1
300	rump.ifconfig -v shmif0
301	export LD_PRELOAD=/usr/lib/librumphijack.so
302	atf_check -s exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP62
303	unset LD_PRELOAD
304	rump.ifconfig -v shmif0
305
306	export RUMP_SERVER=$SOCK3
307	rump.ifconfig -v shmif0
308	export LD_PRELOAD=/usr/lib/librumphijack.so
309	atf_check -s exit:0 -o ignore ping6 -q -n -c 1 -X $TIMEOUT $IP61
310	unset LD_PRELOAD
311	rump.ifconfig -v shmif0
312}
313
314test_ping_member()
315{
316	export RUMP_SERVER=$SOCK1
317	rump.ifconfig -v shmif0
318	atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1
319	rump.ifconfig -v shmif0
320	# It's known to fail. See PR#48104
321	atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2
322	rump.ifconfig -v shmif0
323
324	export RUMP_SERVER=$SOCK3
325	rump.ifconfig -v shmif0
326	# It's known to fail. See PR#48104
327	atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR1
328	rump.ifconfig -v shmif0
329	atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IPBR2
330	rump.ifconfig -v shmif0
331}
332
333test_ping6_member()
334{
335	export LD_PRELOAD=/usr/lib/librumphijack.so
336
337	export RUMP_SERVER=$SOCK1
338	rump.ifconfig -v shmif0
339	atf_check -s exit:0 -o ignore ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1
340	rump.ifconfig -v shmif0
341	# It's known to fail. See PR#48104
342	atf_check -s not-exit:0 -o ignore ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2
343	rump.ifconfig -v shmif0
344
345	export RUMP_SERVER=$SOCK3
346	rump.ifconfig -v shmif0
347	# It's known to fail. See PR#48104
348	atf_check -s not-exit:0 -o ignore ping6 -q -n -X $TIMEOUT -c 1 $IP6BR1
349	rump.ifconfig -v shmif0
350	# FIXME: it doesn't work for some reason
351	atf_check -s exit:0 -o ignore ping6 -q -n -X $TIMEOUT -c 1 $IP6BR2
352	rump.ifconfig -v shmif0
353
354	unset LD_PRELOAD
355}
356
357get_number_of_caches()
358{
359	export RUMP_SERVER=$SOCK2
360	export LD_PRELOAD=/usr/lib/librumphijack.so
361	echo $(($(/sbin/brconfig bridge0 |grep -A 100 "Address cache" |wc -l) - 1))
362	unset LD_PRELOAD
363}
364
365test_brconfig_maxaddr()
366{
367	addr1= addr3= n=
368
369	# Get MAC addresses of the endpoints.
370	export RUMP_SERVER=$SOCK1
371	addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
372	export RUMP_SERVER=$SOCK3
373	addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
374	unset RUMP_SERVER
375
376	# Refill the MAC addresses of the endpoints.
377	export RUMP_SERVER=$SOCK1
378	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
379	export RUMP_SERVER=$SOCK2
380	export LD_PRELOAD=/usr/lib/librumphijack.so
381	/sbin/brconfig bridge0
382	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
383	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
384
385	# Check the default # of caches is 100
386	atf_check -s exit:0 -o match:"max cache: 100" /sbin/brconfig bridge0
387
388	# Test two MAC addresses are cached
389	n=$(get_number_of_caches)
390	atf_check_equal $n 2
391
392	# Limit # of caches to one
393	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 1
394	atf_check -s exit:0 -o match:"max cache: 1" /sbin/brconfig bridge0
395	/sbin/brconfig bridge0
396
397	# Test just one address is cached
398	n=$(get_number_of_caches)
399	atf_check_equal $n 1
400
401	# Increase # of caches to two
402	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 2
403	atf_check -s exit:0 -o match:"max cache: 2" /sbin/brconfig bridge0
404	unset LD_PRELOAD
405
406	# Test we can cache two addresses again
407	export RUMP_SERVER=$SOCK1
408	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
409	export RUMP_SERVER=$SOCK2
410	export LD_PRELOAD=/usr/lib/librumphijack.so
411	/sbin/brconfig bridge0
412	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
413	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
414	unset LD_PRELOAD
415}
416
417basic_body()
418{
419	setup
420	test_setup
421
422	# Enable once PR kern/49219 is fixed
423	#test_ping_failure
424
425	setup_bridge
426	sleep 1
427	test_setup_bridge
428	test_ping_success
429
430	teardown_bridge
431	test_ping_failure
432}
433
434basic6_body()
435{
436	setup6
437	test_setup6
438
439	test_ping6_failure
440
441	setup_bridge
442	sleep 1
443	test_setup_bridge
444	test_ping6_success
445
446	teardown_bridge
447	test_ping6_failure
448}
449
450rtable_body()
451{
452	addr1= addr3=
453
454	setup
455	setup_bridge
456
457	# Get MAC addresses of the endpoints.
458	export RUMP_SERVER=$SOCK1
459	addr1=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
460	export RUMP_SERVER=$SOCK3
461	addr3=$(rump.ifconfig shmif0 |awk '/address:/ { print $2;}')
462	unset RUMP_SERVER
463
464	# Confirm there is no MAC address caches.
465	export RUMP_SERVER=$SOCK2
466	export LD_PRELOAD=/usr/lib/librumphijack.so
467	/sbin/brconfig bridge0
468	atf_check -s exit:0 -o not-match:"$addr1" /sbin/brconfig bridge0
469	atf_check -s exit:0 -o not-match:"$addr3" /sbin/brconfig bridge0
470	unset LD_PRELOAD
471
472	# Make the bridge learn the MAC addresses of the endpoints.
473	export RUMP_SERVER=$SOCK1
474	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
475	unset RUMP_SERVER
476
477	# Tests the addresses are in the cache.
478	export RUMP_SERVER=$SOCK2
479	export LD_PRELOAD=/usr/lib/librumphijack.so
480	/sbin/brconfig bridge0
481	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
482	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
483
484	# Tests brconfig deladdr
485	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr1"
486	atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
487	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr3"
488	atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
489	unset LD_PRELOAD
490
491	# Refill the MAC addresses of the endpoints.
492	export RUMP_SERVER=$SOCK1
493	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
494	unset RUMP_SERVER
495	export RUMP_SERVER=$SOCK2
496	export LD_PRELOAD=/usr/lib/librumphijack.so
497	/sbin/brconfig bridge0
498	atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
499	atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
500
501	# Tests brconfig flush.
502	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 flush
503	atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
504	atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
505	unset LD_PRELOAD
506
507	# Tests brconfig timeout.
508	export RUMP_SERVER=$SOCK2
509	export LD_PRELOAD=/usr/lib/librumphijack.so
510	atf_check -s exit:0 -o match:"timeout: 1200" /sbin/brconfig bridge0
511	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 timeout 10
512	atf_check -s exit:0 -o match:"timeout: 10" /sbin/brconfig bridge0
513	unset LD_PRELOAD
514
515	# Tests brconfig maxaddr.
516	test_brconfig_maxaddr
517
518	# TODO: brconfig static/flushall/discover/learn
519	# TODO: cache expiration; it takes 5 minutes at least and we want to
520	#       wait here so long. Should we have a sysctl to change the period?
521}
522
523member_ip_body()
524{
525	setup
526	test_setup
527
528	# Enable once PR kern/49219 is fixed
529	#test_ping_failure
530
531	setup_bridge
532	sleep 1
533	test_setup_bridge
534	test_ping_success
535
536	setup_member_ip
537	test_ping_member
538
539	teardown_bridge
540	test_ping_failure
541}
542
543member_ip6_body()
544{
545	setup6
546	test_setup6
547
548	test_ping6_failure
549
550	setup_bridge
551	sleep 1
552	test_setup_bridge
553	test_ping6_success
554
555	setup_member_ip6
556	test_ping6_member
557
558	teardown_bridge
559	test_ping6_failure
560}
561
562basic_cleanup()
563{
564	dump_bus
565	cleanup
566}
567
568basic6_cleanup()
569{
570	dump_bus
571	cleanup
572}
573
574rtable_cleanup()
575{
576	dump_bus
577	cleanup
578}
579
580member_ip_cleanup()
581{
582	dump_bus
583	cleanup
584}
585
586member_ip6_cleanup()
587{
588	dump_bus
589	cleanup
590}
591
592atf_init_test_cases()
593{
594	atf_add_test_case basic
595	atf_add_test_case basic6
596	atf_add_test_case rtable
597	atf_add_test_case member_ip
598	atf_add_test_case member_ip6
599}
600