#!/bin/sh
#this is x25_test, but at a slower speed

#Set up the test Environment for pad_tests

clear_scr()
{
if [ -x /usr/bin/clear ]
then
	/usr/bin/clear
else if [ -x /usr/ucb/clear ]
then
	/usr/ucb/clear
fi
fi
}

# Restart the VCOM software after reconfiguration

re_st_start()
{

#vcom_rst -f 0
#vcom_dl 0
#vcom_stat 0
vcom_cfg 0
}

#
# Confiuration files for X25
#

echo "TYPE = X25
L3PLPMODE = DCE
LAPB_MODE = DCE
LAPB_phy_if = DCE
LAPB_MAXFRAME = 4096
LAPB_BAUD = 56000
X25_VSN = 84
LTC = 1
HTC = 255 " > /tmp/x25port.0A
    
echo "TYPE = X25
L3PLPMODE = DTE
LAPB_MODE = DTE
LAPB_phy_if = DTE
LAPB_MAXFRAME = 4096
LAPB_BAUD = 0
X25_VSN = 84
LTC = 1
HTC=255 " > /tmp/x25port.0C

xcf -b0 -ca /tmp/x25port
xcf -b0 -cc /tmp/x25port

# Make a fresh start for the test
re_st_start

# remove the files created for xcf
rm /tmp/x25port.0A
rm /tmp/x25port.0C

# Clear the screen i.e ready to take the input
clear_scr

while :
do
echo "Enter Number of Connections to be made : \c"
read Num_cnct

if [ $Num_cnct -lt 1 -o $Num_cnct -gt 255 ]
then
	echo "Invalid Number of connections."
else
	break
fi
done

while :
do
echo "Enter Test number : \c"
read Test_num

if [ $Test_num -lt 1 -o $Test_num -gt 3 ]
then
	echo "Invalid Test Number."
else
	break
fi
done

while :
do
echo "Enter board number : \c"
read brd_num

if [ $brd_num -lt 0 -o $brd_num -gt 3 ]
then
	echo "Invalid board Number."
else
	break
fi
done

echo "Enter Subnet Id : \c"
read subnet_id

if [ x$Test_num = x1 ]
then
	echo "Enter Number of packets to be sent: \c"
	read Pkt_num
	echo "Enter Packet Size: \c"
	read Pkt_sz
fi

kk=1
while [ $kk -le 1 ]
do

(

xx=1
while : 
do
	if [ $xx -le $Num_cnct ]
	then
		echo "####### Starting the $xx x1 #######"
		xtest1 &
		sleep 1
		xtest2 -b$brd_num -s$subnet_id -t$Test_num -n$Pkt_num \
			-z$Pkt_sz &
		xx=`expr $xx + 1`
	else
		break
	fi
done

#xx=1
#while :
#do
#	if [ $xx -le $Num_cnct ]
#	then
#		echo "####### Starting the $xx x2 #######"
#		if [ x$Test_num = x1 ]
#		then
#			xtest2 -b$brd_num -s$subnet_id -t$Test_num -n$Pkt_num \
#				-z$Pkt_sz &
#		else
#			xtest2 -b$brd_num -s$subnet_id -t$Test_num &
#		fi
#
#		xx=`expr $xx + 1`
#	else
#		break
#	fi
#done

) >> x25.log 2>&1

subnet_id=c
kk=`expr $kk + 1`
done
