1 1.5 christos # $NetBSD: t_mpls_fw64.sh,v 1.5 2020/04/01 01:49:26 christos Exp $ 2 1.1 kefren # 3 1.1 kefren # Copyright (c) 2015 The NetBSD Foundation, Inc. 4 1.1 kefren # All rights reserved. 5 1.1 kefren # 6 1.1 kefren # Redistribution and use in source and binary forms, with or without 7 1.1 kefren # modification, are permitted provided that the following conditions 8 1.1 kefren # are met: 9 1.1 kefren # 1. Redistributions of source code must retain the above copyright 10 1.1 kefren # notice, this list of conditions and the following disclaimer. 11 1.1 kefren # 2. Redistributions in binary form must reproduce the above copyright 12 1.1 kefren # notice, this list of conditions and the following disclaimer in the 13 1.1 kefren # documentation and/or other materials provided with the distribution. 14 1.1 kefren # 15 1.1 kefren # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 1.1 kefren # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 1.1 kefren # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 1.1 kefren # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 1.1 kefren # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 1.1 kefren # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 1.1 kefren # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 1.1 kefren # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 1.1 kefren # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 1.1 kefren # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 1.1 kefren # POSSIBILITY OF SUCH DAMAGE. 26 1.1 kefren # 27 1.1 kefren 28 1.1 kefren # Test MPLS encap/decap and forwarding using INET6 as encapsulated protocol 29 1.1 kefren # Setup four routers connected like this: R1---R2---R3---R4-- 30 1.1 kefren # Goal is to be able to ping from R1 the outermost interface of R4 31 1.1 kefren # Disable net.inet[6].ip[6].forwarding, enable net.mpls.forwarding 32 1.1 kefren # Use IPv6 between R1-R2-R3 and IPv4 between R3-R4 33 1.1 kefren # As we use IPv4 on last link we should use only expl.null there 34 1.1 kefren # because implicit null will assume IPv4 (as the next-hop) 35 1.1 kefren # But we can use impl null on R2-R1 link because stack will correctly 36 1.1 kefren # guess IPv6 (from next-hop) 37 1.1 kefren # Add route on R1 in order to encapsulate into MPLS the IP6 packets with 38 1.1 kefren # destination equal to R4 right hand side interface 39 1.1 kefren # Add MPLS routes on R2 in order to forward frames belonging to that FEC to R3 40 1.1 kefren # Add MPLS expl.null route on R3 for that FEC, pointing to R4 41 1.1 kefren # Do the same for the reverse direction (R4 to R1) 42 1.1 kefren # ping6 from R1 to R4 right hand side interface 43 1.1 kefren 44 1.1 kefren 45 1.1 kefren configservers() 46 1.1 kefren { 47 1.1 kefren 48 1.1 kefren # Setup the first server 49 1.1 kefren export RUMP_SERVER=${RUMP_SERVER1} 50 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 create 51 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1 52 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::1/64 alias 53 1.1 kefren atf_check -s exit:0 rump.ifconfig mpls0 create up 54 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 55 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0 56 1.1 kefren atf_check -s exit:0 rump.route -q add -inet6 fd00:1234:0:3::/64 \ 57 1.1 kefren -ifa fd00:1234::1 \ 58 1.1 kefren -ifp mpls0 -tag 25 -inet6 fd00:1234::2 59 1.1 kefren 60 1.1 kefren # Setup the second server 61 1.1 kefren export RUMP_SERVER=${RUMP_SERVER2} 62 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 create 63 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1 64 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234::2/64 alias 65 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif1 create 66 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2 67 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:1::1/64 alias 68 1.1 kefren atf_check -s exit:0 rump.ifconfig mpls0 create up 69 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 70 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1 71 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0 72 1.1 kefren atf_check -s exit:0 rump.route -q add -mpls 25 -tag 30 \ 73 1.1 kefren -inet6 fd00:1234:0:1::2 74 1.1 kefren atf_check -s exit:0 rump.route -q add -mpls 27 -tag ${1} -inet6 \ 75 1.1 kefren fd00:1234::1 76 1.1 kefren 77 1.1 kefren # Setup the third server 78 1.1 kefren export RUMP_SERVER=${RUMP_SERVER3} 79 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 create 80 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2 81 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 inet6 fd00:1234:0:1::2/64 alias 82 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif1 create 83 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3 84 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif1 inet 10.0.3.1/24 85 1.1 kefren atf_check -s exit:0 rump.ifconfig mpls0 create up 86 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 87 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1 88 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0 89 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 90 1.1 kefren atf_check -s exit:0 rump.route -q add -mpls 30 -tag 2 \ 91 1.1 kefren -inet 10.0.3.2 92 1.1 kefren atf_check -s exit:0 rump.route -q add -mpls 26 -tag 27 \ 93 1.1 kefren -inet6 fd00:1234:0:1::1 94 1.1 kefren 95 1.1 kefren # Setup the fourth server 96 1.1 kefren export RUMP_SERVER=${RUMP_SERVER4} 97 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 create 98 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3 99 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.3.2 100 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif1 create 101 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4 102 1.1 kefren atf_check -s exit:0 rump.ifconfig shmif1 inet6 fd00:1234:0:3::1/64 alias 103 1.1 kefren atf_check -s exit:0 rump.ifconfig mpls0 create up 104 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1 105 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=0 106 1.1 kefren atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0 107 1.1 kefren atf_check -s exit:0 rump.route -q add -inet6 fd00:1234::/64 \ 108 1.1 kefren -ifa fd00:1234:0:3::1 \ 109 1.1 kefren -ifp mpls0 -tag 26 -inet 10.0.3.1 110 1.1 kefren 111 1.1 kefren unset RUMP_SERVER 112 1.1 kefren } 113 1.1 kefren 114 1.1 kefren doping() 115 1.1 kefren { 116 1.1 kefren 117 1.1 kefren export RUMP_SERVER=${RUMP_SERVER1} 118 1.1 kefren atf_check -s exit:0 \ 119 1.1 kefren -o match:" bytes from fd00:1234::2, icmp_seq=" \ 120 1.2 ozaki rump.ping6 -n -o -X 2 fd00:1234::2 121 1.1 kefren export RUMP_SERVER=${RUMP_SERVER2} 122 1.1 kefren atf_check -s exit:0 \ 123 1.1 kefren -o match:" bytes from fd00:1234:0:1::2, icmp_seq=" \ 124 1.2 ozaki rump.ping6 -n -o -X 2 fd00:1234:0:1::2 125 1.1 kefren export RUMP_SERVER=${RUMP_SERVER3} 126 1.1 kefren atf_check -s exit:0 \ 127 1.1 kefren -o match:" bytes from 10.0.3.2: icmp_seq" \ 128 1.1 kefren rump.ping -n -o -w 2 10.0.3.2 129 1.1 kefren export RUMP_SERVER=${RUMP_SERVER1} 130 1.1 kefren atf_check -s exit:0 \ 131 1.1 kefren -o match:" bytes from fd00:1234:0:3::1, icmp_seq=" \ 132 1.2 ozaki rump.ping6 -n -o -X 2 fd00:1234:0:3::1 133 1.1 kefren unset RUMP_SERVER 134 1.1 kefren } 135 1.1 kefren 136 1.1 kefren do_check_route() 137 1.1 kefren { 138 1.1 kefren 139 1.1 kefren export RUMP_SERVER=${RUMP_SERVER1} 140 1.1 kefren atf_check -s exit:0 \ 141 1.1 kefren -o match:"^fd00:1234:0:3::/64.+fd00:1234::2.+25.+mpls0" \ 142 1.1 kefren rump.netstat -nrT 143 1.1 kefren unset RUMP_SERVER 144 1.1 kefren } 145 1.1 kefren 146 1.1 kefren atf_test_case mplsfw64_impl cleanup 147 1.1 kefren mplsfw64_impl_head() 148 1.1 kefren { 149 1.1 kefren 150 1.1 kefren atf_set "descr" "IP6/MPLS test using impl. NULL labels in mixed env." 151 1.1 kefren atf_set "require.progs" "rump_server" 152 1.1 kefren } 153 1.1 kefren 154 1.1 kefren mplsfw64_impl_body() 155 1.1 kefren { 156 1.1 kefren 157 1.5 christos dostart 158 1.1 kefren configservers 3 159 1.1 kefren do_check_route 160 1.1 kefren doping 161 1.1 kefren } 162 1.1 kefren 163 1.1 kefren mplsfw64_impl_cleanup() 164 1.1 kefren { 165 1.1 kefren 166 1.1 kefren docleanup 167 1.1 kefren } 168 1.1 kefren 169 1.1 kefren 170 1.1 kefren atf_test_case mplsfw64_expl cleanup 171 1.1 kefren mplsfw64_expl_head() 172 1.1 kefren { 173 1.1 kefren 174 1.1 kefren atf_set "descr" "IP6/MPLS test using explicit NULL labels in mixed env." 175 1.1 kefren atf_set "require.progs" "rump_server" 176 1.1 kefren } 177 1.1 kefren 178 1.1 kefren mplsfw64_expl_body() 179 1.1 kefren { 180 1.1 kefren 181 1.5 christos dostart 182 1.1 kefren configservers 2 183 1.1 kefren do_check_route 184 1.1 kefren doping 185 1.1 kefren } 186 1.1 kefren 187 1.1 kefren mplsfw64_expl_cleanup() 188 1.1 kefren { 189 1.1 kefren 190 1.1 kefren docleanup 191 1.1 kefren } 192 1.1 kefren 193 1.1 kefren 194 1.1 kefren atf_init_test_cases() 195 1.1 kefren { 196 1.1 kefren 197 1.1 kefren atf_add_test_case mplsfw64_impl 198 1.1 kefren atf_add_test_case mplsfw64_expl 199 1.1 kefren } 200