#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_fast_np - Runs show commands for show tech-support np
#                     using the 'show_tech_fast' infrastructure.
#                     See EDCS-631313 for details on show_tech_fast
#
# October 2012, Alan Phillips
#
# Copyright (c) 2008-2010, 2012-2017 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------


#
# show_tech_main_fragment is part of the show tech infrastructure
# and contains a number of functions and ksh variables that are used
# within this script.  We execute show_tech_main_fragment to
# essentially "#include" those functions.
#
. /pkg/bin/show_tech_main_fragment


#
# Attempts to determine what type of linecard we are executing
# on.
#
set_lc_specific_vars() {

    if [ -x $BIN_DIR/$PROC_NAME_TR ];then
        __is_np_card="yes"
        __lc_type="LC_TR"
        __prm_server_name="$PROC_NAME_TR"
    elif [ -x $BIN_DIR/$PROC_NAME_TY ];then
        __is_np_card="yes"
        __lc_type="LC_TY"
        __prm_server_name="$PROC_NAME_TY"
    elif [ -x $BIN_DIR/$PROC_NAME_TO ];then
        __is_np_card="yes"
        __lc_type="LC_TO"
        __prm_server_name="$PROC_NAME_TO"
    else
        __is_np_card="no"
        __lc_type="UNKNOWN"
        __prm_server_name="UNKNOWN"
    fi

    __prm_server_pid=`sysmgr_show -o -p $__prm_server_name | grep -e PID | cut -c 27-`
    __prm_server_jid=`sysmgr_show -o -p $__prm_server_name | grep -e "Job Id" | cut -c 27-`

    __prm_ssmh_name="prm_ssmh"
    __prm_ssmh_pid=`sysmgr_show -o -p $__prm_ssmh_name | grep -e PID | cut -c 27-`
    __prm_ssmh_jid=`sysmgr_show -o -p $__prm_ssmh_name | grep -e "Job Id" | cut -c 27-`

    __uidb_server_name="uidb_server"
    __uidb_server_pid=`sysmgr_show -o -p $__uidb_server_name | grep -e PID | cut -c 27-`
    __uidb_server_jid=`sysmgr_show -o -p $__uidb_server_name | grep -e "Job Id" | cut -c 27-`


    # Tomahawk: Check for ISSU Identity == 'V1' or 'V2'. 
    if [ "$__lc_type" == "LC_TO" ];then
        __issu_status=`show_np -d issu_state | grep -e "ISSU Ident" | cut -c 20-`
    else 
        __issu_status='V1'
    fi
}

#
# Init commands to be executed at the system level
#
init_sys_commands_qnx() {

    #
    # Use cmd_index rather than hardcoding the array indexes to
    # make it easier / less error prone to reorder commands.
    #

    cmd_index=1

    sys_exec[$cmd_index]='show platform'
    sys__ksh[$cmd_index]='show_platform_vkg -e'

    ((cmd_index++))

    sys_exec[$cmd_index]='show version'
    sys__ksh[$cmd_index]='show_version'

    ((cmd_index++))

    sys_exec[$cmd_index]='show install active'
    sys__ksh[$cmd_index]='instcmd show install active'

    ((cmd_index++))

    sys_exec[$cmd_index]='show install which component asr9k-prm'
    sys__ksh[$cmd_index]='instcmd show install which component asr9k-prm detail'

    ((cmd_index++))

    sys_exec[$cmd_index]='show install which component vkg-ezdriver-4c'
    sys__ksh[$cmd_index]='instcmd show install which component vkg-ezdriver-4c detail'

    ((cmd_index++))

    sys_exec[$cmd_index]='show install which component drivers-ezchip-5c'
    sys__ksh[$cmd_index]='instcmd show install which component drivers-ezchip-5c detail'

    ((cmd_index++))

    sys_exec[$cmd_index]='show install log detail'
    sys__ksh[$cmd_index]='instcmd show install log 0x0 detail'

    ((cmd_index++))

    sys_exec[$cmd_index]='admin show inventory'
    sys__ksh[$cmd_index]='show_inventory -a'

    ((cmd_index++))

    sys_exec[$cmd_index]='show running-config'
    sys__ksh[$cmd_index]='nvgen -c -l 1 -t 1 -o 1'

    ((cmd_index++))

    sys_exec[$cmd_index]='admin show running-config'
    sys__ksh[$cmd_index]='nvgen -b /admin/cfg/'

    ((cmd_index++))

    sys_exec[$cmd_index]='show redundancy location all'
    sys__ksh[$cmd_index]='redcon_show -n all'

    ((cmd_index++))

    sys_exec[$cmd_index]='show logging'
    sys__ksh[$cmd_index]='show_logging'

    ((cmd_index++))
    
    sys_exec[$cmd_index]='show cli history detail'
    sys__ksh[$cmd_index]='show_parser_history -h 0x2'

    ((cmd_index++))

    sys_exec[$cmd_index]='show configuration history'
    sys__ksh[$cmd_index]='cfgmgr_show_history -s -f -n 0x5dc -t all -d'

    ((cmd_index++))

    sys_exec[$cmd_index]='show environment all'
    sys__ksh[$cmd_index]='envmon_show -e -A'

    ((cmd_index++))

    # MUST be the last command
    sys_exec[$cmd_index]=''
    sys__ksh[$cmd_index]=''
}

