#!/pkg/bin/ksh
# -----------------------------------------------------------------------------
# tech_fhrp                     - Shared show tech-support fast script for fhrp 
#                                      
#
# November 2008, Matthew Edwards
#
# Copyright (c) 2008 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"
internal_if="unspecified"
external_if=""
trace_only="0"
show_only="0"

while [ "$#" -gt "0" ]; do
    case "$1" in
        -I) internal_if="$2"; shift 2;;
        -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 route'
sys_show__ksh[1]='show_ipv4_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -s ipv4 ________'

sys_show_exec[2]='show rib tables'
sys_show__ksh[2]='show_ipv4_rib -X 0x1 -4 0x0'

sys_show_exec[3]='show ipv4 interface brief'
sys_show__ksh[3]='show_ip_interface -b -v default'

sys_show_exec[4]=''
sys_show__ksh[4]=''

#
# Show commands that require an interface
#
sys_show_if_exec[1]='show controllers $external_if control'
sys_show_if__ksh[1]='ethernet_show_controller -i $internal_if -s control'

sys_show_if_exec[2]=''
sys_show_if__ksh[2]=''

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

#
# 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 "FHRP tech-support info"
        if [ "$trace_only" = "0" ]; then
            exec_commands sys_show
            if [ "$internal_if" != "unspecified" ]; then
                external_if=`convert_interface_fmt '-e' $internal_if`
                exec_commands sys_show_if
            fi
        fi

        if [ "$show_only" = "0" ]; then
                exec_commands sys_trace
        fi
        print_main_heading "FHRP tech-support info complete"
    fi
    
}

display
