1309466Sngie# $NetBSD: t_rfc4182.sh,v 1.4 2016/08/10 07:50:37 ozaki-r Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2013 The NetBSD Foundation, Inc.
4272343Sngie# All rights reserved.
5272343Sngie#
6272343Sngie# Redistribution and use in source and binary forms, with or without
7272343Sngie# modification, are permitted provided that the following conditions
8272343Sngie# are met:
9272343Sngie# 1. Redistributions of source code must retain the above copyright
10272343Sngie#    notice, this list of conditions and the following disclaimer.
11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#    notice, this list of conditions and the following disclaimer in the
13272343Sngie#    documentation and/or other materials provided with the distribution.
14272343Sngie#
15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie# POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28272343Sngie# TEST RFC 4182
29272343Sngie# Setup four routers connected like this: R1---R2---R3---R4--
30272343Sngie# Goal is to be able to ping from R1 the outermost interface of R4
31272343Sngie# Disable net.inet.ip.forwarding, enable net.mpls.forwarding
32272343Sngie# Add route on R1 in order to encapsulate into MPLS the IP packets with
33272343Sngie#     destination equal to R4 right hand side interface. Use two labels here:
34272343Sngie#     25 and IPv6 Explicit NULL
35272343Sngie# Add a double tagged MPLS route on R2 in order to forward frames belonging to
36272343Sngie#     that FEC to R3, with IPv4 NULL being the most outermost one
37272343Sngie# Add MPLS "POP" route on R3 for that FEC, pointing to R4
38272343Sngie# Do the same for the reverse direction (R4 to R1)
39272343Sngie# ping from R1 to R4 right hand side interface
40272343Sngie
41272343Sngie
42272343SngieRUMP_SERVER1=unix://./r1
43272343SngieRUMP_SERVER2=unix://./r2
44272343SngieRUMP_SERVER3=unix://./r3
45272343SngieRUMP_SERVER4=unix://./r4
46272343Sngie
47309466SngieRUMP_FLAGS="-lrumpnet -lrumpnet_net -lrumpnet_netinet	\
48309466Sngie            -lrumpdev -lrumpnet_netmpls -lrumpnet_shmif"
49272343Sngie
50272343Sngieatf_test_case rfc4182 cleanup
51272343Sngierfc4182_head()
52272343Sngie{
53272343Sngie
54272343Sngie	atf_set "descr" "RFC 4182 conformance test"
55272343Sngie	atf_set "require.progs" "rump_server"
56272343Sngie}
57272343Sngie
58272343Sngiestartservers()
59272343Sngie{
60272343Sngie
61272343Sngie	ulimit -r 300
62272343Sngie	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER1}
63272343Sngie	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER2}
64272343Sngie	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER3}
65272343Sngie	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER4}
66272343Sngie}
67272343Sngie
68272343Sngieconfigservers()
69272343Sngie{
70272343Sngie
71272343Sngie	# Setup the first server
72272343Sngie	export RUMP_SERVER=${RUMP_SERVER1}
73272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 create
74272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
75272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.1/24
76272343Sngie	atf_check -s exit:0 rump.ifconfig mpls0 create up
77272343Sngie	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
78272343Sngie	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
79272343Sngie	atf_check -s exit:0 rump.route -q add 10.0.4.0/24 -ifa 10.0.1.1 \
80272343Sngie	    -ifp mpls0 -tag 25,2 -inet 10.0.1.2
81272343Sngie
82272343Sngie	# Setup the second server
83272343Sngie	export RUMP_SERVER=${RUMP_SERVER2}
84272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 create
85272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
86272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.2/24
87272343Sngie	atf_check -s exit:0 rump.ifconfig shmif1 create
88272343Sngie	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2
89272343Sngie	atf_check -s exit:0 rump.ifconfig shmif1 10.0.2.1/24
90272343Sngie	atf_check -s exit:0 rump.ifconfig mpls0 create up
91272343Sngie	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
92272343Sngie	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
93272343Sngie	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
94272343Sngie	atf_check -s exit:0 rump.route -q add -mpls 25 -tag 30,0 -inet 10.0.2.2
95272343Sngie	atf_check -s exit:0 rump.route -q add -mpls 27 -tag 3 -inet 10.0.1.1
96272343Sngie
97272343Sngie	# Setup the third server
98272343Sngie	export RUMP_SERVER=${RUMP_SERVER3}
99272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 create
100272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2
101272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 10.0.2.2/24
102272343Sngie	atf_check -s exit:0 rump.ifconfig shmif1 create
103272343Sngie	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3
104272343Sngie	atf_check -s exit:0 rump.ifconfig shmif1 10.0.3.1/24
105272343Sngie	atf_check -s exit:0 rump.ifconfig mpls0 create up
106272343Sngie	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
107272343Sngie	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
108272343Sngie	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
109272343Sngie	atf_check -s exit:0 rump.route -q add -mpls 30 -tag 3 -inet 10.0.3.2
110272343Sngie	atf_check -s exit:0 rump.route -q add -mpls 26 -tag 27,0 -inet 10.0.2.1
111272343Sngie
112272343Sngie	# Setup the fourth server
113272343Sngie	export RUMP_SERVER=${RUMP_SERVER4}
114272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 create
115272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3
116272343Sngie	atf_check -s exit:0 rump.ifconfig shmif0 10.0.3.2/24
117272343Sngie	atf_check -s exit:0 rump.ifconfig shmif1 create
118272343Sngie	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4
119272343Sngie	atf_check -s exit:0 rump.ifconfig shmif1 10.0.4.1/24
120272343Sngie	atf_check -s exit:0 rump.ifconfig mpls0 create up
121272343Sngie	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
122272343Sngie	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
123272343Sngie	atf_check -s exit:0 rump.route -q add 10.0.1.0/24 -ifa 10.0.3.2 \
124272343Sngie	    -ifp mpls0 -tag 26 -inet 10.0.3.1
125272343Sngie
126272343Sngie	unset RUMP_SERVER
127272343Sngie}
128272343Sngie
129272343Sngiedoping()
130272343Sngie{
131272343Sngie
132272343Sngie	export RUMP_SERVER=${RUMP_SERVER1}
133272343Sngie	atf_check -s exit:0 -o match:"64 bytes from 10.0.4.1: icmp_seq=" \
134272343Sngie	    rump.ping -n -o -w 5 10.0.4.1
135272343Sngie	unset RUMP_SERVER
136272343Sngie}
137272343Sngie
138272343Sngiedocleanup()
139272343Sngie{
140272343Sngie
141272343Sngie	RUMP_SERVER=${RUMP_SERVER1} rump.halt
142272343Sngie	RUMP_SERVER=${RUMP_SERVER2} rump.halt
143272343Sngie	RUMP_SERVER=${RUMP_SERVER3} rump.halt
144272343Sngie	RUMP_SERVER=${RUMP_SERVER4} rump.halt
145272343Sngie}
146272343Sngie
147272343Sngierfc4182_body()
148272343Sngie{
149272343Sngie
150272343Sngie	startservers
151272343Sngie	configservers
152272343Sngie	doping
153272343Sngie}
154272343Sngie
155272343Sngierfc4182_cleanup()
156272343Sngie{
157272343Sngie
158272343Sngie	docleanup
159272343Sngie}
160272343Sngie
161272343Sngieatf_init_test_cases()
162272343Sngie{ 
163272343Sngie
164272343Sngie	atf_add_test_case rfc4182
165272343Sngie} 
166