#!/pkg/bin/ksh
# -----------------------------------------------------------------------------
# show_tech_fast_ether_common - Shared show tech-support fast script for 
#                               ethernet
#
# October 2008, Simon Osborne
#
# Copyright (c) 2008-2011, 2013-2018 by cisco Systems, Inc.
# All rights reserved.
#------------------------------------------------------------------------------


#
# Load the script provided by show-tech infra, which provides worker functions
#
. /pkg/bin/show_tech_main_fragment

#
# Parse the arguments to the script - card type and interface filter are the 
# only support options currently.  No need to use the default parser function,
# as this has been done by caller.
#
__cardtype="unspecified"
internal_if="unspecified"
external_if=""
ether_arg_string=""
bundle_only_arg_string=""

while [ "$#" -gt "0" ]; do
    case "$1" in
        -I) internal_if="$2"; shift 2;;
        -t) __cardtype="$2"; shift 2;;
        *) shift;;
    esac
done

if [ "$internal_if" != "unspecified" ]; then
    external_if=`convert_interface_fmt '-e' $internal_if`
fi

if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi

#
# List of commands to be run.  East set must finish with a pair of empty 
# strings.  Note that it is important to use single quotes rather than double 
# quotes for the strings containing your commands.
#
# For all of these the __ksh variable is the process that will actually be 
# spawned, the _exec variable is just a string that is printed in the output to
# describe it. 
#

###############################################################################
# Show commands that run once per LR                                          #
###############################################################################
#
# The following commands are the old (show vlan ...) and new (show ethernet 
# ...) versions of the VLAN show commands.
# The legacy commands are only run if the vlan_show_cmds executable
# is available.
#
sys_exec[1]='show ethernet trunk'
sys__ksh[1]='ether_show_cmds -s -t'

sys_exec[2]='show ethernet trunk detail'
sys__ksh[2]='ether_show_cmds -s -u'

sys_exec[3]='show ethernet tags'
sys__ksh[3]='ether_show_cmds -s -e'

sys_exec[4]='show ethernet tags match-order'
sys__ksh[4]='ether_show_cmds -s -e -M'

sys_exec[5]='show ethernet tags detail'
sys__ksh[5]='ether_show_cmds -s -f'

sys_exec[6]='show ethernet driver internal ethlike-mib-stats detail'
sys__ksh[6]='ethernet_etherlike_mib_stats_cmd -S -d'

sys_exec[7]='show ethernet infra internal mac-mib-stats detail all'
sys__ksh[7]='ethernet_macstat_mib_stats_cmd -S -d'

sys_exec[8]='show ethernet infra internal vlan-mib-stats detail all'
sys__ksh[8]='ethernet_vlan_mib_stats_cmd -S -d'

sys_exec[9]=''
sys__ksh[9]=''

#
# Legacy versions
#
sys_legacy_exec[1]='show vlan trunks'
sys_legacy__ksh[1]='vlan_show_cmds -s -t'

sys_legacy_exec[2]='show vlan trunks summary'
sys_legacy__ksh[2]='vlan_show_cmds -s -a'

sys_legacy_exec[3]='show vlan interface'
sys_legacy__ksh[3]='vlan_show_cmds -s -i'

sys_legacy_exec[4]='show vlan tags'
sys_legacy__ksh[4]='vlan_show_cmds -s -g'

sys_legacy_exec[5]=''
sys_legacy__ksh[5]=''

###############################################################################
# Interface specific show commands that run once per LR                       #
# (ie. global commands or those only runnable on RP)                          #
###############################################################################

sys_intf_exec[0]=''
sys_intf__ksh[0]=''

###############################################################################
# Show commands that run on all RP or LC                                      #
###############################################################################
rplc_exec[1]='show ethernet driver trace'
rplc__ksh[1]='ethernet_trace_show'

rplc_exec[2]='show ethernet infra trace'
rplc__ksh[2]='ether_show_trace'

rplc_exec[3]='show processes ether_caps_partner'
rplc__ksh[3]='sysmgr_show -o -p ether_caps_partner'

rplc_exec[4]='show processes ether_sock'
rplc__ksh[4]='sysmgr_show -o -p ether_sock'

rplc_exec[5]='show processes vlan_ma'
rplc__ksh[5]='sysmgr_show -o -p vlan_ma'

rplc_exec[6]='show processes vlan_ea'
rplc__ksh[6]='sysmgr_show -o -p vlan_ea'

#
# Internal ether-infra show commands
#
rplc_exec[7]='show ethernet infra internal ether-ma global'
rplc__ksh[7]='ether_show_cmds_internal -s -h -J'

rplc_exec[8]='show ethernet infra internal ether-ma trunks'
rplc__ksh[8]='ether_show_cmds_internal -s -e -J'

rplc_exec[9]='show ethernet infra internal vlan-ma global'
rplc__ksh[9]='ether_show_cmds_internal -s -f -J'

rplc_exec[10]='show ethernet infra internal vlan-ma trunks'
rplc__ksh[10]='ether_show_cmds_internal -s -b -J -C'

rplc_exec[11]='show ethernet infra internal vlan-ma subs'
rplc__ksh[11]='ether_show_cmds_internal -s -a -J -C'

rplc_exec[12]='show ethernet infra internal ea global'
rplc__ksh[12]='ether_show_cmds_internal -s -g -J'

rplc_exec[13]='show ethernet infra internal ea trunks'
rplc__ksh[13]='ether_show_cmds_internal -s -d -J -C'

rplc_exec[14]='show ethernet infra internal ea subs'
rplc__ksh[14]='ether_show_cmds_internal -s -c -J -C'

#
# Internal G-Ether commands
#
rplc_exec[15]='show ethernet driver internal all driver-id all [location $location]'
rplc__ksh[15]='ethernet_show_internal -F -K -M'

rplc_exec[16]='show ethernet driver api-stats location $location'
rplc__ksh[16]='ethernet_api_stats_command -S'

rplc_exec[17]='show ethernet driver api-stats detail all location $location'
rplc__ksh[17]='ethernet_api_stats_command -S -d'

rplc_exec[18]=''
rplc__ksh[18]=''


###############################################################################
# Show commands that run on all RPs                                           #
###############################################################################
rp_exec[1]=''
rp__ksh[1]=''


###############################################################################
# Commands that need to loop for all nodes within the rack.  This is used for #
# commands that require a location, don't support location all, and don't run #
# on the LCs                                                                  #
###############################################################################

rp_loc_exec[1]=''
rp_loc__ksh[1]=''

#
# The display() function is the one that does all the work - called by us as 
# this is a worker script.
#
display() {
    print_main_heading "show tech-support ether common"
        
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
        if [ "$internal_if" != "unspecified" ]; then
            exec_commands sys_intf
        fi
        if [[ -x `which vlan_show_cmds 2>/dev/null` ]]; then
            exec_commands sys_legacy
        fi
    else
        case "$__cardtype" in
        "RP")
            exec_commands rplc
            exec_commands rp
            exec_commands_rack_nodes rp_loc
            ;;
        "LC")
            exec_commands rplc
            ;;
        esac
    fi
    
    print_main_heading "show tech-support ether common complete"
}

display

