#! /pkg/bin/ksh
# ----------------------------------------------------------------------
# show_tech_acl_es_fast -- Ethernet-services ACL show tech-support script (fast)
#
# May, 2010, Chenna Kesavulu Mediga
#
# Copyright (c) 2010-2011, 2014, 2016-2018 by cisco Systems, Inc.
# All rights reserved.
#-----------------------------------------------------------------------

# ******************************************************************
#  Main heading required by show tech-support
# ******************************************************************
. /pkg/bin/show_tech_main_fragment

# Include the PD commands, if they exist.
if [ -f /pkg/bin/show_tech_acl_pd_util ]; then
    . /pkg/bin/show_tech_acl_pd_util
fi

# Parse the arguments to the script.
while [ "$#" -gt "0" ]; do
    case "$1" in
        *)  default_parser_function "$@"; shift $#;;
    esac
done

if [ "$__filename" = "unspecified" ]; then
    echo "show_tech_acl_es_fast: output file not specified"
    exit
fi

#####################################################################
#  Commands that run on SYS node (i.e. the node where the show tech
#  command is issued from)
#####################################################################
# Use variables since some platforms will skip entries and arrays must be
# contiguously populated
i=1
j=1
es_acl_sys_exec[i++]='show version'
if [[ "$platform" = "panini" || "$platform" = "fretta" ]]; then
    es_acl_sys__ksh[j++]='ng_show_version'
else
    es_acl_sys__ksh[j++]='show_version'
fi

es_acl_sys_exec[i++]='show logging'
es_acl_sys__ksh[j++]='show_logging'

es_acl_sys_exec[i++]='show running-config'
es_acl_sys__ksh[j++]='nvgen -c -l 1 -t 1 -o 1'

es_acl_sys_exec[i++]='show platform'
case "$platform" in
    "viking")
        es_acl_sys__ksh[j++]='show_platform_vkg -e'
        ;;
    "fretta")
        es_acl_sys__ksh[j++]='show_platform_sysdb'
        ;;
    "panini")
        es_acl_sys__ksh[j++]='show_platform_sysdb'
        ;;
    "enxr")
        es_acl_sys__ksh[j++]='show_platform'
        ;;
esac

es_acl_sys_exec[i++]='show interfaces summary'
es_acl_sys__ksh[j++]='show_interface -a -o 0x3'

es_acl_sys_exec[i++]='show interfaces brief'
es_acl_sys__ksh[j++]='show_interface -a -o 0x2'

es_acl_sys__ksh[i++]=''

################################################################
# Commands that run only on RP
################################################################
# Use variables since some platforms will skip entries and arrays must be
# contiguously populated
i=1
j=1
if [[ "$platform" -ne "panini" && "$platform" -ne "fretta" ]]; then
    es_acl_rp_exec[i++]='show install which component es-acl'
    es_acl_rp__ksh[j++]='instcmd show install which component es-acl detail'
fi

es_acl_rp_exec[i++]='show access-lists ethernet-services maximum detail'
es_acl_rp__ksh[j++]='show_es_acl -m -d'

es_acl_rp_exec[i++]='show access-lists ethernet-services summary'
es_acl_rp__ksh[j++]='show_es_acl -s'

es_acl_rp_exec[i++]='show access-lists ethernet-services standby summary'
es_acl_rp__ksh[j++]='show_es_acl -s -b'

es_acl_rp_exec[i++]='show access-lists ethernet-services'
es_acl_rp__ksh[j++]='show_es_acl'

es_acl_rp_exec[i++]='show access-lists ethernet-services usage pfilter location all'
es_acl_rp__ksh[j++]='es_acl_usage_cmd -l -i 0x1'

es_acl_rp_exec[i++]='show process es_acl_mgr'
es_acl_rp__ksh[j++]='sysmgr_show -o -p es_acl_mgr'

es_acl_rp_exec[i++]='show process es_acl_act_agent'
es_acl_rp__ksh[j++]='sysmgr_show -o -p es_acl_act_agent'

es_acl_rp_exec[i++]='show access-lists ethernet-services trace all'
es_acl_rp__ksh[j++]='es_acl_show_ltrace -A'

es_acl_rp_exec[i++]='show access-lists ethernet-services trace both'
es_acl_rp__ksh[j++]='es_acl_show_ltrace -W -U'

es_acl_rp_exec[i++]='show pfilter-ma trace all location all'
es_acl_rp__ksh[j++]='pfilter_ma_show_ltrace -i all -A'

es_acl_rp_exec[i++]='show nrs handles data class ACL_USAGE'
es_acl_rp__ksh[j++]='nrs_show -o ACL_USAGE'

es_acl_rp_exec[i++]='show nrs handles data class NRS_CLASS_ACL_ES_NAME'
es_acl_rp__ksh[j++]='nrs_show -o NRS_CLASS_ACL_ES_NAME'

es_acl_rp_exec[i++]='show access-lists ethernet-services standby'
es_acl_rp__ksh[j++]='show_es_acl -b'

