#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_qos_pd - PD QOS specific show tech command
#
# April 2009, Dileep Kuchhangi
#
# Copyright (c) 2008-2009, 2017-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_qos_pd: output file not specified"
    exit
fi

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

PLATFORM_TYPE=`uname -m`

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

#############################################################
# Show commands that run once per system
sys_show_exec[1]='show version'

if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
     sys_show__ksh[1]='ng_show_version'
else
     sys_show__ksh[1]='show_version' 
fi

sys_show_exec[2]='show logging'
sys_show__ksh[2]='show_logging'
sys_show_exec[3]='show interfaces summary'
sys_show__ksh[3]='show_interface -a -o 0x3'
sys_show_exec[4]='show interfaces brief'
sys_show__ksh[4]='show_interface -a -o 0x2'
sys_show_exec[5]='show running-config'
sys_show__ksh[5]='nvgen -c -l 1 -t 1 -o 1'
sys_show_exec[6]='show policymap targets'
sys_show__ksh[6]='policymgr_show -A -B 0x1'
sys_show_exec[7]='show processes policymgr_rp'
sys_show__ksh[7]='sysmgr_show -o -p policymgr_rp'
sys_show_exec[8]='show uidb data-dump'
sys_show__ksh[8]='uidb_show data-dump -a'
sys_show_exec[9]='show bundle'
sys_show__ksh[9]='bundlemgr_show -b'
sys_show_exec[10]='show bundle ea members'
sys_show__ksh[10]='bundlemgr_ea_show -m -a'
sys_show_exec[11]='show run policy-map'
sys_show__ksh[11]='nvgen -c -q gl/policymgr/policymap/'
sys_show_exec[12]='show run class-map'
sys_show__ksh[12]='nvgen -c -q gl/policymgr/classmap/'
sys_show_exec[13]='show processes ancp'
sys_show__ksh[13]='sysmgr_show -o -p ancp'
sys_show_exec[14]='show configuration failed'
sys_show__ksh[14]='cfgmgr_show_failed -c'
#End
sys_show__ksh[15]=''

# Trace
sys_trace_exec[1]='show policymgr process trace all location all'
sys_trace__ksh[1]='show_ltrace_policymgr -i all -A'
sys_trace_exec[2]='show policy-lib trace all location all'
sys_trace__ksh[2]='show_ltrace_pllib -i all -A'
sys_trace_exec[3]='show qos-lib trace client qos_ea both location all'
sys_trace__ksh[3]='qos_lib_show_ltrace -i all -C qos_ea -W -U'
sys_trace_exec[4]='show qos-ma trace location all'
sys_trace__ksh[4]='show_qos_ma_ltrace -i all'
sys_trace_exec[5]='show qos-ea trace all location all'
sys_trace__ksh[5]='qos_ea_show_ltrace -i all -A'
#End
sys_trace__ksh[6]=''


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

# Show commands

# Show procs
rplc_show_exec[1]='show process blocked'

if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
      rplc_show__ksh[1]='sh_proc_ng_blocked'
else
      rplc_show__ksh[1]='show_processes -b' 
fi
      
rplc_show_exec[2]='show processes qos_ma'
rplc_show__ksh[2]='sysmgr_show -o -p qos_ma'
#End
rplc_show__ksh[3]=''

