#!/pkg/bin/ksh
# -----------------------------------------------------------------------------
# show_tech_fast_ppp               - Shared show tech-support fast script 
#                                      for ppp encapsulated interfaces - 
#
# October 2008, Matthew Edwards
#
# Copyright (c) 2008-2009, 2011, 2017 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"
ether_arg_string=""
bundle_only_arg_string=""

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 [ "$internal_if" != "unspecified" ]; then
    external_if=`convert_interface_fmt '-e' $internal_if`
fi

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
###############################################################################
sys_exec[1]=''
sys__ksh[1]=''

#
# Commands requiring interface handle
#
sys_if_exec[1]='show ppp idb $external_if'
sys_if__ksh[1]='show_ppp_interface -i $internal_if -d'

sys_if_exec[2]='show ppp statistics interface $external_if'
sys_if__ksh[2]='show_ppp_stats -i $internal_if'

sys_if_exec[3]=''
sys_if__ksh[3]=''

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

#
# Trace commands
#
rplc_trace_exec[1]='show ppp trace all location $location'
rplc_trace__ksh[1]='ppp_show_ltrace'

rplc_trace_exec[2]='show ssrp trace all location $location'
rplc_trace__ksh[2]='ssrp_show_ltrace'

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

#
# Show commands
#
rplc_show_exec[1]='show processes ppp_ma location $location'
rplc_show__ksh[1]='sysmgr_show -o -p ppp_ma'

rplc_show_exec[2]='show processes ppp_ea location $location'
rplc_show__ksh[2]='sysmgr_show -o -p ppp_ea'

rplc_show_exec[3]='show processes ppp_socket location $location'
rplc_show__ksh[3]='sysmgr_show -o -p ppp_socket'

rplc_show_exec[4]='show ppp interfaces location $location'
rplc_show__ksh[4]='show_ppp_interface'

rplc_show_exec[5]='show ppp ea interface all location $location'
rplc_show__ksh[5]='ppp_ea_show -a'

rplc_show_exec[6]='show ppp summary location $location'
rplc_show__ksh[6]='show_ppp_summ'

rplc_show_exec[7]='show ppp statistics extended location $location'
rplc_show__ksh[7]='show_ppp_stats -x'

rplc_show_exec[8]='show ppp api calls location $location'
rplc_show__ksh[8]='show_ppp_api_calls'

rplc_show_exec[9]='show ppp disconnect-history location $location'
rplc_show__ksh[9]='show_ppp_disc_history'

rplc_show_exec[10]='show ppp disconnect-history detail location $location'
rplc_show__ksh[10]='show_ppp_disc_history -d'

rplc_show_exec[11]='show ppp disconnect-history unique location $location'
rplc_show__ksh[11]='show_ppp_disc_history -u'

rplc_show_exec[12]='show ppp disconnect-history detail unique location $location'
rplc_show__ksh[12]='show_ppp_disc_history -d -u'

rplc_show_exec[13]='show ppp statistics internal timing location $location'
rplc_show__ksh[13]='show_ppp_stats -t'

rplc_show_exec[14]='show ppp sso state location $location'
rplc_show__ksh[14]='show_ppp_sso_state'

rplc_show_exec[15]='show ppp sso summary location $location'
rplc_show__ksh[15]='show_ppp_sso_summary'

rplc_show_exec[16]='show ppp sso alerts location $location'
rplc_show__ksh[16]='show_ppp_sso_alerts'

rplc_show_exec[17]='show ssrp groups all detailed location $location'
rplc_show__ksh[17]='ssrp_show_group -a -d'

rplc_show_exec[18]='show ssrp profiles all location $location'
rplc_show__ksh[18]='ssrp_show_profile -a'

rplc_show_exec[19]='show ppp preprocessed-packet statistics location $location'
rplc_show__ksh[19]='show_ppp_pkt_preproc -s'

rplc_show_exec[20]=''
rplc_show__ksh[20]=''


#
# The display() function is the one that does all the work - called by us as 
# this is a worker script.
#
display() {
    print_main_heading "show tech-support ppp common"
        
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys

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

            if [ "$trace_only" = "0" ]; then
                exec_commands rplc_show
            fi
            ;;
        "LC")
            if [ "$show_only" = "0" ]; then
                exec_commands rplc_trace
            fi

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

    enable_techs "" /pkg/bin/iedge_show_techsupport_fast\
         /pkg/bin/show_tech_fast_pppoe  
    set_max_depth 5

    
    print_main_heading "show tech-support ppp common complete"
}

display
