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