#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# srg_show_tech - Show tech-support SRG
#
# February 2014, Balaji M (ibalaji)
#
# Copyright (c) 2014, 2017, 2019-2020 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

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

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

PLATFORM_TYPE=`uname -m`

###############################################################################
# Show commands that run once per LR                                          #
###############################################################################
sys_exec[1]='show version'

sys_exec[2]='show install active'

if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
    sys__ksh[1]='ng_show_version'
    sys__ksh[2]='sdr_instcmd show install active'
else
    sys__ksh[1]='show_version'
    sys__ksh[2]='instcmd show install active'
fi


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

sys_exec[4]='show process iedged location all'
sys__ksh[4]='sysmgr_show -o -p iedged -n all'

sys_exec[5]='show context location all'
if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
   sys__ksh[5]='corehelper_context -c 0x1 -n all'
else
   sys__ksh[5]='dumper_context -c 0x1 -n all'
fi

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

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

sys_exec[8]=''
sys__ksh[8]=''

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

# misc info
rp_exec[1]='show subscriber redundancy trace component srg-manager location $location'
rp__ksh[1]='show_ltrace_srg -T 0xffffffff -C 0xffffffff -G 0x700000 -M 0xffffffff'

rp_exec[2]='show subscriber redundancy summary'
rp__ksh[2]='show_srg_mgr -s'

rp_exec[3]='show subscriber redundancy summary group'
rp__ksh[3]='show_srg_mgr -g'

rp_exec[4]='show subscriber redundancy summary interface'
rp__ksh[4]='show_srg_mgr -i'

rp_exec[5]=''
rp__ksh[5]=''

###############################################################################
# Show commands that run on all RP or LC                                      #
###############################################################################
rplc_exec[1]='show subscriber redundancy agent location $location'
rplc__ksh[1]='show_srg -n -l $node_number'

rplc_exec[2]='show subscriber redundancy agent client location $location'
rplc__ksh[2]='show_srg -c 0 -l $node_number'

rplc_exec[3]='show subscriber redundancy agent interface location $location'
rplc__ksh[3]='show_srg -i None -l $node_number'

rplc_exec[4]='show subscriber redundancy agent memory location $location'
rplc__ksh[4]='show_srg -r -l $node_number'

rplc_exec[5]='show subscriber redundancy group location $location'
rplc__ksh[5]='show_srg -g 0 -l $node_number'
 
rplc_exec[6]='show subscriber redundancy group statistics location $location'
rplc__ksh[6]='show_srg -m 0 -l $node_number'

rplc_exec[7]='show subscriber redundancy group all session verbose location $location'
rplc__ksh[7]='show_srg -s 0xffffffff -d -l $node_number'

rplc_exec[8]='show subscriber redundancy trace location $location'
rplc__ksh[8]='show_ltrace_srg -T 0xffffffff -C 0xffffffff -G 0xffffffff -M 0xffffffff'

rplc_exec[9]='show subscriber redundancy group all'
rplc__ksh[9]='show_srg -g 0'

rplc_exec[10]='show process srg_agt txgroup peer          location 0/0/cpu0'
rplc__ksh[10]='txlib_show -N $node_number -E srg_agt -P'

rplc_exec[11]='show process srg_agt txgroup detail        location 0/0/cpu0'
rplc__ksh[11]='txlib_show -N $node_number -E srg_agt -d'

rplc_exec[12]='show process srg_agt txgroup trace events  location 0/0/cpu0'
rplc__ksh[12]='txlist_show_trace -i $node_number -P srg_agt -F 0x2'

rplc_exec[13]='show process srg_agt txgroup trace errors  location 0/0/cpu0'
rplc__ksh[13]='txlist_show_trace -i $node_number -P srg_agt -F 0x3'

rplc_exec[14]='show process srg_agt txgroup txlist detail location 0/0/cpu0'
rplc__ksh[14]='txlib_show -N $node_number -E srg_agt -L -d'

rplc_exec[15]='show process dhcpd txgroup peer          location 0/0/cpu0'
rplc__ksh[15]='txlib_show -N $node_number -E dhcpd -P'

rplc_exec[16]='show process dhcpd txgroup detail        location 0/0/cpu0'
rplc__ksh[16]='txlib_show -N $node_number -E dhcpd -d'

rplc_exec[17]='show process dhcpd txgroup trace events  location 0/0/cpu0'
rplc__ksh[17]='txlist_show_trace -i $node_number -P dhcpd -F 0x2'

rplc_exec[18]='show process dhcpd txgroup trace errors  location 0/0/cpu0'
rplc__ksh[18]='txlist_show_trace -i $node_number -P dhcpd -F 0x3'

rplc_exec[19]='show process dhcpd txgroup txlist detail location 0/0/cpu0'
rplc__ksh[19]='txlib_show -N $node_number -E dhcpd -L -d'

rplc_exec[20]='show process dhcpv6d txgroup peer          location 0/0/cpu0'
rplc__ksh[20]='txlib_show -N $node_number -E dhcpv6d -P'

rplc_exec[21]='show process dhcpv6d txgroup detail        location 0/0/cpu0'
rplc__ksh[21]='txlib_show -N $node_number -E dhcpv6d -d'

