xref: /freebsd/contrib/netbsd-tests/net/mpls/t_mpls_fw.sh (revision 123af6ec70016f5556da5972d4d63c7d175c06d3)
1# $NetBSD: t_mpls_fw.sh,v 1.5 2016/08/10 07:50:37 ozaki-r Exp $
2#
3# Copyright (c) 2013 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 INET 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.ip.forwarding, enable net.mpls.forwarding
32# Add route on R1 in order to encapsulate into MPLS the IP 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# ping from R1 to R4 right hand side interface
38
39
40RUMP_SERVER1=unix://./r1
41RUMP_SERVER2=unix://./r2
42RUMP_SERVER3=unix://./r3
43RUMP_SERVER4=unix://./r4
44
45RUMP_FLAGS="-lrumpnet -lrumpnet_net -lrumpnet_netinet	\
46            -lrumpdev -lrumpnet_netmpls -lrumpnet_shmif"
47
48atf_test_case mplsfw4 cleanup
49mplsfw4_head()
50{
51
52	atf_set "descr" "IP/MPLS forwarding test using PHP"
53	atf_set "require.progs" "rump_server"
54}
55
56startservers()
57{
58
59	ulimit -r 300
60	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER1}
61	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER2}
62	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER3}
63	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER4}
64}
65
66configservers()
67{
68
69	# Setup the first server
70	export RUMP_SERVER=${RUMP_SERVER1}
71	atf_check -s exit:0 rump.ifconfig shmif0 create
72	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
73	atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.1/24
74	atf_check -s exit:0 rump.ifconfig mpls0 create up
75	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
76	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
77	atf_check -s exit:0 rump.route -q add 10.0.4.0/24 -ifa 10.0.1.1 \
78	    -ifp mpls0 -tag 25 -inet 10.0.1.2
79
80	# Setup the second server
81	export RUMP_SERVER=${RUMP_SERVER2}
82	atf_check -s exit:0 rump.ifconfig shmif0 create
83	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
84	atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.2/24
85	atf_check -s exit:0 rump.ifconfig shmif1 create
86	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2
87	atf_check -s exit:0 rump.ifconfig shmif1 10.0.2.1/24
88	atf_check -s exit:0 rump.ifconfig mpls0 create up
89	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
90	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
91	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
92	atf_check -s exit:0 rump.route -q add -mpls 25 -tag 30 -inet 10.0.2.2
93	atf_check -s exit:0 rump.route -q add -mpls 27 -tag ${1} -inet 10.0.1.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 10.0.2.2/24
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 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.inet.ip.forwarding=0
107	atf_check -s exit:0 rump.route -q add -mpls 30 -tag ${1} -inet 10.0.3.2
108	atf_check -s exit:0 rump.route -q add -mpls 26 -tag 27 -inet 10.0.2.1
109
110	# Setup the fourth server
111	export RUMP_SERVER=${RUMP_SERVER4}
112	atf_check -s exit:0 rump.ifconfig shmif0 create
113	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3
114	atf_check -s exit:0 rump.ifconfig shmif0 10.0.3.2/24
115	atf_check -s exit:0 rump.ifconfig shmif1 create
116	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4
117	atf_check -s exit:0 rump.ifconfig shmif1 10.0.4.1/24
118	atf_check -s exit:0 rump.ifconfig mpls0 create up
119	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
120	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
121	atf_check -s exit:0 rump.route -q add 10.0.1.0/24 -ifa 10.0.3.2 \
122	    -ifp mpls0 -tag 26 -inet 10.0.3.1
123
124	unset RUMP_SERVER
125}
126
127doping()
128{
129
130	export RUMP_SERVER=${RUMP_SERVER1}
131	atf_check -s exit:0 -o match:"64 bytes from 10.0.4.1: icmp_seq=" \
132	    rump.ping -n -o -w 5 10.0.4.1
133	unset RUMP_SERVER
134}
135
136docleanup()
137{
138
139	RUMP_SERVER=${RUMP_SERVER1} rump.halt
140	RUMP_SERVER=${RUMP_SERVER2} rump.halt
141	RUMP_SERVER=${RUMP_SERVER3} rump.halt
142	RUMP_SERVER=${RUMP_SERVER4} rump.halt
143}
144
145mplsfw4_body()
146{
147
148	startservers
149	configservers 3
150	doping
151}
152
153mplsfw4_cleanup()
154{
155
156	docleanup
157}
158
159
160atf_test_case mplsfw4_expl cleanup
161mplsfw4_expl_head()
162{
163
164	atf_set "descr" "IP/MPLS forwarding test using explicit NULL labels"
165	atf_set "require.progs" "rump_server"
166}
167
168mplsfw4_expl_body()
169{
170
171	startservers
172	configservers 0
173	doping
174}
175
176mplsfw4_expl_cleanup()
177{
178
179	docleanup
180}
181
182
183atf_init_test_cases()
184{
185
186	atf_add_test_case mplsfw4
187	atf_add_test_case mplsfw4_expl
188}
189