t_vlan.sh revision 1.8 1 # $NetBSD: t_vlan.sh,v 1.8 2018/02/01 05:22:02 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
28 BUS=bus
29 SOCK_LOCAL=unix://commsock1
30 SOCK_REMOTE=unix://commsock2
31 IP_LOCAL0=10.0.0.1
32 IP_LOCAL1=10.0.1.1
33 IP_REMOTE0=10.0.0.2
34 IP_REMOTE1=10.0.1.2
35 IP6_LOCAL0=fc00:0::1
36 IP6_LOCAL1=fc00:1::1
37 IP6_REMOTE0=fc00:0::2
38 IP6_REMOTE1=fc00:1::2
39
40 DEBUG=${DEBUG:-false}
41
42 vlan_create_destroy_body_common()
43 {
44 export RUMP_SERVER=${SOCK_LOCAL}
45
46 atf_check -s exit:0 rump.ifconfig vlan0 create
47 atf_check -s exit:0 rump.ifconfig vlan0 destroy
48
49 atf_check -s exit:0 rump.ifconfig vlan0 create
50 atf_check -s exit:0 rump.ifconfig vlan0 up
51 atf_check -s exit:0 rump.ifconfig vlan0 down
52 atf_check -s exit:0 rump.ifconfig vlan0 destroy
53
54 atf_check -s exit:0 rump.ifconfig shmif0 create
55 atf_check -s exit:0 rump.ifconfig vlan0 create
56 atf_check -s exit:0 rump.ifconfig vlan0 vlan 1 vlanif shmif0
57 atf_check -s exit:0 rump.ifconfig vlan0 up
58 atf_check -s exit:0 rump.ifconfig vlan0 destroy
59
60 # more than one vlan interface with a same parent interface
61 atf_check -s exit:0 rump.ifconfig shmif1 create
62 atf_check -s exit:0 rump.ifconfig vlan0 create
63 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
64 atf_check -s exit:0 rump.ifconfig vlan1 create
65 atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
66
67 # more than one interface with another parent interface
68 atf_check -s exit:0 rump.ifconfig vlan2 create
69 atf_check -s exit:0 rump.ifconfig vlan2 vlan 12 vlanif shmif1
70 atf_check -s exit:0 rump.ifconfig vlan3 create
71 atf_check -s exit:0 rump.ifconfig vlan3 vlan 13 vlanif shmif1
72 atf_check -s exit:0 rump.ifconfig shmif0 destroy
73 atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig vlan0
74 atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig vlan1
75 atf_check -s exit:0 -o match:'shmif1' rump.ifconfig vlan2
76 atf_check -s exit:0 -o match:'shmif1' rump.ifconfig vlan3
77 atf_check -s exit:0 rump.ifconfig vlan0 destroy
78 atf_check -s exit:0 rump.ifconfig vlan1 destroy
79 atf_check -s exit:0 rump.ifconfig vlan2 destroy
80 atf_check -s exit:0 rump.ifconfig vlan3 destroy
81
82 }
83
84 atf_test_case vlan_create_destroy cleanup
85 vlan_create_destroy_head()
86 {
87
88 atf_set "descr" "tests of creation and deletion of vlan interface"
89 atf_set "require.progs" "rump_server"
90 }
91
92 vlan_create_destroy_body()
93 {
94 rump_server_start $SOCK_LOCAL vlan
95
96 vlan_create_destroy_body_common
97 }
98
99
100 vlan_create_destroy_cleanup()
101 {
102
103 $DEBUG && dump
104 cleanup
105 }
106
107 atf_test_case vlan_create_destroy6 cleanup
108 vlan_create_destroy6_head()
109 {
110
111 atf_set "descr" "tests of creation and deletion of vlan interface with IPv6"
112 atf_set "require.progs" "rump_server"
113 }
114
115 vlan_create_destroy6_body()
116 {
117
118 rump_server_start $SOCK_LOCAL vlan netinet6
119
120 vlan_create_destroy_body_common
121 }
122
123 vlan_create_destroy6_cleanup()
124 {
125
126 $DEBUG && dump
127 cleanup
128 }
129
130 vlan_basic_body_common()
131 {
132 local outfile=./out
133 local af=inet
134 local prefix=24
135 local local0=$IP_LOCAL0
136 local remote0=$IP_REMOTE0
137 local ping_cmd="rump.ping -n -w 1 -c 1"
138
139 if [ x"$1" = x"inet6" ]; then
140 af="inet6"
141 prefix=64
142 local0=$IP6_LOCAL0
143 remote0=$IP6_REMOTE0
144 ping_cmd="rump.ping6 -n -c 1"
145 fi
146
147 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
148 rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
149
150 export RUMP_SERVER=$SOCK_LOCAL
151 atf_check -s exit:0 rump.ifconfig shmif0 up
152 export RUMP_SERVER=$SOCK_REMOTE
153 atf_check -s exit:0 rump.ifconfig shmif0 up
154
155 export RUMP_SERVER=$SOCK_LOCAL
156 atf_check -s exit:0 rump.ifconfig vlan0 create
157 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
158 atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
159 atf_check -s exit:0 rump.ifconfig vlan0 up
160 atf_check -s exit:0 rump.ifconfig -w 10
161
162 export RUMP_SERVER=$SOCK_REMOTE
163 atf_check -s exit:0 rump.ifconfig vlan0 create
164 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
165 atf_check -s exit:0 rump.ifconfig vlan0 $af $remote0/$prefix
166 atf_check -s exit:0 rump.ifconfig vlan0 up
167 atf_check -s exit:0 rump.ifconfig -w 10
168
169 extract_new_packets $BUS > $outfile
170
171 export RUMP_SERVER=$SOCK_LOCAL
172 atf_check -s exit:0 -o ignore $ping_cmd $remote0
173
174 extract_new_packets $BUS > $outfile
175 atf_check -s exit:0 -o match:'vlan 10' cat $outfile
176
177 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
178 atf_check -s exit:0 rump.ifconfig vlan0 vlan 20 vlanif shmif0
179 atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
180 atf_check -s exit:0 rump.ifconfig vlan0 up
181 atf_check -s exit:0 rump.ifconfig -w 10
182
183 extract_new_packets $BUS > $outfile
184 atf_check -s not-exit:0 -o ignore $ping_cmd $remote0
185
186 extract_new_packets $BUS > $outfile
187 atf_check -s exit:0 -o match:'vlan 20' cat $outfile
188
189 export RUMP_SERVER=$SOCK_LOCAL
190 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
191 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
192 atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
193 atf_check -s exit:0 rump.ifconfig vlan0 up
194 atf_check -s exit:0 rump.ifconfig -w 10
195
196 atf_check -s exit:0 -o ignore rump.ifconfig -z vlan0
197 atf_check -s exit:0 -o ignore $ping_cmd $remote0
198 rump.ifconfig -v vlan0 > $outfile
199
200 atf_check -s exit:0 -o not-match:' 0 packets' cat $outfile
201 atf_check -s exit:0 -o not-match:' 0 bytes' cat $outfile
202 }
203
204 atf_test_case vlan_basic cleanup
205 vlan_basic_head()
206 {
207
208 atf_set "descr" "tests of communications over vlan interfaces"
209 atf_set "require.progs" "rump_server"
210 }
211
212 vlan_basic_body()
213 {
214 rump_server_start $SOCK_LOCAL vlan
215 rump_server_start $SOCK_REMOTE vlan
216
217 vlan_basic_body_common inet
218
219 }
220
221 vlan_basic_cleanup()
222 {
223
224 $DEBUG && dump
225 cleanup
226 }
227
228 atf_test_case vlan_basic6 cleanup
229 vlan_basic6_head()
230 {
231
232 atf_set "descr" "tests of communications over vlan interfaces using IPv6"
233 atf_set "require.progs" "rump_server"
234 }
235
236 vlan_basic6_body()
237 {
238 rump_server_start $SOCK_LOCAL vlan netinet6
239 rump_server_start $SOCK_REMOTE vlan netinet6
240
241 vlan_basic_body_common inet6
242 }
243
244 vlan_basic6_cleanup()
245 {
246
247 $DEBUG && dump
248 cleanup
249 }
250
251 vlanid_config_and_ping()
252 {
253 local vlanid=$1
254 shift
255
256 export RUMP_SERVER=$SOCK_LOCAL
257 atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
258 atf_check -s exit:0 rump.ifconfig vlan0 $IP_LOCAL0/24
259 atf_check -s exit:0 rump.ifconfig vlan0 up
260
261 export RUMP_SERVER=$SOCK_REMOTE
262 atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
263 atf_check -s exit:0 rump.ifconfig vlan0 $IP_REMOTE0/24
264 atf_check -s exit:0 rump.ifconfig vlan0 up
265
266 export RUMP_SERVER=$SOCK_LOCAL
267 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP_REMOTE0
268 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
269
270 export RUMP_SERVER=$SOCK_REMOTE
271 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
272 }
273
274 vlanid_config_and_ping6()
275 {
276 local vlanid=$1
277 shift
278
279 export RUMP_SERVER=$SOCK_LOCAL
280 atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
281 atf_check -s exit:0 rump.ifconfig vlan0 inet6 $IP6_LOCAL0/64
282 atf_check -s exit:0 rump.ifconfig vlan0 up
283
284 export RUMP_SERVER=$SOCK_REMOTE
285 atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
286 atf_check -s exit:0 rump.ifconfig vlan0 inet6 $IP6_REMOTE0/64
287 atf_check -s exit:0 rump.ifconfig vlan0 up
288
289 export RUMP_SERVER=$SOCK_LOCAL
290 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 $IP6_REMOTE0
291 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
292
293 export RUMP_SERVER=$SOCK_REMOTE
294 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
295 }
296
297 vlan_vlanid_body_common()
298 {
299 local af=inet
300 local prefix=24
301 local sysctl_param="net.inet.ip.dad_count=0"
302 local ping_cmd="rump.ping -n -w 1 -c 1"
303 local config_and_ping=vlanid_config_and_ping
304 local local0=$IP_LOCAL0
305 local local1=$IP_LOCAL1
306 local remote0=$IP_REMOTE0
307 local remote1=$IP_REMOTE1
308
309 if [ x"$1" = x"inet6" ]; then
310 af=inet6
311 prefix=64
312 sysctl_param="net.inet6.ip6.dad_count=0"
313 ping_cmd="rump.ping6 -n -c 1"
314 config_and_ping=vlanid_config_and_ping6
315 local0=$IP6_LOCAL0
316 local1=$IP6_LOCAL1
317 remote0=$IP6_REMOTE0
318 remote1=$IP6_REMOTE1
319 fi
320
321 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
322 rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
323
324 export RUMP_SERVER=$SOCK_LOCAL
325 atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
326 atf_check -s exit:0 rump.ifconfig shmif0 up
327 atf_check -s exit:0 rump.ifconfig vlan0 create
328
329 export RUMP_SERVER=$SOCK_REMOTE
330 atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
331 atf_check -s exit:0 rump.ifconfig shmif0 up
332 atf_check -s exit:0 rump.ifconfig vlan0 create
333
334 export RUMP_SERVER=$SOCK_LOCAL
335 atf_check -s not-exit:0 -e ignore\
336 rump.ifconfig vlan0 vlan -1 vlanif shmif0
337
338 # $config_and_ping 0 # reserved vlan id
339 $config_and_ping 1
340 $config_and_ping 4094
341 # $config_and_ping 4095 #reserved vlan id
342
343 if [ "${RANDOM:-0}" != "${RANDOM:-0}" ]
344 then
345 for TAG in $(( ${RANDOM:-0} % 4092 + 2 )) \
346 $(( ${RANDOM:-0} % 4092 + 2 )) \
347 $(( ${RANDOM:-0} % 4092 + 2 ))
348 do
349 $config_and_ping "${TAG}"
350 done
351 fi
352
353 export RUMP_SERVER=$SOCK_LOCAL
354 for TAG in 0 4095 4096 $((4096*4 + 1)) 65536 65537 $((65536 + 4095))
355 do
356 atf_check -s not-exit:0 -e not-empty \
357 rump.ifconfig vlan0 vlan "${TAG}" vlanif shmif0
358 done
359
360 atf_check -s exit:0 rump.ifconfig vlan0 vlan 1 vlanif shmif0
361 atf_check -s not-exit:0 -e ignore \
362 rump.ifconfig vlan0 vlan 2 vlanif shmif0
363
364 atf_check -s not-exit:0 -e ignore \
365 rump.ifconfig vlan0 vlan 1 vlanif shmif1
366
367 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
368 atf_check -s not-exit:0 -e ignore \
369 rump.ifconfig vlan0 $local0/$prefix
370
371 export RUMP_SERVER=$SOCK_LOCAL
372 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
373 atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
374 atf_check -s exit:0 rump.ifconfig vlan0 up
375 atf_check -s exit:0 rump.ifconfig vlan1 create
376 atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
377 atf_check -s exit:0 rump.ifconfig vlan1 $af $local1/$prefix
378 atf_check -s exit:0 rump.ifconfig vlan1 up
379
380 export RUMP_SERVER=$SOCK_REMOTE
381 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
382 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
383 atf_check -s exit:0 rump.ifconfig vlan0 $af $remote0/$prefix
384 atf_check -s exit:0 rump.ifconfig vlan0 up
385 atf_check -s exit:0 rump.ifconfig vlan1 create
386 atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
387 atf_check -s exit:0 rump.ifconfig vlan1 $af $remote1/$prefix
388 atf_check -s exit:0 rump.ifconfig vlan1 up
389
390 export RUMP_SERVER=$SOCK_LOCAL
391 atf_check -s exit:0 -o ignore $ping_cmd $remote0
392 atf_check -s exit:0 -o ignore $ping_cmd $remote1
393 }
394
395 atf_test_case vlan_vlanid cleanup
396 vlan_vlanid_head()
397 {
398
399 atf_set "descr" "tests of configuration for vlan id"
400 atf_set "require.progs" "rump_server"
401 }
402
403 vlan_vlanid_body()
404 {
405 rump_server_start $SOCK_LOCAL vlan
406 rump_server_start $SOCK_REMOTE vlan
407
408 vlan_vlanid_body_common inet
409 }
410
411 vlan_vlanid_cleanup()
412 {
413
414 $DEBUG && dump
415 cleanup
416 }
417
418 atf_test_case vlan_vlanid6 cleanup
419 vlan_vlanid6_head()
420 {
421
422 atf_set "descr" "tests of configuration for vlan id using IPv6"
423 atf_set "require.progs" "rump_server"
424 }
425
426
427 vlan_vlanid6_body()
428 {
429 rump_server_start $SOCK_LOCAL vlan netinet6
430 rump_server_start $SOCK_REMOTE vlan netinet6
431
432 vlan_vlanid_body_common inet6
433 }
434
435 vlan_vlanid6_cleanup()
436 {
437
438 $DEBUG && dump
439 cleanup
440 }
441
442 vlan_configs_body_common()
443 {
444 export RUMP_SERVER=${SOCK_LOCAL}
445
446 atf_check -s exit:0 rump.ifconfig shmif0 create
447 atf_check -s exit:0 rump.ifconfig shmif1 create
448 atf_check -s exit:0 rump.ifconfig vlan0 create
449
450 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
451 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
452
453 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
454 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif0
455
456 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
457 atf_check -s exit:0 -e ignore rump.ifconfig vlan0 -vlanif shmif1
458 atf_check -s exit:0 -e ignore rump.ifconfig vlan0 -vlanif shmif2
459
460 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
461
462 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
463 atf_check -s exit:0 -e match:'Invalid argument' \
464 rump.ifconfig vlan0 mtu 1497
465 atf_check -s exit:0 rump.ifconfig vlan0 mtu 1496
466 atf_check -s exit:0 rump.ifconfig vlan0 mtu 42
467 atf_check -s exit:0 -e match:'Invalid argument' \
468 rump.ifconfig vlan0 mtu 41
469 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
470
471 atf_check -s exit:0 rump.ifconfig vlan1 create
472 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
473 atf_check -s not-exit:0 -e match:'File exists' \
474 rump.ifconfig vlan1 vlan 10 vlanif shmif0
475 atf_check -s exit:0 rump.ifconfig vlan1 vlan 10 vlanif shmif1
476
477 atf_check -s exit:0 rump.ifconfig vlan1 -vlanif shmif1
478 atf_check -s exit:0 rump.ifconfig vlan1 vlan 10 vlanif shmif1
479
480 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif0
481 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
482 }
483
484 atf_test_case vlan_configs cleanup
485 vlan_configs_head()
486 {
487 atf_set "descr" "tests of configuration except vlan id"
488 atf_set "require.progs" "rump_server"
489 }
490
491 vlan_configs_body()
492 {
493
494 rump_server_start $SOCK_LOCAL vlan
495
496 vlan_configs_body_common
497
498 }
499
500 vlan_configs_cleanup()
501 {
502
503 $DEBUG && dump
504 cleanup
505 }
506
507 atf_test_case vlan_configs6 cleanup
508 vlan_configs6_head()
509 {
510 atf_set "descr" "tests of configuration except vlan id using IPv6"
511 atf_set "require.progs" "rump_server"
512 }
513
514 vlan_configs6_body()
515 {
516 rump_server_start $SOCK_LOCAL vlan netinet6
517
518 vlan_configs_body_common
519 }
520
521 vlan_configs6_cleanup()
522 {
523 $DEBUG && dump
524 cleanup
525 }
526
527 atf_init_test_cases()
528 {
529
530 atf_add_test_case vlan_create_destroy
531 atf_add_test_case vlan_basic
532 atf_add_test_case vlan_vlanid
533 atf_add_test_case vlan_configs
534
535 atf_add_test_case vlan_create_destroy6
536 atf_add_test_case vlan_basic6
537 atf_add_test_case vlan_vlanid6
538 atf_add_test_case vlan_configs6
539 }
540