#!/pkg/bin/ksh
# -----------------------------------------------------------------------------
# tech_rip                     - Shared show tech-support fast script for rip 
#                                      
#
# Manjari Vishnoi
#
# Copyright (c) 2021-2022 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"
vrf_in_exec="vrf default"
vrf_in_ksh="default"

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 rip trace location all'
sys_trace__ksh[1]='rip_show_ltrace -i all -T -C'

sys_trace_exec[2]='show rip ipv6 trace location all'
sys_trace__ksh[2]='rip_show_ltrace -i all -Q -T'

sys_trace_exec[3]='show processes rip'
sys_trace__ksh[3]='sysmgr_show -o -p rip'

sys_trace_exec[4]='show running router rip'
sys_trace__ksh[4]='nvgen "-c" "-q" "gl/rip/"'

sys_trace_exec[5]='show ipv4 vrf all interface brief'
sys_trace__ksh[5]='show_ip_interface -b -v all'

sys_trace_exec[6]='show ipv6 vrf all interface brief'
sys_trace__ksh[6]='show_ipv6_interface -b -v all'

sys_trace_exec[7]='show logging process rip'
sys_trace__ksh[7]='show_logging -p rip'

sys_trace_exec[8]=''
sys_trace__ksh[8]=''

#
# Show commands
# 
sys_show_exec[1]='show rip $vrf_in_exec internal'
sys_show__ksh[1]='rip_show "-v" $vrf_in_ksh "-z" "0"'

sys_show_exec[2]='show rip ipv6 $vrf_in_exec internal'
sys_show__ksh[2]='rip_show "-Q" "-v" $vrf_in_ksh "-z" "0"'

sys_show_exec[3]='show rip $vrf_in_exec statistics'
sys_show__ksh[3]='rip_show "-v" $vrf_in_ksh "-s" "0"'

sys_show_exec[4]='show rip ipv6 $vrf_in_exec statistics'
sys_show__ksh[4]='rip_show "-Q" "-v" $vrf_in_ksh "-s" "0"'

sys_show_exec[5]='show rip $vrf_in_exec database'
sys_show__ksh[5]='rip_show "-v" $vrf_in_ksh "-d" "0"'

sys_show_exec[6]='show rip ipv6 $vrf_in_exec database'
sys_show__ksh[6]='rip_show "-Q" "-v" $vrf_in_ksh "-d" "0"'

sys_show_exec[7]='show rip $vrf_in_exec interface'
sys_show__ksh[7]='rip_show "-v" $vrf_in_ksh "-t" "0"'

sys_show_exec[8]='show rip ipv6 $vrf_in_exec interface'
sys_show__ksh[8]='rip_show "-Q" "-v" $vrf_in_ksh "-t" "0"'

sys_show_exec[9]='show rip $vrf_in_exec'
sys_show__ksh[9]='rip_show "-v" $vrf_in_ksh "-c" "0"'

sys_show_exec[10]='show rip ipv6 $vrf_in_exec'
sys_show__ksh[10]='rip_show "-Q" "-v" $vrf_in_ksh "-c" "0"'

sys_show_exec[11]=''
sys_show__ksh[11]=''

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

#
# 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
        exec_commands sys_trace
    elif [ "$__cardtype" == "RP" -o "$__cardtype" == "DRP" ]; then
        print_main_heading "RIP tech-support info"
            vrf_in_exec='vrf default'
            vrf_in_ksh='default'
            exec_commands sys_show

            vrf_in_exec='vrf all'
            vrf_in_ksh='all'
            exec_commands sys_show
        print_main_heading "RIP tech-support info complete"
    fi

}

display