rplc_exec[22]='show process dhcpv6d txgroup trace events  location 0/0/cpu0'
rplc__ksh[22]='txlist_show_trace -i $node_number -P dhcpv6d -F 0x2'

rplc_exec[23]='show process dhcpv6d txgroup trace errors  location 0/0/cpu0'
rplc__ksh[23]='txlist_show_trace -i $node_number -P dhcpv6d -F 0x3'

rplc_exec[24]='show process dhcpv6d txgroup txlist detail location 0/0/cpu0'
rplc__ksh[24]='txlib_show -N $node_number -E dhcpv6d -L -d'

rplc_exec[25]='show process vpdn_mgr txgroup peer          location 0/0/cpu0'
rplc__ksh[25]='txlib_show -N $node_number -E vpdn_mgr -P'

rplc_exec[26]='show process vpdn_mgr txgroup detail        location 0/0/cpu0'
rplc__ksh[26]='txlib_show -N $node_number -E vpdn_mgr -d'

rplc_exec[27]='show process vpdn_mgr txgroup trace events  location 0/0/cpu0'
rplc__ksh[27]='txlist_show_trace -i $node_number -P vpdn_mgr -F 0x2'

rplc_exec[28]='show process vpdn_mgr txgroup trace errors  location 0/0/cpu0'
rplc__ksh[28]='txlist_show_trace -i $node_number -P vpdn_mgr -F 0x3'

rplc_exec[29]='show process vpdn_mgr txgroup txlist detail location 0/0/cpu0'
rplc__ksh[29]='txlib_show -N $node_number -E vpdn_mgr -L -d'

rplc_exec[30]='show process ppp_ma txgroup peer          location 0/0/cpu0'
rplc__ksh[30]='txlib_show -N $node_number -E ppp_ma -P'

rplc_exec[31]='show process ppp_ma txgroup detail        location 0/0/cpu0'
rplc__ksh[31]='txlib_show -N $node_number -E ppp_ma -d'

rplc_exec[32]='show process ppp_ma txgroup trace events  location 0/0/cpu0'
rplc__ksh[32]='txlist_show_trace -i $node_number -P ppp_ma -F 0x2'

rplc_exec[33]='show process ppp_ma txgroup trace errors  location 0/0/cpu0'
rplc__ksh[33]='txlist_show_trace -i $node_number -P ppp_ma -F 0x3'

rplc_exec[34]='show process ppp_ma txgroup txlist detail location 0/0/cpu0'
rplc__ksh[34]='txlib_show -N $node_number -E ppp_ma -L -d'

rplc_exec[35]='show process pppoe_ma txgroup peer          location 0/0/cpu0'
rplc__ksh[35]='txlib_show -N $node_number -E pppoe_ma -P'

rplc_exec[36]='show process pppoe_ma txgroup detail        location 0/0/cpu0'
rplc__ksh[36]='txlib_show -N $node_number -E pppoe_ma -d'

rplc_exec[37]='show process pppoe_ma txgroup trace events  location 0/0/cpu0'
rplc__ksh[37]='txlist_show_trace -i $node_number -P pppoe_ma -F 0x2'

rplc_exec[38]='show process pppoe_ma txgroup trace errors  location 0/0/cpu0'
rplc__ksh[38]='txlist_show_trace -i $node_number -P pppoe_ma -F 0x3'

rplc_exec[39]='show process pppoe_ma txgroup txlist detail location 0/0/cpu0'
rplc__ksh[39]='txlib_show -N $node_number -E pppoe_ma -L -d'

rplc_exec[40]='show process iedged txgroup peer          location 0/0/cpu0'
rplc__ksh[40]='txlib_show -N $node_number -E iedged -P'

rplc_exec[41]='show process iedged txgroup detail        location 0/0/cpu0'
rplc__ksh[41]='txlib_show -N $node_number -E iedged -d'

rplc_exec[42]='show process iedged txgroup trace events  location 0/0/cpu0'
rplc__ksh[42]='txlist_show_trace -i $node_number -P iedged -F 0x2'

rplc_exec[43]='show process iedged txgroup trace errors  location 0/0/cpu0'
rplc__ksh[43]='txlist_show_trace -i $node_number -P iedged -F 0x3'

rplc_exec[44]='show process iedged txgroup txlist detail location 0/0/cpu0'
rplc__ksh[44]='txlib_show -N $node_number -E iedged -L -d'

rplc_exec[45]='show subscriber redundancy group detail history location '
rplc__ksh[45]='show_srg -m 0 -h -l $node_number'

rplc_exec[46]='show subscriber redundancy agent interface verbose history'
rplc__ksh[46]='show_srg -i None -d 1 -h -l $node_number'

rplc_exec[47]='show process srg_agt txgroup peer all detail location $location'
rplc__ksh[47]='txlib_show -N $node_number -E srg_agt -P -d -a'

rplc_exec[48]='show process iedged txgroup peer all detail location $location'
rplc__ksh[48]='txlib_show -N $node_number -E iedged -P -d -a'

rplc_exec[49]=''
rplc__ksh[49]=''


# 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 srg"
    print_main_heading "Location: $node_name_internal \($node_number\)  CardType: $__cardtype"

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

    # Print the closing heading.
    print_main_heading "show tech-support srg 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
