#!/pkg/bin/ksh
# -----------------------------------------------------------------------------
# tech_arp                      - Shared show tech-support fast script for arp 
#                                      
#
# November 2008, Matthew Edwards
#
# Copyright (c) 2008-2010, 2012-2014, 2017-2018 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]='show arp-gmp trace all'
sys_trace__ksh[1]='arp_gmp_show_ltrace -S -F'

sys_trace_exec[2]=''
sys_trace__ksh[2]=''

#
# Show commands
# 
sys_show_exec[1]='show arp-gmp config'
sys_show__ksh[1]='arp_gmp_command -c'

sys_show_exec[2]='show arp-gmp routes'
sys_show__ksh[2]='arp_gmp_command -r'

sys_show_exec[3]='show arp-gmp vrf'
sys_show__ksh[3]='arp_gmp_command -v'


sys_show_exec[4]='show processes arp_gmp'
sys_show__ksh[4]='sysmgr_show -o -p arp_gmp'

sys_show_exec[5]='show system statistics component ipv4-arp'
sys_show__ksh[5]='ship_show -c ipv4-arp'

sys_show_exec[6]=''
sys_show__ksh[6]=''

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

#
# Trace commands
#
rplc_trace_exec[1]='show arp trace location $location'
rplc_trace__ksh[1]='show_arp_ltrace'

rplc_trace_exec[2]='show arp client trace all location $location'
rplc_trace__ksh[2]='arp_client_show_ltrace -S -F'

rplc_trace_exec[3]=''
rplc_trace__ksh[3]=''

#
# Show commands
#
rplc_show_exec[1]='show arp location $location'
rplc_show__ksh[1]='arp_command show'

rplc_show_exec[2]='show arp vrf all location $location'
rplc_show__ksh[2]='arp_command show -V all'

rplc_show_exec[3]='show arp idb all location $location'
rplc_show__ksh[3]='arp_idb_show -a'

rplc_show_exec[4]='show arp traffic location $location'
rplc_show__ksh[4]='arp_command show -t'

rplc_show_exec[5]='show arp status location $location'
rplc_show__ksh[5]='arp_status_show'

rplc_show_exec[6]='show processes arp location $location'
rplc_show__ksh[6]='sysmgr_show -o -p arp'

rplc_show_exec[7]='show arp resolution history location $location'
rplc_show__ksh[7]='arp_reshist_show -a'

rplc_show_exec[8]='show arp api-stats location $location'
rplc_show__ksh[8]='arp_api_stats_command -S'

rplc_show_exec[9]='show arp api-stats detail all location $location'
rplc_show__ksh[9]='arp_api_stats_command -S -d'

rplc_show_exec[10]='show system statistics component ipv4-arp'
rplc_show__ksh[10]='ship_show -c ipv4-arp'

rplc_show_exec[11]='show arp adjacency history location $location'
rplc_show__ksh[11]='arp_aibhist_show -a'

rplc_show_exec[12]='show arp packet history location $location'
rplc_show__ksh[12]='arp_pakhist_show -a'

rplc_show_exec[13]='show arp thread location $location'
rplc_show__ksh[13]='arp_command show -Q'

rplc_show_exec[14]=''
rplc_show__ksh[14]=''


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

        if [ "$trace_only" = "0" ]; then
                exec_commands sys_show
        fi

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

            if [ "$trace_only" = "0" ]; then
                exec_commands rplc_show
            fi

            ;;
        esac
    fi
    
    print_main_heading "General ARP tech-support info complete"
}

display
