Mon Mar 28 01:53:07 2016 UTC ()
Add tests for "route get"


(ozaki-r)
diff -r1.1 -r1.2 src/tests/net/route/t_route.sh

cvs diff -r1.1 -r1.2 src/tests/net/route/t_route.sh (expand / switch to unified diff)

--- src/tests/net/route/t_route.sh 2016/01/29 04:15:46 1.1
+++ src/tests/net/route/t_route.sh 2016/03/28 01:53:07 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: t_route.sh,v 1.1 2016/01/29 04:15:46 ozaki-r Exp $ 1# $NetBSD: t_route.sh,v 1.2 2016/03/28 01:53:07 ozaki-r Exp $
2# 2#
3# Copyright (c) 2016 Internet Initiative Japan Inc. 3# Copyright (c) 2016 Internet Initiative Japan Inc.
4# All rights reserved. 4# All rights reserved.
5# 5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14# 14#
@@ -16,30 +16,49 @@ @@ -16,30 +16,49 @@
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 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 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE. 25# POSSIBILITY OF SUCH DAMAGE.
26# 26#
27 27
28RUMP_LIBS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif" 28RUMP_LIBS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
 29RUMP_LIBS_IPV6="$RUMP_LIBS -lrumpnet_netinet6"
 30
 31# non_subnet_gateway
29SOCK_CLIENT=unix://commsock1 32SOCK_CLIENT=unix://commsock1
30SOCK_GW=unix://commsock2 33SOCK_GW=unix://commsock2
31BUS=bus1 34BUS=bus1
32 35
 36# command_get
 37SOCKSRC=unix://commsock1
 38SOCKFWD=unix://commsock2
 39SOCKDST=unix://commsock3
 40IP4SRC=10.0.1.2
 41IP4SRCGW=10.0.1.1
 42IP4DSTGW=10.0.2.1
 43IP4DST=10.0.2.2
 44IP4DST_BCAST=10.0.2.255
 45IP6SRC=fc00:0:0:1::2
 46IP6SRCGW=fc00:0:0:1::1
 47IP6DSTGW=fc00:0:0:2::1
 48IP6DST=fc00:0:0:2::2
 49BUS_SRCGW=bus1
 50BUS_DSTGW=bus2
 51
