t_mpls_fw64.sh revision 313498
1# $NetBSD: t_mpls_fw64.sh,v 1.3 2016/08/10 07:50:37 ozaki-r Exp $
2#
3# Copyright (c) 2015 The NetBSD Foundation, 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# Test MPLS encap/decap and forwarding using INET6 as encapsulated protocol
29# Setup four routers connected like this: R1---R2---R3---R4--
30# Goal is to be able to ping from R1 the outermost interface of R4
31# Disable net.inet[6].ip[6].forwarding, enable net.mpls.forwarding
32# Use IPv6 between R1-R2-R3 and IPv4 between R3-R4
33# As we use IPv4 on last link we should use only expl.null there
34# because implicit null will assume IPv4 (as the next-hop)
35# But we can use impl null on R2-R1 link because stack will correctly
36# guess IPv6 (from next-hop)
37# Add route on R1 in order to encapsulate into MPLS the IP6 packets with
38#     destination equal to R4 right hand side interface
39# Add MPLS routes on R2 in order to forward frames belonging to that FEC to R3
40# Add MPLS expl.null route on R3 for that FEC, pointing to R4
41# Do the same for the reverse direction (R4 to R1)
42# ping6 from R1 to R4 right hand side interface
43
44
45RUMP_SERVER1=unix://./r1
46RUMP_SERVER2=unix://./r2
47RUMP_SERVER3=unix://./r3
48RUMP_SERVER4=unix://./r4
49
50RUMP_FLAGS6="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 \
51             -lrumpdev -lrumpnet_shmif -lrumpnet_netmpls"
52
53startservers()
54{
55
56	ulimit -r 300
57	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER1}
58	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER2}
59	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER3}
60	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER4}
61}
62
63configservers()
64{
65
66	# Setup the first server
67	export RUMP_SERVER=${RUMP_SERVER1}
68	atf_check -s exit:0 rump.ifconfig shmif0 create
69	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
70	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::1/64 alias
71	atf_check -s exit:0 rump.ifconfig mpls0 create up
72	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
73	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
74	atf_check -s exit:0 rump.route -q add -inet6 fd00:1234:0:3::/64 \
75	    -ifa fd00:1234::1 \
76	    -ifp mpls0 -tag 25 -inet6 fd00:1234::2
77
78	# Setup the second server
79	export RUMP_SERVER=${RUMP_SERVER2}
80	atf_check -s exit:0 rump.ifconfig shmif0 create
81	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
82	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::2/64 alias
83	atf_check -s exit:0 rump.ifconfig shmif1 create
84	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2
85	atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:1::1/64 alias
86	atf_check -s exit:0 rump.ifconfig mpls0 create up
87	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
88	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
89	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
90	atf_check -s exit:0 rump.route -q add -mpls 25 -tag 30 \
91	    -inet6 fd00:1234:0:1::2
92	atf_check -s exit:0 rump.route -q add -mpls 27 -tag ${1} -inet6 \
93	    fd00:1234::1
94
95	# Setup the third server
96	export RUMP_SERVER=${RUMP_SERVER3}
97	atf_check -s exit:0 rump.ifconfig shmif0 create
98	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2
99	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234:0:1::2/64 alias
100	atf_check -s exit:0 rump.ifconfig shmif1 create
101	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3
102	atf_check -s exit:0 rump.ifconfig shmif1 inet 10.0.3.1/24
103	atf_check -s exit:0 rump.ifconfig mpls0 create up
104	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
105	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
106	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
107	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
108	atf_check -s exit:0 rump.route -q add -mpls 30 -tag 2 \
109	    -inet 10.0.3.2
110	atf_check -s exit:0 rump.route -q add -mpls 26 -tag 27 \
111	    -inet6 fd00:1234:0:1::1
112
113	# Setup the fourth server
114	export RUMP_SERVER=${RUMP_SERVER4}
115	atf_check -s exit:0 rump.ifconfig shmif0 create
116	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3
117	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.3.2
118	atf_check -s exit:0 rump.ifconfig shmif1 create
119	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4
120	atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:3::1/64 alias
121	atf_check -s exit:0 rump.ifconfig mpls0 create up
122	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
123	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
124	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
125	atf_check -s exit:0 rump.route -q add -inet6 fd00:1234::/64 \
126	    -ifa fd00:1234:0:3::1 \
127	    -ifp mpls0 -tag 26 -inet 10.0.3.1
128
129	unset RUMP_SERVER
130}
131
132doping()
133{
134
135	export RUMP_SERVER=${RUMP_SERVER1}
136	atf_check -s exit:0 \
137	    -o match:" bytes from fd00:1234::2, icmp_seq=" \
138	    rump.ping6 -n -o -X 2 fd00:1234::2
139	export RUMP_SERVER=${RUMP_SERVER2}
140	atf_check -s exit:0 \
141	    -o match:" bytes from fd00:1234:0:1::2, icmp_seq=" \
142	    rump.ping6 -n -o -X 2 fd00:1234:0:1::2
143	export RUMP_SERVER=${RUMP_SERVER3}
144	atf_check -s exit:0 \
145	    -o match:" bytes from 10.0.3.2: icmp_seq" \
146	    rump.ping -n -o -w 2 10.0.3.2
147	export RUMP_SERVER=${RUMP_SERVER1}
148	atf_check -s exit:0 \
149	    -o match:" bytes from fd00:1234:0:3::1, icmp_seq=" \
150	    rump.ping6 -n -o -X 2 fd00:1234:0:3::1
151	unset RUMP_SERVER
152}
153
154do_check_route()
155{
156
157	export RUMP_SERVER=${RUMP_SERVER1}
158	atf_check -s exit:0 \
159	    -o match:"^fd00:1234:0:3::/64.+fd00:1234::2.+25.+mpls0" \
160	    rump.netstat -nrT
161	unset RUMP_SERVER
162}
163
164docleanup()
165{
166
167	RUMP_SERVER=${RUMP_SERVER1} rump.halt
168	RUMP_SERVER=${RUMP_SERVER2} rump.halt
169	RUMP_SERVER=${RUMP_SERVER3} rump.halt
170	RUMP_SERVER=${RUMP_SERVER4} rump.halt
171}
172
173atf_test_case mplsfw64_impl cleanup
174mplsfw64_impl_head()
175{
176
177	atf_set "descr" "IP6/MPLS test using impl. NULL labels in mixed env."
178	atf_set "require.progs" "rump_server"
179}
180
181mplsfw64_impl_body()
182{
183
184	startservers
185	configservers 3
186	do_check_route
187	doping
188}
189
190mplsfw64_impl_cleanup()
191{
192
193	docleanup
194}
195
196
197atf_test_case mplsfw64_expl cleanup
198mplsfw64_expl_head()
199{
200
201	atf_set "descr" "IP6/MPLS test using explicit NULL labels in mixed env."
202	atf_set "require.progs" "rump_server"
203}
204
205mplsfw64_expl_body()
206{
207
208	startservers
209	configservers 2
210	do_check_route
211	doping
212}
213
214mplsfw64_expl_cleanup()
215{
216
217	docleanup
218}
219
220
221atf_init_test_cases()
222{ 
223
224	atf_add_test_case mplsfw64_impl
225	atf_add_test_case mplsfw64_expl
226}
227