#
# Init commands to be executed at the system level
#
init_sys_commands_linux() {

    #
    # Use cmd_index rather than hardcoding the array indexes to
    # make it easier / less error prone to reorder commands.
    #

    cmd_index=1

    sys_exec[$cmd_index]='show platform'
    sys__ksh[$cmd_index]='show_platform_sysdb'

    ((cmd_index++))

    sys_exec[$cmd_index]='show version'
    sys__ksh[$cmd_index]='ng_show_version'

    ((cmd_index++))

    sys_exec[$cmd_index]='show install active'
    sys__ksh[$cmd_index]='sdr_instcmd show install active'

    ((cmd_index++))

    sys_exec[$cmd_index]='show install log detail'
    sys__ksh[$cmd_index]='sdr_instcmd show install log 0x0 detail'

    ((cmd_index++))

    sys_exec[$cmd_index]='show inventory'
    sys__ksh[$cmd_index]='show_inventory -e'

    ((cmd_index++))

    sys_exec[$cmd_index]='show running-config'
    sys__ksh[$cmd_index]='nvgen -c -l 1 -t 1 -o 1'

    ((cmd_index++))

    sys_exec[$cmd_index]='show redundancy location all'
    sys__ksh[$cmd_index]='redcon_show -n all'

    ((cmd_index++))

    sys_exec[$cmd_index]='show logging'
    sys__ksh[$cmd_index]='show_logging'

    ((cmd_index++))
    
    sys_exec[$cmd_index]='show cli history detail'
    sys__ksh[$cmd_index]='show_parser_history -h 0x2'

    ((cmd_index++))

    sys_exec[$cmd_index]='show configuration history'
    sys__ksh[$cmd_index]='cfgmgr_show_history -s -f -n 0x5dc -t all -d'

    ((cmd_index++))

    # ISSU commands
    sys_exec[$cmd_index]='show issu summary'
    sys__ksh[$cmd_index]='issu_show_status -I'

    ((cmd_index++))

    sys_exec[$cmd_index]='show issu milestone clients location all'
    sys__ksh[$cmd_index]='issu_show_status -c'

    ((cmd_index++))

    # MUST be the last command
    sys_exec[$cmd_index]=''
    sys__ksh[$cmd_index]=''
}


