xref: /freebsd/contrib/netbsd-tests/net/mpls/t_mpls_fw6.sh (revision 13ea0450a9c8742119d36f3bf8f47accdce46e54)
1# $NetBSD: t_mpls_fw6.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.inet6.ip6.forwarding, enable net.mpls.forwarding
32# Add route on R1 in order to encapsulate into MPLS the IP6 packets with
33#     destination equal to R4 right hand side interface
34# Add MPLS routes on R2 in order to forward frames belonging to that FEC to R3
35# Add MPLS "POP" route on R3 for that FEC, pointing to R4
36# Do the same for the reverse direction (R4 to R1)
37# ping6 from R1 to R4 right hand side interface
38#
39# redo the test using IPv6 explicit null label
40
41RUMP_SERVER1=unix://./r1
42RUMP_SERVER2=unix://./r2
43RUMP_SERVER3=unix://./r3
44RUMP_SERVER4=unix://./r4
45
46RUMP_FLAGS6="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 \
47             -lrumpdev -lrumpnet_shmif -lrumpnet_netmpls"
48
49atf_test_case mplsfw6 cleanup
50mplsfw6_head()
51{
52
53	atf_set "descr" "IP6/MPLS forwarding test using PHP"
54	atf_set "require.progs" "rump_server"
55}
56
57startservers()
58{
59
60	ulimit -r 300
61	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER1}
62	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER2}
63	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER3}
64	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER4}
65}
66
67configservers()
68{
69
70	# Setup the first server
71	export RUMP_SERVER=${RUMP_SERVER1}
72	atf_check -s exit:0 rump.ifconfig shmif0 create
73	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
74	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::1/64 alias
75	atf_check -s exit:0 rump.ifconfig mpls0 create up
76	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
77	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
78	atf_check -s exit:0 rump.route -q add -inet6 fd00:1234:0:3::/64 \
79	    -ifa fd00:1234::1 \
80	    -ifp mpls0 -tag 25 -inet6 fd00:1234::2
81
82	# Setup the second server
83	export RUMP_SERVER=${RUMP_SERVER2}
84	atf_check -s exit:0 rump.ifconfig shmif0 create
85	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
86	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::2/64 alias
87	atf_check -s exit:0 rump.ifconfig shmif1 create
88	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2
89	atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:1::1/64 alias
90	atf_check -s exit:0 rump.ifconfig mpls0 create up
91	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
92	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
93	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
94	atf_check -s exit:0 rump.route -q add -mpls 25 -tag 30 \
95	    -inet6 fd00:1234:0:1::2
96	atf_check -s exit:0 rump.route -q add -mpls 27 -tag ${1} -inet6 \
97	    fd00:1234::1
98
99	# Setup the third server
100	export RUMP_SERVER=${RUMP_SERVER3}
101	atf_check -s exit:0 rump.ifconfig shmif0 create
102	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2
103	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234:0:1::2/64 alias
104	atf_check -s exit:0 rump.ifconfig shmif1 create
105	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3
106	atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:2::1/64 alias
107	atf_check -s exit:0 rump.ifconfig mpls0 create up
108	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
109	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
110	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
111	atf_check -s exit:0 rump.route -q add -mpls 30 -tag ${1} \
112	    -inet6 fd00:1234:0:2::2
113	atf_check -s exit:0 rump.route -q add -mpls 26 -tag 27 \
114	    -inet6 fd00:1234:0:1::1
115
116	# Setup the fourth server
117	export RUMP_SERVER=${RUMP_SERVER4}
118	atf_check -s exit:0 rump.ifconfig shmif0 create
119	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3
120	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234:0:2::2/64 alias
121	atf_check -s exit:0 rump.ifconfig shmif1 create
122	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4
123	atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:3::1/64 alias
124	atf_check -s exit:0 rump.ifconfig mpls0 create up
125	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
126	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0
127	atf_check -s exit:0 rump.route -q add -inet6 fd00:1234::/64 \
128	    -ifa fd00:1234:0:2::2 \
129	    -ifp mpls0 -tag 26 -inet6 fd00:1234:0:2::1
130
131	unset RUMP_SERVER
132}
133
134doping()
135{
136
137	export RUMP_SERVER=${RUMP_SERVER1}
138	atf_check -s exit:0 \
139	    -o match:" bytes from fd00:1234::2, icmp_seq=" \
140	    rump.ping6 -n -o -X 2 fd00:1234::2
141	export RUMP_SERVER=${RUMP_SERVER2}
142	atf_check -s exit:0 \
143	    -o match:" bytes from fd00:1234:0:1::2, icmp_seq=" \
144	    rump.ping6 -n -o -X 2 fd00:1234:0:1::2
145	export RUMP_SERVER=${RUMP_SERVER3}
146	atf_check -s exit:0 \
147	    -o match:" bytes from fd00:1234:0:2::2, icmp_seq=" \
148	    rump.ping6 -n -o -X 2 fd00:1234:0:2::2
149	export RUMP_SERVER=${RUMP_SERVER1}
150	atf_check -s exit:0 \
151	    -o match:" bytes from fd00:1234:0:3::1, icmp_seq=" \
152	    rump.ping6 -n -o -X 2 fd00:1234:0:3::1
153	unset RUMP_SERVER
154}
155
156do_check_route()
157{
158
159	export RUMP_SERVER=${RUMP_SERVER1}
160	atf_check -s exit:0 \
161	    -o match:"^fd00:1234:0:3::/64.+fd00:1234::2.+25.+mpls0" \
162	    rump.netstat -nrT
163	unset RUMP_SERVER
164}
165
166docleanup()
167{
168
169	RUMP_SERVER=${RUMP_SERVER1} rump.halt
170	RUMP_SERVER=${RUMP_SERVER2} rump.halt
171	RUMP_SERVER=${RUMP_SERVER3} rump.halt
172	RUMP_SERVER=${RUMP_SERVER4} rump.halt
173}
174
175mplsfw6_body()
176{
177
178	startservers
179	configservers 3
180	do_check_route
181	doping
182}
183
184mplsfw6_cleanup()
185{
186
187	docleanup
188}
189
190
191atf_test_case mplsfw6_expl cleanup
192mplsfw4_expl_head()
193{
194
195	atf_set "descr" "IP6/MPLS forwarding test using explicit NULL labels"
196	atf_set "require.progs" "rump_server"
197}
198
199mplsfw6_expl_body()
200{
201
202	startservers
203	configservers 2
204	do_check_route
205	doping
206}
207
208mplsfw6_expl_cleanup()
209{
210
211	docleanup
212}
213
214
215atf_init_test_cases()
216{
217
218	atf_add_test_case mplsfw6
219	atf_add_test_case mplsfw6_expl
220}
221