Home | History | Annotate | Download | only in route
      1 #!/bin/sh
      2 
      3 ################################################################################
      4 ##                                                                            ##
      5 ## Copyright (c) International Business Machines  Corp., 2006                 ##
      6 ##                                                                            ##
      7 ## This program is free software;  you can redistribute it and#or modify      ##
      8 ## it under the terms of the GNU General Public License as published by       ##
      9 ## the Free Software Foundation; either version 2 of the License, or          ##
     10 ## (at your option) any later version.                                        ##
     11 ##                                                                            ##
     12 ## This program is distributed in the hope that it will be useful, but        ##
     13 ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
     14 ## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
     15 ## for more details.                                                          ##
     16 ##                                                                            ##
     17 ## You should have received a copy of the GNU General Public License          ##
     18 ## along with this program;  if not, write to the Free Software               ##
     19 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
     20 ##                                                                            ##
     21 ##                                                                            ##
     22 ################################################################################
     23 #
     24 # File:
     25 #   route6-ifdown
     26 #
     27 # Description:
     28 #   Verify the kernel is not crashed when IPv6 route is add then it is deleted
     29 #   by the interface down
     30 #
     31 # Setup:
     32 #   See ltp-yyyymmdd/testcases/network/stress/README
     33 #
     34 # Author:
     35 #   Mitsuru Chinen <mitch (at] jp.ibm.com>
     36 #
     37 # History:
     38 #	Apr 8 2006 - Created (Mitsuru Chinen)
     39 #
     40 #-----------------------------------------------------------------------
     41 # Uncomment line below for debug output.
     42 #trace_logic=${trace_logic:-"set -x"}
     43 $trace_logic
     44 
     45 # Make sure the value of LTPROOT
     46 LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
     47 export LTPROOT
     48 
     49 # Total number of the test case
     50 TST_TOTAL=2
     51 export TST_TOTAL
     52 
     53 # Default of the test case ID and the test case count
     54 TCID=route6-ifdown
     55 TST_COUNT=0
     56 export TCID
     57 export TST_COUNT
     58 
     59 # Check the environmanet variable
     60 . check_envval || exit $TST_TOTAL
     61 
     62 # The number of times where route is add/delete
     63 NS_TIMES=${NS_TIMES:-10000}
     64 
     65 # The number of the test link where tests run
     66 LINK_NUM=${LINK_NUM:-0}
     67 
     68 # Network portion of the IPv6 address
     69 IPV6_NETWORK="fec0:1:1:1"
     70 
     71 # Netmask of for the tested network
     72 IPV6_NETMASK_NUM=64
     73 
     74 # Host portion of the IPv6 address
     75 LHOST_IPV6_HOST=":2"	# src
     76 RHOST_IPV6_HOST=":1"	# gateway
     77 
     78 # The destination network
     79 DST_NETWORK="fec0:100:100:100"	# destination network
     80 DST_HOST=":5"
     81 DST_PORT="7"
     82 
     83 
     84 #-----------------------------------------------------------------------
     85 #
     86 # NAME:
     87 #   do_cleanup
     88 #
     89 # DESCRIPTION:
     90 #   Recover the tested interfaces
     91 #
     92 #-----------------------------------------------------------------------
     93 do_cleanup()
     94 {
     95     # Initialize the interfaces
     96     initialize_if lhost ${LINK_NUM}
     97     initialize_if rhost ${LINK_NUM}
     98 }
     99 
    100 
    101 #-----------------------------------------------------------------------
    102 #
    103 # NAME:
    104 #   do_setup
    105 #
    106 # DESCRIPTION:
    107 #   Make a IPv6 connectivity
    108 #
    109 # SET VALUES:
    110 #   rhost_ipv6addr	- IPv6 Address of the remote host
    111 #   lhost_ifname	- Interface name of the local host
    112 #   rhost_ifname	- Interface name of the remote host
    113 #
    114 #-----------------------------------------------------------------------
    115 do_setup()
    116 {
    117     # Make sure to clean up
    118     do_cleanup
    119 
    120     # IP addres of the local host
    121     lhost_ipv6addr="${IPV6_NETWORK}:${LHOST_IPV6_HOST}"
    122 
    123     # Set IPv6 address to the interfaces of the remote host
    124     add_ipv6addr rhost ${LINK_NUM} ${IPV6_NETWORK} ${RHOST_IPV6_HOST}
    125     if [ $? -ne 0 ]; then
    126 	tst_resm TBROK "Failed to add an IPv6 address the remote host"
    127 	exit $TST_TOTAL
    128     fi
    129     rhost_ipv6addr="${IPV6_NETWORK}:${RHOST_IPV6_HOST}"
    130 
    131     # Get the Interface names
    132     lhost_ifname=`get_ifname lhost ${LINK_NUM}`
    133     if [ $? -ne 0 ]; then
    134 	tst_resm TBROK "Failed to get the interface name at the local host"
    135 	exit $TST_TOTAL
    136     fi
    137 
    138     rhost_ifname=`get_ifname rhost ${LINK_NUM}`
    139     if [ $? -ne 0 ]; then
    140 	tst_resm TBROK "Failed to get the interface name at the remote host"
    141 	exit $TST_TOTAL
    142     fi
    143 
    144     # Set the variables for destination network
    145     dst_addr=${DST_NETWORK}:${DST_HOST}
    146     dst_network=${DST_NETWORK}::
    147 }
    148 
    149 
    150 #-----------------------------------------------------------------------
    151 #
    152 # FUNCTION:
    153 #   test_body
    154 #
    155 # DESCRIPTION:
    156 #   main code of the test
    157 #
    158 # Arguments:
    159 #   $1: define the test type
    160 #	1 - route command case
    161 #	2 - ip command case
    162 #
    163 #-----------------------------------------------------------------------
    164 test_body()
    165 {
    166     test_type=$1
    167 
    168     TCID=route6-ifdown0${test_type}
    169     TST_COUNT=$test_type
    170 
    171     case $test_type in
    172 	1)
    173 	tst_resm TINFO "Verify the kernel is not crashed when IPv6 route is add by route command then it is deleted by the interface down with ifconfing command in $NS_TIMES times"
    174 	;;
    175 	2)
    176 	tst_resm TINFO "Verify the kernel is not crashed when IPv6 route is add by ip command then it is deleted by the interface down with ip command in $NS_TIMES times"
    177 	;;
    178 	*)
    179 	tst_resm TBROK "unspecified case"
    180 	return 1
    181 	;;
    182     esac
    183 
    184     # Start the loop
    185     cnt=0
    186     while [ $cnt -lt $NS_TIMES ]; do
    187 	# Assign IPv6 address to the interface of the local host
    188 	add_ipv6addr lhost ${LINK_NUM} ${IPV6_NETWORK} ${LHOST_IPV6_HOST}
    189 	if [ $? -ne 0 ]; then
    190 	    tst_resm TBROK "Failed to assign an IPv6 address at the local host"
    191 	    return 1
    192 	fi
    193 
    194 	# Check the connectivity to the gateway
    195 	check_icmpv6_connectivity $lhost_ifname $rhost_ipv6addr
    196 	if [ $? -ne 0 ]; then
    197 	    tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
    198 	    return 1
    199 	fi
    200 
    201 	# Add the route
    202 	case $test_type in
    203 	    1)
    204 	    route -A inet6 add ${dst_network}/64 gw $rhost_ipv6addr dev $lhost_ifname
    205 	    ;;
    206 	    2)
    207 	    ip -f inet6 route add ${dst_network}/64 via $rhost_ipv6addr dev $lhost_ifname
    208 	    ;;
    209 	esac
    210 	if [ $? -ne 0 ]; then
    211 	    tst_resm TFAIL "Failed to add the route to ${dst_network}/64"
    212 	    return 1
    213 	fi
    214 
    215 	# Load the route with UDP datagram
    216 	ns-udpsender -f 6 -D $dst_addr -p $DST_PORT -o -s 1452
    217 	if [ $? -ne 0 ]; then
    218 	    tst_resm TFAIL "Failed to run a UDP datagram sender"
    219 	    return 1
    220 	fi
    221 
    222 	# Down then up the interface
    223 	case $test_type in
    224 	    1)
    225 	    ifconfig $lhost_ifname down && ifconfig $lhost_ifname up
    226 	    ;;
    227 	    2)
    228 	    ip link set down dev $lhost_ifname && ip link set up dev $lhost_ifname
    229 	    ;;
    230 	esac
    231 	if [ $? -ne 0 ]; then
    232 	    tst_resm TFAIL "Failed to down/up the interface"
    233 	    return 1
    234 	fi
    235 
    236 	cnt=`expr $cnt + 1`
    237     done
    238 
    239     tst_resm TPASS "Test is finished correctly."
    240     return 0
    241 }
    242 
    243 
    244 #-----------------------------------------------------------------------
    245 #
    246 # Main
    247 #
    248 # Exit Value:
    249 #   The number of the failure
    250 #
    251 #-----------------------------------------------------------------------
    252 
    253 RC=0
    254 do_setup
    255 test_body 1 || RC=`expr $RC + 1`      # Case of route command
    256 test_body 2 || RC=`expr $RC + 1`      # Case of ip command
    257 do_cleanup
    258 
    259 exit $RC
    260