xref: /freebsd/contrib/netbsd-tests/net/mpls/t_mpls_fw64.sh (revision c22165b4f1f5d38b681921797a44b3ba8c13b7e0)
1*640235e2SEnji Cooper# $NetBSD: t_mpls_fw64.sh,v 1.3 2016/08/10 07:50:37 ozaki-r Exp $
2*640235e2SEnji Cooper#
3*640235e2SEnji Cooper# Copyright (c) 2015 The NetBSD Foundation, Inc.
4*640235e2SEnji Cooper# All rights reserved.
5*640235e2SEnji Cooper#
6*640235e2SEnji Cooper# Redistribution and use in source and binary forms, with or without
7*640235e2SEnji Cooper# modification, are permitted provided that the following conditions
8*640235e2SEnji Cooper# are met:
9*640235e2SEnji Cooper# 1. Redistributions of source code must retain the above copyright
10*640235e2SEnji Cooper#    notice, this list of conditions and the following disclaimer.
11*640235e2SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
12*640235e2SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
13*640235e2SEnji Cooper#    documentation and/or other materials provided with the distribution.
14*640235e2SEnji Cooper#
15*640235e2SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16*640235e2SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17*640235e2SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18*640235e2SEnji Cooper# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19*640235e2SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20*640235e2SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21*640235e2SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22*640235e2SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23*640235e2SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24*640235e2SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25*640235e2SEnji Cooper# POSSIBILITY OF SUCH DAMAGE.
26*640235e2SEnji Cooper#
27*640235e2SEnji Cooper
28*640235e2SEnji Cooper# Test MPLS encap/decap and forwarding using INET6 as encapsulated protocol
29*640235e2SEnji Cooper# Setup four routers connected like this: R1---R2---R3---R4--
30*640235e2SEnji Cooper# Goal is to be able to ping from R1 the outermost interface of R4
31*640235e2SEnji Cooper# Disable net.inet[6].ip[6].forwarding, enable net.mpls.forwarding
32*640235e2SEnji Cooper# Use IPv6 between R1-R2-R3 and IPv4 between R3-R4
33*640235e2SEnji Cooper# As we use IPv4 on last link we should use only expl.null there
34*640235e2SEnji Cooper# because implicit null will assume IPv4 (as the next-hop)
35*640235e2SEnji Cooper# But we can use impl null on R2-R1 link because stack will correctly
36*640235e2SEnji Cooper# guess IPv6 (from next-hop)
37*640235e2SEnji Cooper# Add route on R1 in order to encapsulate into MPLS the IP6 packets with
38*640235e2SEnji Cooper#     destination equal to R4 right hand side interface
39*640235e2SEnji Cooper# Add MPLS routes on R2 in order to forward frames belonging to that FEC to R3
40*640235e2SEnji Cooper# Add MPLS expl.null route on R3 for that FEC, pointing to R4
41*640235e2SEnji Cooper# Do the same for the reverse direction (R4 to R1)
42*640235e2SEnji Cooper# ping6 from R1 to R4 right hand side interface
43*640235e2SEnji Cooper
44*640235e2SEnji Cooper
45*640235e2SEnji CooperRUMP_SERVER1=unix://./r1
46*640235e2SEnji CooperRUMP_SERVER2=unix://./r2
47*640235e2SEnji CooperRUMP_SERVER3=unix://./r3
48*640235e2SEnji CooperRUMP_SERVER4=unix://./r4
49*640235e2SEnji Cooper
50*640235e2SEnji CooperRUMP_FLAGS6="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 \
51*640235e2SEnji Cooper             -lrumpdev -lrumpnet_shmif -lrumpnet_netmpls"
52*640235e2SEnji Cooper
53*640235e2SEnji Cooperstartservers()
54*640235e2SEnji Cooper{
55*640235e2SEnji Cooper
56*640235e2SEnji Cooper	ulimit -r 300
57*640235e2SEnji Cooper	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER1}
58*640235e2SEnji Cooper	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER2}
59*640235e2SEnji Cooper	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER3}
60*640235e2SEnji Cooper	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER4}
61*640235e2SEnji Cooper}
62*640235e2SEnji Cooper
63*640235e2SEnji Cooperconfigservers()
64*640235e2SEnji Cooper{
65*640235e2SEnji Cooper
66*640235e2SEnji Cooper	# Setup the first server
67*640235e2SEnji Cooper	export RUMP_SERVER=${RUMP_SERVER1}
68*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 create
69*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
70*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::1/64 alias
71*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig mpls0 create up
72*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
73*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
74*640235e2SEnji Cooper	atf_check -s exit:0 rump.route -q add -inet6 fd00:1234:0:3::/64 \
75*640235e2SEnji Cooper	    -ifa fd00:1234::1 \
76*640235e2SEnji Cooper	    -ifp mpls0 -tag 25 -inet6 fd00:1234::2
77*640235e2SEnji Cooper
78*640235e2SEnji Cooper	# Setup the second server
79*640235e2SEnji Cooper	export RUMP_SERVER=${RUMP_SERVER2}
80*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 create
81*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
82*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::2/64 alias
83*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif1 create
84*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2
85*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:1::1/64 alias
86*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig mpls0 create up
87*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
88*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
89*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
90*640235e2SEnji Cooper	atf_check -s exit:0 rump.route -q add -mpls 25 -tag 30 \
91*640235e2SEnji Cooper	    -inet6 fd00:1234:0:1::2
92*640235e2SEnji Cooper	atf_check -s exit:0 rump.route -q add -mpls 27 -tag ${1} -inet6 \
93*640235e2SEnji Cooper	    fd00:1234::1
94*640235e2SEnji Cooper
95*640235e2SEnji Cooper	# Setup the third server
96*640235e2SEnji Cooper	export RUMP_SERVER=${RUMP_SERVER3}
97*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 create
98*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2
99*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234:0:1::2/64 alias
100*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif1 create
101*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3
102*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif1 inet 10.0.3.1/24
103*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig mpls0 create up
104*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
105*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
106*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
107*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
108*640235e2SEnji Cooper	atf_check -s exit:0 rump.route -q add -mpls 30 -tag 2 \
109*640235e2SEnji Cooper	    -inet 10.0.3.2
110*640235e2SEnji Cooper	atf_check -s exit:0 rump.route -q add -mpls 26 -tag 27 \
111*640235e2SEnji Cooper	    -inet6 fd00:1234:0:1::1
112*640235e2SEnji Cooper
113*640235e2SEnji Cooper	# Setup the fourth server
114*640235e2SEnji Cooper	export RUMP_SERVER=${RUMP_SERVER4}
115*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 create
116*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3
117*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.3.2
118*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif1 create
119*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4
120*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:3::1/64 alias
121*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig mpls0 create up
122*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
123*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
124*640235e2SEnji Cooper	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
125*640235e2SEnji Cooper	atf_check -s exit:0 rump.route -q add -inet6 fd00:1234::/64 \
126*640235e2SEnji Cooper	    -ifa fd00:1234:0:3::1 \
127*640235e2SEnji Cooper	    -ifp mpls0 -tag 26 -inet 10.0.3.1
128*640235e2SEnji Cooper
129*640235e2SEnji Cooper	unset RUMP_SERVER
130*640235e2SEnji Cooper}
131*640235e2SEnji Cooper
132*640235e2SEnji Cooperdoping()
133*640235e2SEnji Cooper{
134*640235e2SEnji Cooper
135*640235e2SEnji Cooper	export RUMP_SERVER=${RUMP_SERVER1}
136*640235e2SEnji Cooper	atf_check -s exit:0 \
137*640235e2SEnji Cooper	    -o match:" bytes from fd00:1234::2, icmp_seq=" \
138*640235e2SEnji Cooper	    rump.ping6 -n -o -X 2 fd00:1234::2
139*640235e2SEnji Cooper	export RUMP_SERVER=${RUMP_SERVER2}
140*640235e2SEnji Cooper	atf_check -s exit:0 \
141*640235e2SEnji Cooper	    -o match:" bytes from fd00:1234:0:1::2, icmp_seq=" \
142*640235e2SEnji Cooper	    rump.ping6 -n -o -X 2 fd00:1234:0:1::2
143*640235e2SEnji Cooper	export RUMP_SERVER=${RUMP_SERVER3}
144*640235e2SEnji Cooper	atf_check -s exit:0 \
145*640235e2SEnji Cooper	    -o match:" bytes from 10.0.3.2: icmp_seq" \
146*640235e2SEnji Cooper	    rump.ping -n -o -w 2 10.0.3.2
147*640235e2SEnji Cooper	export RUMP_SERVER=${RUMP_SERVER1}
148*640235e2SEnji Cooper	atf_check -s exit:0 \
149*640235e2SEnji Cooper	    -o match:" bytes from fd00:1234:0:3::1, icmp_seq=" \
150*640235e2SEnji Cooper	    rump.ping6 -n -o -X 2 fd00:1234:0:3::1
151*640235e2SEnji Cooper	unset RUMP_SERVER
152*640235e2SEnji Cooper}
153*640235e2SEnji Cooper
154*640235e2SEnji Cooperdo_check_route()
155*640235e2SEnji Cooper{
156*640235e2SEnji Cooper
157*640235e2SEnji Cooper	export RUMP_SERVER=${RUMP_SERVER1}
158*640235e2SEnji Cooper	atf_check -s exit:0 \
159*640235e2SEnji Cooper	    -o match:"^fd00:1234:0:3::/64.+fd00:1234::2.+25.+mpls0" \
160*640235e2SEnji Cooper	    rump.netstat -nrT
161*640235e2SEnji Cooper	unset RUMP_SERVER
162*640235e2SEnji Cooper}
163*640235e2SEnji Cooper
164*640235e2SEnji Cooperdocleanup()
165*640235e2SEnji Cooper{
166*640235e2SEnji Cooper
167*640235e2SEnji Cooper	RUMP_SERVER=${RUMP_SERVER1} rump.halt
168*640235e2SEnji Cooper	RUMP_SERVER=${RUMP_SERVER2} rump.halt
169*640235e2SEnji Cooper	RUMP_SERVER=${RUMP_SERVER3} rump.halt
170*640235e2SEnji Cooper	RUMP_SERVER=${RUMP_SERVER4} rump.halt
171*640235e2SEnji Cooper}
172*640235e2SEnji Cooper
173*640235e2SEnji Cooperatf_test_case mplsfw64_impl cleanup
174*640235e2SEnji Coopermplsfw64_impl_head()
175*640235e2SEnji Cooper{
176*640235e2SEnji Cooper
177*640235e2SEnji Cooper	atf_set "descr" "IP6/MPLS test using impl. NULL labels in mixed env."
178*640235e2SEnji Cooper	atf_set "require.progs" "rump_server"
179*640235e2SEnji Cooper}
180*640235e2SEnji Cooper
181*640235e2SEnji Coopermplsfw64_impl_body()
182*640235e2SEnji Cooper{
183*640235e2SEnji Cooper
184*640235e2SEnji Cooper	startservers
185*640235e2SEnji Cooper	configservers 3
186*640235e2SEnji Cooper	do_check_route
187*640235e2SEnji Cooper	doping
188*640235e2SEnji Cooper}
189*640235e2SEnji Cooper
190*640235e2SEnji Coopermplsfw64_impl_cleanup()
191*640235e2SEnji Cooper{
192*640235e2SEnji Cooper
193*640235e2SEnji Cooper	docleanup
194*640235e2SEnji Cooper}
195*640235e2SEnji Cooper
196*640235e2SEnji Cooper
197*640235e2SEnji Cooperatf_test_case mplsfw64_expl cleanup
198*640235e2SEnji Coopermplsfw64_expl_head()
199*640235e2SEnji Cooper{
200*640235e2SEnji Cooper
201*640235e2SEnji Cooper	atf_set "descr" "IP6/MPLS test using explicit NULL labels in mixed env."
202*640235e2SEnji Cooper	atf_set "require.progs" "rump_server"
203*640235e2SEnji Cooper}
204*640235e2SEnji Cooper
205*640235e2SEnji Coopermplsfw64_expl_body()
206*640235e2SEnji Cooper{
207*640235e2SEnji Cooper
208*640235e2SEnji Cooper	startservers
209*640235e2SEnji Cooper	configservers 2
210*640235e2SEnji Cooper	do_check_route
211*640235e2SEnji Cooper	doping
212*640235e2SEnji Cooper}
213*640235e2SEnji Cooper
214*640235e2SEnji Coopermplsfw64_expl_cleanup()
215*640235e2SEnji Cooper{
216*640235e2SEnji Cooper
217*640235e2SEnji Cooper	docleanup
218*640235e2SEnji Cooper}
219*640235e2SEnji Cooper
220*640235e2SEnji Cooper
221*640235e2SEnji Cooperatf_init_test_cases()
222*640235e2SEnji Cooper{
223*640235e2SEnji Cooper
224*640235e2SEnji Cooper	atf_add_test_case mplsfw64_impl
225*640235e2SEnji Cooper	atf_add_test_case mplsfw64_expl
226*640235e2SEnji Cooper}
227