#! /pkg/bin/ksh
# ----------------------------------------------------------------------
# show_tech_fs -- FlowSpec show tech-support script (fast)
#
# October 2013, Andy Karch
#
# Copyright (c) 2013-2015, 2017-2018, 2022 by cisco Systems, Inc.
# All rights reserved.
#-----------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment

. /pkg/bin/show_tech_policy_util

. /pkg/bin/show_tech_pbr_util

__cardtype="unspecified"

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

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

if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi

#####################################################################
#  Commands that run on SYS node (i.e. the node where the show tech
#  command is issued from)
#####################################################################

fs_sys_show_exec[1]='show version'
if [ "$platform" == "panini" ]; then
    fs_sys_show__ksh[1]='ng_show_version'
else
    fs_sys_show__ksh[1]='show_version'
fi

fs_sys_show_exec[2]='show logging'
fs_sys_show__ksh[2]='show_logging'

fs_sys_show_exec[3]='show running-config'
fs_sys_show__ksh[3]='nvgen -c -l 1 -t 1 -o 1'

fs_sys_show_exec[4]='show platform'
if [ "$platform" == "panini" ]; then
    fs_sys_show__ksh[4]='show_platform_sysdb'
elif [ "$platform" == "viking" ]; then
    fs_sys_show__ksh[4]='show_platform_vkg -e'
elif [ "$platform" == "hfr" ]; then
    fs_sys_show__ksh[4]='shelfmgr_show_hfr -e'
else
    fs_sys_show__ksh[4]='show_platform'
fi

fs_sys_show_exec[5]='show redundancy'
fs_sys_show__ksh[5]='redcon_show'

if [ "$platform" == "panini" ]; then
    fs_sys_show_exec[6]='show install active'
    fs_sys_show__ksh[6]='sdr_instcmd show install active'
else
    fs_sys_show_exec[6]='show install active detail'
    fs_sys_show__ksh[6]='instcmd show install active detail'
fi

if [ "$platform" != "panini" ]; then
    fs_sys_show_exec[7]='show install which comp ip-flowspec'
    fs_sys_show__ksh[7]='instcmd show install which component ip-flowspec detail'
fi

fs_sys_show__ksh[8]=''

display_active_standby() {

    fs_sys_active_standby_show_exec[1]='show flowspec client '$1' internal'
    fs_sys_active_standby_show__ksh[1]='flowspec_show client '$2' -I'

    fs_sys_active_standby_show_exec[2]='show flowspec summary '$1' internal'
    fs_sys_active_standby_show__ksh[2]='flowspec_show summary '$2' -I'

    fs_sys_active_standby_show_exec[3]='show flowspec vrf all afi-all summary '$1' internal'
    fs_sys_active_standby_show__ksh[3]='flowspec_show tbl_summary -V -a afi-all '$2' -I'

    fs_sys_active_standby_show_exec[4]='show flowspec vrf all afi-all '$1' internal'
    fs_sys_active_standby_show__ksh[4]='flowspec_show flow -V -a afi-all '$2' -I'

    fs_sys_active_standby_show_exec[5]='show flowspec vrf all afi-all '$1' inactive internal'
    fs_sys_active_standby_show__ksh[5]='flowspec_show flow -V -a afi-all '$2' -N -I'

    fs_sys_active_standby_show_exec[6]='show flowspec vrf all afi-all nlri '$1' internal'
    fs_sys_active_standby_show__ksh[6]='flowspec_show nlri -V -a afi-all '$2' -I'

    fs_sys_active_standby_show_exec[7]='show flowspec vrf all afi-all nlri '$1' inactive internal'
    fs_sys_active_standby_show__ksh[7]='flowspec_show nlri -V -a afi-all '$2' -N -I'

    fs_sys_active_standby_show__ksh[8]=''

    exec_commands fs_sys_active_standby_show
}

################################################################
# Commands that run only on RP
################################################################

fs_rp_show_exec[1]='show process flowspec_mgr detail'
fs_rp_show__ksh[1]='sysmgr_show -o -p flowspec_mgr -D'

fs_rp_show_exec[2]='show flowspec trace manager events errors'
fs_rp_show__ksh[2]='flowspec_show_ltrace -M _event -M _err'

fs_rp_show_exec[3]='show flowspec trace client events errors'
fs_rp_show__ksh[3]='flowspec_show_ltrace -C _event -C _err'

fs_rp_show_exec[4]='show flowspec afi-all internal retry-flows'
fs_rp_show__ksh[4]='flowspec_show flow -v default -a afi-all -I -R'

fs_rp_show__ksh[5]=''

################################################################
# Commands that should run in parallel on all RP/LC nodes
################################################################

fs_rplc_show_exec[1]='show proc blocked'
if [ "$platform" = "panini" ]
then
    fs_rplc_show__ksh[1]='sh_proc_ng_blocked'
else
    fs_rplc_show__ksh[1]='show_processes -b'
fi

fs_rplc_show__ksh[2]=''


#
# 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 flowspec"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands fs_sys_show
        display_active_standby
        display_active_standby standby -S
        display_policy_shim_sys flowspec_mgr
        display_policy_mgr_sys
        display_policy_mgr_sys_cmap traffic
        display_policy_mgr_sys_pmap pbr
        display_policy_mgr_sys_pmap pbr transient
        display_pbr_ma_vrf_sys
    else
        case "$__cardtype" in
        "DRP")
            exec_commands fs_rplc_show
            exec_commands fs_rp_show

            display_policy_xos_rp flowspec_mgr
            display_policy_shim_rp flowspec_mgr
            display_pbr_ea_vrf_rplc
            display_pbr_ea_intf_rplc
            display_pbr_stats_rplc
            display_pbr_trace_rplc
            display_policy_mgr_rp
            display_policy_mgr_rplc
            display_policy_mgr_rplc_client traffic pbr policymgr_rp
            display_policy_mgr_rplc_client traffic pbr flowspec_mgr
            ;;
        "RP")
            exec_commands fs_rplc_show
            exec_commands fs_rp_show

            display_policy_xos_rp flowspec_mgr
            display_policy_shim_rp flowspec_mgr
            display_pbr_ea_vrf_rplc
            display_pbr_ea_intf_rplc
            display_pbr_stats_rplc
            display_pbr_trace_rplc
            display_policy_mgr_rp
            display_policy_mgr_rplc
            display_policy_mgr_rplc_client traffic pbr policymgr_rp
            display_policy_mgr_rplc_client traffic pbr flowspec_mgr
            ;;
        "LC")
            display_policy_mgr_rplc
            exec_commands fs_rplc_show
            display_pbr_ea_vrf_rplc
            display_pbr_ea_intf_rplc
            display_pbr_stats_rplc
            display_pbr_trace_rplc
            display_policy_mgr_rplc_client traffic pbr pbr_ea
            ;;
        esac
    fi

    print_main_heading "show tech-support flowspec 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