#
# Init commands to be executed on both the RP and the LC
#
init_rplc_commands() {

    cmd_index=1
    
    rplc_exec[$cmd_index]='show cef vrf all summary location $ext_node_name'
    rplc__ksh[$cmd_index]='fib_show_command -S -O 0x0 -f all'
    
    ((cmd_index++))

    rplc_exec[$cmd_index]='show cef vrf all ipv6 summary location $ext_node_name'
    rplc__ksh[$cmd_index]='fib_show_command -S -O 0x1 -f all'
    
    ((cmd_index++))
    
    rplc_exec[$cmd_index]='show processes blocked location $ext_node_name'
    if [ "$OS_STRING" == "QNX" ];then
        rplc__ksh[$cmd_index]='show_processes -b'
    else
        rplc__ksh[$cmd_index]='sh_proc_ng_blocked'
    fi
    
    ((cmd_index++))
    
    rplc_exec[$cmd_index]='show memory summary location $ext_node_name'
    if [ "$OS_STRING" == "QNX" ];then
        rplc__ksh[$cmd_index]='show_memory -s'
    else
        rplc__ksh[$cmd_index]='show_memory_ng -s'
    fi

    ((cmd_index++))
    
    rplc_exec[$cmd_index]='show processes memory detail location $ext_node_name'
    if [ "$OS_STRING" == "QNX" ];then
        rplc__ksh[$cmd_index]='show_processes -m -h -t'
    else
        rplc__ksh[$cmd_index]='sh_proc_mem_cli -d'
    fi
    
    ((cmd_index++))
    
    # MUST be the last command
    rplc_exec[$cmd_index]=''
    rplc__ksh[$cmd_index]=''
}

#
# Init commands to be executed on RP only
#
init_rp_commands() {
    
    #
    # Use cmd_index rather than hardcoding the array indexes to
    # make it easier / less error prone to reorder commands.
    #

    cmd_index=1

    #
    # If the mcast PIE is installed (as indicated by the process being
    # there) get a count of the mcast routes for both v4 and v6.  Note
    # that the "vrf all" does not actually include the default VRF routes
    # as it should.  So, we have to get the count for the default VRF
    # and the configured VRFs separately.  Note also that ideally we would
    # want to run these on both the RP and the LC, however the show clients
    # appear to only work on the RP.
    #
    if [ -x $BIN_DIR/$MCAST_PROC_NAME ];then

        rp_exec[$cmd_index]='show mfib route summary'
        rp__ksh[$cmd_index]='show_ipv4_mfwd_client -b'
    
        ((cmd_index++))

        rp_exec[$cmd_index]='show mfib vrf all route summary'
        rp__ksh[$cmd_index]='show_ipv4_mfwd_client -v all -b'
    
        ((cmd_index++))

        rp_exec[$cmd_index]='show mfib ipv6 route summary'
        rp__ksh[$cmd_index]='show_ipv6_mfwd_client -b'
    
        ((cmd_index++))

        rp_exec[$cmd_index]='show mfib vrf all ipv6 route summary'
        rp__ksh[$cmd_index]='show_ipv6_mfwd_client -v all -b'
    
        ((cmd_index++))
    fi

    # MUST be the last command
    rp_exec[$cmd_index]=''
    rp__ksh[$cmd_index]=''
}

