#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_vkgpm - PM show tech commands
#
# March 2014 - Anand
# 
#CSCuu60517 - Narendra Sharma
#
# Copyright (c) 2015 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_vkgpm: output file not specified"
    exit
fi

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

uname -a | grep hfr > /dev/null 2>&1;  RC=$?
uname -a | grep prp > /dev/null 2>&1;  RC1=$?
uname -a | grep enxr > /dev/null 2>&1; RC2=$?
uname -a | grep asr9k > /dev/null 2>&1; RC3=$?

# platform type panini is equivalent to asr9k-eXR
if [[ "$RC" -eq "0" ]]; then
    platform="hfr"
elif [[ "$RC1" -eq "0" ]]; then
    platform="prp"
elif [[ "$RC2" -eq "0" ]]; then
    platform="enxr"
elif [[ "$RC3" -eq "0" ]]; then
    platform="viking"
else
    platform="panini"
fi


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

#############################################################
# Show commands that run once per system
sys_show_exec[1]='show version'
sys_show__ksh[1]='show_version'
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 install summary'
sys_show__ksh[6]='instcmd show install inventory summary'
sys_show_exec[2]='show platform'
if [[ "$platform" == "viking" ]]; then
     sys_show__ksh[2]='show_platform_vkg -e'
elif [[ "$platform" == "panini" ]]; then
     sys_show__ksh[2]='show_platform_sysdb -v'
else
     sys_show__ksh[2]='show_platform -a'
fi
#End
sys_show__ksh[7]=''

# Trace

#End
sys_trace__ksh[0]=''

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

rplc_show_exec[1]='show process blocked location $location'
if [[ "$platform" = "panini" ]]; then
    rplc_show__ksh[1]='sh_proc_ng_blocked -l $fq_nodeid'
else
    rplc_show__ksh[1]='show_processes -b $fq_nodeid'
fi
#End
rplc_show__ksh[2]=''

#############################################################
# Commands that run on all LCs
# Addtional commands are generated dynamically.
# See switch case for LC in display()
lc_exec[1]='show processes pm location $location'
lc__ksh[1]='sysmgr_show -o -p pm -n $fq_nodeid'
lc_exec[2]='show controller pm trace async location $location'
lc__ksh[2]='show_vkg_pm_ltrace -i $fq_nodeid -A'
lc_exec[3]='show controller pm trace error location $location'
lc__ksh[3]='show_vkg_pm_ltrace -i $fq_nodeid -R'
lc_exec[4]='show controller pm trace creat location $location'
lc__ksh[4]='show_vkg_pm_ltrace -i $fq_nodeid -C'
lc_exec[5]='show controller pm trace info location $location'
lc__ksh[5]='show_vkg_pm_ltrace -i $fq_nodeid -I'
lc_exec[6]='show controller pm trace stats location $location'
lc__ksh[6]='show_vkg_pm_ltrace -i $fq_nodeid -S'
lc_exec[7]='pkg/bin/show_ixdb -f vkg_pmlib_ixdb -s'
lc__ksh[7]='pkg/bin/show_ixdb -f vkg_pmlib_ixdb -s'

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

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

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

display() {
    print_main_heading "show tech-support vkgpm"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys_show
        exec_commands sys_trace
    else
        case "$__cardtype" in
        "RP")
            exec_commands rp
            exec_commands rplc_show
            ;;
        "DRP")
            exec_commands rp
            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
