#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# ipsla_tech_show_techsupport - Show tech-support fast script for IPSLA
#
# September 2014
#
# Copyright (c) 2014-2015, 2017, 2019 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

#
# Load the script provided by show-tech infra, which provides worker functions
#
. /pkg/bin/show_tech_main_fragment

# Initialise any variables used.
__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 "$0: output file not specified"
    exit
fi

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

node_name_internal=`uname -n`
node_number=`node_conversion -i $node_name_internal`

###############################################################################
# Show commands that run once per LR                                          #
###############################################################################
sys_exec[1]='show version'
if [ "$platform" == "panini" ]; then
    sys__ksh[1]='ng_show_version'
else
    sys__ksh[1]='show_version'
fi

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

sys_exec[3]='show install active'
if [[ "$platform" = "panini" ]]; then
    sys__ksh[3]='sdr_instcmd show install active'
else
    sys__ksh[3]='instcmd show install active'
fi

sys_exec[4]='show platform'
if [ "$platform" == "panini" ]; then
    sys__ksh[4]='show_platform_sysdb'
elif [ "$platform" == "viking" ]; then
    sys__ksh[4]='show_platform_vkg -e'
elif [ "$platform" == "hfr" ]; then
    sys__ksh[4]='shelfmgr_show_hfr -e'
else
    sys__ksh[4]='show_platform'
fi

sys_exec[5]='show platform vm'
if [ "$platform" == "panini" ]; then
    sys__ksh[5]='show_platform_sysdb'
elif [ "$platform" == "viking" ]; then
    sys__ksh[5]='show_platform_vkg -e'
elif [ "$platform" == "hfr" ]; then
    sys__ksh[5]='shelfmgr_show_hfr -e'
else
    sys__ksh[5]='show_platform'
fi

sys_exec[6]='show logging'
sys__ksh[6]='show_logging'

sys_exec[7]='show context location all'
if [[ "$platform" = "panini" ]]; then
    sys__ksh[7]='corehelper_context -c 0x1 -n all'
else
    sys__ksh[7]='dumper_context -c 0x1'
fi

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

sys_exec[9]='show process ipsla_ma'
sys__ksh[9]='sysmgr_show -o -p ipsla_ma'

sys_exec[10]='show process ipsla_sa'
sys__ksh[10]='sysmgr_show -o -p ipsla_sa'

sys_exec[11]='show process ipsla_responder'
sys__ksh[11]='sysmgr_show -o -p ipsla_responder'

sys_exec[12]='show process ipsla_ippm_server'
sys__ksh[12]='sysmgr_show -o -p ipsla_ippm_server'

sys_exec[13]='show sysdb trace verification shared-plane-sc'
sys__ksh[13]='sysdb_show_ltrace -T vrfn -S -R active'

sys_exec[14]='show sysdb trace access shared-plane'
sys__ksh[14]='sysdb_show_ltrace -T access -s -R active'

sys_exec[15]=''
sys__ksh[15]=''

###############################################################################
# Show commands that run on every RP                                          #
###############################################################################

# misc info
rp_exec[1]='show cli history detail'
rp__ksh[1]='show_parser_history -h 0x2'

#IPSLA specific
rp_exec[2]='show ipsla application'
rp__ksh[2]='show_ipsla_common -a '

rp_exec[3]='show ipsla statistics aggregated'
rp__ksh[3]='show_ipsla_stats -a '

rp_exec[4]='show ipsla statistics aggregated internal'
rp__ksh[4]='show_ipsla_stats -a -n '

rp_exec[5]='show ipsla history'
rp__ksh[5]='show_ipsla_stats -h '

rp_exec[6]='show ipsla responder statistics all ports'
rp__ksh[6]='show_ipsla_resp_stats -a '

rp_exec[7]='show ipsla responder statistics all ports internal'
rp__ksh[7]='show_ipsla_resp_stats -a -n '

rp_exec[8]='show ipsla mpls discovery vpn'
rp__ksh[8]='show_ipsla_mpls_discovery_vpn '

rp_exec[9]='show ipsla mpls lsp-monitor summary'
rp__ksh[9]='show_ipsla_mplslm -s '

rp_exec[10]='show ipsla twamp connection detail '
rp__ksh[10]='show_ipsla_twamp -d '

rp_exec[11]='show ipsla twamp connection requests'
rp__ksh[11]='show_ipsla_twamp -r '

rp_exec[12]='show ipsla twamp session '
rp__ksh[12]='show_ipsla_resp_twamp -e '

rp_exec[13]='show ipsla twamp status'
rp__ksh[13]='show_ipsla_twamp -a '

rp_exec[14]='show ipsla trace master-agent initialization'
rp__ksh[14]='show_ipsla_ma_ltrace -I '

rp_exec[15]='show ipsla trace master-agent events'
rp__ksh[15]='show_ipsla_ma_ltrace -P '

rp_exec[16]='show ipsla trace master-agent messaging'
rp__ksh[16]='show_ipsla_ma_ltrace -C '

rp_exec[17]='show ipsla trace sub-agent initialization'
rp__ksh[17]='show_ipsla_sa_ltrace -I '

rp_exec[18]='show ipsla trace sub-agent messaging'
rp__ksh[18]='show_ipsla_sa_ltrace -C '

rp_exec[19]='show ipsla trace sub-agent edm'
rp__ksh[19]='show_ipsla_sa_ltrace -E '

rp_exec[20]='show ipsla trace sub-agent timestamp'
rp__ksh[20]='show_ipsla_sa_ltrace -T '

rp_exec[21]='show ipsla trace sub-agent runtime'
rp__ksh[21]='show_ipsla_sa_ltrace -R '

