#! /pkg/bin/ksh
# ---------------------------------------------------------------------
# crypto_ipsec_show_tech - CRYPTO IPSEC show tech-support script
#
# November 2011, Virupaxappa G 
#
# Copyright (c) 2011-2012, 2014, 2017 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_crypto: output file not specified"
    exit
fi

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

# ***********************************************************
#  Show commands to be run by the show tech-support commands
# ***********************************************************

# Commands that run on once per system

#crypto ipsec comands
sys_show_exec[1]='show crypto ipsec sa'
sys_show__ksh[1]='ipsec_cmd show sa 0xffff none'

sys_show_exec[2]='show crypto ipsec spi'
sys_show__ksh[2]='ipsec_cmd show spi'
          
sys_show_exec[3]='show crypto ipsec summary'
sys_show__ksh[3]='ipsec_cmd show summary'
          
sys_show_exec[4]='show crypto ipsec icf'
sys_show__ksh[4]='ipsec_cmd show icf'
          
sys_show_exec[5]='show crypto ipsec interface'
sys_show__ksh[5]='ipsec_cmd interface 0xffffffff' 
          
sys_show_exec[6]='show crypto ipsec peers'
sys_show__ksh[6]='ipsec_cmd show peers'
          
sys_show_exec[7]='show crypto ipsec profile'
sys_show__ksh[7]='ipsec_cmd show crypto-profile all'
          
sys_show_exec[8]='show crypto ipsec statistics all'
sys_show__ksh[8]='ipsec_cmd show statistics ivrf all' 
          
sys_show_exec[9]='show crypto ipsec trace'
sys_show__ksh[9]='ipsec_show_ltrace'
          
sys_show_exec[10]='show crypto ipsec transform-set'
sys_show__ksh[10]='ipsec_cmd show transform-set all'

sys_show_exec[11]='show crypto ipsec icf'
sys_show__ksh[11]='ipsec_cmd show icf'

sys_show_exec[12]='show crypto ipsec imp config'
sys_show__ksh[12]='ipsec_cmd show imp 0x0'

sys_show_exec[13]='show crypto ipsec imp flow'
sys_show__ksh[13]='ipsec_cmd show imp 0x3'

sys_show_exec[14]='show crypto ipsec imp internal'
sys_show__ksh[14]='ipsec_cmd show imp 0x1'

sys_show_exec[15]='show crypto ipsec imp members'
sys_show__ksh[15]='ipsec_cmd show imp 0x6'

sys_show_exec[16]='show crypto ipsec imp summary'
sys_show__ksh[16]='ipsec_cmd show imp 0x2'

sys_show_exec[17]='show crypto ipsec imp trans'
sys_show__ksh[17]='ipsec_cmd show imp 0x4'

sys_show_exec[18]='show crypto ipsec ipp flow-table'
sys_show__ksh[18]='ipsec_cmd show ipp flow-table 0x0'

sys_show_exec[19]='show crypto ipsec ipp pkt-stats'
sys_show__ksh[19]='ipsec_cmd show ipp pkt-stats 0x0'

sys_show_exec[20]='show crypto ipsec ipp pkt-table'
sys_show__ksh[20]='ipsec_cmd show ipp pkt-table 0x0'

sys_show_exec[21]='show crypto ipsec ipp sa-table'
sys_show__ksh[21]='ipsec_cmd show ipp sa-table 0x0'

sys_show_exec[22]='show crypto ipsec ipp stalled-table'
sys_show__ksh[22]='ipsec_cmd show ipp stalled-table 0x0'

#common commands
sys_show_exec[23]='show install active'
if [[ "$platform" != "viking" ]]; then
    sys_show__ksh[23]='sdr_instcmd show install active'
else
    sys_show__ksh[23]='instcmd show install active'
fi

if [[ "$platform" != "viking" ]]; then
    sys_show_exec[24]='show install repository'
    sys_show__ksh[24]='sdr_instcmd show install repository'
else
    sys_show_exec[24]='show install inactive'
    sys_show__ksh[24]='instcmd show install inactive'
fi

sys_show_exec[25]='show version'
if [[ "$platform" != "viking" ]]; then
    sys_show__ksh[25]='ng_show_version'
else
    sys_show__ksh[25]='show_version'
fi

sys_show_exec[26]='show platform'
if [[ "$platform" != "viking" ]]; then
    sys_show__ksh[26]='show_platform_sysdb'
else
    sys_show__ksh[26]='show_platform_vkg'
fi

sys_show_exec[27]='show interfaces brief'
sys_show__ksh[27]='show_interface -a -o 0x2'


sys_show_exec[28]='show logging '
sys_show__ksh[28]='show_logging'

sys_show_exec[29]='show running-config '
sys_show__ksh[29]='nvgen -c -l 1 -t 1 -o 1'

sys_show__ksh[30]=''
#############################################################
# Commands that run on all RPs
rp__ksh[1]=''

display() {

     print_main_heading "show tech-support crypto ipsec"
         
     if [ "$__cardtype" == "SYS" ]; then
         exec_commands sys_show
         exec_commands sys_trace
     else
         case "$__cardtype" in
         "RP")
             exec_commands rplc_show
             exec_commands rp
             ;;
         "DRP")
             exec_commands rplc_show
             exec_commands rp
             ;;
         esac
     fi

    print_main_heading "show tech-support crypto ipsec 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
