#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_cef_pd - Runs show commands for show tech cef
#
# March 2014
#
# Copyright (c) 2011-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_dpa_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.
###############################################################################

#####################################################################
#  Commands that run on SYS node (i.e. the node where the show tech
#  command is issued from).
#####################################################################

cmd_index=1
sys_exec[$cmd_index]='show running-config'
sys__ksh[$cmd_index]='nvgen -c -l 1 -t 1 -o 1'

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

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

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

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

((cmd_index++))
sys_exec[$cmd_index]='show cef tables'
sys__ksh[$cmd_index]='fib_show_command "-O" "0x0" "-3"'

((cmd_index++))
sys_exec[$cmd_index]='show cef ipv6 tables'
sys__ksh[$cmd_index]='fib_show_command "-O" "0x1" "-3"'

((cmd_index++))
sys_exec[$cmd_index]='show route'
sys__ksh[$cmd_index]='show_ipv4_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -s ipv4'

((cmd_index++))
sys_exec[$cmd_index]='show grid stats'
sys__ksh[$cmd_index]='grid_show -c'

((cmd_index++))
sys_exec[$cmd_index]='show grid trace all wrapping'
sys__ksh[$cmd_index]='rid_show_ltrace -EV -w'

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

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

((cmd_index++))
sys_exec[$cmd_index]='show spp node-counters'
sys__ksh[$cmd_index]='spp_sysdb_get -M node_counters'

((cmd_index++))
sys_exec[$cmd_index]=''
sys__ksh[$cmd_index]=''

###################################################################
#  Commands run on RP only
###################################################################
cmd_index=1
rp_exec[$cmd_index]='show ppinfo producer trace all location all'
rp__ksh[$cmd_index]='ppinfo_producer_show_ltrace -i all -P 0x0 -P 0x1 -P 0x2 -P 0x4'

((cmd_index++))
rp_exec[$cmd_index]='show ppinfo consumer trace all location all'
rp__ksh[$cmd_index]='ppinfo_consumer_show_ltrace -i all -P 0x0 -P 0x1 -P 0x2 -P 0x4'

((cmd_index++))
rp_exec[$cmd_index]='show cds server trace'
rp__ksh[$cmd_index]='cdssvr_show'

((cmd_index++))
rp_exec[$cmd_index]=''
rp__ksh[$cmd_index]=''

##################################################################
# Commands to be run on RP and LC
##################################################################

cmd_index=1
rplc_exec[$cmd_index]='show adjacency platform trace location $location'
rplc__ksh[$cmd_index]='dpa_aib_show_ltrace -i $fq_nodeid'

((cmd_index++))
rplc_exec[$cmd_index]='show grid trace all location $location'
rplc__ksh[$cmd_index]='rid_show_ltrace -EV -i $fq_nodeid'

((cmd_index++))
rplc_exec[$cmd_index]='show grid stats location $location'
rplc__ksh[$cmd_index]='grid_show -c -l $fq_nodeid'

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

((cmd_index++))
rplc_exec[$cmd_index]='show arp trace location $location'
rplc__ksh[$cmd_index]='show_arp_ltrace -i $fq_nodeid'

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

((cmd_index++))
pplc_exec[$cmd_index]='show cds producer trace location $location'
rplc__ksh[$cmd_index]='cdsproducer_show -i $fq_nodeid'

((cmd_index++))
rplc_exec[$cmd_index]='show cds proxy trace location $location'
rplc__ksh[$cmd_index]='cdsproxy_show -i $fq_nodeid'

((cmd_index++))
rplc_exec[$cmd_index]='show cds consumer trace location $location'
rplc__ksh[$cmd_index]='cdsconsumer_show -i $fq_nodeid'

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

#################################################################
# LC commands
#################################################################
# summary and etc
cmd_index=1

lc_exec[$cmd_index]='show process location $location'
lc__ksh[$cmd_index]='show_processes -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show memory location $location'
lc__ksh[$cmd_index]='show_memory_ng -n $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show captured packets ingress location $location'
lc__ksh[$cmd_index]='pak_capture_show_command -I -N $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show captured packets egress location $location'
lc__ksh[$cmd_index]='pak_capture_show_command -E -N $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show cef platform trace all all location $location'
lc__ksh[$cmd_index]='show_fib_hal_ltrace -P 0x0 -9 -A -i $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show cef trace wrapping loc $location'
lc__ksh[$cmd_index]='show_fib_trace -w -i $fq_nodeid -P 0x0'

((cmd_index++))
lc_exec[$cmd_index]='show cef trace errors location $location'
lc__ksh[$cmd_index]='show_fib_trace -i $fq_nodeid -P 0x0 -T 0x1'

((cmd_index++))
lc_exec[$cmd_index]='show af-ea ipv4 trace events location $location'
lc__ksh[$cmd_index]='dnx_af_ea_show_ltrace ipv4 -E -i $fq_nodeid' 

((cmd_index++))
lc_exec[$cmd_index]='show af-ea ipv4 trace errors location $location'
lc__ksh[$cmd_index]='dnx_af_ea_show_ltrace ipv4 -R -i $fq_nodeid' 

((cmd_index++))
lc_exec[$cmd_index]='show af-ea ipv6 trace events location $location'
lc__ksh[$cmd_index]='dnx_af_ea_show_ltrace ipv6 -E -i $fq_nodeid' 

((cmd_index++))
lc_exec[$cmd_index]='show af-ea ipv6 trace errors location $location'
lc__ksh[$cmd_index]='dnx_af_ea_show_ltrace ipv6 -R -i $fq_nodeid' 

((cmd_index++))
lc_exec[$cmd_index]='show af-ea mpls trace events location $location'
lc__ksh[$cmd_index]='dnx_af_ea_show_ltrace mpls -E -i $fq_nodeid' 

((cmd_index++))
lc_exec[$cmd_index]='show af-ea mpls trace errors location $location'
lc__ksh[$cmd_index]='dnx_af_ea_show_ltrace mpls -R -i $fq_nodeid' 

((cmd_index++))
lc_exec[$cmd_index]='show controllers npu stats counters-all detail instance all location $location'
lc__ksh[$cmd_index]='ofa_npu_stats_show -v a -i 0x10 -t e -p 0xffffffff -s 0x0 -d A -n $fq_nodeid'
 
((cmd_index++))
lc_exec[$cmd_index]='show controllers npu stats traps-all instance all location $location'
lc__ksh[$cmd_index]='ofa_npu_stats_show -v a -i 0x10 -t t -p 0xffffffff -s A -d 0x0 -n $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show controllers npu resources all location $location'
lc__ksh[$cmd_index]='bcmdpa_sysdb_show_hw_resources -t 0x270f -l $fq_nodeid'
 
((cmd_index++))
lc_exec[$cmd_index]=''
lc__ksh[$cmd_index]=''

# do not add any commands to read the adjacencies/prefixes from the HW
# because this can cause the protocol to flip because of many blocking
# IPC calls to the HW

##################################################################
# Run CPU type independent LC specific commands.
##################################################################
display_lc_cmds() {

    exec_commands lc

}

##################################################################
# Run show tech tcam commands
##################################################################
display() {

    print_main_heading "show tech-support cef platform"

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

    print_main_heading "show tech-support cef 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

