#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_ether_platform - Shared show tech-support script for ethernet
# Cisco_user: Ravi Kant(rakant)
# Copyright (c) 2019-2021 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

# Load the script fragment containing the code for the following functions
# - print_main_heading
# - print_command_heading
# - run_single_command
# - run_commands
# - run_single_command_on_all_nodes
# - run_commands_on_all_nodes
# - default_parser_function
. /pkg/bin/show_tech_main_fragment
. /pkg/bin/show_tech_pmdb_util

# Parse the arguments to the script.
__cardtype="unspecified"

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

if [ "$__filename" = "unspecified" ]; then
    echo "$0: output file not specified"
    exit
fi

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

################################################################################
# List each set of show commands to be run. Each set must finish with an empty
# string. Note that it is important to use single quotes rather than double
# quotes for the strings containing your commands.
###############################################################################

#############################################################
# Show commands that run once per system                    #
#############################################################

cmd_index=1
sys_exec[$cmd_index]='show context'
sys__ksh[$cmd_index]='corehelper_context -c 0x1 -n all'
((cmd_index++))

sys_exec[$cmd_index]='show redundancy'
sys__ksh[$cmd_index]='redcon_show'
((cmd_index++))

sys_exec[$cmd_index]='show issu'
sys__ksh[$cmd_index]='issu_show_status -I'
((cmd_index++))

sys_exec[$cmd_index]='show inventory all'
sys__ksh[$cmd_index]='show_inventory -e -t'
((cmd_index++))

sys_exec[$cmd_index]='show platform vm'
sys__ksh[$cmd_index]='show_platform_sysdb -v'
((cmd_index++))

sys_exec[$cmd_index]='show process blocked location all'
sys__ksh[$cmd_index]='sh_proc_ng_blocked -l all'
((cmd_index++))

sys_exec[$cmd_index]='show im status'
sys__ksh[$cmd_index]='im_show status'
((cmd_index++))

sys_exec[$cmd_index]=''
sys__ksh[$cmd_index]=''

#############################################################
# Commands that run on RP and LC nodes                      #
#############################################################

cmd_index=1
rplc_exec[$cmd_index]='show im trace'
rplc__ksh[$cmd_index]='im_show_trace'
((cmd_index++))

rplc_exec[$cmd_index]='show ethernet v-ether trace location $location'
rplc__ksh[$cmd_index]='eth_intf_show_trace -i $fq_nodeid'
((cmd_index++))

rplc_exec[$cmd_index]='show ethernet infra trace location $location'
rplc__ksh[$cmd_index]='ether_show_trace -i $fq_nodeid'
((cmd_index++))

rplc_exec[$cmd_index]='show spp trace platform common all location $location'
rplc__ksh[$cmd_index]='spp_fretta_show_ltrace -i $fq_nodeid -A'
((cmd_index++))

rplc_exec[$cmd_index]='show spp node-counters location $location'
rplc__ksh[$cmd_index]='spp_sysdb_get -L $fq_nodeid node_counters'
((cmd_index++))

rplc_exec[$cmd_index]='show spp trace platform socket all location $location'
rplc__ksh[$cmd_index]='spp_socket_show_ltrace -i $fq_nodeid -A'
((cmd_index++))

rplc_exec[$cmd_index]='show ethernet driver trace location $location'
rplc__ksh[$cmd_index]='ethernet_trace_show -i $fq_nodeid'
((cmd_index++))

rplc_exec[$cmd_index]='show fwdlib trace all '
rplc__ksh[$cmd_index]='fwdlib_show_ltrace -A'
((cmd_index++))

rplc_exec[$cmd_index]='show optics trace all '
rplc__ksh[$cmd_index]='optics_show_ltrace -A'
((cmd_index++))

rplc_exec[$cmd_index]='show eapd optics trace all '
rplc__ksh[$cmd_index]='optics_eapd_show_ltrace -A '
((cmd_index++))

rplc_exec[$cmd_index]='show dpfpga trace all '
rplc__ksh[$cmd_index]='dpfpga_show_ltrace -E -V '
((cmd_index++))

rplc_exec[$cmd_index]=''
rplc__ksh[$cmd_index]=''

#############################################################
# Commands that run on RP nodes                             #
#############################################################
cmd_index=1
rp_exec[$cmd_index]='show portmode trace all'
rp__ksh[$cmd_index]='portmode_show_ltrace -A'
((cmd_index++))

rp_exec[$cmd_index]=''
rp__ksh[$cmd_index]=''

#############################################################
# Commands that run on LC nodes                             #
#############################################################

cmd_index=1
lc_exec[$cmd_index]='show qos ea trace all location $location'
lc__ksh[$cmd_index]='qos_ea_show_ltrace -i $fq_nodeid -A'
((cmd_index++))

lc_exec[$cmd_index]='show pidb trace location $location'
lc__ksh[$cmd_index]='dpa_pidb_show_ltrace -i $fq_nodeid -T 0x0'
((cmd_index++))

lc_exec[$cmd_index]='show pidb error location $location'
lc__ksh[$cmd_index]='dpa_pidb_show_ltrace -i $fq_nodeid -T 0x1'
((cmd_index++))

lc_exec[$cmd_index]='show ether-ea stats location $location'
lc__ksh[$cmd_index]='dpa_ether_ea_interface_debug_show -o s -n $fq_nodeid -i'
((cmd_index++))

lc_exec[$cmd_index]='show ether-ea stats location $location'
lc__ksh[$cmd_index]='dnx_ether_ea_interface_debug_show -o s -n $fq_nodeid -i'
((cmd_index++))

lc_exec[$cmd_index]='show bundle load-balancing detail location $location $fq_nodeid'
lc__ksh[$cmd_index]='bundlemgr_adj_show -d -h $fq_nodeid'
((cmd_index++))

lc_exec[$cmd_index]=''
lc__ksh[$cmd_index]=''

###############################################################################
# Run this after all other commands, to leave a time stamp after the last     #
# command we run - makes analysis easier!                                     #
###############################################################################
final_exec[1]='Last show tech ethernet command'
final__ksh[1]='echo Last show tech ethernet command'

final_exec[2]=''
final__ksh[2]=''
##################################################################
# Run show tech commands
##################################################################
display() {

    print_main_heading "show tech-support ethernet platform"

    # Get the card_type: SYS|RP|DRP|LC.
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case "$__cardtype" in
        "RP")
            exec_commands rplc
            exec_commands rp
            display_pmdb
            ;;
        "LC")
            exec_commands rplc
            exec_commands lc
            display_pmdb
            ;;
        esac
    fi

    # Run the common modules
    arg_string="$arg_string -t $__cardtype"
    if [[ -x `which show_tech_fast_ether_pd 2>/dev/null` ]]; then
        run_module show_tech_fast_ether_pd "$arg_string"
    fi

    exec_commands final

    print_main_heading "show tech-support ethernet platform complete"
}

# This function calls the display() function and sends the output to file if
# the file option has been set.
. /pkg/bin/show_tech_file_fragment
