#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_clns_fast - Runs show commands for show tech-support clns
#
# August 2020 - Devashish Negi
#
# Copyright (c) 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_clns_fast: output file not specified"
    exit
fi

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

local_node=`uname -n`
local_nodeid=`node_conversion -i $local_node`

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

# Show commands that run once per system
#
# Use variable 'i' for array index
i=1
sys_exec[$((i+0))]="show running-config"
sys__ksh[$((i++))]='nvgen -c -l 1 -t 1 -i1 -o 1'

if [ "$platform" = "panini" ]; then
    sys_exec[$((i+0))]="show install active"
    sys__ksh[$((i++))]='sdr_instcmd show install active'
    sys_exec[$((i+0))]='show version'
    sys__ksh[$((i++))]='ng_show_version'
else
    sys_exec[$((i+0))]="show install package all detail"
    sys__ksh[$((i++))]='instcmd show install package all detail'
    sys_exec[$((i+0))]='show version'
    sys__ksh[$((i++))]='show_version'
fi

sys_exec[$((i+0))]="show platform"
if [[ "$platform" = "viking" ]]; then
    sys__ksh[$((i++))]='show_platform_vkg -e'
elif [[ "$platform" = "hfr" ]]; then
    sys__ksh[$((i++))]='shelfmgr_show_hfr -e'
elif [[ "$platform" = "enxr" || "$platform" = "prp" ]]; then
    sys__ksh[$((i++))]='show_platform'
else
    sys__ksh[$((i++))]='show_platform_sysdb'
fi

sys_exec[$((i+0))]="show redundancy"
sys__ksh[$((i++))]='redcon_show'
sys_exec[$((i+0))]="show process clns location all"
sys__ksh[$((i++))]='sysmgr_show -o -p clns -n all'
sys_exec[$((i+0))]="show logging"
sys__ksh[$((i++))]='show_logging'
sys_exec[$((i+0))]=''
sys__ksh[$((i++))]=''

 
#############################################################
# Commands that run on RP and LC nodes
#rplc_show__ksh[0]=''

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

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

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

# Trace commands
rp_trace_exec[1]='show clns trace location $location'
rp_trace__ksh[1]='clns_show_ltrace'

rp_trace__ksh[3]=''

# show clns 
rp_exec[1]='show clns statistics location $location'
rp__ksh[1]='show_clns_traffic show statistics'

#sh netio cl
rp_exec[2]='show netio clients $location'
rp__ksh[2]='netio_show -L'

#show cef

rp_exec[3]='show cef ipv4 drops'
rp__ksh[3]='fib_statistics_show_command -P 0x0 -d'
rp_exec[4]='show cef ipv4 exceptions'
rp__ksh[4]='fib_statistics_show_command -P 0x0 -e'
rp_exec[5]='show cef ipv6 drops'
rp__ksh[5]='fib_statistics_show_command -P 0x1 -d'
rp_exec[6]='show cef ipv6 exceptions'
rp__ksh[6]='fib_statistics_show_command -P 0x1 -e'

#show socket trace
rp_exec[7]='show socket trace process clns location $location'
rp__ksh[7]='socket_show_ltrace -P clns'

rp_exec[8]='show clns pcb interface-filter location $local_node'
rp__ksh[8]='lpts_show_pcb -p 0x4 -f 0x2 -N $local_nodeid -e /oper/clns/'

rp_exec[9]='show clns pcb location $local_node'
rp__ksh[9]='lpts_show_pcb -p 0x4 -f 0x0 -N $local_nodeid -e /oper/clns/'
#End

rp__ksh[10]=''

display_clns_xipcq() {
    i=1

    clns_pid=`sysmgr_show -o -p clns | grep -E PID: | cut -d ":" -f 2`
    clns_xipcq_exec[$((i+0))]='show xipcq pid $clns_pid'
    clns_xipcq__ksh[$((i++))]='xipc_show -p $clns_pid'

    clns_xipcq_exec[$((i+0))]=''
    clns_xipcq__ksh[$((i++))]=''
}

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

display() {
    print_main_heading "show tech-support clns fast "
        
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case "$__cardtype" in
        "RP")
            exec_commands rp_trace
            exec_commands rp            
            exec_commands rplc_show        

            display_clns_xipcq
            exec_commands clns_xipcq
            ;;
        "DRP")
            exec_commands rp_trace
            exec_commands rp            
            exec_commands rplc_show        a

            display_clns_xipcq
            exec_commands clns_xipcq
            ;;
        "LC")
            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

