#!/pkg/bin/ksh
# -----------------------------------------------------------------------------
# tech_vrrp                     - Shared show tech-support fast script for vrrp 
#                                      
#
# November 2008, Matthew Edwards
#
# Copyright (c) 2008-2010, 2012, 2014-2015, 2019 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 vrrp trace all'
sys_trace__ksh[1]='vrrp_show_ltrace -N -B'

sys_trace_exec[2]='show vrrp trace bulk'
sys_trace__ksh[2]='vrrp_show_ltrace -B'

sys_trace_exec[3]=''
sys_trace__ksh[3]=''

#
# Show commands
# 
sys_show_exec[1]='show vrrp'
sys_show__ksh[1]='vrrp_show'

sys_show_exec[2]='show vrrp detail'
sys_show__ksh[2]='vrrp_show -d'

sys_show_exec[3]='show vrrp statistics'
sys_show__ksh[3]='vrrp_show -s'

sys_show_exec[4]='show vrrp ipv4 statistics'
sys_show__ksh[4]='vrrp_show -f ipv4 -s'

sys_show_exec[5]='show vrrp ipv6 statistics'
sys_show__ksh[5]='vrrp_show -f ipv6 -s'

sys_show_exec[6]='show processes vrrp'
sys_show__ksh[6]='sysmgr_show -o -p vrrp'

sys_show_exec[7]='show vrrp idb'
sys_show__ksh[7]='vrrp_show -I'

sys_show_exec[8]='show vrrp api-statistics'
sys_show__ksh[8]='vrrp_api_stats_command'

sys_show_exec[9]='show vrrp api-statistics detail all'
sys_show__ksh[9]='vrrp_api_stats_command -d'

sys_show_exec[10]='show vrrp summary'
sys_show__ksh[10]='vrrp_show -u'

sys_show_exec[11]='show ipv6 vrinfo'
sys_show__ksh[11]='show_ipv6_vrinfo -a'

sys_show_exec[12]='show vrrp state history'
sys_show__ksh[12]='vrrp_show -h'


sys_show_exec[13]=''
sys_show__ksh[13]=''

#
# No show commands run on individual RP or LC for VRRP
#

#
# The display() function is the one that does all the work - called by us as 
# this is a worker script.
#
display() {

    if [ "$__cardtype" = "SYS" ]; then
        print_main_heading "VRRP tech-support info"
        if [ "$show_only" = "0" ]; then
                exec_commands sys_trace
        fi

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

        print_main_heading "VRRP tech-support info complete"
    fi
    
}

display
