#!/pkg/bin/ksh
# -----------------------------------------------------------------------------
# tech_arp                      - Shared show tech-support fast script for arp 
#                                      
#
# November 2008, Matthew Edwards
#
# Copyright (c) 2008-2009, 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

#
# Parse the arguments to the script - card type and interface filter are the 
# only support options currently.  No need to use the default parser function,
# as this has been done by caller.
#
__cardtype="unspecified"
trace_only="0"
show_only="0"

while [ "$#" -gt "0" ]; do
    case "$1" in
        -T) trace_only="1"; shift 1;;
        -S) show_only="1"; shift 1;;
        -t) __cardtype="$2"; shift 2;;
        *) shift;;
    esac
done

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

#
# List of commands to be run.  East set must finish with a pair of empty 
# strings.  Note that it is important to use single quotes rather than double 
# quotes for the strings containing your commands.
#
# For all of these the __ksh variable is the process that will actually be 
# spawned, the _exec variable is just a string that is printed in the output to
# describe it. 
#

###############################################################################
# Show commands that run once per LR
###############################################################################
#
# Trace commands
#
sys_trace_exec[1]=''
sys_trace__ksh[1]=''

#
# Show commands
#
sys_show_exec[1]='show adjacency location all'
sys_show__ksh[1]='aib_show_command -A'

sys_show_exec[2]='show cef'
sys_show__ksh[2]='fib_show_command -t -O 0x0'

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

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

sys_show_exec[5]='show cli history detail'
sys_show__ksh[5]='show_parser_history -h 0x2'

sys_show_exec[6]='show version'
if [ -f "/pkg/bin/ng_show_version" ]; then
    sys_show__ksh[6]='ng_show_version'
else
    sys_show__ksh[6]='show_version'
fi

sys_show_exec[7]='show install active'
if [ -f "/pkg/bin/sdr_instcmd" ]; then
    sys_show__ksh[7]='sdr_instcmd show install active'
else
    sys_show__ksh[7]='instcmd show install active'
fi

sys_show_exec[8]='show redundancy location all'
sys_show__ksh[8]='redcon_show -n all'

sys_show_exec[9]='show platform'
if [ -f "/pkg/bin/show_platform_sysdb" ]; then
    sys_show__ksh[9]='show_platform_sysdb'
else
    sys_show__ksh[9]='show_platform'
fi

sys_show_exec[10]='show adjacency ipv4 internal detail location all'
sys_show__ksh[10]='aib_show_command -E -P ipv4 -D -A'

sys_show_exec[11]='show adjacency mpls internal detail location all'
sys_show__ksh[11]='aib_show_command -E -P mpls -D -A'

sys_show_exec[12]='show bundle'
sys_show__ksh[12]="bundlemgr_show -b all"

sys_show_exec[13]='show arp detail'
sys_show__ksh[13]='arp_command show -A -E'

sys_show_exec[14]=''
sys_show__ksh[14]=''

###############################################################################
# Show commands that run on all RP or LC                                      #
###############################################################################

#
# Trace commands
#
rplc_trace_exec[1]=''
rplc_trace__ksh[1]=''

#
# Show commands
#
rplc_show_exec[1]='show im chains location $location'
rplc_show__ksh[1]='im_show database'

# assumes "platform" is set for us by show_tech_main_fragment
if [ -f "/pkg/bin/sh_proc_ng_blocked" ]
then
    rplc_show_exec[2]='show process blocked'
    rplc_show__ksh[2]='sh_proc_ng_blocked'
else
    rplc_show_exec[2]='show process blocked'
    rplc_show__ksh[2]='show_processes -b'
fi

rplc_show_exec[3]=''
rplc_show__ksh[3]=''


#
# The display() function is the one that does all the work - called by us as 
# this is a worker script.
#
display() {
    print_main_heading "Extra ARP tech-support info"
        
    if [ "$__cardtype" = "SYS" ]; then
        if [ "$trace_only" = "0" ]; then
            exec_commands sys_show
        fi

        if [ "$show_only" = "0" ]; then
            exec_commands sys_trace
        fi
        
    else
        case "$__cardtype" in
        "DRP"|"RP"|"LC")
            if [ "$trace_only" = "0" ]; then
                exec_commands rplc_show
            fi

            if [ "$show_only" = "0" ]; then
                exec_commands rplc_trace
            fi
            ;;
        esac
    fi
    
    print_main_heading "Extra ARP tech-support info complete"
}

display
