#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_pfi - PFI-specific show tech command
#
# January 2006, Jon Culver
#
# Copyright (c) 2006-2014, 2017 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment


__cardtype="unspecified"
is_imdr_abort=0
is_show_verbose_enable=1
# Parse the arguments to the script.  Supported arguments are:
#
#   -t <card-type>  The type of card to collect information for
#                   (RP, DRP, LC).
#
#   -i              If being invoked as part of iMDR-abort handling.
#                   In this case, we allow printing output to stdout because
#                   the output is getting redirected to a file.
#
#                   Note that we can't rely on the showtech infra's standard
#                   -f <filename> option, because the format is incompatible
#                   with the filename we get when invoked by iMDR abort
#                   handling.
#
#   -f <path_to_show_tech_file_caller> <show_tech_file>
#                   If show tech pfi is called using enable_techs infra,
#                   In this case, we need to jump to 4th argument passed to tech pfi.
#
#   -Z              If being invoked using enable_techs, in this case we restrict the call
#                   to cli "show im database verbose" Refer ddts: CSCvf82576
#                   
while [ "$#" -gt "0" ]; do
    case "$1" in
        -t) __cardtype="$2"; shift 2;;
        -i) is_imdr_abort=1; shift 1;;
        -f) shift 3;;
        -Z) is_show_verbose_enable=0; shift 1;;
        *)  default_parser_function "$@"; shift $#;;
    esac
done

if [[ "$__filename" == "unspecified" && $is_imdr_abort -eq 0 ]]; then
    echo "show_tech_pfi: 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
sys_show_exec[1]='show im history system location all'
sys_show__ksh[1]='im_show system-history -a'
sys_show_exec[2]='show interfaces summary'
sys_show__ksh[2]='show_interface -a -o 0x3'
sys_show_exec[3]='show interfaces brief'
sys_show__ksh[3]='show_interface -a -o 0x2'
sys_show_exec[4]='show im dampening'
sys_show__ksh[4]='im_show dampening'
sys_show_exec[5]='show im rules'
sys_show__ksh[5]='im_show rules -r 0x3 -l 0x2'
sys_show_exec[6]='show platform'
# assumes "platform" is set for us by show_tech_main_fragment
if [ "$platform" = "panini" ]
then
    sys_show__ksh[6]='show_platform_sysdb -v'
elif [ "$platform" = "viking" ]
then
    sys_show__ksh[6]='show_platform_vkg -e'
else
    sys_show__ksh[6]='show_platform'
fi
sys_show_exec[7]='show im status'
sys_show__ksh[7]='im_show status'
sys_show_exec[8]='show im ihms database location all'
sys_show__ksh[8]='im_show issu-database -a '
sys_show_exec[9]='show im ihms missing location all'
sys_show__ksh[9]='im_show issu-missing -a'
sys_show_exec[10]='show im ownerchaninfo location all'
sys_show__ksh[10]='im_show ownerchaninfo -a'
sys_show__ksh[11]=''

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

# Trace
rplc_trace_exec[1]='show im trace'
rplc_trace__ksh[1]='im_show_trace'
rplc_trace_exec[2]='show netio trace all'
rplc_trace__ksh[2]='netio_show_ltrace -A'
rplc_trace_exec[3]='show fwd trace all'
rplc_trace__ksh[3]='fwd_show_ltrace -A'
rplc_trace_exec[4]='show attribute trace'
rplc_trace__ksh[4]='im_attr_show_ltrace'
# assumes "platform" is set for us by show_tech_main_fragment
# like "$platform" = "panini"
# "show attractor" is no more
rplc_trace__ksh[5]=''
rplc_trace_exec[5]=''
rplc_trace__ksh[6]=''

# Show commands
# Summary IM commands
count=1
rplc_show_exec[count]='show im database summary location $location'
rplc_show__ksh[count]='im_show db-summary'
let count+=1
rplc_show_exec[count]='show im registrations summary location $location'
rplc_show__ksh[count]='im_show registrations-summary'
let count+=1
# Brief IM commands
rplc_show_exec[count]='show im database brief location $location'
rplc_show__ksh[count]='im_show database -l 0x1'
let count+=1
rplc_show_exec[count]='show im resource-descriptions brief location $location'
rplc_show__ksh[count]='im_show resource-descriptions -l 0x1'
let count+=1
rplc_show_exec[count]='show im history operations brief location $location'
rplc_show__ksh[count]='im_show operation-history -l 0x1'
let count+=1
rplc_show_exec[count]='show im clients brief location $location'
rplc_show__ksh[count]='im_show clients -l 0x1'
let count+=1
rplc_show_exec[count]='show im registrations all brief location $location'
rplc_show__ksh[count]='im_show registrations -t 0x8 -l 0x1'
let count+=1
rplc_show_exec[count]='show im statistics client brief location $location'
rplc_show__ksh[count]='im_show stats-client -l 0x1'
let count+=1
rplc_show_exec[count]='show im statistics server location $location'
rplc_show__ksh[count]='im_show stats-server'

