1f08c3bdfSopenharmony_ci#!/bin/sh 2f08c3bdfSopenharmony_ci 3f08c3bdfSopenharmony_ci################################################################################ 4f08c3bdfSopenharmony_ci## ## 5f08c3bdfSopenharmony_ci## Copyright (c) International Business Machines Corp., 2005 ## 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# tcp4-uni-basic01 26f08c3bdfSopenharmony_ci# 27f08c3bdfSopenharmony_ci# Description: 28f08c3bdfSopenharmony_ci# Verify that the kernel is not crashed with a connection to with 29f08c3bdfSopenharmony_ci# the following condition: 30f08c3bdfSopenharmony_ci# - The version of IP is IPv4 31f08c3bdfSopenharmony_ci# - Network is not delayed 32f08c3bdfSopenharmony_ci# - IPsec is not used 33f08c3bdfSopenharmony_ci# - Disable window scaling 34f08c3bdfSopenharmony_ci# - Enable Nagle algorithm 35f08c3bdfSopenharmony_ci# - Enable TCP Duplicate SACK support 36f08c3bdfSopenharmony_ci# - Enable SACK Support 37f08c3bdfSopenharmony_ci# - No packet are lost 38f08c3bdfSopenharmony_ci# - No packet are duplicated 39f08c3bdfSopenharmony_ci# - Disable TSO if it is avalable 40f08c3bdfSopenharmony_ci# 41f08c3bdfSopenharmony_ci# *) This script may be read by the other test case 42f08c3bdfSopenharmony_ci# 43f08c3bdfSopenharmony_ci# Setup: 44f08c3bdfSopenharmony_ci# See testcases/network/stress/README 45f08c3bdfSopenharmony_ci# 46f08c3bdfSopenharmony_ci# Author: 47f08c3bdfSopenharmony_ci# Mitsuru Chinen <mitch@jp.ibm.com> 48f08c3bdfSopenharmony_ci# 49f08c3bdfSopenharmony_ci# History: 50f08c3bdfSopenharmony_ci# Oct 19 2005 - Created (Mitsuru Chinen) 51f08c3bdfSopenharmony_ci# 52f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 53f08c3bdfSopenharmony_ci# Uncomment line below for debug output. 54f08c3bdfSopenharmony_ci#trace_logic=${trace_logic:-"set -x"} 55f08c3bdfSopenharmony_ci$trace_logic 56f08c3bdfSopenharmony_ci 57f08c3bdfSopenharmony_ci# The test case ID, the test case count and the total number of test case 58f08c3bdfSopenharmony_ciTCID=${TCID:-tcp4-uni-basic01} 59f08c3bdfSopenharmony_ciTST_TOTAL=1 60f08c3bdfSopenharmony_ciTST_COUNT=1 61f08c3bdfSopenharmony_ciexport TCID 62f08c3bdfSopenharmony_ciexport TST_COUNT 63f08c3bdfSopenharmony_ciexport TST_TOTAL 64f08c3bdfSopenharmony_ci 65f08c3bdfSopenharmony_ci 66f08c3bdfSopenharmony_ci 67f08c3bdfSopenharmony_ci# Test description 68f08c3bdfSopenharmony_ciNON_BASIC=${NON_BASIC:-false} 69f08c3bdfSopenharmony_ci$NON_BASIC || tst_resm TINFO "Verify that the kernel is not crashed by a TCP connection" 70f08c3bdfSopenharmony_ci 71f08c3bdfSopenharmony_ci# Make sure the value of LTPROOT 72f08c3bdfSopenharmony_ciLTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`} 73f08c3bdfSopenharmony_ciexport LTPROOT 74f08c3bdfSopenharmony_ci 75f08c3bdfSopenharmony_ci# Check the environmanet variable 76f08c3bdfSopenharmony_ci. check_envval || exit $TST_TOTAL 77f08c3bdfSopenharmony_ci 78f08c3bdfSopenharmony_ci# Dulation of the test [sec] 79f08c3bdfSopenharmony_ciNS_DURATION=${NS_DURATION:-3600} # 1 hour 80f08c3bdfSopenharmony_ci 81f08c3bdfSopenharmony_ci# The number of the test link where tests run 82f08c3bdfSopenharmony_ciLINK_NUM=${LINK_NUM:-0} 83f08c3bdfSopenharmony_ci 84f08c3bdfSopenharmony_ci# The version of IP 85f08c3bdfSopenharmony_ciIP_VER=${IP_VER:-4} 86f08c3bdfSopenharmony_ci 87f08c3bdfSopenharmony_ci# true, if ipsec is used 88f08c3bdfSopenharmony_ciDO_IPSEC=${DO_IPSEC:-false} 89f08c3bdfSopenharmony_ci 90f08c3bdfSopenharmony_ci# The value of SPI 91f08c3bdfSopenharmony_ciSPI=${SPI:-1000} 92f08c3bdfSopenharmony_ci 93f08c3bdfSopenharmony_ci# IPsec Protocol ( ah / esp / ipcomp ) 94f08c3bdfSopenharmony_ciIPSEC_PROTO=${IPSEC_PROTO:-ah} 95f08c3bdfSopenharmony_ci 96f08c3bdfSopenharmony_ci# IPsec Mode ( transport / tunnel ) 97f08c3bdfSopenharmony_ciIPSEC_MODE=${IPSEC_MODE:-transport} 98f08c3bdfSopenharmony_ci 99f08c3bdfSopenharmony_ci# true, if network is delayed 100f08c3bdfSopenharmony_ciDO_NET_DELAY=${DO_NET_DELAY:-false} 101f08c3bdfSopenharmony_ci 102f08c3bdfSopenharmony_ci# Amount of network delay [ms] 103f08c3bdfSopenharmony_ciNET_DELAY=${NET_DELAY:-600} 104f08c3bdfSopenharmony_ci 105f08c3bdfSopenharmony_ci# The deflection of network delay [ms] 106f08c3bdfSopenharmony_ciNET_DELAY_DEFL=${NET_DELAY_DEFL:-200} 107f08c3bdfSopenharmony_ci 108f08c3bdfSopenharmony_ci# true, if some packets are lost 109f08c3bdfSopenharmony_ciDO_PACKET_LOSS=${DO_PACKET_LOSS:-false} 110f08c3bdfSopenharmony_ci 111f08c3bdfSopenharmony_ci# Rate of packet loss [%] 112f08c3bdfSopenharmony_ciPACKET_LOSS_RATE=${PACKET_LOSS_RATE:-8} 113f08c3bdfSopenharmony_ci 114f08c3bdfSopenharmony_ci# true, if some packets are duplicated 115f08c3bdfSopenharmony_ciDO_PACKET_DUP=${DO_PACKET_DUP:-false} 116f08c3bdfSopenharmony_ci 117f08c3bdfSopenharmony_ci# Rate of packet dupulication [%] 118f08c3bdfSopenharmony_ciPACKET_DUP_RATE=${PACKET_DUP_RATE:-1} 119f08c3bdfSopenharmony_ci 120f08c3bdfSopenharmony_ci# true, if test is for small sending (Namely, disable NAGLE algorithm) 121f08c3bdfSopenharmony_ciDO_SMALL_SEND=${DO_SMALL_SEND:-false} 122f08c3bdfSopenharmony_ci 123f08c3bdfSopenharmony_ci# true, if test is for window scaling 124f08c3bdfSopenharmony_ciDO_WINDOW_SCALING=${DO_WINDOW_SCALING:-false} 125f08c3bdfSopenharmony_ci 126f08c3bdfSopenharmony_ci# true, if test is for DSACK 127f08c3bdfSopenharmony_ciDO_DSACK=${DO_DSACK:-true} 128f08c3bdfSopenharmony_ci 129f08c3bdfSopenharmony_ci# true, if test is for SACK 130f08c3bdfSopenharmony_ciDO_SACK=${DO_SACK:-true} 131f08c3bdfSopenharmony_ci 132f08c3bdfSopenharmony_ci# true, if test is for TSO 133f08c3bdfSopenharmony_ciDO_TSO=${DO_TSO:-false} 134f08c3bdfSopenharmony_ci 135f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 136f08c3bdfSopenharmony_ci# 137f08c3bdfSopenharmony_ci# Function: do_cleanup 138f08c3bdfSopenharmony_ci# 139f08c3bdfSopenharmony_ci# Description: 140f08c3bdfSopenharmony_ci# Recover the system configuration 141f08c3bdfSopenharmony_ci# 142f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 143f08c3bdfSopenharmony_cido_cleanup() 144f08c3bdfSopenharmony_ci{ 145f08c3bdfSopenharmony_ci # Kill the tcp traffic server 146f08c3bdfSopenharmony_ci killall_tcp_traffic 147f08c3bdfSopenharmony_ci 148f08c3bdfSopenharmony_ci # Enable window scaling 149f08c3bdfSopenharmony_ci sysctl -w net.ipv4.tcp_window_scaling=1 >/dev/null 2>&1 150f08c3bdfSopenharmony_ci 151f08c3bdfSopenharmony_ci # Enable TCP Duplicate SACK support 152f08c3bdfSopenharmony_ci sysctl -w net.ipv4.tcp_dsack=1 >/dev/null 2>&1 153f08c3bdfSopenharmony_ci 154f08c3bdfSopenharmony_ci # Enable SACK support 155f08c3bdfSopenharmony_ci sysctl -w net.ipv4.tcp_sack=1 >/dev/null 2>&1 156f08c3bdfSopenharmony_ci 157f08c3bdfSopenharmony_ci # Restore the tcp segmentation offload setting 158f08c3bdfSopenharmony_ci if [ x${tso_orig} != x ]; then 159f08c3bdfSopenharmony_ci ethtool -K $lhost_ifname tso $tso_orig 160f08c3bdfSopenharmony_ci fi 161f08c3bdfSopenharmony_ci 162f08c3bdfSopenharmony_ci # Unset SAD/SPD 163f08c3bdfSopenharmony_ci output_ipsec_conf flush | setkey -c >/dev/null 2>&1 164f08c3bdfSopenharmony_ci $LTP_RSH $RHOST ${LTPROOT}/'testcases/bin/output_ipsec_conf flush | PATH=/sbin:/usr/sbin:$PATH setkey -c' >/dev/null 2>&1 165f08c3bdfSopenharmony_ci 166f08c3bdfSopenharmony_ci # Disable network emulator 167f08c3bdfSopenharmony_ci if [ x$rhost_ifname = x ]; then 168f08c3bdfSopenharmony_ci rhost_ifname=`get_ifname rhost $LINK_NUM` 169f08c3bdfSopenharmony_ci fi 170f08c3bdfSopenharmony_ci $LTP_RSH $RHOST "PATH=/sbin:/usr/sbin:$PATH tc qdisc del dev $rhost_ifname root netem" >/dev/null 2>&1 171f08c3bdfSopenharmony_ci 172f08c3bdfSopenharmony_ci # Clean up each interface 173f08c3bdfSopenharmony_ci initialize_if lhost ${LINK_NUM} || exit 1 174f08c3bdfSopenharmony_ci initialize_if rhost ${LINK_NUM} || exit 1 175f08c3bdfSopenharmony_ci} 176f08c3bdfSopenharmony_ci 177f08c3bdfSopenharmony_ci 178f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 179f08c3bdfSopenharmony_ci# 180f08c3bdfSopenharmony_ci# Function: do_setup 181f08c3bdfSopenharmony_ci# 182f08c3bdfSopenharmony_ci# Description: 183f08c3bdfSopenharmony_ci# Setup the system for testing 184f08c3bdfSopenharmony_ci# 185f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 186f08c3bdfSopenharmony_cido_setup() 187f08c3bdfSopenharmony_ci{ 188f08c3bdfSopenharmony_ci # Output the informaion 189f08c3bdfSopenharmony_ci tst_resm TINFO "- Test duration is $NS_DURATION [sec]" 190f08c3bdfSopenharmony_ci tst_resm TINFO "- Version of IP is IPv${IP_VER}" 191f08c3bdfSopenharmony_ci 192f08c3bdfSopenharmony_ci # Addtional server option 193f08c3bdfSopenharmony_ci server_opt="" 194f08c3bdfSopenharmony_ci 195f08c3bdfSopenharmony_ci # Addtional client option 196f08c3bdfSopenharmony_ci client_opt="" 197f08c3bdfSopenharmony_ci 198f08c3bdfSopenharmony_ci # Original TSO parameter 199f08c3bdfSopenharmony_ci tso_orig="" 200f08c3bdfSopenharmony_ci 201f08c3bdfSopenharmony_ci # Check the remote host has netem functionality 202f08c3bdfSopenharmony_ci if $DO_NET_DELAY || $DO_PACKET_LOSS || $DO_PACKET_DUP ; then 203f08c3bdfSopenharmony_ci message=`check_netem` 204f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 205f08c3bdfSopenharmony_ci tst_resm TBROK "$message" 206f08c3bdfSopenharmony_ci exit 1 207f08c3bdfSopenharmony_ci fi 208f08c3bdfSopenharmony_ci fi 209f08c3bdfSopenharmony_ci 210f08c3bdfSopenharmony_ci $DO_NET_DELAY && tst_resm TINFO "- Network delay is ${NET_DELAY}ms +/- ${NET_DELAY_DEFL}ms" 211f08c3bdfSopenharmony_ci 212f08c3bdfSopenharmony_ci $DO_PACKET_LOSS && tst_resm TINFO "- Packet loss rate is ${PACKET_LOSS_RATE}%%" 213f08c3bdfSopenharmony_ci 214f08c3bdfSopenharmony_ci $DO_PACKET_DUP && tst_resm TINFO "- Packet duplication rate is ${PACKET_DUP_RATE}%%" 215f08c3bdfSopenharmony_ci 216f08c3bdfSopenharmony_ci # Check the setkey command is available 217f08c3bdfSopenharmony_ci if $DO_IPSEC ; then 218f08c3bdfSopenharmony_ci message=`check_setkey` 219f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 220f08c3bdfSopenharmony_ci tst_resm TBROK "$message" 221f08c3bdfSopenharmony_ci exit 1 222f08c3bdfSopenharmony_ci fi 223f08c3bdfSopenharmony_ci 224f08c3bdfSopenharmony_ci case $IPSEC_PROTO in 225f08c3bdfSopenharmony_ci ah) 226f08c3bdfSopenharmony_ci tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]" 227f08c3bdfSopenharmony_ci ;; 228f08c3bdfSopenharmony_ci esp) 229f08c3bdfSopenharmony_ci tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]" 230f08c3bdfSopenharmony_ci ;; 231f08c3bdfSopenharmony_ci ipcomp) 232f08c3bdfSopenharmony_ci tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]" 233f08c3bdfSopenharmony_ci ;; 234f08c3bdfSopenharmony_ci esac 235f08c3bdfSopenharmony_ci fi 236f08c3bdfSopenharmony_ci 237f08c3bdfSopenharmony_ci # name of interface of the local/remote host 238f08c3bdfSopenharmony_ci lhost_ifname=`get_ifname lhost $LINK_NUM` 239f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 240f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to get the interface name at the local host" 241f08c3bdfSopenharmony_ci exit $TST_TOTAL 242f08c3bdfSopenharmony_ci fi 243f08c3bdfSopenharmony_ci rhost_ifname=`get_ifname rhost $LINK_NUM` 244f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 245f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to get the interface name at the remote host" 246f08c3bdfSopenharmony_ci exit $TST_TOTAL 247f08c3bdfSopenharmony_ci fi 248f08c3bdfSopenharmony_ci 249f08c3bdfSopenharmony_ci # Initialize the system configuration 250f08c3bdfSopenharmony_ci do_cleanup 251f08c3bdfSopenharmony_ci 252f08c3bdfSopenharmony_ci # Call do_cleanup function before exit 253f08c3bdfSopenharmony_ci trap do_cleanup 0 254f08c3bdfSopenharmony_ci 255f08c3bdfSopenharmony_ci # Add option for small sending test 256f08c3bdfSopenharmony_ci if $DO_SMALL_SEND ; then 257f08c3bdfSopenharmony_ci server_opt="-s" 258f08c3bdfSopenharmony_ci fi 259f08c3bdfSopenharmony_ci 260f08c3bdfSopenharmony_ci # Configure window scaling parameter 261f08c3bdfSopenharmony_ci if $DO_WINDOW_SCALING ; then 262f08c3bdfSopenharmony_ci server_opt="-w" 263f08c3bdfSopenharmony_ci client_opt="-w" 264f08c3bdfSopenharmony_ci sysctl -w net.ipv4.tcp_window_scaling=1 >/dev/null 265f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 266f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to enable window scaling" 267f08c3bdfSopenharmony_ci exit 1 268f08c3bdfSopenharmony_ci fi 269f08c3bdfSopenharmony_ci else 270f08c3bdfSopenharmony_ci sysctl -w net.ipv4.tcp_window_scaling=0 >/dev/null 2>&1 271f08c3bdfSopenharmony_ci fi 272f08c3bdfSopenharmony_ci 273f08c3bdfSopenharmony_ci # Configure DSACK parameter 274f08c3bdfSopenharmony_ci if $DO_DSACK ; then 275f08c3bdfSopenharmony_ci sysctl -w net.ipv4.tcp_dsack=1 >/dev/null 276f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 277f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to enable Duplicate SACK" 278f08c3bdfSopenharmony_ci exit 1 279f08c3bdfSopenharmony_ci fi 280f08c3bdfSopenharmony_ci else 281f08c3bdfSopenharmony_ci sysctl -w net.ipv4.tcp_dsack=0 >/dev/null 2>&1 282f08c3bdfSopenharmony_ci fi 283f08c3bdfSopenharmony_ci 284f08c3bdfSopenharmony_ci # Configure SACK parameter 285f08c3bdfSopenharmony_ci if $DO_SACK ; then 286f08c3bdfSopenharmony_ci sysctl -w net.ipv4.tcp_sack=1 >/dev/null 287f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 288f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to enable SACK" 289f08c3bdfSopenharmony_ci exit 1 290f08c3bdfSopenharmony_ci fi 291f08c3bdfSopenharmony_ci else 292f08c3bdfSopenharmony_ci sysctl -w net.ipv4.tcp_sack=0 >/dev/null 2>&1 293f08c3bdfSopenharmony_ci fi 294f08c3bdfSopenharmony_ci 295f08c3bdfSopenharmony_ci # Store the current TSO parameter, then configure it 296f08c3bdfSopenharmony_ci offload_info=`mktemp -p $TMPDIR` 297f08c3bdfSopenharmony_ci ethtool -k $lhost_ifname > $offload_info 2>/dev/null 298f08c3bdfSopenharmony_ci fgrep "tcp segmentation offload" $offload_info >/dev/null 2>&1 299f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 300f08c3bdfSopenharmony_ci if $DO_TSO ; then 301f08c3bdfSopenharmony_ci tst_resm TCONF "The device at $lhost_ifname does not support TSO." 302f08c3bdfSopenharmony_ci rm -f $offload_info 303f08c3bdfSopenharmony_ci exit 1 304f08c3bdfSopenharmony_ci fi 305f08c3bdfSopenharmony_ci tso_orig=`fgrep "tcp segmentation offload" $offload_info | sed -e 's/^.*: //'` 306f08c3bdfSopenharmony_ci if $DO_TSO ; then 307f08c3bdfSopenharmony_ci server_opt="-w" 308f08c3bdfSopenharmony_ci client_opt="-w" 309f08c3bdfSopenharmony_ci ethtool -K $lhost_ifname tso on 310f08c3bdfSopenharmony_ci else 311f08c3bdfSopenharmony_ci ethtool -K $lhost_ifname tso off 312f08c3bdfSopenharmony_ci fi 313f08c3bdfSopenharmony_ci fi 314f08c3bdfSopenharmony_ci rm -f $offload_info 315f08c3bdfSopenharmony_ci 316f08c3bdfSopenharmony_ci # Configure the network interface 317f08c3bdfSopenharmony_ci case $IP_VER in 318f08c3bdfSopenharmony_ci 4) 319f08c3bdfSopenharmony_ci # Network portion of the IPv4 address 320f08c3bdfSopenharmony_ci network_part=${IPV4_NETWORK:-"10.0.0"} 321f08c3bdfSopenharmony_ci 322f08c3bdfSopenharmony_ci # Netmask of the IPv4 network 323f08c3bdfSopenharmony_ci network_mask=24 324f08c3bdfSopenharmony_ci 325f08c3bdfSopenharmony_ci # Host portion of the IPv4 address 326f08c3bdfSopenharmony_ci lhost_host_part=${LHOST_IPV4_HOST:-"2"} # local host 327f08c3bdfSopenharmony_ci rhost_host_part=${RHOST_IPV4_HOST:-"1"} # remote host 328f08c3bdfSopenharmony_ci 329f08c3bdfSopenharmony_ci # Set IPv4 addresses to the interfaces 330f08c3bdfSopenharmony_ci set_ipv4addr lhost $LINK_NUM $network_part $lhost_host_part 331f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 332f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to add any IP address at the local host" 333f08c3bdfSopenharmony_ci exit 1 334f08c3bdfSopenharmony_ci fi 335f08c3bdfSopenharmony_ci 336f08c3bdfSopenharmony_ci set_ipv4addr rhost $LINK_NUM $network_part $rhost_host_part 337f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 338f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to add any IP address at the remote host" 339f08c3bdfSopenharmony_ci exit 1 340f08c3bdfSopenharmony_ci fi 341f08c3bdfSopenharmony_ci 342f08c3bdfSopenharmony_ci # IPv4 address of the local/remote host 343f08c3bdfSopenharmony_ci lhost_addr="${network_part}.${lhost_host_part}" 344f08c3bdfSopenharmony_ci rhost_addr="${network_part}.${rhost_host_part}" 345f08c3bdfSopenharmony_ci ;; 346f08c3bdfSopenharmony_ci 347f08c3bdfSopenharmony_ci 6) 348f08c3bdfSopenharmony_ci # Network portion of the IPv6 address 349f08c3bdfSopenharmony_ci network_part="fd00:1:1:1" 350f08c3bdfSopenharmony_ci 351f08c3bdfSopenharmony_ci # Netmask of the IPv6 network 352f08c3bdfSopenharmony_ci network_mask=64 353f08c3bdfSopenharmony_ci 354f08c3bdfSopenharmony_ci # Host portion of the IPv6 address 355f08c3bdfSopenharmony_ci lhost_host_part=":2" # local host 356f08c3bdfSopenharmony_ci rhost_host_part=":1" # remote host 357f08c3bdfSopenharmony_ci 358f08c3bdfSopenharmony_ci # Set IPv6 addresses to the interfaces 359f08c3bdfSopenharmony_ci add_ipv6addr lhost $LINK_NUM $network_part $lhost_host_part 360f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 361f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to add any IP address at the local host" 362f08c3bdfSopenharmony_ci exit 1 363f08c3bdfSopenharmony_ci fi 364f08c3bdfSopenharmony_ci 365f08c3bdfSopenharmony_ci add_ipv6addr rhost $LINK_NUM $network_part $rhost_host_part 366f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 367f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to add any IP address at the remote host" 368f08c3bdfSopenharmony_ci exit 1 369f08c3bdfSopenharmony_ci fi 370f08c3bdfSopenharmony_ci 371f08c3bdfSopenharmony_ci # IPv6 address of the local/remote host 372f08c3bdfSopenharmony_ci lhost_addr="${network_part}:${lhost_host_part}" 373f08c3bdfSopenharmony_ci rhost_addr="${network_part}:${rhost_host_part}" 374f08c3bdfSopenharmony_ci ;; 375f08c3bdfSopenharmony_ci 376f08c3bdfSopenharmony_ci *) 377f08c3bdfSopenharmony_ci tst_resm TBROK "Unknown IP version" 378f08c3bdfSopenharmony_ci ;; 379f08c3bdfSopenharmony_ci esac 380f08c3bdfSopenharmony_ci 381f08c3bdfSopenharmony_ci netem_param= 382f08c3bdfSopenharmony_ci 383f08c3bdfSopenharmony_ci # Make the network delay 384f08c3bdfSopenharmony_ci if $DO_NET_DELAY ; then 385f08c3bdfSopenharmony_ci netem_param="delay ${NET_DELAY}ms ${NET_DELAY_DEFL}ms distribution normal" 386f08c3bdfSopenharmony_ci ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH tc' qdisc add dev $rhost_ifname root netem $netem_param' ; echo $?'` 387f08c3bdfSopenharmony_ci if [ $ret -ne 0 ]; then 388f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to make the delayed network" 389f08c3bdfSopenharmony_ci exit 1 390f08c3bdfSopenharmony_ci fi 391f08c3bdfSopenharmony_ci fi 392f08c3bdfSopenharmony_ci 393f08c3bdfSopenharmony_ci # Make some packets lost 394f08c3bdfSopenharmony_ci if $DO_PACKET_LOSS ; then 395f08c3bdfSopenharmony_ci tc_cmd="add" 396f08c3bdfSopenharmony_ci if [ x"$netem_param" != x ]; then 397f08c3bdfSopenharmony_ci tc_cmd="change" 398f08c3bdfSopenharmony_ci fi 399f08c3bdfSopenharmony_ci netem_param="loss ${PACKET_LOSS_RATE}% $netem_param" 400f08c3bdfSopenharmony_ci ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH tc' qdisc $tc_cmd dev $rhost_ifname root netem $netem_param' ; echo $?'` 401f08c3bdfSopenharmony_ci if [ $ret -ne 0 ]; then 402f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to use netem functionality" 403f08c3bdfSopenharmony_ci exit 1 404f08c3bdfSopenharmony_ci fi 405f08c3bdfSopenharmony_ci fi 406f08c3bdfSopenharmony_ci 407f08c3bdfSopenharmony_ci # Make some packets duplicated 408f08c3bdfSopenharmony_ci if $DO_PACKET_DUP ; then 409f08c3bdfSopenharmony_ci tc_cmd="add" 410f08c3bdfSopenharmony_ci if [ x"$netem_param" != x ]; then 411f08c3bdfSopenharmony_ci tc_cmd="change" 412f08c3bdfSopenharmony_ci fi 413f08c3bdfSopenharmony_ci netem_param="duplicate ${PACKET_DUP_RATE}% $netem_param" 414f08c3bdfSopenharmony_ci ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH tc' qdisc $tc_cmd dev $rhost_ifname root netem $netem_param' ; echo $?'` 415f08c3bdfSopenharmony_ci if [ $ret -ne 0 ]; then 416f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to use netem functionality" 417f08c3bdfSopenharmony_ci exit 1 418f08c3bdfSopenharmony_ci fi 419f08c3bdfSopenharmony_ci fi 420f08c3bdfSopenharmony_ci 421f08c3bdfSopenharmony_ci # Configure SAD/SPD 422f08c3bdfSopenharmony_ci if $DO_IPSEC ; then 423f08c3bdfSopenharmony_ci # Set SAD/SPD according to the variables 424f08c3bdfSopenharmony_ci ipsec_log=`mktemp -p $TMPDIR` 425f08c3bdfSopenharmony_ci output_ipsec_conf src \ 426f08c3bdfSopenharmony_ci $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \ 427f08c3bdfSopenharmony_ci | setkey -c 2>&1 | tee $ipsec_log 428f08c3bdfSopenharmony_ci if [ $? -ne 0 -o -s $ipsec_log ]; then 429f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to configure SAD/SPD on the local host." 430f08c3bdfSopenharmony_ci rm -f $ipsec_log 431f08c3bdfSopenharmony_ci exit 1 432f08c3bdfSopenharmony_ci fi 433f08c3bdfSopenharmony_ci 434f08c3bdfSopenharmony_ci $LTP_RSH $RHOST ${LTPROOT}/testcases/bin/output_ipsec_conf dst $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr' | PATH=/sbin:/usr/sbin:$PATH setkey -c' 2>&1 | tee $ipsec_log 435f08c3bdfSopenharmony_ci if [ $? -ne 0 -o -s $ipsec_log ]; then 436f08c3bdfSopenharmony_ci tst_resm TBROK "Failed to configure SAD/SPD on the remote host." 437f08c3bdfSopenharmony_ci rm -f $ipsec_log 438f08c3bdfSopenharmony_ci exit 1 439f08c3bdfSopenharmony_ci fi 440f08c3bdfSopenharmony_ci fi 441f08c3bdfSopenharmony_ci 442f08c3bdfSopenharmony_ci # Make sure the connectvity 443f08c3bdfSopenharmony_ci case $IP_VER in 444f08c3bdfSopenharmony_ci 4) 445f08c3bdfSopenharmony_ci ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'` 446f08c3bdfSopenharmony_ci if [ $ret -ne 0 ]; then 447f08c3bdfSopenharmony_ci tst_resm TBROK "There is no IPv4 connectivity." 448f08c3bdfSopenharmony_ci exit 1 449f08c3bdfSopenharmony_ci fi 450f08c3bdfSopenharmony_ci ;; 451f08c3bdfSopenharmony_ci 452f08c3bdfSopenharmony_ci 6) 453f08c3bdfSopenharmony_ci ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'` 454f08c3bdfSopenharmony_ci if [ $ret -ne 0 ]; then 455f08c3bdfSopenharmony_ci tst_resm TBROK "There is no IPv6 connectivity." 456f08c3bdfSopenharmony_ci exit 1 457f08c3bdfSopenharmony_ci fi 458f08c3bdfSopenharmony_ci ;; 459f08c3bdfSopenharmony_ci esac 460f08c3bdfSopenharmony_ci 461f08c3bdfSopenharmony_ci} 462f08c3bdfSopenharmony_ci 463f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 464f08c3bdfSopenharmony_ci# 465f08c3bdfSopenharmony_ci# Main 466f08c3bdfSopenharmony_ci# 467f08c3bdfSopenharmony_ci# 468f08c3bdfSopenharmony_ci 469f08c3bdfSopenharmony_cido_setup 470f08c3bdfSopenharmony_ci 471f08c3bdfSopenharmony_ci# Find the available consecutive ports 472f08c3bdfSopenharmony_ciserver_port=`find_portbundle tcp 1025 1` 473f08c3bdfSopenharmony_ciif [ $? -ne 0 ]; then 474f08c3bdfSopenharmony_ci tst_resm TBROK "No port is available." 475f08c3bdfSopenharmony_ci exit 1 476f08c3bdfSopenharmony_cifi 477f08c3bdfSopenharmony_ci 478f08c3bdfSopenharmony_ci# Run a tcp traffic server 479f08c3bdfSopenharmony_ciinfo_file=`mktemp -p $TMPDIR` 480f08c3bdfSopenharmony_cins-tcpserver -b -f $IP_VER -p $server_port -o $info_file $server_opt 481f08c3bdfSopenharmony_ciif [ $? -ne 0 ]; then 482f08c3bdfSopenharmony_ci tst_resm TFAIL "Failed to run a tcp traffic server." 483f08c3bdfSopenharmony_ci rm -f $info_file 484f08c3bdfSopenharmony_ci exit 1 485f08c3bdfSopenharmony_cifi 486f08c3bdfSopenharmony_ci 487f08c3bdfSopenharmony_ciwhile true ; do 488f08c3bdfSopenharmony_ci if [ -s $info_file ]; then 489f08c3bdfSopenharmony_ci break 490f08c3bdfSopenharmony_ci fi 491f08c3bdfSopenharmony_cidone 492f08c3bdfSopenharmony_ci 493f08c3bdfSopenharmony_ciserver_pid=`grep PID: $info_file | cut -f 2 -d ' '` 494f08c3bdfSopenharmony_cirm -f $info_file 495f08c3bdfSopenharmony_ci 496f08c3bdfSopenharmony_ci# Run a tcp taffic client 497f08c3bdfSopenharmony_ciret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-tcpclient -b -f $IP_VER -S $lhost_addr -p $server_port $client_opt' ; echo $?'` 498f08c3bdfSopenharmony_ciif [ $ret -ne 0 ]; then 499f08c3bdfSopenharmony_ci tst_resm TFAIL "Failed to run a tcp traffic client" 500f08c3bdfSopenharmony_ci exit 1 501f08c3bdfSopenharmony_cifi 502f08c3bdfSopenharmony_ci 503f08c3bdfSopenharmony_cistart_epoc=`date +%s` 504f08c3bdfSopenharmony_ciwhile true ; do 505f08c3bdfSopenharmony_ci current_epoc=`date +%s` 506f08c3bdfSopenharmony_ci elapse_epoc=`expr $current_epoc - $start_epoc` 507f08c3bdfSopenharmony_ci 508f08c3bdfSopenharmony_ci if [ $elapse_epoc -ge $NS_DURATION ]; then 509f08c3bdfSopenharmony_ci killall -SIGHUP ns-tcpserver 510f08c3bdfSopenharmony_ci break 511f08c3bdfSopenharmony_ci fi 512f08c3bdfSopenharmony_ci 513f08c3bdfSopenharmony_ci # Watch the TCP traffic server 514f08c3bdfSopenharmony_ci ps auxw | fgrep ns-tcpserver | fgrep -l $server_pid >/dev/null 2>&1 515f08c3bdfSopenharmony_ci if [ $? -ne 0 ]; then 516f08c3bdfSopenharmony_ci tst_resm TFAIL "tcp traffic server is dead in $elapse_epoc [sec]" 517f08c3bdfSopenharmony_ci exit 1 518f08c3bdfSopenharmony_ci fi 519f08c3bdfSopenharmony_ci sleep 1 520f08c3bdfSopenharmony_cidone 521f08c3bdfSopenharmony_ci 522f08c3bdfSopenharmony_ci 523f08c3bdfSopenharmony_ci#----------------------------------------------------------------------- 524f08c3bdfSopenharmony_ci# 525f08c3bdfSopenharmony_ci# Clean up 526f08c3bdfSopenharmony_ci# 527f08c3bdfSopenharmony_ci 528f08c3bdfSopenharmony_citst_resm TPASS "Test is finished successfully." 529f08c3bdfSopenharmony_ciexit 0 530