#!/pkg/bin/ksh
# -----------------------------------------------------------------------------
# show_tech_fast_ether_pd - Show tech-support ethernet script for
#                           ethernet PD (generic PI version)
#
# Copyright (c) 2019-2020 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=""
ether_arg_string=""
bundle_only_arg_string=""

while [ "$#" -gt "0" ]; do
    case "$1" in
        -I) internal_if="$2"; shift 2;;
        -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. 
#

###############################################################################
# Commands that need to loop for all nodes within the rack.  This is used for #
# commands that require a location, don't support location all, and don't run #
# on the LCs                                                                  #
###############################################################################

rp_loc_exec[1]=''
rp_loc__ksh[1]=''


###############################################################################
# Commands that need to loop for all nodes within the rack.  This is used for #
# commands that require a location, don't support location all, and don't run #
# on the RPs                                                                  #
###############################################################################

cmd_index=1
lc_loc_exec[$cmd_index]='show controllers npu voq-usage interface all instance all location $location'
lc_loc__ksh[$cmd_index]='dpa_qosea_voq_show -v x -i 16 -n A -t n -p 0'
((cmd_index++))

lc_loc_exec[$cmd_index]='show vether-ea trace all location $location'
lc_loc__ksh[$cmd_index]='dpa_vether_ea_show_ltrace -E -V'
((cmd_index++))

lc_loc_exec[$cmd_index]='show ether-ea trace all location $location'
lc_loc__ksh[$cmd_index]='dpa_ether_ea_show_ltrace -E -V'
((cmd_index++))

lc_loc_exec[$cmd_index]='show vether-driver server event location $location'
lc_loc__ksh[$cmd_index]='easy_debug_ltrace -W 0 -X 0x1 -Y 0x0 -Z libvether_server'
((cmd_index++))

lc_loc_exec[$cmd_index]='show vether-driver server error location $location'
lc_loc__ksh[$cmd_index]='easy_debug_ltrace -W 0 -X 0x0 -Y 0x0 -Z libvether_server'
((cmd_index++))

lc_loc_exec[$cmd_index]='show port DB'
lc_loc__ksh[$cmd_index]='vether_test ddb -t 0'
((cmd_index++))

# platform_variant is not correct for ncs560(RSP4), it need to be fixed from script/lib api
platform_variant_=`echo $(grep "platform" /proc/cmdline | cut -d'=' -f4 | cut -d' ' -f1)`
if [ "$platform_variant" == "fretta" ]; then
    lc_loc_exec[$cmd_index]='show vether ea event'
    lc_loc__ksh[$cmd_index]='/pkg/bin/fretta_vether_ea_show_ltrace -V'
    ((cmd_index++))

    lc_loc_exec[$cmd_index]='show vether ea error'
    lc_loc__ksh[$cmd_index]='/pkg/bin/fretta_vether_ea_show_ltrace -E'
    ((cmd_index++))
elif [ "$platform_variant_" == "ncs560" ]; then
    lc_loc_exec[$cmd_index]='show vether ea trace all'
    lc_loc__ksh[$cmd_index]='ether_lc_show_ltrace -E -V -B'
    ((cmd_index++))
fi

lc_loc_exec[$cmd_index]='show vether-driver fsm event location $location'
lc_loc__ksh[$cmd_index]='easy_debug_ltrace -W 0 -X 0x3 -Y 0x0 -Z libvether_server' 
((cmd_index++))

lc_loc_exec[$cmd_index]='show vether-driver fsm error location $location'
lc_loc__ksh[$cmd_index]='easy_debug_ltrace -W 0 -X 0x2 -Y 0x0 -Z libvether_server' 
((cmd_index++))

lc_loc_exec[$cmd_index]='show vether-client client error location $location'
lc_loc__ksh[$cmd_index]='easy_debug_ltrace -W 0 -X 0x1 -Y 0x0 -Z libvether_client'
((cmd_index++))

lc_loc_exec[$cmd_index]='show vether-client client event location $location'
lc_loc__ksh[$cmd_index]='easy_debug_ltrace -W 0 -X 0x0 -Y 0x0 -Z libvether_client'
((cmd_index++))

lc_loc_exec[$cmd_index]=''
lc_loc__ksh[$cmd_index]=''

#
# 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 ether pd"
        
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case "$__cardtype" in
        "RP")
            exec_commands rp_loc
            ;;
        "LC")
            exec_commands lc_loc
            ;;
        esac
    fi
    
    print_main_heading "show tech-support ether pd complete"

}

display