es_acl_rp_exec[i++]='show install active'
if [[ "$platform" = "panini" || "$platform" = "fretta" ]]; then
    es_acl_rp__ksh[j++]='sdr_instcmd show install active'
else
    es_acl_rp__ksh[j++]='instcmd show install active'
fi

es_acl_rp_exec[i++]='show configuration commit list detail'
es_acl_rp__ksh[j++]='config_history -r -d -n 0xffffffff'

es_acl_rp_exec[i++]='show configuration commit changes all'
es_acl_rp__ksh[j++]='show_config_changes -x'

es_acl_rp__ksh[j++]=''

################################################################
# Commands that should run in parallel on all applicable nodes
################################################################
i=1
j=1

es_acl_rplc_exec[i++]='show process pfilter_ma'
es_acl_rplc__ksh[j++]='sysmgr_show -o -p pfilter_ma'

es_acl_rplc_exec[i++]='show process pfilter_ea'
es_acl_rplc__ksh[j++]='sysmgr_show -o -p pfilter_ea'

es_acl_rplc_exec[i++]='show pfilter-netio trace all'
es_acl_rplc__ksh[j++]='pfilter_netio_show_ltrace -A'

es_acl_rplc_exec[i++]='show access-lists ethernet-services usage pfilter location $location'
es_acl_rplc__ksh[j++]='es_acl_usage_cmd -n $fq_nodeid -i 0x1'

es_acl_rplc_exec[i++]='show process pfilter_ea location all'
es_acl_rplc__ksh[j++]='sysmgr_show -o -p pfilter_ea -n all'

es_acl_rplc_exec[i++]='show system statistics component es-acl'
es_acl_rplc__ksh[j++]='ship_show -c es-acl'

es_acl_rplc_exec[i++]='show system statistics component es-acl-mgr'
es_acl_rplc__ksh[j++]='ship_show -c es-acl-mgr'

es_acl_rplc_exec[i++]='show netio db dll'
es_acl_rplc__ksh[j++]='netio_show -D'

es_acl_rplc_exec[i++]='show process blocked'
if [[ "$platform" = "panini" || "$platform" = "fretta" ]]; then
    es_acl_rplc__ksh[j++]='sh_proc_ng_blocked'
else
    es_acl_rplc__ksh[j++]='show_processes -b'
fi

es_acl_rplc__ksh[j++]=''

es_acl_rplc_prp_exec[1]='show pfilter-ea trace location $location'
es_acl_rplc_prp__ksh[1]='pfilter_ea_show_ltrace'
es_acl_rplc_prp__ksh[2]=''

es_acl_rplc_vkg_exec[1]='show pfilter-ea ethernet-service trace critical all location $location'
es_acl_rplc_vkg__ksh[1]='pfilter_ea_show_ltrace es critical -J -i $fq_nodeid'
es_acl_rplc_vkg_exec[2]='show pfilter-ea ethernet-service trace intermittent all location $location'
es_acl_rplc_vkg__ksh[2]='pfilter_ea_show_ltrace es intermittent -J -i $fq_nodeid'
es_acl_rplc_vkg_exec[3]='show pfilter-ea fea trace location $location'
es_acl_rplc_vkg__ksh[3]='fea_show_ltrace -i $fq_nodeid'
es_acl_rplc_vkg__ksh[4]=''     

display_platform() {
    case "$platform" in
    "prp")
        exec_commands es_acl_rplc_prp
        ;;
    "viking")
        exec_commands es_acl_rplc_vkg
        ;;
    "enxr")
        ;;
    esac 

    # Run PD command if it exists
    if type display_platform_rplc_acl_pd | grep -i -q function; then
        display_platform_rplc_acl_pd
    fi
}

################################################################
# Commands that should run in parallel on all LCs only
################################################################
display_platform_lc() {
    # Run PD command if it exists
    if type display_platform_lc_acl_es_pd | grep -i -q function; then
        display_platform_lc_acl_es_pd
    fi
}

#
# A function called display() must be provided that calls the functions to
# run the required show commands. The display() function is called in
# /pkg/bin/show_tech_comp_file_frag
#

display() {
    print_main_heading "show tech-support access-lists ethernet-service"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands es_acl_sys
    else
        case "$__cardtype" in
        "DRP")
            exec_commands es_acl_rp
            exec_commands es_acl_rplc
            display_platform
            ;;
        "RP")
            exec_commands es_acl_rp
            exec_commands es_acl_rplc
            display_platform
            ;;
        "LC")
            exec_commands es_acl_rplc
            display_platform
            display_platform_lc
            ;;
        esac
    fi

    print_main_heading "show tech-support access-lists ethernet-service complete"
}

# Run the appropriate function depending on the node specified and if a
# file is specified write the output to that file. We need to redirect
# stderr to stdout when writing to a file because some of the show
# commands output to stderr instead of stdout
. /pkg/bin/show_tech_file_fragment
