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