1309466Sngie# $NetBSD: t_mpls_fw.sh,v 1.5 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 MPLS encap/decap and forwarding using INET as encapsulated protocol 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 34272343Sngie# Add MPLS routes on R2 in order to forward frames belonging to that FEC to R3 35272343Sngie# Add MPLS "POP" route on R3 for that FEC, pointing to R4 36272343Sngie# Do the same for the reverse direction (R4 to R1) 37272343Sngie# ping from R1 to R4 right hand side interface 38272343Sngie 39272343Sngie 40272343SngieRUMP_SERVER1=unix://./r1 41272343SngieRUMP_SERVER2=unix://./r2 42272343SngieRUMP_SERVER3=unix://./r3 43272343SngieRUMP_SERVER4=unix://./r4 44272343Sngie 45309466SngieRUMP_FLAGS="-lrumpnet -lrumpnet_net -lrumpnet_netinet \ 46309466Sngie -lrumpdev -lrumpnet_netmpls -lrumpnet_shmif" 47272343Sngie 48272343Sngieatf_test_case mplsfw4 cleanup 49272343Sngiemplsfw4_head() 50272343Sngie{ 51272343Sngie 52272343Sngie atf_set "descr" "IP/MPLS forwarding test using PHP" 53272343Sngie atf_set "require.progs" "rump_server" 54272343Sngie} 55272343Sngie 56272343Sngiestartservers() 57272343Sngie{ 58272343Sngie 59272343Sngie ulimit -r 300 60272343Sngie atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER1} 61272343Sngie atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER2} 62272343Sngie atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER3} 63272343Sngie atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER4} 64272343Sngie} 65272343Sngie 66272343Sngieconfigservers() 67272343Sngie{ 68272343Sngie 69272343Sngie # Setup the first server 70272343Sngie export RUMP_SERVER=${RUMP_SERVER1} 71272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 72272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1 73272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.1/24 74272343Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 75272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 76272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 77272343Sngie atf_check -s exit:0 rump.route -q add 10.0.4.0/24 -ifa 10.0.1.1 \ 78272343Sngie -ifp mpls0 -tag 25 -inet 10.0.1.2 79272343Sngie 80272343Sngie # Setup the second server 81272343Sngie export RUMP_SERVER=${RUMP_SERVER2} 82272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 83272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1 84272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.2/24 85272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 86272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2 87272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 10.0.2.1/24 88272343Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 89272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 90272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1 91272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 92272343Sngie atf_check -s exit:0 rump.route -q add -mpls 25 -tag 30 -inet 10.0.2.2 93272343Sngie atf_check -s exit:0 rump.route -q add -mpls 27 -tag ${1} -inet 10.0.1.1 94272343Sngie 95272343Sngie # Setup the third server 96272343Sngie export RUMP_SERVER=${RUMP_SERVER3} 97272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 98272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2 99272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.2.2/24 100272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 101272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3 102272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 10.0.3.1/24 103272343Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 104272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 105272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1 106272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 107272343Sngie atf_check -s exit:0 rump.route -q add -mpls 30 -tag ${1} -inet 10.0.3.2 108272343Sngie atf_check -s exit:0 rump.route -q add -mpls 26 -tag 27 -inet 10.0.2.1 109272343Sngie 110272343Sngie # Setup the fourth server 111272343Sngie export RUMP_SERVER=${RUMP_SERVER4} 112272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 113272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3 114272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.3.2/24 115272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 116272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4 117272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 10.0.4.1/24 118272343Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 119272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 120272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 121272343Sngie atf_check -s exit:0 rump.route -q add 10.0.1.0/24 -ifa 10.0.3.2 \ 122272343Sngie -ifp mpls0 -tag 26 -inet 10.0.3.1 123272343Sngie 124272343Sngie unset RUMP_SERVER 125272343Sngie} 126272343Sngie 127272343Sngiedoping() 128272343Sngie{ 129272343Sngie 130272343Sngie export RUMP_SERVER=${RUMP_SERVER1} 131272343Sngie atf_check -s exit:0 -o match:"64 bytes from 10.0.4.1: icmp_seq=" \ 132272343Sngie rump.ping -n -o -w 5 10.0.4.1 133272343Sngie unset RUMP_SERVER 134272343Sngie} 135272343Sngie 136272343Sngiedocleanup() 137272343Sngie{ 138272343Sngie 139272343Sngie RUMP_SERVER=${RUMP_SERVER1} rump.halt 140272343Sngie RUMP_SERVER=${RUMP_SERVER2} rump.halt 141272343Sngie RUMP_SERVER=${RUMP_SERVER3} rump.halt 142272343Sngie RUMP_SERVER=${RUMP_SERVER4} rump.halt 143272343Sngie} 144272343Sngie 145272343Sngiemplsfw4_body() 146272343Sngie{ 147272343Sngie 148272343Sngie startservers 149272343Sngie configservers 3 150272343Sngie doping 151272343Sngie} 152272343Sngie 153272343Sngiemplsfw4_cleanup() 154272343Sngie{ 155272343Sngie 156272343Sngie docleanup 157272343Sngie} 158272343Sngie 159272343Sngie 160272343Sngieatf_test_case mplsfw4_expl cleanup 161272343Sngiemplsfw4_expl_head() 162272343Sngie{ 163272343Sngie 164272343Sngie atf_set "descr" "IP/MPLS forwarding test using explicit NULL labels" 165272343Sngie atf_set "require.progs" "rump_server" 166272343Sngie} 167272343Sngie 168272343Sngiemplsfw4_expl_body() 169272343Sngie{ 170272343Sngie 171272343Sngie startservers 172272343Sngie configservers 0 173272343Sngie doping 174272343Sngie} 175272343Sngie 176272343Sngiemplsfw4_expl_cleanup() 177272343Sngie{ 178272343Sngie 179272343Sngie docleanup 180272343Sngie} 181272343Sngie 182272343Sngie 183272343Sngieatf_init_test_cases() 184272343Sngie{ 185272343Sngie 186272343Sngie atf_add_test_case mplsfw4 187272343Sngie atf_add_test_case mplsfw4_expl 188272343Sngie} 189