# This section is for "show tech np" when customer experiences
#  an ISSU upgrade failure. The failed V2 virtual machine will
#  be alive for collecting limited set of information. Note
#  ISSU 'V2' commands have limitations for example:
#     1. NP registers cannot be read
#     2. NP statistics cannot be read
#
init_lc_issu_commands() {

    #
    # Use cmd_index rather than hardcoding the array indexes to
    # make it easier / less error prone to reorder commands.
    #

    cmd_index=1
    
    lc_exec[$cmd_index]='show process $__prm_server_jid location $ext_node_name'
    lc__ksh[$cmd_index]='sysmgr_show -o -p $__prm_server_name -n $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show dll pid $__prm_server_pid location $ext_node_name'
    lc__ksh[$cmd_index]='show_dll -p $__prm_server_pid -n $fq_nodeid'
    
    ((cmd_index++))

    
    lc_exec[$cmd_index]='follow process $__prm_server_pid iteration 2 location $ext_node_name'
    lc__ksh[$cmd_index]='attach_process -p $__prm_server_pid -i 2 -n $fq_nodeid'

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

    lc_exec[$cmd_index]='show dll pid $__prm_ssmh_pid location $ext_node_name'
    lc__ksh[$cmd_index]='show_dll -p $__prm_ssmh_pid -n $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='follow process $__prm_ssmh_pid iteration 2 location $ext_node_name'
    lc__ksh[$cmd_index]='attach_process -p $__prm_ssmh_pid -i 2 -n $fq_nodeid'

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

    lc_exec[$cmd_index]='show dll pid $__uidb_server_pid location $ext_node_name'
    lc__ksh[$cmd_index]='show_dll -p $__uidb_server_pid -n $fq_nodeid'

    ((cmd_index++))
    
    lc_exec[$cmd_index]='follow process $__uidb_server_pid iteration 2 location $ext_node_name'
    lc__ksh[$cmd_index]='attach_process -p $__uidb_server_pid -i 2 -n $fq_nodeid'

   ((cmd_index++))

   lc_exec[$cmd_index]='run top -b -n 2 -d 2'
   lc__ksh[$cmd_index]='top -b -n 2 -d 2'

   ((cmd_index++))

    if [ "$__is_np_card" != "yes" ];then
        # MUST be the last command
        lc_exec[$cmd_index]=''
        lc__ksh[$cmd_index]=''
        return
    fi

    lc_exec[$cmd_index]='show controllers np summary all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_np_show summary -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm server trace init location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -N -i $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm server trace error location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -E -i $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm server trace event location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -V -i $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show prm server trace internal location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -B -i $fq_nodeid'

    ((cmd_index++))

    lc_exec[$cmd_index]='show prm server trace ucode location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -U -i $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show prm server trace oir location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -R -i $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show prm client trace error location $ext_node_name'
    lc__ksh[$cmd_index]='prm_lib_show_ltrace -E -i $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm client trace event location $ext_node_name'
    lc__ksh[$cmd_index]='prm_lib_show_ltrace -V -i $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm client trace init location $ext_node_name'
    lc__ksh[$cmd_index]='prm_lib_show_ltrace -N -i $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show prm stats segment all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_stats_show segment -g 0x9 -s $fq_nodeid'

    ((cmd_index++))

    lc_exec[$cmd_index]='show prm stats client all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_stats_show client -c 0x0 -s$fq_nodeid'

    ((cmd_index++))

    lc_exec[$cmd_index]='show pfm location $ext_node_name'
    lc__ksh[$cmd_index]='pfm_node_show -N -L $fq_nodeid'

    ((cmd_index++))

    lc_exec[$cmd_index]='run xostrace issul'
    lc__ksh[$cmd_index]='xostrace issul'

    ((cmd_index++))

    # *here


    # Wait!  Before adding a new command *here, be sure to
    # evaluate whether the command should go in this 
    # function, the non-ISSU one, or both. See init_lc_commands

    # MUST be the last command
    lc_exec[$cmd_index]=''
    lc__ksh[$cmd_index]=''
}

