#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# ipsec_show_techsupport - Show tech-support script for ipsec
#
# Aug 2021 Krishna Balakrishnan, Tawrun Vankineeni, Sujal Sheth
#
# Copyright (c) 2021-2022, 2024 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

# This script fragment contains the code for the following functions
# - print_main_heading
# - print_command_heading
# - run_single_command
# - run_commands
# - run_single_command_on_all_nodes
# - run_commands_on_all_nodes
# - default_parser_function
. /pkg/bin/show_tech_main_fragment

# List each set of show commands to be run. Each set must finish with an empty
# string. Note that it is important to use single quotes rather than double
# quotes for the strings containing your commands.

__cardtype="unspecified"

# Set the default values of the file name for which show tech-support ipsec
# is to run and the file it is to write to.
# Read in the arguments to the script, setting node_required and filename
# according to these arguments.
# Note that it is important for security reasons that users can only enter
# alphanumeric filenames and nodes and that anywhere calling this script must
# enforce this.
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

# global commands on RP


###############################################################################
# Show commands that run once per LR                                          #
###############################################################################


sys_exec[1]='show install active'
if [[ "$platform" != "viking" ]]; then
sys__ksh[1]='sdr_instcmd show install active'
else
sys__ksh[1]='instcmd show install active'
fi

if [[ "$platform" != "viking" ]]; then
sys_exec[2]='show install repository'
sys__ksh[2]='sdr_instcmd show install repository'
else
sys_exec[2]='show install inactive'
sys__ksh[2]='instcmd show install inactive'
fi

sys_exec[3]='show version'
if [[ "$platform" != "viking" ]]; then
sys__ksh[3]='ng_show_version'
else
sys__ksh[3]='show_version'
fi

sys_exec[4]='show platform'
if [[ "$platform" != "viking" ]]; then
sys__ksh[4]='show_platform_sysdb'
else
sys__ksh[4]='show_platform_vkg'
fi

sys_exec[5]=''
sys__ksh[5]=''


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


rp_exec[1]='show logging'
rp__ksh[1]='show_logging'


rp_exec[2]='show redundancy location all'
rp__ksh[2]='redcon_show -n all'

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

rp_exec[4]='show running-config'
rp__ksh[4]='nvgen -c -l 1 -t 1 -o 1'

rp_exec[5]='show process ipsec_ma location $location'
rp__ksh[5]='sysmgr_show -o -p ipsec_ma'

rp_exec[6]='show process ipsec_pp location $location'
rp__ksh[6]='sysmgr_show -o -p ipsec_pp'

rp_exec[7]='show process ike location $location'
rp__ksh[7]='sysmgr_show -o -p ike'

rp_exec[8]='show ip int brief'
rp__ksh[8]='show_ip_interface -b -v all'

rp_exec[9]='show ipsec sa interface'
rp__ksh[9]='ipsec_show_sa -I -A'

rp_exec[10]='show ipsec trace ma all location all'
rp__ksh[10]='ipsec_show_trace "-A" "ma" "-i" "all"'

rp_exec[11]='show im database brief location all'
rp__ksh[11]='im_show database -l 0x1 -a'

rp_exec[12]="show rsi vrf all"
rp__ksh[12]='show_rsi_agent -c 0x17'

rp_exec[13]=''
rp__ksh[13]=''

###############################################################################
# Show commands of ipsec that run on every LC                       #
###############################################################################
lc_exec[1]=''
lc__ksh[1]=''

# Parse the arguments to the script.
# Usage:
#
#sys.exit()
# A function called display() must be provided that calls the functions to
# Print the output heading

do_show_command() {
    print_main_heading "show tech-support ipsec"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case "$__cardtype" in
            "RP"|"DRP")
                exec_commands rp
                ;;
        esac
    fi
    enable_techs "" /pkg/bin/ikev2_show_techsupport
    if [ -f /pkg/bin/crypto_ipsec_show_tech ]; then
        enable_techs "" /pkg/bin/crypto_ipsec_show_tech
    fi

    # Print the closing heading.
    print_main_heading "show tech-support ipsec complete"
}
# The display function.
display() {
    do_show_command
}

# 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
