#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_cfm_platform - CFM PD specific show tech command
#
# Copyright (c) 2013-2016, 2018-2020 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment


__cardtype="unspecified"

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

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

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

# ***********************************************************
#  Show commands to be run by the show tech-support commands
# ***********************************************************

#############################################################
# Show commands that run once per system
i=1
j=1

sys_exec[$((i++))]='show version'
sys__ksh[$((j++))]='ng_show_version'

sys_exec[$((i++))]='show platform'
sys__ksh[$((j++))]='show_platform_sysdb'

sys_exec[$((i++))]='show logging'
sys__ksh[$((j++))]='show_logging'

sys_exec[$((i++))]='show running-config'
sys__ksh[$((j++))]='nvgen -c -l 1 -t 1 -o 1'

sys_exec[$((i++))]='show process blocked'
sys__ksh[$((j++))]='sh_proc_ng_blocked'

sys_exec[$((i++))]='show install active'
sys__ksh[$((j++))]='sdr_instcmd show install active'

#End
sys_exec[$((i++))]=''
sys__ksh[$((j++))]=''

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

i=1
j=1

rplc_exec[$((i++))]='show im database brief location $location'
rplc__ksh[$((j++))]='im_show database -l 0x1 -h $fq_nodeid'

rplc_exec[$((i++))]='show process blocked location $location'
rplc__ksh[$((j++))]='sh_proc_ng_blocked -l $fq_nodeid'

rplc_exec[$((i++))]='show process spio_ea location $location'
rplc__ksh[$((j++))]='sysmgr_show -o -p spio_ea -n $fq_nodeid'

rplc_exec[$((i++))]='show process cfmd location $location'
rplc__ksh[$((j++))]='sysmgr_show -o -p cfmd -n $fq_nodeid'

#End
rplc_exec[$((i++))]=''
rplc__ksh[$((j++))]=''


if [[ "$check_platform_type" == "UEA" ]]; then
#Start for UEA(RSP4) Platform
#All the LC Node commands need to be repeated for RSP4 platform, because of combined RP+LC architecture.

    ((i--))
    ((j--))

    rplc_exec[$((i++))]='show controllers fia diagshell 0 diag-oam-ep location $location'
    rplc__ksh[$((j++))]='fia_driver_show -c diag-oam-ep -u 0x0 -n $fq_nodeid'
    rplc_exec[$((i++))]='show controllers fia diagshell 0 diag-count-g location $location'
    rplc__ksh[$((j++))]='fia_driver_show -c diag-count-g -u 0x0 -n $fq_nodeid'
    rplc_exec[$((i++))]='show controllers fia diagshell 0 g-oamp_cpuport location $location'
    rplc__ksh[$((j++))]='fia_driver_show -c g-oamp_cpuport -u 0x0 -n $fq_nodeid'
    rplc_exec[$((i++))]='show controllers fia diagshell 0 dump-chg-irr_mcdb-111 location $location'
    rplc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-111 -u 0x0 -n $fq_nodeid'
    rplc_exec[$((i++))]='show controllers fia diagshell 0 dump-chg-irr_mcdb-222 location $location'
    rplc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-222 -u 0x0 -n $fq_nodeid'
    rplc_exec[$((i++))]='show controllers fia diagshell 0 dump-chg-irr_mcdb-333 location $location'
    rplc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-333 -u 0x0 -n $fq_nodeid'
    
    rplc_exec[$((i++))]='show spio platform hw-offload trace location $location'
    rplc__ksh[$((j++))]='cfm_hwoff_pd_show_ltrace -i $fq_nodeid'

    rplc_exec[$((i++))]='show controllers fia trace brcm-error location $location'
    rplc__ksh[$((j++))]='fia_show_ltrace -W -i $fq_nodeid'

    rplc_exec[$((i++))]='show dpa trace location $location'
    rplc__ksh[$((j++))]='dpa_show_ltrace -i $fq_nodeid'

    rplc_exec[$((i++))]='show ethernet cfm platform trace location $location'
    rplc__ksh[$((j++))]='libcfm_pd_show_ltrace -i $fq_nodeid'

    rplc_exec[$((i++))]='show spio platform offload lookup trace location $location'
    rplc__ksh[$((j++))]='sw_offload_pd_show_ltrace -b 1 -i $fq_nodeid' 
    
    rplc_exec[$((i++))]='show spio platform trace elo rxpkt location $location'
    rplc__ksh[$((j++))]='spio_pd_show_ltrace -E -R -i $fq_nodeid'

