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