#! /pkg/bin/ksh
# ----------------------------------------------------------------------
# show_tech_acl_ipv6_fast -- IPv6 ACL show tech-support script (fast)
#
# June, 2009, Gangadhara Valluri
#
# Copyright (c) 2009-2014, 2016-2019 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_ipv6_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
ipv6_acl_sys_exec[i++]='show version'
if [[ "$platform" = "panini" || "$platform" = "fretta" ]]; then
    ipv6_acl_sys__ksh[j++]='ng_show_version'
else
    ipv6_acl_sys__ksh[j++]='show_version'
fi

ipv6_acl_sys_exec[i++]='show logging'
ipv6_acl_sys__ksh[j++]='show_logging'

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

ipv6_acl_sys_exec[i++]='show redundancy'
ipv6_acl_sys__ksh[j++]='redcon_show'

ipv6_acl_sys_exec[i++]='show platform'
case "$platform" in
    "prp")
        ipv6_acl_sys__ksh[j++]='show_platform'
        ;;
    "hfr")
        ipv6_acl_sys__ksh[j++]='shelfmgr_show_hfr -e'
        ;;
    "viking")
        ipv6_acl_sys__ksh[j++]='show_platform_vkg -e'
        ;;
    "panini")
        ipv6_acl_sys__ksh[j++]='show_platform_sysdb'
        ;;
    "fretta")
        ipv6_acl_sys__ksh[j++]='show_platform_sysdb'
        ;;
    "enxr")
        ipv6_acl_sys__ksh[j++]='show_platform'
        ;;
esac

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

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

ipv6_acl_sys__ksh[j++]=''

################################################################
# 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" != "panini" && "$platform" != "fretta" ]]; then
    ipv6_acl_rp_exec[i++]='show install which component ipv6-acl'
    ipv6_acl_rp__ksh[j++]='instcmd show install which component ipv6-acl detail'
fi

ipv6_acl_rp_exec[i++]='show access-lists ipv6 maximum detail'
ipv6_acl_rp__ksh[j++]='ipv6_acl_oor_show_cmd -d'

ipv6_acl_rp_exec[i++]='show access-lists ipv6 summary'
ipv6_acl_rp__ksh[j++]='ipv6_acl_show -s'

ipv6_acl_rp_exec[i++]='show access-lists ipv6 standby summary'
ipv6_acl_rp__ksh[j++]='ipv6_acl_show -s -b'

ipv6_acl_rp_exec[i++]='show access-lists ipv6'
ipv6_acl_rp__ksh[j++]='ipv6_acl_show'

ipv6_acl_rp_exec[i++]='show access-lists ipv6 usage pfilter location all'
ipv6_acl_rp__ksh[j++]='ipv6_acl_usage_cmd -l -i 0x1'

ipv6_acl_rp_exec[i++]='show prefix-list ipv6 summary'
ipv6_acl_rp__ksh[j++]='ipv6_acl_show -P -s'

ipv6_acl_rp_exec[i++]='show prefix-list ipv6'
ipv6_acl_rp__ksh[j++]='ipv6_acl_show -P'

ipv6_acl_rp_exec[i++]='show prefix-list ipv6 standby'
ipv6_acl_rp__ksh[j++]='ipv6_acl_show -P -b'

ipv6_acl_rp_exec[i++]='show process ipv6_acl_daemon'
ipv6_acl_rp__ksh[j++]='sysmgr_show -o -p ipv6_acl_daemon'

ipv6_acl_rp_exec[i++]='show process ipv6_acl_cfg_agent'
ipv6_acl_rp__ksh[j++]='sysmgr_show -o -p ipv6_acl_cfg_agent'

ipv6_acl_rp_exec[i++]='show access-lists ipv6 trace all'
ipv6_acl_rp__ksh[j++]='ipv6_acl_show_ltrace -A'

ipv6_acl_rp_exec[i++]='show access-lists ipv6 trace both'
ipv6_acl_rp__ksh[j++]='ipv6_acl_show_ltrace -W -U'

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

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

ipv6_acl_rp_exec[i++]='show nrs handles data class NRS_CLASS_ACL_V6_NAME'
ipv6_acl_rp__ksh[j++]='nrs_show -o NRS_CLASS_ACL_V6_NAME'

ipv6_acl_rp_exec[i++]='show access-lists ipv6 standby'
ipv6_acl_rp__ksh[j++]='ipv6_acl_show -b'

ipv6_acl_rp_exec[i++]='show access-lists ipv6 internal nexthops'
ipv6_acl_rp__ksh[j++]='ipv6_acl_show -n'

ipv6_acl_rp_exec[i++]='show process mibd_interface'
ipv6_acl_rp__ksh[j++]='sysmgr_show -o -p mibd_interface'
   
ipv6_acl_rp_exec[i++]='show process snmpd'
ipv6_acl_rp__ksh[j++]='sysmgr_show -o -p snmpd'

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

ipv6_acl_rp_exec[i++]='show snmp trace aclmib'
ipv6_acl_rp__ksh[j++]='aclmib_show_ltrace'

ipv6_acl_rp_exec[i++]='show acl mib internal db'
ipv6_acl_rp__ksh[j++]='show_aclmib_db -b'

ipv6_acl_rp_exec[i++]='show object-group trace manager all'
ipv6_acl_rp__ksh[j++]='obj_group_show_mgr_ltrace -A'

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

ipv6_acl_rp_exec[i++]='show configuration commit changes all'
ipv6_acl_rp__ksh[j++]='show_config_changes -x'

ipv6_acl_rp__ksh[j++]=''


################################################################
# Commands that should run in parallel on all applicable nodes
################################################################

