#/bin/sh
#
#ident	"@(#)lsalr_6.sh	1.5	05/06/24 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# NIC Stress Test on IPv6 
# Several remote shell-commands created and run in the background.
#
# Checks for interface hangs - if it hangs, no !PASS will be output,
# hence a FAIL

Usage()
{
	printf "\nUsage:$0 [remote dest]\n"
	exit 1
}

version=`/usr/bin/uname -r|awk -F. '{print $2}'`

# Get Command line arguments

if [ $# -ne 1 ]; then
	Usage
else
	dest="$1"
fi
	
ping $dest > /dev/null 2>/dev/null

if [ $? -ne 0 ]; then
	printf "\n!ERROR: Ping error: Host \"$dest\" not found/responding.\n"
	exit 1
else
	# Set tcp_time_wait_interval short
	init_time_wait=`ndd /dev/tcp6 tcp_time_wait_interval`
	ndd -set /dev/tcp6 tcp_time_wait_interval 5000

	echo "Running time: $RUNTIME seconds."
	sleep $RUNTIME &
	sleepid=$!

	count=0
	while [ -d /proc/$sleepid ] ; do
                if [ $version -lt 10 ]
                then
                        rsh $dest ls -alR /export  > /dev/null 2>/dev/null
                else
                        ssh $dest ls -alR /export  > /dev/null 2>/dev/null
                fi

		if [ $? -ne 0 ]; then
			ndd -set /dev/tcp6 tcp_time_wait_interval $init_time_wait
			echo "!ERROR: Unable to start remote process. Completed $count iterations."
			exit 1
		fi
		count=`expr $count + 1`
		sleep 1
	done
	echo "!PASS: No errors detected in lsalr_6 on IPv6. Completed $count iterations."
	ndd -set /dev/tcp6 tcp_time_wait_interval $init_time_wait
fi

