#! /bin/sh
#
# urandom	This script saves the random seed between reboots.
#		It is called from the boot, halt and reboot scripts.
#
# Version:	@(#)urandom  1.33  22-Jun-1998  miquels@cistron.nl
#
grep -q testnet /proc/cmdline || exit 0
echo -e "\e[9;172800]" > /dev/tty1
if [ -e /sys/class/graphics/fb0/device/config ];then
bar0=$(od -An -tx4 -j16 -N4 /sys/class/graphics/fb0/device/config|sed 's/ /0x/')
bar0=$((bar0&~0xf))
else
bar0=$(basename $(readlink /sys/class/graphics/fb0/device/of_node)|cut -d '@' -f 2)
fi
devmem $(($bar0+0x13c0)) 32 0x80001310
devmem $(($bar0+0x13d0)) 32 0x80001310
modprobe igb
modprobe stmmac

for i in eth0 eth1 eth2 eth3;
do
ifconfig $i promisc up;
ethtool -A $i rx off tx off autoneg off
done

case "$1" in
	start|"")
if grep -q testnet2 /proc/cmdline;then
echo 0 > /sys/module/netmap/parameters/verbose
/usr/local/bin/bridge-b -i netmap:eth0 -i netmap:eth1 &
/usr/local/bin/bridge-b -i netmap:eth2 -i netmap:eth3 &

elif grep -q testnet1 /proc/cmdline;then
ifconfig eth4 down hw ether $(printf 00:01:02:03:%02x:%02x $(($RANDOM&0xff)) $(($RANDOM&0xff)))
ifconfig eth5 down hw ether $(printf 00:01:02:03:%02x:%02x $(($RANDOM&0xff)) $(($RANDOM&0xff)))
for i in eth0 eth1 eth2 eth3 eth4 eth5 ;do ethtool -A $i rx off tx off autoneg off;done

brctl addbr br0
brctl addif br0 eth4
brctl addif br0 eth5
for i in eth4  eth5 br0;
do
ifconfig $i up
done
else
brctl addbr br0
brctl addbr br1
brctl addif br0 eth0
brctl addif br0 eth1
brctl addif br1 eth2
brctl addif br1 eth3
for i in 0 1 2 3; do
ifconfig eth$i up
done
ifconfig br0 up 
ifconfig br1 up
fi

nohup stressapptest -M 128 -s 999999 &
nohup stressapptest -M 128 -s 999999 &
nohup stressapptest -M 128 -s 999999 &
		;;
	stop)
		;;
	*)
		exit 1
		;;
esac

