#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_qos_platform - PD QOS specific show tech command
# Ported from SSE
#
# Oct 2015 - Xujing Zhang
#
# Copyright (c) 2013-2015, 2019 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_qos_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 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 policy-map interface all'
sys_show__ksh[$cmd_index]='qos_ma_show_stats -x -p 0x1 -q 0x2'

#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'


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

#############################################################
# Commands that run on all LCs
cmd_index=1

lc_exec[$cmd_index]='show processes qos_ea location $location'
lc__ksh[$cmd_index]='sysmgr_show -o -p qos_ea -n $fq_nodeid'

((cmd_index++))
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 controller npu voq-usage interface all instance all location $location'
lc__ksh[$cmd_index]='dpa_qosea_voq_show -v x -i 0x10 -n $fq_nodeid -t n -p 0x0'

((cmd_index++))
lc_exec[$cmd_index]='show controller npu stats voq ingress interface all instance all location $location'
lc__ksh[$cmd_index]='ofa_npu_stats_show -v a -i 0x10 -n $fq_nodeid -t n -p 0x0 -s 0x0'


########the following commands no working right now because of double quotes###
# list all Unit number for command show controllers fia diagshell <uint> "diag pp rif" location <loc>
#string='"diag pp rif"'
#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 0 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x0 -n $fq_nodeid \
#					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 1 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x1 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 2 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x2 -n $fq_nodeid 	 \ 
#					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 3 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x3 -n $fq_nodeid 	 \
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 4 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x4 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 5 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x5 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 6 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x6 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 7 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x7 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 8 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x8 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 9 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x9 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 10 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xa -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 11 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xb -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 12 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xc -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 13 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xd -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 14 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xe -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 15 $string location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xf -n $fq_nodeid 	 \ 
# 					 -c \"diag pp rif\""



########the following commands no working right now because of double quotes###
# list all Unit number for command show controllers fia diagshell <uint> "diag pp pkttm" location <loc>
## this commands no working on latest efr
#string1='"diag pp pkttm"'
#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 0 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x0 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 1 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x1 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 2 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x2 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 3 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x3 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 4 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x4 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 5 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x5 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 6 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x6 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 7 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x7 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 8 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x8 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 9 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0x9 -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 10 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xa -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 11 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xb -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 12 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xc -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 13 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xd -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 14 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xe -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""

#((cmd_index++))
#lc_exec[$cmd_index]='show controllers fia diagshell 15 $string1 location $location'
#lc__ksh[$cmd_index]="fia_driver_show -u 0xf -n $fq_nodeid 	 \ 
# 					 -c \"diag pp pkttm\""
#######################end of no working commands###############


((cmd_index++))
lc_exec[$cmd_index]='show feature-mgr client qos-ea feature-info summary location $location'
lc__ksh[$cmd_index]='dpa_fm_show -R -S -c 0x1 -n $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show feature-mgr client qos-ea policy summary location $location'
lc__ksh[$cmd_index]='dpa_fm_show -P -S -c 0x1 -n $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show feature-mgr client qos-ea idb summary location $location'
lc__ksh[$cmd_index]='dpa_fm_show -I -S -c 0x1 -n $fq_nodeid'

((cmd_index++))
lc_exec[$cmd_index]='show feature-mgr client qos-ea trace all location $location'
lc__ksh[$cmd_index]='dpa_fm_show_ltrace -A -C 0x1 -i $fq_nodeid'

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

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

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

display() {
    print_main_heading "show tech-support qos 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
    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
