#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_pbr - pbr specific show tech command
#
# Oct 2011, Sunil Gogikari 
#
# Copyright (c) 2011-2017, 2019 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_pbr: output file not specified"
    exit
fi

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

check_platform_type=`get_platform_type`

# ***********************************************************
#  Show commands to be run by the show tech-support commands
# ***********************************************************

#############################################################
# Show commands that run once per system
sys_show_exec[1]='show version'
if [ "$platform" == "panini" ]; then
    sys_show__ksh[1]='ng_show_version'
else
    sys_show__ksh[1]='show_version'
fi
sys_show_exec[2]='show platform'
if [ "$platform" == "panini" ]; then
    sys_show__ksh[2]='show_platform_sysdb'
elif [ "$platform" == "viking" ]; then
    sys_show__ksh[2]='show_platform_vkg -e'
elif [ "$platform" == "hfr" ]; then
    sys_show__ksh[2]='shelfmgr_show_hfr -e'
else
    sys_show__ksh[2]='show_platform'
fi
sys_show_exec[3]='show logging'
sys_show__ksh[3]='show_logging'
sys_show_exec[4]='show interfaces summary'
sys_show__ksh[4]='show_interface -a -o 0x3'
sys_show_exec[5]='show interfaces brief'
sys_show__ksh[5]='show_interface -a -o 0x2'
sys_show_exec[6]='show running-config'
sys_show__ksh[6]='nvgen -c -l 1 -t 1 -o 1'
sys_show_exec[7]='show policy-lib transient sysdb-dump'
sys_show__ksh[7]='show_pllib_client -a'
if [[ "$check_platform_type" == "ASR9k" || \
      "$check_platform_type" == "IOS-XRv 9000" ]]; then
    sys_show_exec[8]='show pbr service-node table detail'
    sys_show__ksh[8]='vservice_db_show -m -d'
fi
sys_show__ksh[9]=''

#############################################################
# Commands that run on RP and LC nodes

# Show commands
rplc_show_exec[1]='show im database brief location $location'
rplc_show__ksh[1]='im_show database -l 0x0 -h $fq_nodeid'
# Show procs
rplc_show_exec[2]='show process blocked'
if [ "$platform" == "panini" ]; then
    rplc_show__ksh[2]='sh_proc_ng_blocked'
else
    rplc_show__ksh[2]='show_processes -b'
fi
rplc_show_exec[3]='show processes pbr_ma'
rplc_show__ksh[3]='sysmgr_show -o -p pbr_ma'
#End
rplc_show__ksh[4]=''

#############################################################
# Commands that run on all LCs
lc_exec[1]='show processes pbr_ea'
lc__ksh[1]='sysmgr_show -o -p pbr_ea'
#End
lc__ksh[2]=''

#############################################################
# Script
display() {
    print_main_heading "show tech-support pbr"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys_show
        display_policy_mgr_sys_cmap traffic
        display_policy_mgr_sys_pmap pbr
        display_policy_mgr_sys_cmap traffic transient
        display_policy_mgr_sys_pmap pbr transient
        display_pbr_ma_vrf_sys
        display_pbr_sys_stats
    else
        case "$__cardtype" in
        "RP")
            exec_commands rplc_show
            exec_commands rp
            display_pbr_ma_intf_rplc
            display_pbr_ea_vrf_rplc
            display_pbr_ea_intf_rplc
            display_pbr_ea_redir_rplc
            display_pbr_ma_stats_rplc
            display_pbr_ea_stats_rplc
            display_pbr_trace_rplc
            display_policy_mgr_rp
            display_policy_mgr_rplc
            display_policy_mgr_rplc_client traffic pbr policymgr_rp
            if [[ "$check_platform_type" == "ASR9k" || \
                  "$check_platform_type" == "IOS-XRv 9000" ]]; then
                display_vservice_mgr_nsh_rplc
                display_vservice_trace_rplc
            fi
            ;;
        "DRP")
            exec_commands rplc_show
            exec_commands rp
            display_pbr_ma_intf_rplc
            display_pbr_ea_vrf_rplc
            display_pbr_ea_intf_rplc
            display_pbr_ea_redir_rplc
            display_pbr_ma_stats_rplc
            display_pbr_ea_stats_rplc
            display_pbr_trace_rplc
            display_policy_mgr_rp
            display_policy_mgr_rplc
            display_policy_mgr_rplc_client traffic pbr policymgr_rp
            if [[ "$check_platform_type" == "ASR9k" || \
                  "$check_platform_type" == "IOS-XRv 9000" ]]; then
                display_vservice_mgr_nsh_rplc
                display_vservice_trace_rplc
            fi
            ;;
        "LC")
            exec_commands rplc_show
            exec_commands lc
            display_pbr_ma_intf_rplc
            display_pbr_ea_vrf_rplc
            display_pbr_ea_intf_rplc
            display_pbr_ea_redir_rplc
            display_pbr_ma_stats_rplc
            display_pbr_ea_stats_rplc
            display_pbr_trace_rplc
            display_policy_mgr_rplc
            display_policy_mgr_rplc_client traffic pbr pbr_ea
            if [[ "$check_platform_type" == "ASR9k" || \
                  "$check_platform_type" == "IOS-XRv 9000" ]]; then
                display_vservice_mgr_nsh_rplc
                display_vservice_trace_rplc
            fi
            ;;
        esac
    fi

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

