#!/pkg/bin/ksh
# -----------------------------------------------------------------------------
# show_tech_fast_pppoe_common   - Show tech-support fast script for pppoe  - 
#
# December 2010, Matthew Edwards
#
# Copyright (c) 2010-2015 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]=''
sys_if__ksh[1]=''

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

#
# Trace commands
#
rplc_trace_exec[1]='show pppoe trace all location $location'
rplc_trace__ksh[1]='pppoe_show_ltrace'

rplc_trace_exec[2]=''
rplc_trace__ksh[2]=''

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

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

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

rplc_show_exec[4]='show pppoe ma database all location $location'
rplc_show__ksh[4]='pppoe_ma_show -d'

rplc_show_exec[5]='show pppoe statistics location $location'
rplc_show__ksh[5]='pppoe_ma_show_stats'

rplc_show_exec[6]='show pppoe statistics internal location $location'
rplc_show__ksh[6]='pppoe_ma_show_stats -a'

rplc_show_exec[7]='show pppoe statistics internal timing location $location'
rplc_show__ksh[7]='pppoe_ma_show_stats -a -t'
                 
rplc_show_exec[8]='show pppoe summary total location $location'
rplc_show__ksh[8]='pppoe_ma_show -s -t'
                 
rplc_show_exec[9]='show pppoe disconnect-history location $location'
rplc_show__ksh[9]='pppoe_ma_show_disc_history'

rplc_show_exec[10]='show pppoe disconnect-history unique location $location'
rplc_show__ksh[10]='pppoe_ma_show_disc_history -u'

rplc_show_exec[11]='show pppoe disconnect-history detail location $location'
rplc_show__ksh[11]='pppoe_ma_show_disc_history -d'

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

rplc_show_exec[13]='show pppoe limits location $location'
rplc_show__ksh[13]='pppoe_ma_show -L'

rplc_show_exec[14]='show pppoe throttles location $location'
rplc_show__ksh[14]='pppoe_ma_show -T'

rplc_show_exec[15]='show pppoe summary per-access-interface location $location'
rplc_show__ksh[15]='pppoe_ma_show -s'

rplc_show_exec[16]=''
rplc_show__ksh[16]=''

#
# Interface commands
#
rplc_intf_exec[1]='show pppoe ma database session-idb $external_if location $location'
rplc_intf__ksh[1]='pppoe_ma_show -d -v $internal_if'

rplc_intf_exec[2]='show pppoe ea interface $external_if location $location'
rplc_intf__ksh[2]='pppoe_ea_show -i $internal_if'

rplc_intf_exec[3]=''
rplc_intf__ksh[3]=''

#
# 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 pppoe 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
            
            if [ "$internal_if" != "unspecified" ]; then
                exec_commands rplc_intf
            fi
            ;;
        "LC")
            if [ "$show_only" = "0" ]; then
                exec_commands rplc_trace
            fi

            if [ "$trace_only" = "0" ]; then
                exec_commands rplc_show
            fi
            
            if [ "$internal_if" != "unspecified" ]; then
                exec_commands rplc_intf
            fi
            ;;
        esac
    fi
    
    print_main_heading "show tech-support pppoe common complete"
}

display
