# @name ALE Table test using SWITCH-CONFIG 
# @desc Checks default entries in ALE table and verifies addition and deletion of multicast entries.
# @requires net

ETHSWITCH_XS_FUNC_DUMP_UNICAST source 'common.sh'; dual_mac=`find /proc/device-tree/ -name dual_emac`; if [[ ! -z "$dual_mac" ]]; then die "This is a dual mac case, use a different dtb to test switch mode"; fi; iface=`get_eth_iface_name.sh` || die "error getting eth interface name"; mac_address=`cat /sys/class/net/$iface/address`; if [ -z "`switch-config -d|grep -i ucast| grep $mac_address`" ]; then die "TEST has failed since there is no unicast entry with the mac address of ethernet interface in ALE table."; fi
ETHSWITCH_XS_FUNC_DUMP_MCAST source 'common.sh'; dual_mac=`find /proc/device-tree/ -name dual_emac`; if [[ ! -z "$dual_mac" ]]; then die "This is a dual mac case, use a different dtb to test switch mode"; fi; if [ -z "`switch-config -d|grep -i mcast|grep -i "ff:ff:ff:ff:ff:ff"`" ]; then die "TEST has failed since there is no default multicast entry in ALE table."; fi
ETHSWITCH_XS_FUNC_DUMP_VLAN source 'common.sh'; dual_mac=`find /proc/device-tree/ -name dual_emac`; if [[ ! -z "$dual_mac" ]]; then die "This is a dual mac case, use a different dtb to test switch mode"; fi; if [ -z "`switch-config -d|grep -i vlan|grep -i "vid\s*=\s*0"`" ]; then die "TEST has failed since there is no default vlan entry in ALE table."; fi
ETHSWITCH_XS_FUNC_ADD_DELETE_MCAST source 'common.sh'; dual_mac=`find /proc/device-tree/ -name dual_emac`; if [[ ! -z "$dual_mac" ]]; then die "This is a dual mac case, use a different dtb to test switch mode"; fi; test_multi_addr=01:00:5E:00:55:55; if [ ! -z "`switch-config -d|grep -i $test_multi_addr`" ]; then die "Non-default multicast address $test_multi_addr is already in ALE table. Double-check or test with a different mcast address"; fi; do_cmd "switch-config --add-multi $test_multi_addr --port 7"; if [ -z "`switch-config -d|grep -i mcast|grep -i $test_multi_addr|grep -i "port_mask\s*=\s*0x7"`" ]; then die "New multicast entry is not present in ALE table or port mask is incorrect."; fi; do_cmd "switch-config -x $test_multi_addr"; if [ ! -z "`switch-config -d|grep -i mcast|grep -i $test_multi_addr`" ]; then die "Switch-config delete is not working correctly. Check manually."; fi
ETHSWITCH_XS_FUNC_SPEED_DUPLEXITY source 'common.sh'; dual_mac=`find /proc/device-tree/ -name dual_emac`; if [[ ! -z "$dual_mac" ]]; then die "This is a dual mac case, use a different dtb to test switch mode"; fi;  iface=`get_eth_iface_name.sh` || die "error getting eth interface name";  do_cmd "switch-config -S 10 -n 1 -D full"; do_cmd "switch-config -S 100 -n 2 -D half"; if [ -z "`switch-config -G -n 1|grep -i "10Mb/s"`" ]; then die "Port 1 is not set to 10 Mbps as expected"; fi; if [ -z "`switch-config -G -n 2|grep -i "100Mb/s"`" ]; then die "Port 2 is not set to 100 Mbps as expected"; fi; if [ -z "`switch-config -G -n 1|grep -i duplex|grep -i "full"`" ]; then die "Port 1 is not set to full-duplex as expected"; fi; if [ -z "`switch-config -G -n 2|grep -i duplex|grep -i "half"`" ]; then die "Port 2 is not set to half duplex as expected"; fi
ETHSWITCH_XS_FUNC_ETH0_ADD_DELETE_MCAST_IPROUTE source 'common.sh'; test_multi_addr=01:00:5E:00:55:55; interface="eth0"; if [ ! -z "`ip maddr show dev $interface|grep -i $test_multi_addr`" ]; then die "Non-default multicast address $test_multi_addr is already in ALE table. Double-check or test with a different mcast address"; fi; do_cmd "ip maddr add dev $interface $test_multi_addr"; if [ -z "`ip maddr show dev $interface|grep -i $test_multi_addr`" ]; then die "New multicast entry is not present in ip table."; fi; if [ -z "`switch-config -d|grep -i mcast|grep -i $test_multi_addr`" ]; then die "New multicast entry is not present in ALE table."; fi; do_cmd "ip maddr del dev $interface $test_multi_addr"; if [ ! -z "`switch-config -d|grep -i mcast|grep -i $test_multi_addr`" ]; then die "switch-config delete is not working correctly. Check manually."; fi
