1309466Sngie# $NetBSD: t_ldp_regen.sh,v 1.7 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# IP/MPLS & LDP label reallocation test 29272343Sngie# Create 4 routers connected like this: R1--R2--R3--R4-- 30272343Sngie# The goal is to push packets from R1 to the R4 shmif1 (the right one) interface 31272343Sngie# Enable MPLS forwarding on R2 32272343Sngie# Disable IP forwarding and enable MPLS forwarding on R3 33272343Sngie# Start ldpd and wait for adjancencies to come up 34272343Sngie# Add an alias on shmif1 on R4 for which we already have a route on R3 35272343Sngie# Now: * R4 should install label IMPLNULL for that prefix 36272343Sngie# * R3 should realloc the target label from IMPLNULL to something else 37272343Sngie 38272343Sngie 39272343SngieRUMP_SERVER1=unix://./r1 40272343SngieRUMP_SERVER2=unix://./r2 41272343SngieRUMP_SERVER3=unix://./r3 42272343SngieRUMP_SERVER4=unix://./r4 43272343Sngie 44309466SngieRUMP_LIBS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 \ 45309466Sngie -lrumpdev -lrumpnet_netmpls -lrumpnet_shmif" 46272343SngieLDP_FLAGS="" 47272343Sngie 48272343Sngieatf_test_case ldp_regen cleanup 49272343Sngieldp_regen_head() { 50272343Sngie 51272343Sngie atf_set "descr" "IP/MPLS and LDP label regeneration test" 52272343Sngie atf_set "require.progs" "rump_server" 53272343Sngie atf_set "use.fs" "true" 54272343Sngie} 55272343Sngie 56272343Sngienewaddr_and_ping() { 57272343Sngie 58272343Sngie # Add new address on R4 59272343Sngie RUMP_SERVER=${RUMP_SERVER4} atf_check -s exit:0 \ 60272343Sngie rump.ifconfig shmif1 10.0.5.1/24 alias 61309466Sngie RUMP_SERVER=${RUMP_SERVER4} atf_check -s exit:0 \ 62309466Sngie rump.ifconfig -w 60 63272343Sngie 64272343Sngie # Now ldpd on R5 should take notice of the new route and announce it 65272343Sngie # to R4's ldpd. ldpd on R4 should verify that the next hop 66272343Sngie # corresponds to its routing table and change its tag entry 67272343Sngie RUMP_SERVER=${RUMP_SERVER1} atf_check -s exit:0 -o ignore -e ignore \ 68272343Sngie rump.ping -n -o -w 5 10.0.5.1 69272343Sngie} 70272343Sngie 71272343Sngiecreate_servers() { 72272343Sngie 73272343Sngie # allows us to run as normal user 74272343Sngie ulimit -r 400 75272343Sngie 76272343Sngie atf_check -s exit:0 rump_server ${RUMP_LIBS} ${RUMP_SERVER1} 77272343Sngie atf_check -s exit:0 rump_server ${RUMP_LIBS} ${RUMP_SERVER2} 78272343Sngie atf_check -s exit:0 rump_server ${RUMP_LIBS} ${RUMP_SERVER3} 79272343Sngie atf_check -s exit:0 rump_server ${RUMP_LIBS} ${RUMP_SERVER4} 80272343Sngie 81272343Sngie # LDP HIJACK 82272343Sngie export RUMPHIJACK=path=/rump,socket=all,sysctl=yes 83272343Sngie export LD_PRELOAD=/usr/lib/librumphijack.so 84272343Sngie 85272343Sngie # Setup first server 86272343Sngie export RUMP_SERVER=${RUMP_SERVER1} 87272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 88272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1 89272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.1/24 90272343Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 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 10.0.4.0/24 10.0.1.2 93272343Sngie atf_check -s exit:0 rump.route -q add 10.0.5.0/24 10.0.1.2 94272343Sngie atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS} 95272343Sngie 96272343Sngie # Setup second server 97272343Sngie export RUMP_SERVER=${RUMP_SERVER2} 98272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 99272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1 100272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.2/24 101272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 102272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2 103272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 10.0.2.1/24 104272343Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 105272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 106272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1 107272343Sngie # This one should still do ip forwarding because it announces IMPLNULL 108272343Sngie # for the 10.0.1.0/24 subnet 109272343Sngie atf_check -s exit:0 rump.route -q add 10.0.4.0/24 10.0.2.2 110272343Sngie atf_check -s exit:0 rump.route -q add 10.0.5.0/24 10.0.2.2 111272343Sngie atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS} 112272343Sngie 113272343Sngie # Setup third server 114272343Sngie export RUMP_SERVER=${RUMP_SERVER3} 115272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 116272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2 117272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.2.2/24 118272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 119272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3 120272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 10.0.3.1/24 121272343Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 122272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 123272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1 124272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 125272343Sngie atf_check -s exit:0 rump.route -q add 10.0.1.0/24 10.0.2.1 126272343Sngie atf_check -s exit:0 rump.route -q add 10.0.4.0/24 10.0.3.2 127272343Sngie atf_check -s exit:0 rump.route -q add 10.0.5.0/24 10.0.3.2 128272343Sngie atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS} 129272343Sngie 130272343Sngie # Setup fourth server 131272343Sngie export RUMP_SERVER=${RUMP_SERVER4} 132272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 133272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3 134272343Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.3.2/24 135272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 136272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4 137272343Sngie atf_check -s exit:0 rump.ifconfig shmif1 10.0.4.1/24 138272343Sngie atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 139272343Sngie atf_check -s exit:0 rump.ifconfig mpls0 create up 140272343Sngie atf_check -s exit:0 rump.route -q add 10.0.1.0/24 10.0.3.1 141272343Sngie atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS} 142272343Sngie 143272343Sngie unset RUMP_SERVER 144272343Sngie unset LD_PRELOAD 145272343Sngie unset RUMPHIJACK 146272343Sngie} 147272343Sngie 148272343Sngiewait_ldp_ok() { 149272343Sngie 150272343Sngie RUMP_SERVER=${RUMP_SERVER1} atf_check -s exit:0 -o ignore -e ignore \ 151309466Sngie rump.ifconfig -w 60 152309466Sngie RUMP_SERVER=${RUMP_SERVER1} atf_check -s exit:0 -o ignore -e ignore \ 153272343Sngie rump.ping -o -w 60 10.0.4.1 154272343Sngie} 155272343Sngie 156272343Sngiedocleanup() { 157272343Sngie 158272343Sngie RUMP_SERVER=${RUMP_SERVER1} rump.halt 159272343Sngie RUMP_SERVER=${RUMP_SERVER2} rump.halt 160272343Sngie RUMP_SERVER=${RUMP_SERVER3} rump.halt 161272343Sngie RUMP_SERVER=${RUMP_SERVER4} rump.halt 162272343Sngie} 163272343Sngie 164272343Sngieldp_regen_body() { 165272343Sngie 166309466Sngie if sysctl machdep.cpu_brand 2>/dev/null | grep QEMU >/dev/null 2>&1 167272343Sngie then 168272343Sngie atf_skip "unreliable under qemu, skip until PR kern/43997 fixed" 169272343Sngie fi 170272343Sngie create_servers 171272343Sngie wait_ldp_ok 172272343Sngie newaddr_and_ping 173272343Sngie} 174272343Sngie 175272343Sngieldp_regen_cleanup() { 176272343Sngie 177272343Sngie docleanup 178272343Sngie} 179272343Sngie 180272343Sngieatf_init_test_cases() { 181272343Sngie 182272343Sngie atf_add_test_case ldp_regen 183272343Sngie} 184