#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_svd - show commands for show tech-support svd 
#                     spawned by show_tech_fast
#
# November 2010, Atul Kant Kaushik 
#
# Copyright (c) 2010-2013, 2018 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_svd: output file not specified"
    exit
fi

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

#Get the Platform
platform=`get_platform_type`

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

# Commands that run on once per system
sys_exec[1]="show running-config"
sys__ksh[1]='nvgen -c -l 1 -t 1 -i1 -o 1'
sys_exec[2]="show install package all detail"
sys__ksh[2]='instcmd show install package all detail'
sys_exec[3]="show redundancy"
sys__ksh[3]='redcon_show'
sys_exec[4]="show logging"
sys__ksh[4]='show_logging'
sys_exec[5]="show svd state"
sys__ksh[5]='show_rsi_master -c 0x47'
sys_exec[6]="show svd role"
sys__ksh[6]='show_rsi_agent -c 0x48'
sys_exec[7]="show bgp vrf all dependency"
sys__ksh[7]='bgp_show -V all -A 0x1 -W 0x1 -10'
sys_exec[8]="show bgp vrf all ipv6 unicast dependency"
sys__ksh[8]='bgp_show -V all -A 0x2 -W 0x1 -10'
sys_exec[9]="show static vrf all afi-all co-location"
sys__ksh[9]='all_afi_static_show -A 0x0 -S 0x1 -Z all -T ________ -H -X'
sys_exec[10]="show bcdlv2"
sys__ksh[10]='show_bcdlv2 -C 0x1'
sys_exec[11]="show bcdlv2 trace location all"
sys__ksh[11]='bcdl2_show_ltrace -i all'
sys_exec[12]="show process rsi_master"
sys__ksh[12]='sysmgr_show -o -p rsi_master'
sys_exec[13]="show platform"
if [ "$platform" == "panini" ]; then
    sys__ksh[13]='show_platform_sysdb'
elif [ "$platform" == "viking" ]; then
    sys__ksh[13]='show_platform_vkg -e'
elif [ "$platform" == "hfr" ]; then
    sys__ksh[13]='shelfmgr_show_hfr -e'
elif [ "$platform" == "fretta" ]; then
    sys__ksh[13]='show_platform_sysdb'
else
    sys__ksh[13]='show_platform'
fi

sys_exec[14]="show adjacency internal detail"                             
sys__ksh[14]='aib_show_command -E -D'                                  
sys_exec[15]="show vrf all"                                               
sys__ksh[15]='mpls_vpn_show -a'                                           
sys_exec[16]=''

#############################################################
# Commands that run on all Nodes
all_exec[1]="show rsi table"
all__ksh[1]='show_rsi_agent -c 0x1f'
all_exec[2]="show rsi table collocation"
all__ksh[2]='show_rsi_agent -c 0x1f -h'
all_exec[3]="show rsi table lst"       
all__ksh[3]='show_rsi_agent -c 0x1f -g 0x1'
all_exec[4]="show cef ipv4 table summary"
all__ksh[4]='fib_show_command -t -O 0x0 -3 -4'
all_exec[5]="show cef ipv6 table summary"      
all__ksh[5]='fib_show_command -t -O 0x1 -3 -4'
all_exec[6]="show cef ipv4 table"      
all__ksh[6]='fib_show_command -t -O 0x0 -3'
all_exec[7]="show cef ipv6 table" 
all__ksh[7]='fib_show_command -t -O 0x1 -3'
all_exec[8]="show cef ipv4 unresolved"
all__ksh[8]='fib_show_command -t -O 0x0 -u'
all_exec[9]="show cef ipv6 unresolved"
all__ksh[9]='fib_show_command -t -O 0x1 -u'
all_exec[10]="show cef ipv4 resource"
all__ksh[10]='fib_show_command -K -O 0x0'
all_exec[11]="show cef ipv6 resource"
all__ksh[11]='fib_show_command -K -O 0x1'
all_exec[12]="show cef misc"
all__ksh[12]='fib_show_command -s -O 0x0'
all_exec[13]="show rsi clients"
all__ksh[13]='show_rsi_agent -c 0x29'
all_exec[14]="show rsi producers"
all__ksh[14]='show_rsi_agent -c 0x33'
all_exec[15]="show rsi interface all global"
all__ksh[15]='show_rsi_agent -c 0x3d -h'
all_exec[16]="show rsi state"
all__ksh[16]='show_rsi_agent -c 0x50'
all_exec[17]="show rsi role-transactions"
all__ksh[17]='show_rsi_agent -c 0x51'
all_exec[18]="show rsi trace"
all__ksh[18]='rsi_show_ltrace'
all_exec[19]="show process rsi_agent"
all__ksh[19]='sysmgr_show -o -p rsi_agent'
all_exec[20]="show process fib_mgr"
all__ksh[20]='sysmgr_show -o -p fib_mgr'
all_exec[21]="show vrf-group all internal"
all__ksh[21]='show_rsi_agent -c 0x5d'
all__ksh[22]=''

#############################################################
# Commands that run on all RPs
rp_exec[1]="show rib afi-all tables summary"
rp__ksh[1]='show_all_afi_rib -X 0x0 -0 0x0'
rp_exec[2]="show rib afi-all tables"
rp__ksh[2]='show_all_afi_rib -X 0x0 -4 0x0'
rp_exec[3]="show rib afi-all update-groups"
rp__ksh[3]='show_all_afi_rib -X 0x0 -k 0x0'
rp_exec[4]="show rib afi-all tables selective-vrf-download"
rp__ksh[4]='show_all_afi_rib -X 0x0 -y 0x0'
rp_exec[5]="show process ipv4_rib"
rp__ksh[5]='sysmgr_show -o -p ipv4_rib'
rp_exec[6]="show process ipv6_rib"
rp__ksh[6]='sysmgr_show -o -p ipv6_rib'
rp_exec[7]="show rib clients redistribution"
rp__ksh[7]='show_ipv4_rib -X 0x1 -v 0x0'
rp_exec[8]="show rib ipv6 clients redistribution"
rp__ksh[8]='show_ipv6_rib -X 0x2 -v 0x0'
rp_exec[9]="show rib ipv4 trace"
rp__ksh[9]='show_ipv4_rib_ltrace'
rp_exec[10]="show rib ipv6 trace"
rp__ksh[10]='show_ipv6_rib_ltrace'
rp_exec[11]="show bgp trace event"
rp__ksh[11]='bgp_show_ltrace -C 0x3'
rp_exec[12]="show process ipv4_static"
rp__ksh[12]='sysmgr_show -o -p ipv4_static'
rp_exec[13]="show process ipv6_static"
rp__ksh[13]='sysmgr_show -o -p ipv6_static'
rp_exec[14]="show bcdlv2 update-gropus tabular"
rp__ksh[14]='show_bcdlv2 -b -C 0x5'
rp__ksh[15]=''


display() {
    print_main_heading "show tech-support svd"

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

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