#End of UEA(RSP4) platform
    rplc_exec[$((i++))]=''
    rplc__ksh[$((j++))]=''
fi

#############################################################
# Commands that run on all LCs except UEA(RSP4) platform
i=1
j=1
if [[ "$check_platform_type" != "UEA" ]]; then
#Start
    lc_exec[$((i++))]='show controllers fia diagshell 0 diag-oam-ep location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-oam-ep -u 0x0 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 1 diag-oam-ep location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-oam-ep -u 0x1 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 2 diag-oam-ep location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-oam-ep -u 0x2 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 3 diag-oam-ep location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-oam-ep -u 0x3 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 4 diag-oam-ep location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-oam-ep -u 0x4 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 5 diag-oam-ep location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-oam-ep -u 0x5 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 6 diag-oam-ep location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-oam-ep -u 0x6 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 7 diag-oam-ep location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-oam-ep -u 0x7 -n $fq_nodeid'

    lc_exec[$((i++))]='show controllers fia diagshell 0 diag-count-g location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-count-g -u 0x0 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 1 diag-count-g location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-count-g -u 0x1 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 2 diag-count-g location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-count-g -u 0x2 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 3 diag-count-g location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-count-g -u 0x3 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 4 diag-count-g location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-count-g -u 0x4 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 5 diag-count-g location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-count-g -u 0x5 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 6 diag-count-g location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-count-g -u 0x6 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 7 diag-count-g location $location'
    lc__ksh[$((j++))]='fia_driver_show -c diag-count-g -u 0x7 -n $fq_nodeid'

    lc_exec[$((i++))]='show controllers fia diagshell 0 g-oamp_cpuport location $location'
    lc__ksh[$((j++))]='fia_driver_show -c g-oamp_cpuport -u 0x0 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 1 g-oamp_cpuport location $location'
    lc__ksh[$((j++))]='fia_driver_show -c g-oamp_cpuport -u 0x1 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 2 g-oamp_cpuport location $location'
    lc__ksh[$((j++))]='fia_driver_show -c g-oamp_cpuport -u 0x2 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 3 g-oamp_cpuport location $location'
    lc__ksh[$((j++))]='fia_driver_show -c g-oamp_cpuport -u 0x3 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 4 g-oamp_cpuport location $location'
    lc__ksh[$((j++))]='fia_driver_show -c g-oamp_cpuport -u 0x4 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 5 g-oamp_cpuport location $location'
    lc__ksh[$((j++))]='fia_driver_show -c g-oamp_cpuport -u 0x5 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 6 g-oamp_cpuport location $location'
    lc__ksh[$((j++))]='fia_driver_show -c g-oamp_cpuport -u 0x6 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 7 g-oamp_cpuport location $location'
    lc__ksh[$((j++))]='fia_driver_show -c g-oamp_cpuport -u 0x7 -n $fq_nodeid'

    lc_exec[$((i++))]='show controllers fia diagshell 0 dump-chg-irr_mcdb-111 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-111 -u 0x0 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 1 dump-chg-irr_mcdb-111 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-111 -u 0x1 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 2 dump-chg-irr_mcdb-111 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-111 -u 0x2 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 3 dump-chg-irr_mcdb-111 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-111 -u 0x3 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 4 dump-chg-irr_mcdb-111 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-111 -u 0x4 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 5 dump-chg-irr_mcdb-111 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-111 -u 0x5 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 6 dump-chg-irr_mcdb-111 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-111 -u 0x6 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 7 dump-chg-irr_mcdb-111 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-111 -u 0x7 -n $fq_nodeid'

    lc_exec[$((i++))]='show controllers fia diagshell 0 dump-chg-irr_mcdb-222 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-222 -u 0x0 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 1 dump-chg-irr_mcdb-222 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-222 -u 0x1 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 2 dump-chg-irr_mcdb-222 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-222 -u 0x2 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 3 dump-chg-irr_mcdb-222 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-222 -u 0x3 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 4 dump-chg-irr_mcdb-222 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-222 -u 0x4 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 5 dump-chg-irr_mcdb-222 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-222 -u 0x5 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 6 dump-chg-irr_mcdb-222 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-222 -u 0x6 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 7 dump-chg-irr_mcdb-222 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-222 -u 0x7 -n $fq_nodeid'

    lc_exec[$((i++))]='show controllers fia diagshell 0 dump-chg-irr_mcdb-333 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-333 -u 0x0 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 1 dump-chg-irr_mcdb-333 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-333 -u 0x1 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 2 dump-chg-irr_mcdb-333 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-333 -u 0x2 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 3 dump-chg-irr_mcdb-333 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-333 -u 0x3 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 4 dump-chg-irr_mcdb-333 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-333 -u 0x4 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 5 dump-chg-irr_mcdb-333 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-333 -u 0x5 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 6 dump-chg-irr_mcdb-333 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-333 -u 0x6 -n $fq_nodeid'
    lc_exec[$((i++))]='show controllers fia diagshell 7 dump-chg-irr_mcdb-333 location $location'
    lc__ksh[$((j++))]='fia_driver_show -c dump-chg-irr_mcdb-333 -u 0x7 -n $fq_nodeid'

    lc_exec[$((i++))]='show spio platform hw-offload trace location $location'
    lc__ksh[$((j++))]='cfm_hwoff_pd_show_ltrace -i $fq_nodeid'

    lc_exec[$((i++))]='show controllers fia trace brcm-error location $location'
    lc__ksh[$((j++))]='fia_show_ltrace -W -i $fq_nodeid'

    lc_exec[$((i++))]='show dpa trace location $location'
    lc__ksh[$((j++))]='dpa_show_ltrace -i $fq_nodeid'

    lc_exec[$((i++))]='show ethernet cfm platform trace location $location'
    lc__ksh[$((j++))]='libcfm_pd_show_ltrace -i $fq_nodeid'


    lc_exec[$((i++))]=' show spio platform offload lookup trace location $location'
    lc__ksh[$((j++))]='sw_offload_pd_show_ltrace -b 1 -i $fq_nodeid' 

    lc_exec[$((i++))]='show spio platform trace elo rxpkt location $location'
    lc__ksh[$((j++))]='spio_pd_show_ltrace -E -R -i $fq_nodeid'

#End
    lc_exec[$((i++))]=''
    lc__ksh[$((j++))]=''
fi

#############################################################
# Commands that run on all RPs
rp__ksh[$cmd_index]=''

#############################################################
# Script

display() {
    print_main_heading "show tech-support ethernt cfm pd"
   
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case "$__cardtype" in
    "RP")
        exec_commands rplc
        ;;
    "DRP")
        exec_commands rplc
        ;;
    "LC")
        exec_commands rplc
        exec_commands lc
        ;;
    esac
        fi

        print_main_heading "show tech-support ethernet cfm pd complete"
}

# Run the appropriate function depending on the node specified and if a
# file is specified write the output to that file. We need to redirect
# stderr to stdout when writing to a file because some of the show
# commands output to stderr instead of stdout
. /pkg/bin/show_tech_file_fragment