#
# Init commands to be executed on LC only
#
init_lc_commands() {

    #
    # Use cmd_index rather than hardcoding the array indexes to
    # make it easier / less error prone to reorder commands.
    #

    cmd_index=1
    
    lc_exec[$cmd_index]='show process $__prm_server_jid location $ext_node_name'
    lc__ksh[$cmd_index]='sysmgr_show -o -p $__prm_server_name -n $fq_nodeid'
    
    ((cmd_index++))
    
    if [ "$OS_STRING" == "QNX" ];then

        lc_exec[$cmd_index]='show process threadname $__prm_server_jid location $ext_node_name'
        lc__ksh[$cmd_index]='show_processes -T -p $__prm_server_jid -n $fq_nodeid'
    
        ((cmd_index++))

        lc_exec[$cmd_index]='show dll jobid $__prm_server_jid location $ext_node_name'
        lc__ksh[$cmd_index]='show_dll -j $__prm_server_jid -n $fq_nodeid'

        ((cmd_index++))
    else
        lc_exec[$cmd_index]='show dll pid $__prm_server_pid location $ext_node_name'
        lc__ksh[$cmd_index]='show_dll -p $__prm_server_pid -n $fq_nodeid'

        ((cmd_index++))
    fi
    
    lc_exec[$cmd_index]='follow process $__prm_server_pid iteration 2 location $ext_node_name'
    lc__ksh[$cmd_index]='attach_process -p $__prm_server_pid -i 2 -n $fq_nodeid'

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

    if [ "$OS_STRING" == "QNX" ];then
        lc_exec[$cmd_index]='show dll jobid $__prm_ssmh_jid location $ext_node_name'
        lc__ksh[$cmd_index]='show_dll -j $__prm_ssmh_jid -n $fq_nodeid'

        ((cmd_index++))
    else
        lc_exec[$cmd_index]='show dll pid $__prm_ssmh_pid location $ext_node_name'
        lc__ksh[$cmd_index]='show_dll -p $__prm_ssmh_pid -n $fq_nodeid'

        ((cmd_index++))
    fi
    
    lc_exec[$cmd_index]='follow process $__prm_ssmh_pid iteration 2 location $ext_node_name'
    lc__ksh[$cmd_index]='attach_process -p $__prm_ssmh_pid -i 2 -n $fq_nodeid'

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

    if [ "$OS_STRING" == "QNX" ];then
        lc_exec[$cmd_index]='show dll jobid $__uidb_server_jid location $ext_node_name'
        lc__ksh[$cmd_index]='show_dll -j $__uidb_server_jid -n $fq_nodeid'

        ((cmd_index++))
    else
        lc_exec[$cmd_index]='show dll pid $__uidb_server_pid location $ext_node_name'
        lc__ksh[$cmd_index]='show_dll -p $__uidb_server_pid -n $fq_nodeid'

        ((cmd_index++))
    fi
    
    lc_exec[$cmd_index]='follow process $__uidb_server_pid iteration 2 location $ext_node_name'
    lc__ksh[$cmd_index]='attach_process -p $__uidb_server_pid -i 2 -n $fq_nodeid'

   ((cmd_index++))

    if [ "$OS_STRING" == "QNX" ];then
        lc_exec[$cmd_index]='show dll location $ext_node_name'
        lc__ksh[$cmd_index]='show_dll -n $fq_nodeid'

        ((cmd_index++))
    fi
    
    if [ "$OS_STRING" == "QNX" ];then
        lc_exec[$cmd_index]='run top -d -i 2 -t 2'
        lc__ksh[$cmd_index]='top -d -i 2 -t 2'
    else
        lc_exec[$cmd_index]='run top -b -n 2 -d 2'
        lc__ksh[$cmd_index]='top -b -n 2 -d 2'
    fi
    
    ((cmd_index++))

    if [ "$__is_np_card" != "yes" ];then
        # MUST be the last command
        lc_exec[$cmd_index]=''
        lc__ksh[$cmd_index]=''
        return
    fi

    lc_exec[$cmd_index]='show controllers np summary all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_np_show summary -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show controllers np drvlog'
    lc__ksh[$cmd_index]='prm_np_show drvlog -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show controllers np crashinfo all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_np_show dumpcrash -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show controllers np counters all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_np_show counters -s $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show controllers np fabric-counters all all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_np_show xaui -x 0 -a -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show drops location $ext_node_name'
    lc__ksh[$cmd_index]='show_drops show -t 0x3 -s $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show controllers np ports all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_np_show ports -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show controllers np portmap all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_np_show portmap -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show controllers np interrupts all all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_np_show interrupts -n 999999 -s $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show controllers np soft-errors all all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_np_show soft-errors -n 999999 -s $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show prm server context location $ext_node_name'
    lc__ksh[$cmd_index]='prm_server_show context -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm server clinfo location $ext_node_name'
    lc__ksh[$cmd_index]='prm_server_show clinfo -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm server tcam summary all all all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_np_show tcam -S -l 0x4 -a 0x5 -e 0xa -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm server trace init location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -N -i $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm server trace error location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -E -i $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm server trace event location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -V -i $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show prm server trace internal location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -B -i $fq_nodeid'

    ((cmd_index++))

    lc_exec[$cmd_index]='show prm server trace ucode location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -U -i $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show prm server trace oir location $ext_node_name'
    lc__ksh[$cmd_index]='show_prm_server_ltrace -R -i $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show prm client trace error location $ext_node_name'
    lc__ksh[$cmd_index]='prm_lib_show_ltrace -E -i $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm client trace event location $ext_node_name'
    lc__ksh[$cmd_index]='prm_lib_show_ltrace -V -i $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm client trace init location $ext_node_name'
    lc__ksh[$cmd_index]='prm_lib_show_ltrace -N -i $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm stats summary location $ext_node_name'
    lc__ksh[$cmd_index]='prm_stats_show summary -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm stats table all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_stats_show table -b 0x0 -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show prm stats segment all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_stats_show segment -g 0x9 -s $fq_nodeid'

    ((cmd_index++))

    lc_exec[$cmd_index]='show prm stats client all location $ext_node_name'
    lc__ksh[$cmd_index]='prm_stats_show client -c 0x0 -s$fq_nodeid'

    ((cmd_index++))
    
    lc_exec[$cmd_index]='show pfm location $ext_node_name'
    lc__ksh[$cmd_index]='pfm_node_show -N -L $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show uidb index location $ext_node_name'
    lc__ksh[$cmd_index]='uidb_show index -s $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show uidb trace init location $ext_node_name'
    lc__ksh[$cmd_index]='uidb_show_ltrace -I -i $fq_nodeid'
    
    ((cmd_index++))
    
    lc_exec[$cmd_index]='show uidb trace error location $ext_node_name'
    lc__ksh[$cmd_index]='uidb_show_ltrace -R -i $fq_nodeid'
    
    ((cmd_index++))

    lc_exec[$cmd_index]='show ssmh-ltrace init location $ext_node_name'
    lc__ksh[$cmd_index]='ssmh_show_ltrace -I -i $fq_nodeid'

    ((cmd_index++))

    lc_exec[$cmd_index]='show ssmh-ltrace event location $ext_node_name'
    lc__ksh[$cmd_index]='ssmh_show_ltrace -E -i $fq_nodeid'

    ((cmd_index++))

    lc_exec[$cmd_index]='show ssmh-ltrace error location $ext_node_name'
    lc__ksh[$cmd_index]='ssmh_show_ltrace -R -i $fq_nodeid'

    ((cmd_index++))

    if [ "$OS_STRING" == "QNX" ];then
        lc_exec[$cmd_index]='admin show logging onboard common location $ext_node_name'
        lc__ksh[$cmd_index]='obfl_exec_command show -A -F genstr -n $fq_nodeid'

	((cmd_index++))

        lc_exec[$cmd_index]='admin show logging onboard error location $ext_node_name'
        lc__ksh[$cmd_index]='obfl_exec_command show -A -F errmsg -n $fq_nodeid'

	((cmd_index++))

#   add OBFL support for eXR here 

    fi

    lc_exec[$cmd_index]='run test_prm_srh -s'
    lc__ksh[$cmd_index]='test_prm_srh -s'

    ((cmd_index++))

    lc_exec[$cmd_index]='run test_prm_srh -d'
    lc__ksh[$cmd_index]='test_prm_srh -d'
    
    ((cmd_index++))

    # *here


    # Wait!  Before adding a new command *here, be sure to
    # evaluate whether the command should go in this 
    # function, the ISSU one, or both - see init_lc_issu_commands. 

    # MUST be the last command
    lc_exec[$cmd_index]=''
    lc__ksh[$cmd_index]=''
}

