Home | History | Annotate | Download | only in ns-tools
      1 #!/bin/sh
      2 
      3 ################################################################################
      4 ##                                                                            ##
      5 ## Copyright (c) International Business Machines  Corp., 2005                 ##
      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 #   add_ipv6addr
     26 #
     27 # Description:
     28 #   Add an IPv6 address to the interface which belongs to the specified
     29 #   test link
     30 #
     31 # Author:
     32 #   Mitsuru Chinen <mitch (at] jp.ibm.com>
     33 #
     34 # Arguments:
     35 #   $1: target host to add the IPv6 address
     36 #	  lhost - local host / rhost - remote host
     37 #   $2: number of the test link
     38 #   $3: network portion of the IPv6 address
     39 #   $4: host portion of the IPv6 address
     40 #
     41 # Exit Value:
     42 #    0: Exit normally
     43 #   >0: Exit abnormally
     44 #
     45 # History:
     46 #   Oct 19 2005 - Created (Mitsuru Chinen)
     47 #
     48 #-----------------------------------------------------------------------
     49 #Uncomment line below for debug output.
     50 #trace_logic=${trace_logic:-"set -x"}
     51 $trace_logic
     52 
     53 # Make sure the value of LTPROOT
     54 LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
     55 export LTPROOT
     56 
     57 # Check the environmanet variable for the test
     58 . check_envval || exit 1
     59 
     60 # Arguments
     61 if [ $# -ne 4 ]; then
     62     echo "Usage: $0 host_type link_number network_portion host_portion" >&2
     63     exit 1
     64 fi
     65 host_type=$1
     66 link_num=$2
     67 network_part=$3
     68 host_part=$4
     69 
     70 # Check the host type
     71 if [ $host_type != lhost -a $host_type != rhost ]; then
     72     echo "$0: 1st argumet is lhost or rhost" >&2
     73     exit 1
     74 fi
     75 
     76 # Define IPv6 address and netmask
     77 addr="${network_part}:${host_part}"
     78 netmask=64
     79 
     80 # Assign IPv6 address to the interface belongs the nth Test Link
     81 ifname=`get_ifname $host_type $link_num` || exit 1
     82 
     83 if [ $host_type = lhost ]; then
     84     ifconfig ${ifname} up ; ifconfig ${ifname} add ${addr}/${netmask}
     85     ret=$?
     86 else
     87     ret=`$LTP_RSH $RHOST '( PATH=/sbin:/usr/sbin:$PATH ; ifconfig '${ifname}' up && ifconfig '${ifname}' add '${addr}/${netmask}' ) >/dev/null 2>&1; echo $?'`
     88 fi
     89 
     90 if [ $ret -ne 0 ]; then
     91     echo "Cannot assign $addr to $ifname" >&2
     92     exit 1
     93 fi
     94