Home | History | Annotate | Line # | Download | only in traceroute
t_traceroute.sh revision 1.2
      1 #	$NetBSD: t_traceroute.sh,v 1.2 2010/12/18 08:34:56 pooka Exp $
      2 #
      3 # Copyright (c) 2010 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 atf_test_case basic cleanup
     29 basic_head()
     30 {
     31 
     32 	atf_set "descr" "Does a simple three-hop traceroute"
     33 }
     34 
     35 cfgendpt ()
     36 {
     37 
     38 	sock=${1}
     39 	addr=${2}
     40 	route=${3}
     41 	bus=${4}
     42 
     43 	export RUMP_SERVER=${sock}
     44 	atf_check -s exit:0 rump.ifconfig shmif0 create
     45 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${bus}
     46 	atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
     47 	atf_check -s exit:0 -o ignore rump.route add default ${route}
     48 }
     49 
     50 threeservers()
     51 {
     52 
     53 	atf_check -s exit:0 rump_allserver unix://commsock1
     54 	atf_check -s exit:0 rump_allserver unix://commsock2
     55 	atf_check -s exit:0 rump_allserver unix://commsock3
     56 
     57 	# configure endpoints
     58 	cfgendpt unix://commsock1 1.2.3.4 1.2.3.1 bus1
     59 	cfgendpt unix://commsock3 2.3.4.5 2.3.4.1 bus2
     60 
     61 	# configure the router
     62 	export RUMP_SERVER=unix://commsock2
     63 	atf_check -s exit:0 rump.ifconfig shmif0 create
     64 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
     65 	atf_check -s exit:0 rump.ifconfig shmif0 inet 1.2.3.1 netmask 0xffffff00
     66 
     67 	atf_check -s exit:0 rump.ifconfig shmif1 create
     68 	atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus2
     69 	atf_check -s exit:0 rump.ifconfig shmif1 inet 2.3.4.1 netmask 0xffffff00
     70 }
     71 
     72 threecleanup()
     73 {
     74 	env RUMP_SERVER=unix://commsock1 rump.halt
     75 	env RUMP_SERVER=unix://commsock2 rump.halt
     76 	env RUMP_SERVER=unix://commsock3 rump.halt
     77 }
     78 
     79 threetests()
     80 {
     81 
     82 	threeservers
     83 	export RUMP_SERVER=unix://commsock1
     84 	atf_check -s exit:0	\
     85 	     -o save:tmpfile -e ignore rump.traceroute ${1} -n 2.3.4.5
     86 	atf_check -o inline:'1.2.3.1\n2.3.4.5\n' awk '{print $2}' < tmpfile
     87 	export RUMP_SERVER=unix://commsock3
     88 	atf_check -s exit:0	\
     89 	     -o save:tmpfile -e ignore rump.traceroute ${1} -n 1.2.3.4
     90 	atf_check -o inline:'2.3.4.1\n1.2.3.4\n' awk '{print $2}' < tmpfile
     91 }
     92 
     93 basic_body()
     94 {
     95 	threetests
     96 }
     97 
     98 basic_cleanup()
     99 {
    100 	threecleanup
    101 }
    102 
    103 atf_test_case basic_icmp cleanup
    104 basic_icmp_head()
    105 {
    106 
    107 	atf_set "descr" "Does an ICMP-based three-hop traceroute"
    108 }
    109 
    110 basic_icmp_body()
    111 {
    112 	threetests -I
    113 }
    114 
    115 basic_icmp_cleanup()
    116 {
    117 	threecleanup
    118 }
    119 
    120 atf_init_test_cases()
    121 {
    122 
    123 	atf_add_test_case basic
    124 	atf_add_test_case basic_icmp
    125 }
    126