#
# Init SHIP commands to be executed on the LC
#
init_lc_ship_commands() {

    #
    # Use cmd_index rather than hardcoding the array indexes to
    # make it easier / less error prone to reorder commands.
    #

    cmd_index=1

    #
    # Get the SHIP data for all components that include "prm" in their
    # name.
    #
    ship_components=`ship_show -i | grep prm`
    for one_comp in $ship_components;do

       lc_ship_exec[$cmd_index]="run ship_show -c $one_comp"
       lc_ship__ksh[$cmd_index]="ship_show -c $one_comp"

       ((cmd_index++))

    done

    #
    # Get the SHIP data for UIDB related components.  Note that in the
    # future the UIDB component may be renamed to something like "prm-uidb"
    # so, we exclude any components that include "prm" to avoid dups.
    #
    ship_components=`ship_show -i | grep uidb | grep -v prm`
    for one_comp in $ship_components;do

        lc_ship_exec[$cmd_index]="run ship_show -c $one_comp"
        lc_ship__ksh[$cmd_index]="ship_show -c $one_comp"

        ((cmd_index++))

    done

    # MUST be the last command
    lc_ship_exec[$cmd_index]=""
    lc_ship__ksh[$cmd_index]=""

}

run_local_lc_debug_commands() {

    #
    # Note that because of changes in the show tech infra, things that just
    # write to STDOUT, such as the print_heading calls below, no longer 
    # get captured.  All of the important output captured below is redirected
    # to files that are bundled as part of the created TAR file.  Any
    # new captures added should be handled the same way.
    #

    if [ -d $__tar_file_directory_on_node ];then
        this_node=$(node_conversion -n $fq_nodeid | cut -c5-)
        np_regs_file="all_np_regs_$this_node$(date +__%Y:%m:%d_%H:%M:%S).txt"

        print_heading "+++ Collecting all registers for all NPs [`iosclock -d 0`] +++"
        prm_np_show register -r 0 -l 999999 > $__tar_file_directory_on_node/$np_regs_file
        print_heading "--- Registers written to $np_regs_file [`iosclock -d 0`] ---"


        if_counters_file="if_counters_$this_node$(date +__%Y:%m:%d_%H:%M:%S).txt"
        num_nps=`prm_np_show summary -s $fq_nodeid | grep -E "NP *[0-9]* *: *"  | wc -l`

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

            print_heading "+++ run show_np -e $npid -d if_counters [`iosclock -d 0`] +++"
            show_np -e $npid -d if_counters >> $__tar_file_directory_on_node/$if_counters_file
            print_heading "--- run show_np -e $npid -d if_counters [`iosclock -d 0`] ---"

            ((npid++))

        done


    fi
}

