1# $NetBSD: t_ldp_regen.sh,v 1.11 2021/11/25 14:17:22 hannken 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 38LDP_FLAGS="" 39 40atf_test_case ldp_regen cleanup 41ldp_regen_head() { 42 43 atf_set "descr" "IP/MPLS and LDP label regeneration test" 44 atf_set "require.progs" "rump_server" 45 atf_set "use.fs" "true" 46} 47 48newaddr_and_ping() { 49 50 # Add new address on R4 51 RUMP_SERVER=${RUMP_SERVER4} atf_check -s exit:0 \ 52 rump.ifconfig shmif1 10.0.5.1/24 alias 53 RUMP_SERVER=${RUMP_SERVER4} atf_check -s exit:0 \ 54 rump.ifconfig -w 60 55 56 # Now ldpd on R5 should take notice of the new route and announce it 57 # to R4's ldpd. ldpd on R4 should verify that the next hop 58 # corresponds to its routing table and change its tag entry 59 RUMP_SERVER=${RUMP_SERVER1} atf_check -s exit:0 -o ignore -e ignore \ 60 rump.ping -n -o -w 5 10.0.5.1 61} 62 63configservers() { 64 65 # LDP HIJACK 66 export RUMPHIJACK=path=/rump,socket=all,sysctl=yes 67 export LD_PRELOAD=/usr/lib/librumphijack.so 68 69 # Setup first server 70 export RUMP_SERVER=${RUMP_SERVER1} 71 atf_check -s exit:0 rump.ifconfig shmif0 create 72 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1 73 atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.1/24 74 atf_check -s exit:0 rump.ifconfig mpls0 create up 75 atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 76 atf_check -s exit:0 rump.route -q add 10.0.4.0/24 10.0.1.2 77 atf_check -s exit:0 rump.route -q add 10.0.5.0/24 10.0.1.2 78 atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS} 79 80 # Setup second server 81 export RUMP_SERVER=${RUMP_SERVER2} 82 atf_check -s exit:0 rump.ifconfig shmif0 create 83 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1 84 atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.2/24 85 atf_check -s exit:0 rump.ifconfig shmif1 create 86 atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2 87 atf_check -s exit:0 rump.ifconfig shmif1 10.0.2.1/24 88 atf_check -s exit:0 rump.ifconfig mpls0 create up 89 atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 90 atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1 91 # This one should still do ip forwarding because it announces IMPLNULL 92 # for the 10.0.1.0/24 subnet 93 atf_check -s exit:0 rump.route -q add 10.0.4.0/24 10.0.2.2 94 atf_check -s exit:0 rump.route -q add 10.0.5.0/24 10.0.2.2 95 atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS} 96 97 # Setup third server 98 export RUMP_SERVER=${RUMP_SERVER3} 99 atf_check -s exit:0 rump.ifconfig shmif0 create 100 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2 101 atf_check -s exit:0 rump.ifconfig shmif0 10.0.2.2/24 102 atf_check -s exit:0 rump.ifconfig shmif1 create 103 atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3 104 atf_check -s exit:0 rump.ifconfig shmif1 10.0.3.1/24 105 atf_check -s exit:0 rump.ifconfig mpls0 create up 106 atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 107 atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1 108 atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 109 atf_check -s exit:0 rump.route -q add 10.0.1.0/24 10.0.2.1 110 atf_check -s exit:0 rump.route -q add 10.0.4.0/24 10.0.3.2 111 atf_check -s exit:0 rump.route -q add 10.0.5.0/24 10.0.3.2 112 atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS} 113 114 # Setup fourth server 115 export RUMP_SERVER=${RUMP_SERVER4} 116 atf_check -s exit:0 rump.ifconfig shmif0 create 117 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3 118 atf_check -s exit:0 rump.ifconfig shmif0 10.0.3.2/24 119 atf_check -s exit:0 rump.ifconfig shmif1 create 120 atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4 121 atf_check -s exit:0 rump.ifconfig shmif1 10.0.4.1/24 122 atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 123 atf_check -s exit:0 rump.ifconfig mpls0 create up 124 atf_check -s exit:0 rump.route -q add 10.0.1.0/24 10.0.3.1 125 atf_check -s exit:0 /usr/sbin/ldpd ${LDP_FLAGS} 126 127 unset RUMP_SERVER 128 unset LD_PRELOAD 129 unset RUMPHIJACK 130} 131 132wait_ldp_ok() { 133 134 RUMP_SERVER=${RUMP_SERVER1} atf_check -s exit:0 -o ignore -e ignore \ 135 rump.ifconfig -w 60 136 RUMP_SERVER=${RUMP_SERVER1} atf_check -s exit:0 -o ignore -e ignore \ 137 rump.ping -o -w 60 10.0.4.1 138} 139 140ldp_regen_body() { 141 142 if drvctl -l qemufwcfg0 >/dev/null 2>&1 143 then 144 atf_skip "unreliable under qemu, skip until PR kern/43997 fixed" 145 fi 146 dostart 147 configservers 148 wait_ldp_ok 149 newaddr_and_ping 150} 151 152ldp_regen_cleanup() { 153 154 docleanup 155} 156 157atf_init_test_cases() { 158 159 atf_add_test_case ldp_regen 160} 161