t_mpls_fw.sh revision 272345
1178825Sdfr# $NetBSD: t_mpls_fw.sh,v 1.4 2014/03/18 18:20:44 riastradh Exp $
2233294Sstas#
3233294Sstas# Copyright (c) 2013 The NetBSD Foundation, Inc.
4233294Sstas# All rights reserved.
5178825Sdfr#
6233294Sstas# Redistribution and use in source and binary forms, with or without
7233294Sstas# modification, are permitted provided that the following conditions
8233294Sstas# are met:
9178825Sdfr# 1. Redistributions of source code must retain the above copyright
10233294Sstas#    notice, this list of conditions and the following disclaimer.
11233294Sstas# 2. Redistributions in binary form must reproduce the above copyright
12178825Sdfr#    notice, this list of conditions and the following disclaimer in the
13233294Sstas#    documentation and/or other materials provided with the distribution.
14233294Sstas#
15233294Sstas# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16178825Sdfr# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17233294Sstas# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18233294Sstas# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19233294Sstas# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20178825Sdfr# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21233294Sstas# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22233294Sstas# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23233294Sstas# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24233294Sstas# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25233294Sstas# POSSIBILITY OF SUCH DAMAGE.
26233294Sstas#
27233294Sstas
28233294Sstas# TEST MPLS encap/decap and forwarding using INET as encapsulated protocol
29233294Sstas# Setup four routers connected like this: R1---R2---R3---R4--
30233294Sstas# Goal is to be able to ping from R1 the outermost interface of R4
31233294Sstas# Disable net.inet.ip.forwarding, enable net.mpls.forwarding
32178825Sdfr# Add route on R1 in order to encapsulate into MPLS the IP packets with
33178825Sdfr#     destination equal to R4 right hand side interface
34178825Sdfr# Add MPLS routes on R2 in order to forward frames belonging to that FEC to R3
35178825Sdfr# Add MPLS "POP" route on R3 for that FEC, pointing to R4
36178825Sdfr# Do the same for the reverse direction (R4 to R1)
37178825Sdfr# ping from R1 to R4 right hand side interface
38178825Sdfr
39178825Sdfr
40178825SdfrRUMP_SERVER1=unix://./r1
41178825SdfrRUMP_SERVER2=unix://./r2
42178825SdfrRUMP_SERVER3=unix://./r3
43233294SstasRUMP_SERVER4=unix://./r4
44178825Sdfr
45178825SdfrRUMP_FLAGS=\
46233294Sstas"-lrumpnet -lrumpnet_net -lrumpnet_netmpls -lrumpnet_netinet -lrumpnet_shmif"
47233294Sstas
48233294Sstasatf_test_case mplsfw4 cleanup
49178825Sdfrmplsfw4_head()
50178825Sdfr{
51178825Sdfr
52178825Sdfr	atf_set "descr" "IP/MPLS forwarding test using PHP"
53178825Sdfr	atf_set "require.progs" "rump_server"
54178825Sdfr}
55178825Sdfr
56233294Sstasstartservers()
57233294Sstas{
58178825Sdfr
59233294Sstas	ulimit -r 300
60233294Sstas	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER1}
61233294Sstas	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER2}
62233294Sstas	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER3}
63178825Sdfr	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER4}
64178825Sdfr}
65178825Sdfr
66233294Sstasconfigservers()
67233294Sstas{
68233294Sstas
69233294Sstas	# Setup the first server
70233294Sstas	export RUMP_SERVER=${RUMP_SERVER1}
71233294Sstas	atf_check -s exit:0 rump.ifconfig shmif0 create
72233294Sstas	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
73233294Sstas	atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.1/24
74233294Sstas	atf_check -s exit:0 rump.ifconfig mpls0 create up
75233294Sstas	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
76233294Sstas	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
77233294Sstas	atf_check -s exit:0 rump.route -q add 10.0.4.0/24 -ifa 10.0.1.1 \
78233294Sstas	    -ifp mpls0 -tag 25 -inet 10.0.1.2
79233294Sstas
80233294Sstas	# Setup the second server
81233294Sstas	export RUMP_SERVER=${RUMP_SERVER2}
82233294Sstas	atf_check -s exit:0 rump.ifconfig shmif0 create
83233294Sstas	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
84233294Sstas	atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.2/24
85233294Sstas	atf_check -s exit:0 rump.ifconfig shmif1 create
86233294Sstas	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2
87233294Sstas	atf_check -s exit:0 rump.ifconfig shmif1 10.0.2.1/24
88233294Sstas	atf_check -s exit:0 rump.ifconfig mpls0 create up
89233294Sstas	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
90178825Sdfr	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
91178825Sdfr	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
92178825Sdfr	atf_check -s exit:0 rump.route -q add -mpls 25 -tag 30 -inet 10.0.2.2
93178825Sdfr	atf_check -s exit:0 rump.route -q add -mpls 27 -tag ${1} -inet 10.0.1.1
94233294Sstas
95178825Sdfr	# Setup the third server
96178825Sdfr	export RUMP_SERVER=${RUMP_SERVER3}
97178825Sdfr	atf_check -s exit:0 rump.ifconfig shmif0 create
98178825Sdfr	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2
99233294Sstas	atf_check -s exit:0 rump.ifconfig shmif0 10.0.2.2/24
100178825Sdfr	atf_check -s exit:0 rump.ifconfig shmif1 create
101178825Sdfr	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3
102178825Sdfr	atf_check -s exit:0 rump.ifconfig shmif1 10.0.3.1/24
103178825Sdfr	atf_check -s exit:0 rump.ifconfig mpls0 create up
104178825Sdfr	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
105178825Sdfr	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
106178825Sdfr	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
107233294Sstas	atf_check -s exit:0 rump.route -q add -mpls 30 -tag ${1} -inet 10.0.3.2
108233294Sstas	atf_check -s exit:0 rump.route -q add -mpls 26 -tag 27 -inet 10.0.2.1
109178825Sdfr
110233294Sstas	# Setup the fourth server
111178825Sdfr	export RUMP_SERVER=${RUMP_SERVER4}
112233294Sstas	atf_check -s exit:0 rump.ifconfig shmif0 create
113233294Sstas	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3
114178825Sdfr	atf_check -s exit:0 rump.ifconfig shmif0 10.0.3.2/24
115178825Sdfr	atf_check -s exit:0 rump.ifconfig shmif1 create
116178825Sdfr	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4
117233294Sstas	atf_check -s exit:0 rump.ifconfig shmif1 10.0.4.1/24
118233294Sstas	atf_check -s exit:0 rump.ifconfig mpls0 create up
119233294Sstas	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
120233294Sstas	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
121233294Sstas	atf_check -s exit:0 rump.route -q add 10.0.1.0/24 -ifa 10.0.3.2 \
122233294Sstas	    -ifp mpls0 -tag 26 -inet 10.0.3.1
123178825Sdfr
124178825Sdfr	unset RUMP_SERVER
125233294Sstas}
126233294Sstas
127233294Sstasdoping()
128233294Sstas{
129233294Sstas
130233294Sstas	export RUMP_SERVER=${RUMP_SERVER1}
131233294Sstas	atf_check -s exit:0 -o match:"64 bytes from 10.0.4.1: icmp_seq=" \
132233294Sstas	    rump.ping -n -o -w 5 10.0.4.1
133233294Sstas	unset RUMP_SERVER
134233294Sstas}
135233294Sstas
136178825Sdfrdocleanup()
137178825Sdfr{
138178825Sdfr
139233294Sstas	RUMP_SERVER=${RUMP_SERVER1} rump.halt
140178825Sdfr	RUMP_SERVER=${RUMP_SERVER2} rump.halt
141233294Sstas	RUMP_SERVER=${RUMP_SERVER3} rump.halt
142178825Sdfr	RUMP_SERVER=${RUMP_SERVER4} rump.halt
143178825Sdfr}
144178825Sdfr
145178825Sdfrmplsfw4_body()
146178825Sdfr{
147178825Sdfr
148178825Sdfr	startservers
149178825Sdfr	configservers 3
150178825Sdfr	doping
151178825Sdfr}
152178825Sdfr
153178825Sdfrmplsfw4_cleanup()
154178825Sdfr{
155178825Sdfr
156178825Sdfr	docleanup
157233294Sstas}
158233294Sstas
159233294Sstas
160233294Sstasatf_test_case mplsfw4_expl cleanup
161233294Sstasmplsfw4_expl_head()
162233294Sstas{
163233294Sstas
164233294Sstas	atf_set "descr" "IP/MPLS forwarding test using explicit NULL labels"
165178825Sdfr	atf_set "require.progs" "rump_server"
166233294Sstas}
167233294Sstas
168233294Sstasmplsfw4_expl_body()
169233294Sstas{
170233294Sstas
171233294Sstas	startservers
172233294Sstas	configservers 0
173233294Sstas	doping
174233294Sstas}
175233294Sstas
176233294Sstasmplsfw4_expl_cleanup()
177233294Sstas{
178233294Sstas
179233294Sstas	docleanup
180233294Sstas}
181233294Sstas
182233294Sstas
183233294Sstasatf_init_test_cases()
184233294Sstas{ 
185178825Sdfr
186178825Sdfr	atf_add_test_case mplsfw4
187178825Sdfr	atf_add_test_case mplsfw4_expl
188178825Sdfr} 
189178825Sdfr