#
# This function is executed on each linecard.  It collects the files from
# /harddisk:/np with filenames that include the linecard location on which
# the script is executing.
#
bundle_saved_np_files_lc() {

    this_node=$(node_conversion -n $fq_nodeid | cut -c5-)

    if [ -d $__tar_file_directory_on_node ];then


        print_heading "Compressing and archiving the following files from $NP_DIR_ON_RP:"

        cd $NP_DIR_ON_LC

        ls -lt *$this_node*.txt

        txt_file_list=`ls *$this_node*.txt`
        for onefile in $txt_file_list;do
            gzip -c $onefile > $__tar_file_directory_on_node/$onefile.gz
        done

        zip_file_list=`ls *$this_node*.txt.gz`
        for onefile in $zip_file_list;do
            cp $onefile $__tar_file_directory_on_node/$onefile
        done

        cd $__tar_file_directory_on_node
        tar cf np_dir_files-${this_node}.tar *.txt.gz
        for onefile in $txt_file_list;do
            rm $onefile.gz
        done
        for onefile in $zip_file_list;do
            rm $onefile
        done

        print_heading "Archive file np_dir_files-$this_node created"
    else
        echo "Cannot access tar file directory $__tar_file_directory_on_node"
        echo "to bundle NP log files from RP"
    fi
}