ipv6_acl_rplc_exec[1]='show process pfilter_ma location all'
ipv6_acl_rplc__ksh[1]='sysmgr_show -o -p pfilter_ma -n all'

ipv6_acl_rplc_exec[2]='show pfilter-netio trace all'
ipv6_acl_rplc__ksh[2]='pfilter_netio_show_ltrace -A'

ipv6_acl_rplc_exec[3]='show access-lists ipv6 usage pfilter location $location'
ipv6_acl_rplc__ksh[3]='ipv6_acl_usage_cmd -F -i 0x1'

ipv6_acl_rplc_exec[4]='show process pfilter_ea location all'
ipv6_acl_rplc__ksh[4]='sysmgr_show -o -p pfilter_ea -n all'

ipv6_acl_rplc_exec[5]='show system statistics component ipv6-acl'
ipv6_acl_rplc__ksh[5]='ship_show -c ipv6-acl'

ipv6_acl_rplc_exec[6]='show system statistics component ipv6-acl-mgr'
ipv6_acl_rplc__ksh[6]='ship_show -c ipv6-acl-mgr'

ipv6_acl_rplc_exec[7]='show netio db dll'
ipv6_acl_rplc__ksh[7]='netio_show -D'

ipv6_acl_rplc_exec[8]='show ACL SHIP counters common'
ipv6_acl_rplc__ksh[8]='ship_show -c acl-common'

ipv6_acl_rplc_exec[9]='show ACL SHIP counters IPv6'
ipv6_acl_rplc__ksh[9]='ship_show -c ipv6-acl'

ipv6_acl_rplc_exec[10]='show process blocked'
if [[ "$platform" == "panini" || "$platform" == "fretta" ]]; then
    ipv6_acl_rplc__ksh[10]='sh_proc_ng_blocked'
else
    ipv6_acl_rplc__ksh[10]='show_processes -b'
fi

ipv6_acl_rplc__ksh[11]=''

ipv6_acl_rplc_prp_exec[1]='show pfilter-ea trace location $location'
ipv6_acl_rplc_prp__ksh[1]='pfilter_ea_show_ltrace'
ipv6_acl_rplc_prp__ksh[2]=''

ipv6_acl_rplc_hfr_exec[1]='show pfilter-ea ipv6 trace critical all location $location'
ipv6_acl_rplc_hfr__ksh[1]='pfilter_ea_show_ltrace ipv6 critical -J'
ipv6_acl_rplc_hfr_exec[2]='show pfilter-ea ipv6 trace intermittent all location $location'
ipv6_acl_rplc_hfr__ksh[2]='pfilter_ea_show_ltrace ipv6 intermittent -J'
ipv6_acl_rplc_hfr__ksh[3]=''

ipv6_acl_rplc_vkg_exec[1]='show pfilter-ea ipv6 trace critical all location $location'
ipv6_acl_rplc_vkg__ksh[1]='pfilter_ea_show_ltrace ipv6 critical -J -i $fq_nodeid'
ipv6_acl_rplc_vkg_exec[2]='show pfilter-ea ipv6 trace intermittent all location $location'
ipv6_acl_rplc_vkg__ksh[2]='pfilter_ea_show_ltrace ipv6 intermittent -J -i $fq_nodeid'
ipv6_acl_rplc_vkg_exec[3]='show pfilter-ea fea trace location $location'
ipv6_acl_rplc_vkg__ksh[3]='fea_show_ltrace -i $fq_nodeid'
ipv6_acl_rplc_vkg_exec[4]='show object-group trace client netio all location $location'
ipv6_acl_rplc_vkg__ksh[4]='obj_group_show_client_ltrace -i $fq_nodeid -P netio -A'
ipv6_acl_rplc_vkg_exec[5]='show object-group trace client pfilter_ea all location $location'
ipv6_acl_rplc_vkg__ksh[5]='obj_group_show_client_ltrace -i $fq_nodeid -P pfilter_ea -A'
ipv6_acl_rplc_vkg_exec[6]='show access-list trace compress all location $location' 
ipv6_acl_rplc_vkg__ksh[6]='acl_compress_show_trace -i $fq_nodeid -P pfilter_ea -A'    
ipv6_acl_rplc_vkg__ksh[7]=''

display_platform() {
    case "$platform" in
    "prp")
        exec_commands ipv6_acl_rplc_prp
        ;;
    "hfr")
        exec_commands ipv6_acl_rplc_hfr
        ;;
    "viking")
        exec_commands ipv6_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
################################################################
# Use variables since some platforms will skip entries and arrays must be
# contiguously populated
i=1
j=1
if [ "$platform" != "prp" ]; then
    ipv6_acl_lc_exec[i++]='show IPv6 ACL Based Forwarding DB'
    ipv6_acl_lc__ksh[j++]='ipv6_acl_nh_show'

    ipv6_acl_lc_exec[i++]='show IPv6 ACL Based Forwarding summary'
    ipv6_acl_lc__ksh[j++]='ipv6_acl_nh_show -s'
fi

display_platform_lc() {
    # Run PD command if it exists
    if type display_platform_lc_acl_ipv6_pd | grep -i -q function; then
        display_platform_lc_acl_ipv6_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 ipv6"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands ipv6_acl_sys
    else
        case "$__cardtype" in
        "DRP")
            exec_commands ipv6_acl_rp
            exec_commands ipv6_acl_rplc
            display_platform
            ;;
        "RP")
            exec_commands ipv6_acl_rp
            exec_commands ipv6_acl_rplc
            display_platform
            ;;
        "LC")
            exec_commands ipv6_acl_rplc
            exec_commands ipv6_acl_lc
            display_platform
            display_platform_lc
            ;;
        esac
    fi

    print_main_heading "show tech-support access-lists ipv6 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

