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