#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_tcp_nsr_fast - Runs show commands for show tech-support nsr
#
# Jan 2009 Yan Chen
#
# Copyright (c) 2004-2009, 2014-2019 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_tcp_nsr_fast: 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
#
# 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 tcp location all"
sys__ksh[$((i++))]='sysmgr_show -o -p tcp -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 tcp trace location $location'
rp_trace__ksh[1]='tcp_show_ltrace'

rp_trace_exec[2]='show pqmon trace location $location'
rp_trace__ksh[2]='show_pqmon_ltrace -D -T'

rp_trace__ksh[3]=''



# show tcp 
rp_exec[1]='show tcp br location $location'
rp__ksh[1]='tcp_cmd_client show brief'

rp_exec[2]='show tcp detail pcb all location $location'
rp__ksh[2]='tcp_cmd_client show table -a'

rp_exec[3]='show tcp statistics pcb all location $location'
rp__ksh[3]='tcp_cmd_client show statistics -a'

# show tcp nsr client
rp_exec[4]='show tcp nsr client brief location $location'
rp__ksh[4]='tss_show -t b -c 0'
rp_exec[5]='show tcp nsr detail client all location $location'
rp__ksh[5]='tss_show -t d -c 0'
rp_exec[6]='show tcp nsr statistics client all location $location'
rp__ksh[6]='tss_show -t s -c 0'

#show tcp nsr session-set
rp_exec[7]='show tcp nsr session-set brief location $location'
rp__ksh[7]='tss_show -t b -s 0'
rp_exec[8]='show tcp nsr detail session-set all location $location'
rp__ksh[8]='tss_show -t d -s 0'
rp_exec[9]='show tcp nsr statistics session-set all location $location'
rp__ksh[9]='tss_show -t s -s 0'

#show tcp nsr pcb
rp_exec[10]='show tcp nsr location $location'
rp__ksh[10]='tss_show -t b -p 0'
rp_exec[11]='show tcp nsr detail pcb all location $location' 
rp__ksh[11]='tss_show -t d -p 0'
rp_exec[12]='show tcp nsr statistics pcb all location $location'
rp__ksh[12]='tss_show -t s -p 0'

#show tcp nsr stats summary
rp_exec[13]='show tcp nsr statistics summary location $location'
rp__ksh[13]='tss_show -t s'

# show nsr ncd
rp_exec[14]='show nsr ncd queue all location $location'
rp__ksh[14]='ncd_show -q all'
rp_exec[15]='show nsr ncd client all location $location'
rp__ksh[15]='ncd_show -c all'
rp_exec[16]='Show qad queue stats'
rp__ksh[16]='qad_show -b'

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

#show cef

rp_exec[18]='show cef ipv4 drops'
rp__ksh[18]='fib_statistics_show_command -P 0x0 -d'
rp_exec[19]='show cef ipv4 exceptions'
rp__ksh[19]='fib_statistics_show_command -P 0x0 -e'
rp_exec[20]='show cef ipv6 drops'
rp__ksh[20]='fib_statistics_show_command -P 0x1 -d'
rp_exec[21]='show cef ipv6 exceptions'
rp__ksh[21]='fib_statistics_show_command -P 0x1 -e'

#show socket trace
rp_exec[22]='show socket trace process tcp location $location'
rp__ksh[22]='socket_show_ltrace -P tcp'
rp_exec[23]='show socket trace process bgp location $location'
rp__ksh[23]='socket_show_ltrace -P bgp'
rp_exec[24]='show socket trace process mpls_ldp location $location'
rp__ksh[24]='socket_show_ltrace -P mpls_ldp'
rp_exec[25]='show socket trace process msdp location $location'
rp__ksh[25]='socket_show_ltrace -P msdp'

#show nsr npl trace <process> all
rp_exec[26]='show nsr npl trace bgp  all location $location'
rp__ksh[26]='npl_show_ltrace -E -V -W -X -Y -Z -O'
rp_exec[27]='show nsr npl trace ospf  all location $location'
rp__ksh[27]='npl_show_ltrace -F -V -W -X -Y -Z -O' 
rp_exec[28]='show nsr npl trace ospfv3  all location $location'
rp__ksh[28]='npl_show_ltrace -G -V -W -X -Y -Z -O'
rp_exec[29]='show nsr npl trace tcp  all location $location'
rp__ksh[29]='npl_show_ltrace -C -V -W -X -Y -Z -O'

#show nsr nal trace <process> all
rp_exec[30]='show nsr nal trace bgp all location $location'
rp__ksh[30]='nal_show_ltrace -E -Z -Y -X -W'
rp_exec[31]='show nsr nal trace ospf all location $location'
rp__ksh[31]='nal_show_ltrace -F -Z -Y -X -W'
rp_exec[32]='show nsr nal trace ospfv3 all location $location'
rp__ksh[32]='nal_show_ltrace -G -Z -Y -X -W'
rp_exec[33]='show nsr nal trace tcp  all location $location'
rp__ksh[33]='npl_show_ltrace -C -V -W -X -Y -Z'

#nsr end point
rp_exec[34]='show tcp nsr endpoint location $location'
rp__ksh[34]='tss_show -t b -e'
#nsr ping
rp_exec[35]='nsr ping location $location'
rp__ksh[35]='nsr_ping -c 1 -s -z 1000 -Z 65535 -y 5000 -f' 

#TCP AO commands
rp_exec[36]='show tcp authentication keychain all detail location $location'
rp__ksh[36]='tcp_cmd_client show authdb -k all -e' 
rp_exec[37]='show key chain trace client bgp both location $location'
rp__ksh[37]='show_ltrace_kc -C tcp -W -U'

#ip-lib trace
rp_exec[38]='show ip-lib trace process tcp location $location'
rp__ksh[38]='ip_lib_show_ltrace -P tcp'

rp_exec[39]='show tcp statistics summary location $location'
rp__ksh[39]='tcp_cmd_client show statistics -s'

#nsr lib show commands
rp_exec[39]='show nsr npl client bgp instance 0 wheels detail location $location'
rp__ksh[39]='npl_show -c bgp -i 0x0 -w 0x0 -d'
rp_exec[40]='show nsr npl client bgp instance 1 wheels detail location $location'
rp__ksh[40]='npl_show -c bgp -i 0x1 -w 0x0 -d'
rp_exec[41]='show nsr npl client bgp instance 2 wheels detail location $location'
rp__ksh[41]='npl_show -c bgp -i 0x2 -w 0x0 -d'
rp_exec[42]='show nsr npl client bgp instance 3 wheels detail location $location'
rp__ksh[42]='npl_show -c bgp -i 0x3 -w 0x0 -d'
rp_exec[43]='show nsr npl client tcp instance 1 wheels detail location $location'
rp__ksh[43]='npl_show -c tcp -i 0x1 -w 0x0 -d'

#End

rp__ksh[44]=''

display_tcp_xipcq() {
    i=1

    tcp_pid=`sysmgr_show -o -p tcp | grep -E PID: | cut -d ":" -f 2`
    tcp_xipcq_exec[$((i+0))]='show xipcq pid $tcp_pid'
    tcp_xipcq__ksh[$((i++))]='xipc_show -p $tcp_pid'

    tcp_xipcq_exec[$((i+0))]=''
    tcp_xipcq__ksh[$((i++))]=''
}

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

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

            display_tcp_xipcq
            exec_commands tcp_xipcq
            ;;
        "DRP")
            exec_commands rp_trace
            exec_commands rp            
            exec_commands rplc_show        a

            display_tcp_xipcq
            exec_commands tcp_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

