xref: /freebsd/contrib/netbsd-tests/net/mpls/t_ldp_regen.sh (revision c22165b4f1f5d38b681921797a44b3ba8c13b7e0)
1# $NetBSD: t_ldp_regen.sh,v 1.7 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# IP/MPLS & LDP label reallocation test
29# Create 4 routers connected like this: R1--R2--R3--R4--
30# The goal is to push packets from R1 to the R4 shmif1 (the right one) interface
31# Enable MPLS forwarding on R2
32# Disable IP forwarding and enable MPLS forwarding on R3
33# Start ldpd and wait for adjancencies to come up
34# Add an alias on shmif1 on R4 for which we already have a route on R3
35# Now: * R4 should install label IMPLNULL for that prefix
36#      * R3 should realloc the target label from IMPLNULL to something else
37
38
39RUMP_SERVER1=unix://./r1
40RUMP_SERVER2=unix://./r2
41RUMP_SERVER3=unix://./r3
42RUMP_SERVER4=unix://./r4
43
44RUMP_LIBS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 \
45           -lrumpdev -lrumpnet_netmpls -lrumpnet_shmif"
46LDP_FLAGS=""
47
48atf_test_case ldp_regen cleanup
49ldp_regen_head() {
50
51	atf_set "descr" "IP/MPLS and LDP label regeneration test"
52	atf_set "require.progs" "rump_server"
53	atf_set "use.fs" "true"
54}
55
56newaddr_and_ping() {
57
58	# Add new address on R4
59	RUMP_SERVER=${RUMP_SERVER4} atf_check -s exit:0 \
60		rump.ifconfig shmif1 10.0.5.1/24 alias
61	RUMP_SERVER=${RUMP_SERVER4} atf_check -s exit:0 \
62		rump.ifconfig -w 60
63
64	# Now ldpd on R5 should take notice of the new route and announce it
65	# to R4's ldpd. ldpd on R4 should verify that the next hop
66	# corresponds to its routing table and change its tag entry
67	RUMP_SERVER=${RUMP_SERVER1} atf_check -s exit:0 -o ignore -e ignore \
68		rump.ping -n -o -w 5 10.0.5.1
69}
70
71create_servers() {
72
73	# allows us to run as normal user
74	ulimit -r 400
75
76	atf_check -s exit:0 rump_server ${RUMP_LIBS} ${RUMP_SERVER1}
77	atf_check -s exit:0 rump_server ${RUMP_LIBS} ${RUMP_SERVER2}
78	atf_check -s exit:0 rump_server ${RUMP_LIBS} ${RUMP_SERVER3}
79	atf_check -s exit:0 rump_server ${RUMP_LIBS} ${RUMP_SERVER4}
80
81	# LDP HIJACK
82	export RUMPHIJACK=path=/rump,socket=all,sysctl=yes
83	export LD_PRELOAD=/usr/lib/librumphijack.so
84
85	# Setup first server
86	export RUMP_SERVER=${RUMP_SERVER1}
87	atf_check -s exit:0 rump.ifconfig shmif0 create
88	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
89	atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.1/24
90	atf_check -s exit:0 rump.ifconfig mpls0 create up
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 10.0.4.0/24 10.0.1.2
93	atf_check -s exit:0 rump.route -q add 10.0.5.0/24 10.0.1.2
94	atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS}
95
96	# Setup second server
97	export RUMP_SERVER=${RUMP_SERVER2}
98	atf_check -s exit:0 rump.ifconfig shmif0 create
99	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
100	atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.2/24
101	atf_check -s exit:0 rump.ifconfig shmif1 create
102	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2
103	atf_check -s exit:0 rump.ifconfig shmif1 10.0.2.1/24
104	atf_check -s exit:0 rump.ifconfig mpls0 create up
105	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
106	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
107	# This one should still do ip forwarding because it announces IMPLNULL
108	# for the 10.0.1.0/24 subnet
109	atf_check -s exit:0 rump.route -q add 10.0.4.0/24 10.0.2.2
110	atf_check -s exit:0 rump.route -q add 10.0.5.0/24 10.0.2.2
111	atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS}
112
113	# Setup third server
114	export RUMP_SERVER=${RUMP_SERVER3}
115	atf_check -s exit:0 rump.ifconfig shmif0 create
116	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2
117	atf_check -s exit:0 rump.ifconfig shmif0 10.0.2.2/24
118	atf_check -s exit:0 rump.ifconfig shmif1 create
119	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3
120	atf_check -s exit:0 rump.ifconfig shmif1 10.0.3.1/24
121	atf_check -s exit:0 rump.ifconfig mpls0 create up
122	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
123	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
124	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
125	atf_check -s exit:0 rump.route -q add 10.0.1.0/24 10.0.2.1
126	atf_check -s exit:0 rump.route -q add 10.0.4.0/24 10.0.3.2
127	atf_check -s exit:0 rump.route -q add 10.0.5.0/24 10.0.3.2
128	atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS}
129
130	# Setup fourth server
131	export RUMP_SERVER=${RUMP_SERVER4}
132	atf_check -s exit:0 rump.ifconfig shmif0 create
133	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3
134	atf_check -s exit:0 rump.ifconfig shmif0 10.0.3.2/24
135	atf_check -s exit:0 rump.ifconfig shmif1 create
136	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4
137	atf_check -s exit:0 rump.ifconfig shmif1 10.0.4.1/24
138	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
139	atf_check -s exit:0 rump.ifconfig mpls0 create up
140	atf_check -s exit:0 rump.route -q add 10.0.1.0/24 10.0.3.1
141	atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS}
142
143	unset RUMP_SERVER
144	unset LD_PRELOAD
145	unset RUMPHIJACK
146}
147
148wait_ldp_ok() {
149
150	RUMP_SERVER=${RUMP_SERVER1} atf_check -s exit:0 -o ignore -e ignore \
151		rump.ifconfig -w 60
152	RUMP_SERVER=${RUMP_SERVER1} atf_check -s exit:0 -o ignore -e ignore \
153		rump.ping -o -w 60 10.0.4.1
154}
155
156docleanup() {
157
158	RUMP_SERVER=${RUMP_SERVER1} rump.halt
159	RUMP_SERVER=${RUMP_SERVER2} rump.halt
160	RUMP_SERVER=${RUMP_SERVER3} rump.halt
161	RUMP_SERVER=${RUMP_SERVER4} rump.halt
162}
163
164ldp_regen_body() {
165
166        if sysctl machdep.cpu_brand 2>/dev/null | grep QEMU >/dev/null 2>&1
167	then
168	    atf_skip "unreliable under qemu, skip until PR kern/43997 fixed"
169	fi
170	create_servers
171	wait_ldp_ok
172	newaddr_and_ping
173}
174
175ldp_regen_cleanup() {
176
177	docleanup
178}
179
180atf_init_test_cases() {
181
182	atf_add_test_case ldp_regen
183}
184