rp_exec[22]='show ipsla trace responder initialization'
rp__ksh[22]='show_ipsla_resp_ltrace -I '

rp_exec[23]='show ipsla trace responder probe'
rp__ksh[23]='show_ipsla_resp_ltrace -P '

rp_exec[24]='show ipsla trace responder control'
rp__ksh[24]='show_ipsla_resp_ltrace -C '

rp_exec[25]='show ipsla trace twamp all'
rp__ksh[25]='show_ipsla_twamp_ltrace -A'

rp_exec[26]='show udp brief'
rp__ksh[26]='udp_cmd_client show brief '

rp_exec[27]='show udp statistics clients'
rp__ksh[27]='udp_cmd_client show statistics -c '

rp_exec[28]='show udp statistics pcb all'
rp__ksh[28]='udp_cmd_client show statistics -a '

rp_exec[29]='show lpts bindings brief'
rp__ksh[29]='show_lpts_pa -a -B '

rp_exec[30]='show lpts ifib brief'
rp__ksh[30]='show_lpts_ifib -m entries -b '

rp_exec[31]='show netio rates'
rp__ksh[31]='netio_show -r '

rp_exec[32]='show netio bypass'
rp__ksh[32]='netio_show -b '

rp_exec[33]='show netio clients'
rp__ksh[33]='netio_show -L '

rp_exec[34]='show ntp status'
rp__ksh[34]='ntp_command show -s '

rp_exec[35]='show ntp associations'
rp__ksh[35]='ntp_command show -a '

rp_exec[36]='show ntp history'
rp__ksh[36]='ntp_command show -h '

rp_exec[37]='show spp node-counters location all'
rp__ksh[37]='spp_sysdb_get -M node_counters'

rp_exec[38]='sh processes cpu'
if [ "$platform" == "panini" ]; then
    rp__ksh[38]='show_watchdog -p'
else
    rp__ksh[38]='show_proc_cpu -c'
fi

rp_exec[39]='sh memory summary detail'
if [ "$platform" == "panini" ]; then
    rp__ksh[39]='show_memory_ng -s -d'
else
    rp__ksh[39]='show_memory -s -d'
fi

rp_exec[40]='sh memory heap summary all'
rp__ksh[40]='malloc_dump -A -s'

rp_exec[41]='desc show tcp brief'
rp__ksh[41]='tcp_cmd_client show brief'

rp_exec[42]='desc show tcp statistics summary'
rp__ksh[42]='tcp_cmd_client show statistics -s'

rp_exec[43]='desc show tcp statistics clients'
rp__ksh[43]='tcp_cmd_client show statistics -c'

rp_exec[44]='desc show tcp statistics pcb all'
rp__ksh[44]='tcp_cmd_client show statistics -a'

rp_exec[45]='desc show tcp detail pcb all'
rp__ksh[45]='tcp_cmd_client show table -a'

index=46

if [ -x /pkg/bin/show_platform_pifib ]; then
    rp_exec[$index]="show lpts trace platform"
    rp__ksh[$index]='show_platform_pifib_trace -A'
    ((++index))
elif [ -x /pkg/bin/platform_pifib_show_trace ]; then
    rp_exec[$index]="show lpts trace platform"
    rp__ksh[$index]='platform_pifib_show_trace'
    ((++index))
fi

rp_exec[$index]=''
rp__ksh[$index]=''

###############################################################################
# Show commands that run on all RP or LC                                      #
###############################################################################

rplc_exec[1]='show lpts pifib entry'
rplc__ksh[1]='show_lpts_pifib -z 0x0 -k 0x9 -a 0x0'

rplc_exec[2]=''
rplc__ksh[2]=''

###############################################################################
# Show commands that run only on LC                                      #
###############################################################################

if [ -x /pkg/bin/show_platform_pifib ]; then

  lc_exec[1]='show lpts pifib hardware police location $location'
  lc__ksh[1]='show_platform_pifib -z 0x6 -i $node_number'

  lc_exec[2]="sh lpts pifib hardware entry brief"
  lc__ksh[2]='show_platform_pifib -z 0x2'

  lc_exec[3]="show lpts pifib hardware entry"
  lc__ksh[3]='show_platform_pifib -z 0x1'

  lc_exec[4]="show lpts pifib hardware entry statistics"
  lc__ksh[4]='show_platform_pifib -z 0x3'

elif [ -x /pkg/bin/platform_show_pifib ]; then

  lc_exec[1]='show lpts pifib hardware police location $location'
  lc__ksh[1]='platform_show_pifib -z 0x6 -i $node_number'

  lc_exec[2]="sh lpts pifib hardware entry brief location $location"
  lc__ksh[2]='platform_show_pifib -z 0x2 -i $node_number'

  lc_exec[3]="show lpts pifib hardware entry location $location"
  lc__ksh[3]='platform_show_pifib -z 0x1 -i $node_number'

  lc_exec[4]="show lpts pifib hardware entry statistics location $location"
  lc__ksh[4]='platform_show_pifib -z 0x3 -i $node_number'

fi

lc_exec[5]=''
lc__ksh[5]=''

# A function called display() must be provided that calls the functions to
# run the required show commands. The display() function will be called in
# the /pkg/bin/show_tech_comp_file_frag

display() {
     
   # Print the output heading
   print_main_heading "show tech-support ipsla"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case "$__cardtype" in
        "DRP"|"RP")
            exec_commands rp
            exec_commands rplc
            ;;
        "LC")
            exec_commands rplc
            exec_commands lc
            ;;
        esac
    fi

    # Print the closing heading.
    print_main_heading "show tech-support ipsla complete"
}

# This function calls the display() function and sends the output to file if
# the file option has been set.
. /pkg/bin/show_tech_file_fragment