# Netio
let count+=1
rplc_show_exec[count]='show netio idb all brief'
rplc_show__ksh[count]='netio_show -A' 
let count+=1
rplc_show_exec[count]='show netio clients'
rplc_show__ksh[count]='netio_show -L'
# Pakman
let count+=1
rplc_show_exec[count]='show packet-memory'
rplc_show__ksh[count]='packet_show statistics'
let count+=1
rplc_show_exec[count]='show packet clients'
rplc_show__ksh[count]='packet_show clients'
let count+=1
rplc_show_exec[count]='show packet old summary'
rplc_show__ksh[count]='packet_show old summary'
let count+=1
rplc_show_exec[count]='show packet hssd'
rplc_show__ksh[count]='packet_show hssd'
let count+=1
rplc_show_exec[count]='show packet fsv'
rplc_show__ksh[count]='packet_show fsv'
# Show procs
let count+=1
rplc_show_exec[count]='show process blocked'
# assumes "platform" is set for us by show_tech_main_fragment
if [ "$platform" = "panini" ]
then
    rplc_show__ksh[count]='sh_proc_ng_blocked'	
else
    rplc_show__ksh[count]='show_processes -b'
fi
let count+=1
rplc_show_exec[count]='show processes ifmgr'
rplc_show__ksh[count]='sysmgr_show -o -p ifmgr'
let count+=1
rplc_show_exec[count]='show processes netio'
rplc_show__ksh[count]='sysmgr_show -o -p netio'
let count+=1
rplc_show_exec[count]='show processes packet'
rplc_show__ksh[count]='sysmgr_show -o -p packet'

# Shmwin stats
let count+=1
rplc_show_exec[count]='show shmwin im_db malloc-stats location $location'
rplc_show__ksh[count]='shmwin_show -N im_db -c 0x9'
let count+=1
rplc_show_exec[count]='show shmwin im_rd malloc-stats location $location'
rplc_show__ksh[count]='shmwin_show -N im_rd -c 0x9'
let count+=1
rplc_show_exec[count]='show shmwin im_rules malloc-stats location $location'
rplc_show__ksh[count]='shmwin_show -N im_rules -c 0x9'

# GSP group info
let count+=1
rplc_show_exec[count]='show gsp groups name IM_GROUP location $location'
rplc_show__ksh[count]='gsp_show -n IM_GROUP'

# Detail IM commands
# Refer ddts: CSCvf82576
if [ $is_show_verbose_enable -eq 1 ]; then
    let count+=1
    rplc_show_exec[count]='show im database verbose view owner location $location'
    rplc_show__ksh[count]='im_show database -v 0x0 -l 0x4'
fi
let count+=1
rplc_show_exec[count]='show im resource-descriptions verbose location $location'
rplc_show__ksh[count]='im_show resource-descriptions -l 0x4'
let count+=1
rplc_show_exec[count]='show im statistics client detail location $location'
rplc_show__ksh[count]='im_show stats-client -l 0x3'

# Internal commands
let count+=1
rplc_show_exec[count]='show im internals location $location'
rplc_show__ksh[count]='im_show internals'


# End
let count+=1
rplc_show__ksh[count]=''

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

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

#############################################################
# Commands that run on all RPs

# VICR
rp_exec[1]='show vicr trace'
rp__ksh[1]='vicr_show_ltrace'
rp_exec[2]='show vicr info'
rp__ksh[2]='vi_config_show'
# Loopback
rp_exec[3]='show loopback trace'
rp__ksh[3]='loopback_show_ltrace'
# intf mgbl info
rp_exec[4]='show interfaces edm trace'
rp__ksh[4]='intf_mgbl_show'
rp_exec[5]='show interfaces edm statistics'
rp__ksh[5]='intf_mgbl_show -u -S'
rp_exec[6]='show interfaces edm requests'
rp__ksh[6]='intf_mgbl_show -w -r -R'
# End
rp_exec[7]='show processes intf_mgbl'
rp__ksh[7]='sysmgr_show -o -p intf_mgbl'
rp_exec[8]='show processes loopback_caps_partner'
rp__ksh[8]='sysmgr_show -o -p loopback_caps_partner'
rp_exec[9]='show processes vi_config_replicator'
rp__ksh[9]='sysmgr_show -o -p vi_config_replicator'
rp__ksh[10]=''

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

display() {
    print_main_heading "show tech-support pfi"
        
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys_show
    else
        case "$__cardtype" in
        "RP")
            exec_commands rplc_trace
            exec_commands rplc_show        
            exec_commands rp
            ;;
        "DRP")
            exec_commands rplc_trace
            exec_commands rplc_show        
            exec_commands rp
            ;;
        "LC")
            exec_commands rplc_trace
            exec_commands rplc_show
            ;;
        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

