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# route4-rmmod 26f08c3bdfSopenharmony_ci# 27f08c3bdfSopenharmony_ci# Description: 28f08c3bdfSopenharmony_ci# Verify the kernel is not crashed when IPv4 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=route4-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 IPv4 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 IPv4 address 69f08c3bdfSopenharmony_ciIPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"} 70f08c3bdfSopenharmony_ci 71f08c3bdfSopenharmony_ci# Netmask of for the tested network 72f08c3bdfSopenharmony_ciIPV4_NETMASK="255.255.255.0" 73f08c3bdfSopenharmony_ciIPV4_NETMASK_NUM=24 74f08c3bdfSopenharmony_ci 75f08c3bdfSopenharmony_ci# Broadcast address of the tested network 76f08c3bdfSopenharmony_ciIPV4_BROADCAST=${IPV4_NETWORK}.255 77f08c3bdfSopenharmony_ci 78f08c3bdfSopenharmony_ci# Host portion of the IPv4 address 79f08c3bdfSopenharmony_ciLHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"} # src 80f08c3bdfSopenharmony_ciRHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"} # gateway 81f08c3bdfSopenharmony_ci 82f08c3bdfSopenharmony_ci# The destination network 83f08c3bdfSopenharmony_ciDST_NETWORK="10.10.10" # destination network would be 10.10.10.0/24 84f08c3bdfSopenharmony_ciDST_HOST="5" 85f08c3bdfSopenharmony_ciDST_PORT="7" 86f08c3bdfSopenharmony_ci 87f08c3bdfSopenharmony_ci 88f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 89f08c3bdfSopenharmony_ci# 90f08c3bdfSopenharmony_ci# NAME: 91f08c3bdfSopenharmony_ci# do_cleanup 92f08c3bdfSopenharmony_ci# 93f08c3bdfSopenharmony_ci# DESCRIPTION: 94f08c3bdfSopenharmony_ci# Recover the tested interfaces 95f08c3bdfSopenharmony_ci# 96f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 97f08c3bdfSopenharmony_cido_cleanup() 98f08c3bdfSopenharmony_ci{ 99f08c3bdfSopenharmony_ci # Make sure to load the network driver 100f08c3bdfSopenharmony_ci if [ x${lhost_module} != x ]; then 101f08c3bdfSopenharmony_ci modprobe $lhost_module 102f08c3bdfSopenharmony_ci fi 103f08c3bdfSopenharmony_ci 104f08c3bdfSopenharmony_ci # Initialize the interfaces 105f08c3bdfSopenharmony_ci initialize_if lhost ${LINK_NUM} 106f08c3bdfSopenharmony_ci initialize_if rhost ${LINK_NUM} 107f08c3bdfSopenharmony_ci} 108f08c3bdfSopenharmony_ci 109f08c3bdfSopenharmony_ci 110f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 111f08c3bdfSopenharmony_ci# 112f08c3bdfSopenharmony_ci# NAME: 113f08c3bdfSopenharmony_ci# do_setup 114f08c3bdfSopenharmony_ci# 115f08c3bdfSopenharmony_ci# DESCRIPTION: 116f08c3bdfSopenharmony_ci# Make a IPv4 connectivity 117f08c3bdfSopenharmony_ci# 118f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 119f08c3bdfSopenharmony_cido_setup() 120f08c3bdfSopenharmony_ci{ 121f08c3bdfSopenharmony_ci # Check the local host has ethtool utility 122f08c3bdfSopenharmony_ci which ethtool >/dev/null 123f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 124f08c3bdfSopenharmony_ci tst_resm TBROK "This test case requires ethtool utility" 125f08c3bdfSopenharmony_ci exit $TST_TOTAL 126f08c3bdfSopenharmony_ci fi 127f08c3bdfSopenharmony_ci 128f08c3bdfSopenharmony_ci # The module name of the interface at the local host 129f08c3bdfSopenharmony_ci lhost_module= 130f08c3bdfSopenharmony_ci 131f08c3bdfSopenharmony_ci # Make sure to clean up 132f08c3bdfSopenharmony_ci do_cleanup 133f08c3bdfSopenharmony_ci 134f08c3bdfSopenharmony_ci # Set IPv4 address to the interfaces of the remote host 135f08c3bdfSopenharmony_ci set_ipv4addr rhost ${LINK_NUM} ${IPV4_NETWORK} ${RHOST_IPV4_HOST} 136f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 137f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to add an IPv4 address the remote host" 138f08c3bdfSopenharmony_ci exit $TST_TOTAL 139f08c3bdfSopenharmony_ci fi 140f08c3bdfSopenharmony_ci rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}" 141f08c3bdfSopenharmony_ci 142f08c3bdfSopenharmony_ci # Assign IPv4 address to the interface of the local host 143f08c3bdfSopenharmony_ci set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST} 144f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 145f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to assign an IPv4 address at the local host" 146f08c3bdfSopenharmony_ci return 1 147f08c3bdfSopenharmony_ci fi 148f08c3bdfSopenharmony_ci lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}" 149f08c3bdfSopenharmony_ci 150f08c3bdfSopenharmony_ci # Get the Interface names 151f08c3bdfSopenharmony_ci lhost_ifname=`get_ifname lhost ${LINK_NUM}` 152f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 153f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to get the interface name at the local host" 154f08c3bdfSopenharmony_ci exit $TST_TOTAL 155f08c3bdfSopenharmony_ci fi 156f08c3bdfSopenharmony_ci 157f08c3bdfSopenharmony_ci rhost_ifname=`get_ifname rhost ${LINK_NUM}` 158f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 159f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to get the interface name at the remote host" 160f08c3bdfSopenharmony_ci exit $TST_TOTAL 161f08c3bdfSopenharmony_ci fi 162f08c3bdfSopenharmony_ci 163f08c3bdfSopenharmony_ci # Get the module name of the interface at the local host 164f08c3bdfSopenharmony_ci lhost_module=`ethtool -i $lhost_ifname | grep driver | sed "s/driver:[[:blank:]]*//"` 165f08c3bdfSopenharmony_ci 166f08c3bdfSopenharmony_ci # Chack the other active interface uses the same driver 167f08c3bdfSopenharmony_ci for ifname in `ifconfig | grep ^eth | awk '{ print $1}'`; do 168f08c3bdfSopenharmony_ci if [ $lhost_ifname = $ifname ]; then 169f08c3bdfSopenharmony_ci continue 170f08c3bdfSopenharmony_ci fi 171f08c3bdfSopenharmony_ci 172f08c3bdfSopenharmony_ci module=`ethtool -i $ifname | grep driver | sed "s/driver:[[:blank:]]*//"` 173f08c3bdfSopenharmony_ci if [ $lhost_module = $module ]; then 174f08c3bdfSopenharmony_ci tst_resm TBROK "An active interface $ifname uses the same network deriver $module with the test intreface." 175f08c3bdfSopenharmony_ci exit $TST_TOTAL 176f08c3bdfSopenharmony_ci fi 177f08c3bdfSopenharmony_ci done 178f08c3bdfSopenharmony_ci 179f08c3bdfSopenharmony_ci # Set the variables for destination network 180f08c3bdfSopenharmony_ci dst_addr=${DST_NETWORK}.${DST_HOST} 181f08c3bdfSopenharmony_ci dst_network=${DST_NETWORK}.0 182f08c3bdfSopenharmony_ci} 183f08c3bdfSopenharmony_ci 184f08c3bdfSopenharmony_ci 185f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 186f08c3bdfSopenharmony_ci# 187f08c3bdfSopenharmony_ci# FUNCTION: 188f08c3bdfSopenharmony_ci# test_body 189f08c3bdfSopenharmony_ci# 190f08c3bdfSopenharmony_ci# DESCRIPTION: 191f08c3bdfSopenharmony_ci# main code of the test 192f08c3bdfSopenharmony_ci# 193f08c3bdfSopenharmony_ci# Arguments: 194f08c3bdfSopenharmony_ci# $1: define the test type 195f08c3bdfSopenharmony_ci# 1 - route command case 196f08c3bdfSopenharmony_ci# 2 - ip command case 197f08c3bdfSopenharmony_ci# 198f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 199f08c3bdfSopenharmony_citest_body() 200f08c3bdfSopenharmony_ci{ 201f08c3bdfSopenharmony_ci test_type=$1 202f08c3bdfSopenharmony_ci 203f08c3bdfSopenharmony_ci TCID=route4-rmmod0${test_type} 204f08c3bdfSopenharmony_ci TST_COUNT=$test_type 205f08c3bdfSopenharmony_ci 206f08c3bdfSopenharmony_ci case $test_type in 207f08c3bdfSopenharmony_ci 1) 208f08c3bdfSopenharmony_ci tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by route command then it is deleted by removing network driver in $NS_TIMES times" 209f08c3bdfSopenharmony_ci ;; 210f08c3bdfSopenharmony_ci 2) 211f08c3bdfSopenharmony_ci tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by ip command then it is deleted by removing network driver in $NS_TIMES times" 212f08c3bdfSopenharmony_ci ;; 213f08c3bdfSopenharmony_ci *) 214f08c3bdfSopenharmony_ci tst_resm TBROK "unspecified case" 215f08c3bdfSopenharmony_ci return 1 216f08c3bdfSopenharmony_ci ;; 217f08c3bdfSopenharmony_ci esac 218f08c3bdfSopenharmony_ci 219f08c3bdfSopenharmony_ci # Start the loop 220f08c3bdfSopenharmony_ci cnt=0 221f08c3bdfSopenharmony_ci while [ $cnt -lt $NS_TIMES ]; do 222f08c3bdfSopenharmony_ci # Check the connectivity to the gateway 223f08c3bdfSopenharmony_ci check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr 224f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 225f08c3bdfSopenharmony_ci tst_resm TBROK "Test Link $LINK_NUM is somthing wrong." 226f08c3bdfSopenharmony_ci return 1 227f08c3bdfSopenharmony_ci fi 228f08c3bdfSopenharmony_ci 229f08c3bdfSopenharmony_ci # Add the route 230f08c3bdfSopenharmony_ci case $test_type in 231f08c3bdfSopenharmony_ci 1) 232f08c3bdfSopenharmony_ci route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname 233f08c3bdfSopenharmony_ci ;; 234f08c3bdfSopenharmony_ci 2) 235f08c3bdfSopenharmony_ci ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname 236f08c3bdfSopenharmony_ci ;; 237f08c3bdfSopenharmony_ci esac 238f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 239f08c3bdfSopenharmony_ci tst_resm TFAIL "Failed to add the route to ${dst_network}/24" 240f08c3bdfSopenharmony_ci return 1 241f08c3bdfSopenharmony_ci fi 242f08c3bdfSopenharmony_ci 243f08c3bdfSopenharmony_ci # Load the route with UDP datagram 244f08c3bdfSopenharmony_ci ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472 245f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 246f08c3bdfSopenharmony_ci tst_resm TFAIL "Failed to run a UDP datagram sender" 247f08c3bdfSopenharmony_ci return 1 248f08c3bdfSopenharmony_ci fi 249f08c3bdfSopenharmony_ci 250f08c3bdfSopenharmony_ci # Remove and reload the network driver 251f08c3bdfSopenharmony_ci rmmod $lhost_module && modprobe $lhost_module 252f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 253f08c3bdfSopenharmony_ci tst_resm TFAIL "Failed to unload/reload the network driver" 254f08c3bdfSopenharmony_ci return 1 255f08c3bdfSopenharmony_ci fi 256f08c3bdfSopenharmony_ci 257f08c3bdfSopenharmony_ci # Make sure to assing the IPv4 address 258f08c3bdfSopenharmony_ci set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST} >/dev/null 2>&1 259f08c3bdfSopenharmony_ci 260f08c3bdfSopenharmony_ci cnt=`expr $cnt + 1` 261f08c3bdfSopenharmony_ci done 262f08c3bdfSopenharmony_ci 263f08c3bdfSopenharmony_ci tst_resm TPASS "Test is finished correctly." 264f08c3bdfSopenharmony_ci return 0 265f08c3bdfSopenharmony_ci} 266f08c3bdfSopenharmony_ci 267f08c3bdfSopenharmony_ci 268f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 269f08c3bdfSopenharmony_ci# 270f08c3bdfSopenharmony_ci# Main 271f08c3bdfSopenharmony_ci# 272f08c3bdfSopenharmony_ci# Exit Value: 273f08c3bdfSopenharmony_ci# The number of the failure 274f08c3bdfSopenharmony_ci# 275f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 276f08c3bdfSopenharmony_ci 277f08c3bdfSopenharmony_ciRC=0 278f08c3bdfSopenharmony_cido_setup 279f08c3bdfSopenharmony_citest_body 1 || RC=`expr $RC + 1` # Case of route command 280f08c3bdfSopenharmony_citest_body 2 || RC=`expr $RC + 1` # Case of ip command 281f08c3bdfSopenharmony_cido_cleanup 282f08c3bdfSopenharmony_ci 283f08c3bdfSopenharmony_ciexit $RC 284