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

. /pkg/bin/show_tech_main_fragment

if [ -e /pkg/bin/show_tech_bfd_hwoff_pd ]; then
    . /pkg/bin/show_tech_bfd_hwoff_pd
fi    
__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_bfd_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
cmd_index=1
sys_show_exec[$cmd_index]='show version'
sys_show__ksh[$cmd_index]='ng_show_version'

((cmd_index++))
sys_show_exec[$cmd_index]='show platform'
sys_show__ksh[$cmd_index]='show_platform_sysdb'

((cmd_index++))
sys_show_exec[$cmd_index]='show logging'
sys_show__ksh[$cmd_index]='show_logging'

((cmd_index++))
sys_show_exec[$cmd_index]='show running-config'
sys_show__ksh[$cmd_index]='nvgen -c -l 1 -t 1 -o 1'

((cmd_index++))
sys_show_exec[$cmd_index]='show bfd all'
sys_show__ksh[$cmd_index]='bfd_show_command -o 0x3 -x 0x4'

((cmd_index++))
sys_show_exec[$cmd_index]='show bfd all session'
sys_show__ksh[$cmd_index]='bfd_show_command -o 0x1 -x 0x4'

((cmd_index++))
sys_show_exec[$cmd_index]='show bfd all session detail'
sys_show__ksh[$cmd_index]='bfd_show_command -o 0x1 -x 0x4 -d'

((cmd_index++))
sys_show_exec[$cmd_index]='show process bfd'
sys_show__ksh[$cmd_index]='sysmgr_show -o -p bfd'

((cmd_index++))
sys_show_exec[$cmd_index]='show install active'
sys_show__ksh[$cmd_index]='sdr_instcmd show install active'

((cmd_index++))
sys_show_exec[$cmd_index]='show redundancy'
sys_show__ksh[$cmd_index]='show_rmf_sysdb'

#End
((cmd_index++))
sys_show__ksh[$cmd_index]=''

#############################################################
# Commands that run on RP and LC nodes
cmd_index=1
rplc_show_exec[$cmd_index]='show im database brief location $location'
rplc_show__ksh[$cmd_index]='im_show database -l 0x1 -h $fq_nodeid'

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

((cmd_index++))
rplc_show_exec[$cmd_index]='show controllers npu voq-usage interface all instance all location $location'
rplc_show__ksh[$cmd_index]='dpa_qosea_voq_show -v x -i 0x10 -n $fq_nodeid -t n -p 0x0'

#End
((cmd_index++))
rplc_show__ksh[$cmd_index]=''

#############################################################
# Commands that run on all LCs

cmd_index=1
lc_exec[$cmd_index]='show bfd all location $location'
lc__ksh[$cmd_index]='bfd_show_command -o 0x3 -x 0x4 -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show process bfd_agent location $location'
lc__ksh[$cmd_index]='sysmgr_show -o -p bfd_agent -n $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd all session agent detail location $location'
lc__ksh[$cmd_index]='bfd_show_command -o 0x1 -d -b -x 0x4 -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd timer-groups location $location'
lc__ksh[$cmd_index]='bfd_show_command -o 0x5 -b -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd session-array location $location'
lc__ksh[$cmd_index]='bfd_show_command -o 0x7 -b -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd interfaces location $location'
lc__ksh[$cmd_index]='bfd_show_command -o 0x8 -b -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd counters all packet invalid location $location'
lc__ksh[$cmd_index]='bfd_show_command -o 0x4 -c 0x3 -b -x 0x4 -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd counters all packet private detail location $location'
lc__ksh[$cmd_index]='bfd_show_command -o 0x4 -c 0x2 -d -x 0x4 -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd all session status detail location $location'
lc__ksh[$cmd_index]='bfd_show_command -o 0x1 -d -f -x 0x4 -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd all session status history location $location'
lc__ksh[$cmd_index]='bfd_show_command -o 0x1 -f -h -x 0x4 -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd all session status non-active history location $location'
lc__ksh[$cmd_index]='bfd_show_command -o 0x1 -h -k -f -x 0x4 -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd client history'
lc__ksh[$cmd_index]='bfd_show_command -o 0x2 -y'

((cmd_index++))
lc_exec[$cmd_index]='show bfd-hw-offload trace error location $location'
lc__ksh[$cmd_index]='bfd_offload_show_ltrace -E -i $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd-hw-offload trace event location $location'
lc__ksh[$cmd_index]='bfd_offload_show_ltrace -V -i $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd-hw-offload trace packet location $location'
lc__ksh[$cmd_index]='bfd_offload_show_ltrace -P -i $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show bfd-hw-offload trace info location $location'
lc__ksh[$cmd_index]='bfd_offload_show_ltrace -N -i $fq_nodeid'

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

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

((cmd_index++))
lc_exec[cmd_index]='show dpa resources bfdhwoff location $location'
lc__ksh[cmd_index]='ofa_sysdb_show_resources -r -t 0x270f -l $fq_nodeid'

((cmd_index++))
lc_exec[cmd_index]='show dpa statistics bfdhwoff location $location'
lc__ksh[cmd_index]='ofa_sysdb_show_resources -s -t 0x270f -l $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show controller fia trace all location $location'
lc__ksh[$cmd_index]='fia_show_ltrace -A -i $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='spp_ui node counters'
lc__ksh[$cmd_index]='spp_ui node counters'

((cmd_index++))
lc_exec[$cmd_index]='DPA BFDHWOFF OBJECT'
lc__ksh[$cmd_index]='ofa_show_client -t bfdhwoff -D'

((cmd_index++))
lc_exec[$cmd_index]='DPA MPLSLBL OBJECT'
lc__ksh[$cmd_index]='ofa_show_client -t mplslabel -D'

((cmd_index++))
lc_exec[$cmd_index]='DPA MPLSNH OBJECT'
lc__ksh[$cmd_index]='ofa_show_client -t mplsnh -D'

((cmd_index++))
lc_exec[$cmd_index]='spp_ui node counters'
lc__ksh[$cmd_index]='spp_ui node counters'

#End
((cmd_index++))
rp_show__ksh[$cmd_index]=''
#############################################################
# Commands that run on all RPs
rp__ksh[$cmd_index]=''

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

display() {
    print_main_heading "show tech-support bfd pd"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys_show
          exec_commands sys_trace
    else
        case "$__cardtype" in
        "RP")
            exec_commands rplc_show
            ;;
        "DRP")
            exec_commands rplc_show
            ;;
        "LC")
            exec_commands rplc_show
            exec_commands lc
            ;;
        esac

        if type display_bfd_hwoff_pd | grep -i -q function; then
            display_bfd_hwoff_pd
        fi
    fi

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