#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_udp_fast - Runs show commands for show tech-support udp
#
# June 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_udp_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 udp location all"
sys__ksh[$((i++))]='sysmgr_show -o -p udp -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]=''

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

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

# Trace commands
rp_trace_exec[1]='show udp trace location $location'
rp_trace__ksh[1]='udp_show_ltrace'

rp_trace__ksh[2]=''



# show udp 
rp_exec[1]='show udp br location $location'
rp__ksh[1]='udp_cmd_client show brief'

rp_exec[2]='show udp detail pcb all location $location'
rp__ksh[2]='udp_cmd_client show detail -a'

rp_exec[3]='show udp statistics summary'
rp__ksh[3]='udp_cmd_client show statistics -s'

rp_exec[4]='show udp statistics pcb all location $location'
rp__ksh[4]='udp_cmd_client show statistics -a'

rp_exec[5]='show udp statistics clients location $location'
rp__ksh[5]='udp_cmd_client show statistics -c'

rp_exec[6]='show udp extended-filters location $local_node'
rp__ksh[6]='lpts_show_pcb -p 0x2 -s 0x0 -N $local_nodeid -e /oper/udp_cmd_edm/'

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

#show cef

rp_exec[8]='show cef ipv4 drops'
rp__ksh[8]='fib_statistics_show_command -P 0x0 -d'
rp_exec[9]='show cef ipv4 exceptions'
rp__ksh[9]='fib_statistics_show_command -P 0x0 -e'
rp_exec[10]='show cef ipv6 drops'
rp__ksh[10]='fib_statistics_show_command -P 0x1 -d'
rp_exec[11]='show cef ipv6 exceptions'
rp__ksh[11]='fib_statistics_show_command -P 0x1 -e'

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

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

#End

rp__ksh[13]=''

display_udp_xipcq() {
    i=1

    udp_pid=`sysmgr_show -o -p udp | grep -E PID: | cut -d ":" -f 2`
    udp_xipcq_exec[$((i+0))]='show xipcq pid $udp_pid'
    udp_xipcq__ksh[$((i++))]='xipc_show -p $udp_pid'

    udp_xipcq_exec[$((i+0))]=''
    udp_xipcq__ksh[$((i++))]=''
}

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

display() {
    print_main_heading "show tech-support udp 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_udp_xipcq
            exec_commands udp_xipcq
            ;;
        "DRP")
            exec_commands rp_trace
            exec_commands rp            
            exec_commands rplc_show        a

            display_udp_xipcq
            exec_commands udp_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