#############################################################
# Commands that run on all LCs
count=1
lc_exec[count]='show qos summary police location $location input'
lc__ksh[count]='qos_ea_show_interface -u summary -t police -d input -l $fq_nodeid'
let count+=1
lc_exec[count]='show qos summary police location $location output'
lc__ksh[count]='qos_ea_show_interface -u summary -t police -d output -l $fq_nodeid'
let count+=1
lc_exec[count]='show qos summary queue location $location input'
lc__ksh[count]='qos_ea_show_interface -u summary -t queue -d input -l $fq_nodeid'
let count+=1
lc_exec[count]='show qos summary queue location $location output'
lc__ksh[count]='qos_ea_show_interface -u summary -t queue -d output -l $fq_nodeid'
let count+=1
lc_exec[count]='show controllers np counters all location $location'
lc__ksh[count]='prm_np_show counters -s $fq_nodeid'
let count+=1
lc_exec[count]='show processes qos_ma_ea location $location'
lc__ksh[count]='sysmgr_show -o -p qos_ma_ea -n $fq_nodeid'
let count+=1
lc_exec[count]='show qos-ea ha state location $location'
lc__ksh[count]='qos_ea_show_ha -p $fq_nodeid -S'
let count+=1
lc_exec[count]='show qos-ea ha chkpt all info $location'
lc__ksh[count]='qos_ea_show_ha -p $fq_nodeid -t 0x7 -I' 
let count+=1
lc_exec[count]='show qoshal resource summary location $location'
lc__ksh[count]='nphal_show_chk -p $fq_nodeid resource summary'
let count+=1
lc_exec[count]='show qoshal trace all location all'
lc__ksh[count]='nphal_show_ltrace -i all -A'
let count+=1
lc_exec[count]='show process prm_server  location $location' 
lc__ksh[count]='sysmgr_show -o -p prm_server -n $fq_nodeid'
let count+=1
lc_exec[count]='show controllers np tm counters all'
lc__ksh[count]='prm_np_show TM counters'
let count+=1
lc_exec[count]='show processes qos_ma location $location'
lc__ksh[count]='sysmgr_show -o -p qos_ma -n $fq_nodeid'
let count+=1
lc_exec[count]='show qos capability location $location'
lc__ksh[count]='qos_ea_show_interface -y capability -l $fq_nodeid'
let count+=1
lc_exec[count]='show uidb trace all location all'
lc__ksh[count]='uidb_show_ltrace -J -i all'
let count+=1
lc_exec[count]='show qos inconsistency summary location $location'
lc__ksh[count]='qos_ea_show_interface -a inconsistency -l $fq_nodeid'
let count+=1
lc_exec[count]='show qos inconsistency detail 0 location $location'
lc__ksh[count]='qos_ea_show_interface -a inconsistency -v 0x0 -l $fq_nodeid'
let count+=1
lc_exec[count]='show prm server trace hal location all'
lc__ksh[count]='show_prm_server_ltrace -i all -H'
let count+=1
lc_exec[count]='show controllers fabric fia drops ingress location $location'
lc__ksh[count]='fsi_show -n $fq_nodeid -f -d -N'
let count+=1
lc_exec[count]='show controllers fabric fia drops egress location $location'
lc__ksh[count]='fsi_show -n $fq_nodeid -f -d -E'
let count+=1
lc_exec[count]='show controllers fabric  fia bridge flow-control location $location'
lc__ksh[count]='fsi_show -n $fq_nodeid -f -b -X'
let count+=1
lc_exec[count]='show controllers fabric  fia bridge stats location $location'
lc__ksh[count]='fsi_show -n $fq_nodeid -f -b -S'
let count+=1
# The following command are added again to check the counters update
lc_exec[count]='show qos summary police location $location input'
lc__ksh[count]='qos_ea_show_interface -u summary -t police -d input -l $fq_nodeid'
let count+=1
lc_exec[count]='show qos summary police location $location output'
lc__ksh[count]='qos_ea_show_interface -u summary -t police -d output -l $fq_nodeid'
let count+=1
lc_exec[count]='show qos summary queue location $location input'
lc__ksh[count]='qos_ea_show_interface -u summary -t queue -d input -l $fq_nodeid'
let count+=1
lc_exec[count]='show qos summary queue location $location output'
lc__ksh[count]='qos_ea_show_interface -u summary -t queue -d output -l $fq_nodeid'
let count+=1
lc_exec[count]='show controllers np counters all location $location'
lc__ksh[count]='prm_np_show counters -s $fq_nodeid'
let count+=1
#End
lc__ksh[count]=''



#############################################################
#
# Commands that must be done on a per-NP basis.  So, we first find
# out what the list of NPs is, then we loop through and do the commands
# once for each NP.
#
per_np_lc_commands() {

    cmd_index=1

    num_nps=`prm_np_show summary -s $fq_nodeid | grep -E "NP[0-9]" | wc -l`

    npid=0; while [ "$npid" -lt "$num_nps" ];do

        per_np_lc_exec[$cmd_index]="show qoshal punt-queue np $npid location $location"
        per_np_lc__ksh[$cmd_index]="nphal_show_chk -p $fq_nodeid punt-queue -n $npid"
        ((cmd_index++))
	  per_np_lc_exec[$cmd_index]="show qoshal loopback-queue np $npid location $location"
        per_np_lc__ksh[$cmd_index]="nphal_show_chk -p $fq_nodeid loopback-queue -n $npid"
        ((cmd_index++))
	  ((npid++))
    done

    per_np_lc_exec[$cmd_index]=""
    per_np_lc__ksh[$cmd_index]=""
}





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

#############################################################
# Commands that run on all SCs
sc__ksh[0]=''

#############################################################
# Commands that run on all SPs
sp__ksh[0]=''

#############################################################
# 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
            exec_commands rp
            ;;
        "DRP")
            exec_commands rplc_show
            exec_commands rp
            ;;
        "LC")
   	    per_np_lc_commands
            exec_commands rplc_show
            exec_commands lc
	       exec_commands per_np_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
