1#	$NetBSD: t_vlan.sh,v 1.1 2016/11/26 03:19:49 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
28BUS=bus
29SOCK_LOCAL=unix://commsock1
30SOCK_REMOTE=unix://commsock2
31IP_LOCAL=10.0.0.1
32IP_REMOTE=10.0.0.2
33
34DEBUG=${DEBUG:-false}
35
36atf_test_case vlan_create_destroy cleanup
37vlan_create_destroy_head()
38{
39
40	atf_set "descr" "tests of creation and deletion of vlan interface"
41	atf_set "require.progs" "rump_server"
42}
43
44vlan_create_destroy_body()
45{
46
47	rump_server_start $SOCK_LOCAL vlan
48
49	export RUMP_SERVER=${SOCK_LOCAL}
50
51	atf_check -s exit:0 rump.ifconfig vlan0 create
52	atf_check -s exit:0 rump.ifconfig vlan0 up
53	atf_check -s exit:0 rump.ifconfig vlan0 down
54	atf_check -s exit:0 rump.ifconfig vlan0 destroy
55}
56
57vlan_create_destroy_cleanup()
58{
59
60	$DEBUG && dump
61	cleanup
62}
63
64atf_test_case vlan_basic cleanup
65vlan_basic_head()
66{
67
68	atf_set "descr" "tests of communications over vlan interfaces"
69	atf_set "require.progs" "rump_server"
70}
71
72vlan_basic_body()
73{
74
75	rump_server_start $SOCK_LOCAL vlan
76	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
77	rump_server_start $SOCK_REMOTE vlan
78	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
79
80	export RUMP_SERVER=$SOCK_LOCAL
81	atf_check -s exit:0 rump.ifconfig shmif0 up
82	export RUMP_SERVER=$SOCK_REMOTE
83	atf_check -s exit:0 rump.ifconfig shmif0 up
84
85	export RUMP_SERVER=$SOCK_LOCAL
86	atf_check -s exit:0 rump.ifconfig vlan0 create
87	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
88	atf_check -s exit:0 rump.ifconfig vlan0 $IP_LOCAL/24
89	atf_check -s exit:0 rump.ifconfig vlan0 up
90	atf_check -s exit:0 rump.ifconfig -w 10
91
92	export RUMP_SERVER=$SOCK_REMOTE
93	atf_check -s exit:0 rump.ifconfig vlan0 create
94	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
95	atf_check -s exit:0 rump.ifconfig vlan0 $IP_REMOTE/24
96	atf_check -s exit:0 rump.ifconfig vlan0 up
97	atf_check -s exit:0 rump.ifconfig -w 10
98
99	export RUMP_SERVER=$SOCK_LOCAL
100	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP_REMOTE
101}
102
103vlan_basic_cleanup()
104{
105
106	$DEBUG && dump
107	cleanup
108}
109
110atf_init_test_cases()
111{
112
113	atf_add_test_case vlan_create_destroy
114	atf_add_test_case vlan_basic
115}
116