#!/bin/sh

subcmd="$1"
phyport="$2"
phyname="$3"

case "$subcmd" in
	"getState")	
		if [ $phyname = "phy1" ]; then
			link_status=$(ethtool dpdk1|grep Link|awk '{print $3}')
			speed=$(ethtool dpdk1|grep Speed|awk '{print $2}')
			duplex=$(ethtool dpdk1|grep Duplex|awk '{print $2}')
			if [ $link_status = "yes" ]; then
				port_state="connected"
				if [ $speed = "10000Mb/s" ];then
					port_speed="10000M"
				else
					port_speed="1000M"
				fi
				port_dup_mode=$duplex
				port_flowcontrol="off"
			else
				port_state="disconnected"
				port_speed="---"
				port_dup_mode="---"
				port_flowcontrol="---"
			fi

		echo "Port $phyport:"
		echo "   state       : $port_state "
		echo "   speed       : $port_speed "
		echo "   dup_mode    : $port_dup_mode "    
		echo "   flowcontrol : $port_flowcontrol "
		echo "" 
		fi
	;;
	"setState")
	
	;;
	"setNegotiation")
		if [ "$4" == "10000MF" ]; then
			ethtool -s dpdk1 speed 10000 duplex full autoneg off
		else
			ethtool -s dpdk1 speed 1000 duplex full autoneg off
		fi
	;;
	"statistics")
		if [ $phyname = "phy1" ]; then
			rx_pkgs=`cat /proc/net/dev|grep -w kern1:|awk '{print $2}'`
			echo "RxAll:"$(($rx_pkgs))
			tx_pkgs=`cat /proc/net/dev|grep -w kern1:|awk '{print $10}'`
			echo "TxAll:"$(($tx_pkgs))
			rx_bytes=`cat /proc/net/dev|grep -w kern1:|awk '{print $3}'`
			echo "RxNormal:"$(($rx_bytes))
			tx_bytes=`cat /proc/net/dev|grep -w kern1:|awk '{print $11}'`
			echo "TxNormal:"$(($tx_bytes))
		fi
	;;
	"init")	
		
	;;
	"setFlowcontrol")	
		if [ $phyname = "phy1" ]; then
			if ["$4" == "on"]; then
				ethtool --pause dpdk1 autoneg on rx on tx on
			else
				ethtool --pause dpdk1 autoneg off rx off tx off
			fi
		fi
	;;
esac
