#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# serg_show_tech - show tech-support serg
#
# August 2016, A. Sankaranarayana
#
# Copyright (c) 2016-2017 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'
if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
    sys__ksh[1]='ng_show_version'
else
    sys__ksh[1]='show_version'
fi

sys_exec[2]='show install active'
if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
    sys__ksh[2]='sdr_instcmd show install active'
else
    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 context location all'
if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
    sys__ksh[4]='corehelper_context -c 0x1 -n all'
else
    sys__ksh[4]='dumper_context -c 0x1 -n all'
fi

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

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

sys_exec[7]=''
sys__ksh[7]=''

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

# misc info
rp_exec[1]='show session-redundancy trace component serg-manager'
rp__ksh[1]='show_ltrace_serg -T 0xffffffff -C 0xffffffff -G 0x300000 -M 0xffffffff'

rp_exec[2]='show session-redundancy summary'
rp__ksh[2]='show_serg_mgr -s'

rp_exec[3]='show session-redundancy summary group'
rp__ksh[3]='show_serg_mgr -g'

rp_exec[4]='show session-redundancy summary interface'
rp__ksh[4]='show_serg_mgr -i'

rp_exec[5]='show process serg_mgr'
rp__ksh[5]='sysmgr_show -o -p serg_mgr'

rp_exec[6]=''
rp__ksh[6]=''

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

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

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

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

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

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

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

rplc_exec[9]='show session-redundancy group all'
rplc__ksh[9]='show_serg -g 0'

rplc_exec[10]='show process serg_agt txgroup peer location $location'
rplc__ksh[10]='txlib_show -N $node_number -E serg_agt -P'

rplc_exec[11]='show process serg_agt txgroup detail location $location'
rplc__ksh[11]='txlib_show -N $node_number -E serg_agt -d'

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

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

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

rplc_exec[15]='show process ipv6_nd txgroup peer location $location'
rplc__ksh[15]='txlib_show -N $node_number -E ipv6_nd -P'

rplc_exec[16]='show process ipv6_nd txgroup detail location $location'
rplc__ksh[16]='txlib_show -N $node_number -E ipv6_nd -d'

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

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

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

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

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

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

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

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

rplc_exec[25]='show process serg_agt location $location'
rplc__ksh[25]='sysmgr_show -o -p serg_agt -n $node_number'

rplc_exec[26]='show session-redundancy client ipv6nd location $location'
rplc__ksh[26]='show_client_serg -c 1 -s -l $node_number'

rplc_exec[27]='show session-redundancy client dhcpv6 location $location'
rplc__ksh[27]='show_client_serg -c 2 -s -l $node_number'

rplc_exec[28]=''
rplc__ksh[28]=''

# 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 serg"
    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 serg 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
