t_vlan.sh revision 1.1.8.2 1 # $NetBSD: t_vlan.sh,v 1.1.8.2 2018/02/26 00:41:14 snj 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 export RUMP_SERVER=$SOCK_LOCAL
344 atf_check -s not-exit:0 -e ignore \
345 rump.ifconfig vlan0 vlan 4096 vlanif shmif0
346
347 atf_check -s exit:0 rump.ifconfig vlan0 vlan 1 vlanif shmif0
348 atf_check -s not-exit:0 -e ignore \
349 rump.ifconfig vlan0 vlan 2 vlanif shmif0
350
351 atf_check -s not-exit:0 -e ignore \
352 rump.ifconfig vlan0 vlan 1 vlanif shmif1
353
354 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
355 atf_check -s not-exit:0 -e ignore \
356 rump.ifconfig vlan0 $local0/$prefix
357
358 export RUMP_SERVER=$SOCK_LOCAL
359 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
360 atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
361 atf_check -s exit:0 rump.ifconfig vlan0 up
362 atf_check -s exit:0 rump.ifconfig vlan1 create
363 atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
364 atf_check -s exit:0 rump.ifconfig vlan1 $af $local1/$prefix
365 atf_check -s exit:0 rump.ifconfig vlan1 up
366
367 export RUMP_SERVER=$SOCK_REMOTE
368 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
369 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
370 atf_check -s exit:0 rump.ifconfig vlan0 $af $remote0/$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 $remote1/$prefix
375 atf_check -s exit:0 rump.ifconfig vlan1 up
376
377 export RUMP_SERVER=$SOCK_LOCAL
378 atf_check -s exit:0 -o ignore $ping_cmd $remote0
379 atf_check -s exit:0 -o ignore $ping_cmd $remote1
380 }
381
382 atf_test_case vlan_vlanid cleanup
383 vlan_vlanid_head()
384 {
385
386 atf_set "descr" "tests of configuration for vlan id"
387 atf_set "require.progs" "rump_server"
388 }
389
390 vlan_vlanid_body()
391 {
392 rump_server_start $SOCK_LOCAL vlan
393 rump_server_start $SOCK_REMOTE vlan
394
395 vlan_vlanid_body_common inet
396 }
397
398 vlan_vlanid_cleanup()
399 {
400
401 $DEBUG && dump
402 cleanup
403 }
404
405 atf_test_case vlan_vlanid6 cleanup
406 vlan_vlanid6_head()
407 {
408
409 atf_set "descr" "tests of configuration for vlan id using IPv6"
410 atf_set "require.progs" "rump_server"
411 }
412
413
414 vlan_vlanid6_body()
415 {
416 rump_server_start $SOCK_LOCAL vlan netinet6
417 rump_server_start $SOCK_REMOTE vlan netinet6
418
419 vlan_vlanid_body_common inet6
420 }
421
422 vlan_vlanid6_cleanup()
423 {
424
425 $DEBUG && dump
426 cleanup
427 }
428
429 vlan_configs_body_common()
430 {
431 export RUMP_SERVER=${SOCK_LOCAL}
432
433 atf_check -s exit:0 rump.ifconfig shmif0 create
434 atf_check -s exit:0 rump.ifconfig shmif1 create
435 atf_check -s exit:0 rump.ifconfig vlan0 create
436
437 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
438 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
439
440 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
441 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif0
442
443 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
444 atf_check -s exit:0 -e ignore rump.ifconfig vlan0 -vlanif shmif1
445 atf_check -s exit:0 -e ignore rump.ifconfig vlan0 -vlanif shmif2
446
447 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
448
449 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
450 atf_check -s exit:0 -e match:'Invalid argument' \
451 rump.ifconfig vlan0 mtu 1497
452 atf_check -s exit:0 rump.ifconfig vlan0 mtu 1496
453 atf_check -s exit:0 rump.ifconfig vlan0 mtu 42
454 atf_check -s exit:0 -e match:'Invalid argument' \
455 rump.ifconfig vlan0 mtu 41
456 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
457
458 atf_check -s exit:0 rump.ifconfig vlan1 create
459 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
460 atf_check -s not-exit:0 -e match:'File exists' \
461 rump.ifconfig vlan1 vlan 10 vlanif shmif0
462 atf_check -s exit:0 rump.ifconfig vlan1 vlan 10 vlanif shmif1
463
464 atf_check -s exit:0 rump.ifconfig vlan1 -vlanif shmif1
465 atf_check -s exit:0 rump.ifconfig vlan1 vlan 10 vlanif shmif1
466
467 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif0
468 atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
469 }
470
471 atf_test_case vlan_configs cleanup
472 vlan_configs_head()
473 {
474 atf_set "descr" "tests of configuration except vlan id"
475 atf_set "require.progs" "rump_server"
476 }
477
478 vlan_configs_body()
479 {
480
481 rump_server_start $SOCK_LOCAL vlan
482
483 vlan_configs_body_common
484
485 }
486
487 vlan_configs_cleanup()
488 {
489
490 $DEBUG && dump
491 cleanup
492 }
493
494 atf_test_case vlan_configs6 cleanup
495 vlan_configs6_head()
496 {
497 atf_set "descr" "tests of configuration except vlan id using IPv6"
498 atf_set "require.progs" "rump_server"
499 }
500
501 vlan_configs6_body()
502 {
503 rump_server_start $SOCK_LOCAL vlan netinet6
504
505 vlan_configs_body_common
506 }
507
508 vlan_configs6_cleanup()
509 {
510 $DEBUG && dump
511 cleanup
512 }
513
514 atf_init_test_cases()
515 {
516
517 atf_add_test_case vlan_create_destroy
518 atf_add_test_case vlan_basic
519 atf_add_test_case vlan_vlanid
520 atf_add_test_case vlan_configs
521
522 atf_add_test_case vlan_create_destroy6
523 atf_add_test_case vlan_basic6
524 atf_add_test_case vlan_vlanid6
525 atf_add_test_case vlan_configs6
526 }
527