33DEBUG=false 52DEBUG=false
34TIMEOUT=1 53TIMEOUT=1
35PING_OPTS="-n -c 1 -w $TIMEOUT" 54PING_OPTS="-n -c 1 -w $TIMEOUT"
36 55
37atf_test_case non_subnet_gateway cleanup 56atf_test_case non_subnet_gateway cleanup
38non_subnet_gateway_head() 57non_subnet_gateway_head()
39{ 58{
40 59
41 atf_set "descr" "tests of a gateway not on the local subnet" 60 atf_set "descr" "tests of a gateway not on the local subnet"
42 atf_set "require.progs" "rump_server" 61 atf_set "require.progs" "rump_server"
43} 62}
44 63
45non_subnet_gateway_body() 64non_subnet_gateway_body()
@@ -86,18 +105,325 @@ non_subnet_gateway_body() @@ -86,18 +105,325 @@ non_subnet_gateway_body()
86 atf_check -s exit:0 -o ignore rump.ping $PING_OPTS 192.168.0.1 105 atf_check -s exit:0 -o ignore rump.ping $PING_OPTS 192.168.0.1
87 106
88 unset RUMP_SERVER 107 unset RUMP_SERVER
89} 108}
90 109
91non_subnet_gateway_cleanup() 110non_subnet_gateway_cleanup()
92{ 111{
93 112
94 $DEBUG && shmif_dumpbus -p - $BUS 2>/dev/null | tcpdump -n -e -r - 113 $DEBUG && shmif_dumpbus -p - $BUS 2>/dev/null | tcpdump -n -e -r -
95 env RUMP_SERVER=$SOCK_CLIENT rump.halt 114 env RUMP_SERVER=$SOCK_CLIENT rump.halt
96 env RUMP_SERVER=$SOCK_GW rump.halt 115 env RUMP_SERVER=$SOCK_GW rump.halt
97} 116}
98 117
 118atf_test_case command_get cleanup
 119atf_test_case command_get6 cleanup
 120command_get_head()
 121{
 122
 123 atf_set "descr" "tests of route get command"
 124 atf_set "require.progs" "rump_server"
 125}
 126
 127command_get6_head()
 128{
 129
 130 atf_set "descr" "tests of route get command (IPv6)"
 131 atf_set "require.progs" "rump_server"
 132}
 133
 134setup_endpoint()
 135{
 136 local sock=${1}
 137 local addr=${2}
 138 local bus=${3}
 139 local mode=${4}
 140 local gw=${5}
 141
 142 export RUMP_SERVER=${sock}
 143 atf_check -s exit:0 rump.ifconfig shmif0 create
 144 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${bus}
 145 if [ $mode = "ipv6" ]; then
 146 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
 147 atf_check -s exit:0 -o ignore rump.route add -inet6 default ${gw}
 148 else
 149 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
 150 atf_check -s exit:0 -o ignore rump.route add default ${gw}
 151 fi
 152 atf_check -s exit:0 rump.ifconfig shmif0 up
 153
 154 if $DEBUG; then
 155 rump.ifconfig shmif0
 156 rump.netstat -nr
 157 fi
 158}
 159
 160setup_forwarder()
 161{
 162 mode=${1}
 163
 164 export RUMP_SERVER=$SOCKFWD
 165 atf_check -s exit:0 rump.ifconfig shmif0 create
 166 atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS_SRCGW
 167
 168 atf_check -s exit:0 rump.ifconfig shmif1 create
 169 atf_check -s exit:0 rump.ifconfig shmif1 linkstr $BUS_DSTGW
 170
 171 if [ $mode = "ipv6" ]; then
 172 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6SRCGW}
 173 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DSTGW}
 174 else
 175 atf_check -s exit:0 rump.ifconfig shmif0 inet ${IP4SRCGW} netmask 0xffffff00
 176 atf_check -s exit:0 rump.ifconfig shmif1 inet ${IP4DSTGW} netmask 0xffffff00
 177 fi
 178
 179 atf_check -s exit:0 rump.ifconfig shmif0 up
 180 atf_check -s exit:0 rump.ifconfig shmif1 up
 181
 182 if $DEBUG; then
 183 rump.netstat -nr
 184 if [ $mode = "ipv6" ]; then
 185 rump.sysctl net.inet6.ip6.forwarding
 186 else
 187 rump.sysctl net.inet.ip.forwarding
 188 fi
 189 fi
 190}
 191
 192setup_forwarding()
 193{
 194 export RUMP_SERVER=$SOCKFWD
 195 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
 196}
 197
 198setup_forwarding6()
 199{
 200 export RUMP_SERVER=$SOCKFWD
 201 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=1
 202}
 203
 204setup()
 205{
 206
 207 atf_check -s exit:0 rump_server $RUMP_LIBS $SOCKSRC
 208 atf_check -s exit:0 rump_server $RUMP_LIBS $SOCKFWD
 209 atf_check -s exit:0 rump_server $RUMP_LIBS $SOCKDST
 210
 211 setup_endpoint $SOCKSRC $IP4SRC $BUS_SRCGW ipv4 $IP4SRCGW
 212 setup_endpoint $SOCKDST $IP4DST $BUS_DSTGW ipv4 $IP4DSTGW
 213 setup_forwarder ipv4
 214}
 215
 216setup6()
 217{
 218
 219 atf_check -s exit:0 rump_server $RUMP_LIBS_IPV6 $SOCKSRC
 220 atf_check -s exit:0 rump_server $RUMP_LIBS_IPV6 $SOCKFWD
 221 atf_check -s exit:0 rump_server $RUMP_LIBS_IPV6 $SOCKDST
 222
 223 setup_endpoint $SOCKSRC $IP6SRC $BUS_SRCGW ipv6 $IP6SRCGW
 224 setup_endpoint $SOCKDST $IP6DST $BUS_DSTGW ipv6 $IP6DSTGW
 225 setup_forwarder ipv6
 226}
 227
 228test_route_get()
 229{
 230
 231 export RUMP_SERVER=$SOCKSRC
 232 $DEBUG && rump.netstat -nr -f inet
 233 $DEBUG && rump.arp -n -a
 234
 235 # Make sure an ARP cache to the gateway doesn't exist
 236 rump.arp -d $IP4SRCGW
 237
 238 # Local
 239 cat >./expect <<-EOF
 240 route to: 10.0.1.2
 241destination: 10.0.1.2
 242 local addr: 10.0.1.2
 243 interface: lo0
 244 flags: <UP,HOST,DONE,LLINFO,LOCAL>
 245 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
 246 0 0 0 0 0 0 0 0
 247 EOF
 248 rump.route -n get $IP4SRC > ./output
 249 $DEBUG && cat ./expect ./output
 250 atf_check -s exit:0 diff -q ./expect ./output
 251
 252 # Neighbor
 253 cat >./expect <<-EOF
 254 route to: 10.0.1.1
 255destination: 10.0.1.0
 256 mask: 255.255.255.0
 257 local addr: 10.0.1.2
 258 interface: shmif0
 259 flags: <UP,DONE,CLONING>
 260 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
 261 0 0 0 0 0 0 0 0
 262 EOF
 263 rump.route -n get $IP4SRCGW > ./output
 264 $DEBUG && cat ./expect ./output
 265 atf_check -s exit:0 diff -q ./expect ./output
 266
 267 # Remote host
 268 cat >./expect <<-EOF
 269 route to: 10.0.2.2
 270destination: default
 271 mask: default
 272 gateway: 10.0.1.1
 273 local addr: 10.0.1.2
 274 interface: shmif0
 275 flags: <UP,GATEWAY,DONE,STATIC>
 276 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
 277 0 0 0 0 0 0 0 0
 278 EOF
 279 rump.route -n get $IP4DST > ./output
 280 $DEBUG && cat ./expect ./output
 281 atf_check -s exit:0 diff -q ./expect ./output
 282
 283 # Create a ARP cache
 284 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRCGW
 285
 286 # Neighbor with a cache (cloned route)
 287 cat >./expect <<-EOF
 288 route to: 10.0.1.1
 289destination: 10.0.1.1
 290 local addr: 10.0.1.2
 291 interface: shmif0
 292 flags: <UP,HOST,DONE,LLINFO,CLONED>
 293 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
 294 EOF
 295 rump.route -n get $IP4SRCGW > ./output
 296 $DEBUG && cat ./expect ./output
 297 # Trim the last line including unfixed expire time
 298 head -6 ./output > ./trimed
 299 atf_check -s exit:0 diff -q ./expect ./trimed
 300}
 301
 302test_route_get6()
 303{
 304
 305 export RUMP_SERVER=$SOCKSRC
 306 $DEBUG && rump.netstat -nr -f inet
 307 $DEBUG && rump.ndp -n -a
 308
 309 # Make sure an ARP cache to the gateway doesn't exist
 310 rump.ndp -d $IP6SRCGW
 311
 312 # Local
 313 cat >./expect <<-EOF
 314 route to: fc00:0:0:1::2
 315destination: fc00:0:0:1::2
 316 local addr: fc00:0:0:1::2
 317 interface: lo0
 318 flags: <UP,HOST,DONE,LLINFO,LOCAL>
 319 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
 320 0 0 0 0 0 0 0 0
 321 EOF
 322 rump.route -n get -inet6 $IP6SRC > ./output
 323 $DEBUG && cat ./expect ./output
 324 atf_check -s exit:0 diff -q ./expect ./output
 325
 326 # Neighbor
 327 cat >./expect <<-EOF
 328 route to: fc00:0:0:1::1
 329destination: fc00:0:0:1::
 330 mask: ffff:ffff:ffff:ffff::
 331 local addr: fc00:0:0:1::2
 332 interface: shmif0
 333 flags: <UP,DONE,CLONING>
 334 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
 335 0 0 0 0 0 0 0 0
 336 EOF
 337 rump.route -n get -inet6 $IP6SRCGW > ./output
 338 $DEBUG && cat ./expect ./output
 339 atf_check -s exit:0 diff -q ./expect ./output
 340
 341 # Remote host
 342 cat >./expect <<-EOF
 343 route to: fc00:0:0:2::2
 344destination: ::
 345 mask: default
 346 gateway: fc00:0:0:1::1
 347 local addr: fc00:0:0:1::2
 348 interface: shmif0
 349 flags: <UP,GATEWAY,DONE,STATIC>
 350 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
 351 0 0 0 0 0 0 0 0
 352 EOF
 353 rump.route -n get -inet6 $IP6DST > ./output
 354 $DEBUG && cat ./expect ./output
 355 atf_check -s exit:0 diff -q ./expect ./output
 356
 357 # Create a NDP cache
 358 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6SRCGW
 359
 360 # Neighbor with a cache (cloned route)
 361 cat >./expect <<-EOF
 362 route to: fc00:0:0:1::1
 363destination: fc00:0:0:1::1
 364 local addr: fc00:0:0:1::2
 365 interface: shmif0
 366 flags: <UP,HOST,DONE,LLINFO,CLONED>
 367 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
 368 0 0 0 0 0 0 0 0
 369 EOF
 370 rump.route -n get -inet6 $IP6SRCGW > ./output
 371 $DEBUG && cat ./expect ./output
 372 # No need to trim, because a NDP cache doesn't set an expire time
 373 atf_check -s exit:0 diff -q ./expect ./output
 374}
 375
 376command_get_body()
 377{
 378
 379 setup
 380 setup_forwarding
 381 test_route_get
 382}
 383
 384command_get6_body()
 385{
 386
 387 setup6
 388 setup_forwarding6
 389 test_route_get6
 390}
 391
 392dump()
 393{
 394
 395 env RUMP_SERVER=$SOCKSRC rump.netstat -nr
 396 env RUMP_SERVER=$SOCKFWD rump.netstat -nr
 397 env RUMP_SERVER=$SOCKDST rump.netstat -nr
 398
 399 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
 400 shmif_dumpbus -p - bus2 2>/dev/null| tcpdump -n -e -r -
 401}
 402
 403cleanup()
 404{
 405
 406 env RUMP_SERVER=$SOCKSRC rump.halt
 407 env RUMP_SERVER=$SOCKFWD rump.halt
 408 env RUMP_SERVER=$SOCKDST rump.halt
 409}
 410
 411command_get_cleanup()
 412{
 413 $DEBUG && dump
 414 cleanup
 415}
 416
 417command_get6_cleanup()
 418{
 419 dump
 420 cleanup
 421}
 422
99atf_init_test_cases() 423atf_init_test_cases()
100{ 424{
101 425
102 atf_add_test_case non_subnet_gateway 426 atf_add_test_case non_subnet_gateway
 427 atf_add_test_case command_get
 428 atf_add_test_case command_get6
103} 429}