1303980Sngie# $NetBSD: t_mpls_fw64.sh,v 1.3 2016/08/10 07:50:37 ozaki-r Exp $ 2303980Sngie# 3303980Sngie# Copyright (c) 2015 The NetBSD Foundation, Inc. 4303980Sngie# All rights reserved. 5303980Sngie# 6303980Sngie# Redistribution and use in source and binary forms, with or without 7303980Sngie# modification, are permitted provided that the following conditions 8303980Sngie# are met: 9303980Sngie# 1. Redistributions of source code must retain the above copyright 10303980Sngie# notice, this list of conditions and the following disclaimer. 11303980Sngie# 2. Redistributions in binary form must reproduce the above copyright 12303980Sngie# notice, this list of conditions and the following disclaimer in the 13303980Sngie# documentation and/or other materials provided with the distribution. 14303980Sngie# 15303980Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16303980Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17303980Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18303980Sngie# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19303980Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20303980Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21303980Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22303980Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23303980Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24303980Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25303980Sngie# POSSIBILITY OF SUCH DAMAGE. 26303980Sngie# 27303980Sngie 28303980Sngie# Test MPLS encap/decap and forwarding using INET6 as encapsulated protocol 29303980Sngie# Setup four routers connected like this: R1---R2---R3---R4-- 30303980Sngie# Goal is to be able to ping from R1 the outermost interface of R4 31303980Sngie# Disable net.inet[6].ip[6].forwarding, enable net.mpls.forwarding 32303980Sngie# Use IPv6 between R1-R2-R3 and IPv4 between R3-R4 33303980Sngie# As we use IPv4 on last link we should use only expl.null there 34303980Sngie# because implicit null will assume IPv4 (as the next-hop) 35303980Sngie# But we can use impl null on R2-R1 link because stack will correctly 36303980Sngie# guess IPv6 (from next-hop) 37303980Sngie# Add route on R1 in order to encapsulate into MPLS the IP6 packets with 38303980Sngie# destination equal to R4 right hand side interface 39303980Sngie# Add MPLS routes on R2 in order to forward frames belonging to that FEC to R3 40303980Sngie# Add MPLS expl.null route on R3 for that FEC, pointing to R4 41303980Sngie# Do the same for the reverse direction (R4 to R1) 42303980Sngie# ping6 from R1 to R4 right hand side interface 43303980Sngie 44303980Sngie 45303980SngieRUMP_SERVER1=unix://./r1 46303980SngieRUMP_SERVER2=unix://./r2 47303980SngieRUMP_SERVER3=unix://./r3 48303980SngieRUMP_SERVER4=unix://./r4 49303980Sngie 50303980SngieRUMP_FLAGS6="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 \ 51303980Sngie -lrumpdev -lrumpnet_shmif -lrumpnet_netmpls" 52303980Sngie 53303980Sngiestartservers() 54303980Sngie{ 55303980Sngie 56303980Sngie ulimit -r 300 57303980Sngie atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER1} 58303980Sngie atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER2} 59303980Sngie atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER3} 60303980Sngie atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER4} 61303980Sngie} 62303980Sngie 63303980Sngieconfigservers() 64303980Sngie{ 65303980Sngie 66303980Sngie # Setup the first server 67303980Sngie export RUMP_SERVER=${RUMP_SERVER1} 68303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 69303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1 70303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::1/64 alias 71303980Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 72303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 73303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0 74303980Sngie atf_check -s exit:0 rump.route -q add -inet6 fd00:1234:0:3::/64 \ 75303980Sngie -ifa fd00:1234::1 \ 76303980Sngie -ifp mpls0 -tag 25 -inet6 fd00:1234::2 77303980Sngie 78303980Sngie # Setup the second server 79303980Sngie export RUMP_SERVER=${RUMP_SERVER2} 80303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 81303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1 82303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::2/64 alias 83303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 84303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2 85303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:1::1/64 alias 86303980Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 87303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 88303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1 89303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0 90303980Sngie atf_check -s exit:0 rump.route -q add -mpls 25 -tag 30 \ 91303980Sngie -inet6 fd00:1234:0:1::2 92303980Sngie atf_check -s exit:0 rump.route -q add -mpls 27 -tag ${1} -inet6 \ 93303980Sngie fd00:1234::1 94303980Sngie 95303980Sngie # Setup the third server 96303980Sngie export RUMP_SERVER=${RUMP_SERVER3} 97303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 98303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2 99303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234:0:1::2/64 alias 100303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 101303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3 102303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 inet 10.0.3.1/24 103303980Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 104303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 105303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1 106303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0 107303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 108303980Sngie atf_check -s exit:0 rump.route -q add -mpls 30 -tag 2 \ 109303980Sngie -inet 10.0.3.2 110303980Sngie atf_check -s exit:0 rump.route -q add -mpls 26 -tag 27 \ 111303980Sngie -inet6 fd00:1234:0:1::1 112303980Sngie 113303980Sngie # Setup the fourth server 114303980Sngie export RUMP_SERVER=${RUMP_SERVER4} 115303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 116303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3 117303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.3.2 118303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 119303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4 120303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:3::1/64 alias 121303980Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 122303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 123303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0 124303980Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 125303980Sngie atf_check -s exit:0 rump.route -q add -inet6 fd00:1234::/64 \ 126303980Sngie -ifa fd00:1234:0:3::1 \ 127303980Sngie -ifp mpls0 -tag 26 -inet 10.0.3.1 128303980Sngie 129303980Sngie unset RUMP_SERVER 130303980Sngie} 131303980Sngie 132303980Sngiedoping() 133303980Sngie{ 134303980Sngie 135303980Sngie export RUMP_SERVER=${RUMP_SERVER1} 136303980Sngie atf_check -s exit:0 \ 137303980Sngie -o match:" bytes from fd00:1234::2, icmp_seq=" \ 138303980Sngie rump.ping6 -n -o -X 2 fd00:1234::2 139303980Sngie export RUMP_SERVER=${RUMP_SERVER2} 140303980Sngie atf_check -s exit:0 \ 141303980Sngie -o match:" bytes from fd00:1234:0:1::2, icmp_seq=" \ 142303980Sngie rump.ping6 -n -o -X 2 fd00:1234:0:1::2 143303980Sngie export RUMP_SERVER=${RUMP_SERVER3} 144303980Sngie atf_check -s exit:0 \ 145303980Sngie -o match:" bytes from 10.0.3.2: icmp_seq" \ 146303980Sngie rump.ping -n -o -w 2 10.0.3.2 147303980Sngie export RUMP_SERVER=${RUMP_SERVER1} 148303980Sngie atf_check -s exit:0 \ 149303980Sngie -o match:" bytes from fd00:1234:0:3::1, icmp_seq=" \ 150303980Sngie rump.ping6 -n -o -X 2 fd00:1234:0:3::1 151303980Sngie unset RUMP_SERVER 152303980Sngie} 153303980Sngie 154303980Sngiedo_check_route() 155303980Sngie{ 156303980Sngie 157303980Sngie export RUMP_SERVER=${RUMP_SERVER1} 158303980Sngie atf_check -s exit:0 \ 159303980Sngie -o match:"^fd00:1234:0:3::/64.+fd00:1234::2.+25.+mpls0" \ 160303980Sngie rump.netstat -nrT 161303980Sngie unset RUMP_SERVER 162303980Sngie} 163303980Sngie 164303980Sngiedocleanup() 165303980Sngie{ 166303980Sngie 167303980Sngie RUMP_SERVER=${RUMP_SERVER1} rump.halt 168303980Sngie RUMP_SERVER=${RUMP_SERVER2} rump.halt 169303980Sngie RUMP_SERVER=${RUMP_SERVER3} rump.halt 170303980Sngie RUMP_SERVER=${RUMP_SERVER4} rump.halt 171303980Sngie} 172303980Sngie 173303980Sngieatf_test_case mplsfw64_impl cleanup 174303980Sngiemplsfw64_impl_head() 175303980Sngie{ 176303980Sngie 177303980Sngie atf_set "descr" "IP6/MPLS test using impl. NULL labels in mixed env." 178303980Sngie atf_set "require.progs" "rump_server" 179303980Sngie} 180303980Sngie 181303980Sngiemplsfw64_impl_body() 182303980Sngie{ 183303980Sngie 184303980Sngie startservers 185303980Sngie configservers 3 186303980Sngie do_check_route 187303980Sngie doping 188303980Sngie} 189303980Sngie 190303980Sngiemplsfw64_impl_cleanup() 191303980Sngie{ 192303980Sngie 193303980Sngie docleanup 194303980Sngie} 195303980Sngie 196303980Sngie 197303980Sngieatf_test_case mplsfw64_expl cleanup 198303980Sngiemplsfw64_expl_head() 199303980Sngie{ 200303980Sngie 201303980Sngie atf_set "descr" "IP6/MPLS test using explicit NULL labels in mixed env." 202303980Sngie atf_set "require.progs" "rump_server" 203303980Sngie} 204303980Sngie 205303980Sngiemplsfw64_expl_body() 206303980Sngie{ 207303980Sngie 208303980Sngie startservers 209303980Sngie configservers 2 210303980Sngie do_check_route 211303980Sngie doping 212303980Sngie} 213303980Sngie 214303980Sngiemplsfw64_expl_cleanup() 215303980Sngie{ 216303980Sngie 217303980Sngie docleanup 218303980Sngie} 219303980Sngie 220303980Sngie 221303980Sngieatf_init_test_cases() 222303980Sngie{ 223303980Sngie 224303980Sngie atf_add_test_case mplsfw64_impl 225303980Sngie atf_add_test_case mplsfw64_expl 226303980Sngie} 227