#
# This function is executed on each RP.  For cXR, it collects the files from
# /harddisk:/np for any linecards that are not currently in IOS XR RUN state.  
# For eXR, it collects the files in /misc/scratch/np since that's where cards 
# that fail to boot store their debug data.
#
bundle_saved_np_files_rp() {

    if [ "$OS_STRING" == "QNX" ];then
        offline_lcs=`show_platform_vkg -e | grep CPU | grep -v -E "IOS XR RUN|READY|RSP"  | cut -f1 -d " "`
    else
        cp $NP_DIR_ON_RP/* $__tar_file_directory
	return
    fi

    if [ "$offline_lcs" == "" ];then
        return
    fi

    if [ -d $__tar_file_directory ];then

        this_node=$(node_conversion -n $fq_nodeid | cut -c5-)
        all_files_list=""

        print_heading "Compressing and archiving files from $NP_DIR_ON_RP for these nodes:"

        print_heading "$offline_lcs"

        cd $NP_DIR_ON_RP

        for one_offline_lc in $offline_lcs; do
            one_node=`node_conversion -N $one_offline_lc | cut -c5-`

            txt_file_list=`ls *$one_node*.txt`
            for onefile in $txt_file_list;do
                all_files_list="$all_files_list $onefile.gz"
                gzip -c $onefile > $__tar_file_directory/$onefile.gz
            done

            zip_file_list=`ls *$one_node*.txt.gz`
            for onefile in $zip_file_list;do
                cp $onefile $__tar_file_directory/$onefile
                all_files_list="$all_files_list $onefile"
            done

        done

        if [ "$all_files_list" != "" ]; then
            cd $__tar_file_directory
            tar cf np_dir_files-${this_node}.tar *.txt.gz
            for onefile in $all_files_list;do
                rm $onefile
            done

            print_heading "Archive file np_dir_files-${this_node} created"
        fi
    else
        echo "Cannot access tar file directory $__tar_file_directory"
        echo "to bundle NP log files for offline LCs from RP"
    fi
}

#
# Init 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.
#
init_per_np_lc_commands() {

    #
    # Use cmd_index rather than hardcoding the array indexes to
    # make it easier / less error prone to reorder 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]="run show_np -e $npid -d hist=60"
        per_np_lc__ksh[$cmd_index]="show_np -e $npid -d hist=60"

        ((cmd_index++))

        ((npid++))
    done

    #
    # Command(s) that are not applicable to Trident
    # 
    if [ "$__lc_type" != "LC_TR" ];then

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

            per_np_lc_exec[$cmd_index]="run np_perf -e $npid"
            per_np_lc__ksh[$cmd_index]="np_perf -e $npid"

            ((cmd_index++))
    
            ((npid++))
        done
    fi

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

# ********************************
#  Main part of script starts here 
# ********************************

. /pkg/bin/show_tech_main_fragment

OS_STRING=`uname -s`

PROC_NAME_BASE="prm_server"
PROC_NAME_TR="prm_server_tr"
PROC_NAME_TY="prm_server_ty"
PROC_NAME_TO="prm_server_to"

# In Classic XR, the NP logs are stored in a disk on the RP that is
# accessible from both the LC and RP. In FleXR, the NP logs are stored
# on a disk that is on the LC and only accessible to the RP through a
# mountpoint.  
if [ "$OS_STRING" == "QNX" ];then
    NP_DIR_ON_LC="/harddisk:/np"
    NP_DIR_ON_RP="/harddisk:/np"
else
    NP_DIR_ON_LC="/misc/scratch/np"
    NP_DIR_ON_RP="/misc/scratch/np"
fi

BIN_DIR=/pkg/bin
MCAST_PROC_NAME=ipv4_mfwd_partner

__prm_server_name="unspecified"
__cardtype="unspecified"
__is_np_card="no"
__lc_type="UNKNOWN"

# 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 [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi

#
# display() is the function called by the show tech infrastructure
# to collect the collect/display the component specific info.
#
# Note that the same script executes on both the RP and the LCs
# concurrently.  So, below, we check to determine what kind of 
# card this is and load/exec the correct commands.  exec_commands
# is a function provided by the show tech infrastructure.
#
display() {

    if [ "$__cardtype" == "SYS" ]; then
        if [ "$OS_STRING" == "QNX" ];then
            init_sys_commands_qnx
        else
            init_sys_commands_linux
        fi

        exec_commands sys
    else
        case "$__cardtype" in
        "RP")
            init_rp_commands

            init_rplc_commands

            exec_commands rp

            exec_commands rplc 

            bundle_saved_np_files_rp
            ;;
        "LC")
            set_lc_specific_vars

            if [ "$__issu_status" == "V2" ];then

                 init_lc_issu_commands

                 init_rplc_commands

                 init_lc_ship_commands

                 exec_commands lc

                 exec_commands rplc 

                 exec_commands lc_ship

            else    

                 init_lc_commands

                 init_per_np_lc_commands

                 init_rplc_commands

                 init_lc_ship_commands

                 exec_commands lc

                 exec_commands per_np_lc
   
                 exec_commands rplc 

                 exec_commands lc_ship

                 run_local_lc_debug_commands

            fi

            bundle_saved_np_files_lc
            ;;
        *)
            ;;
        esac
    fi
}


#
# show_tech_file_fragment is part of the show tech infrastructure and
# is the script that will call our display() function.  It also collects
# the output and writes it to a file if that file is specified.  It
# then compresses the file.
#
. /pkg/bin/show_tech_file_fragment

