#!/pkg/bin/ksh
#
# Created by David Toscano, August 2004
#
# Copyright (c) 2004-2019 by cisco Systems, Inc. 
# All rights reserved.
#----------------------------------------------------------------------

# This script fragment contains the code for the following functions
# - print_main_heading
# - print_command_heading
# - run_single_command
# - run_commands
# - run_single_command_on_all_nodes
# - run_commands_on_all_nodes
# - default_parser_function
. /pkg/bin/show_tech_main_fragment

# Initialise any variables used.
debug_level_nb="0x3"
debug_level_str=""
location=""
__node_regex="*CPU*"

# Password flag to indicate whether log will include pw or not
__cardtype="unspecified"
__password="FALSE"
__sanitized="FALSE"
__split="TRUE"

# Read in the arguments to the script, setting node_required and filename
# according to these arguments.
# Note that it is important for security reasons that users can only enter
# alphanumeric filenames and nodes and that anywhere calling this script must
# enforce this.
while [ $# -gt 0 ]; do
    case "$1" in
       -O) __split="FALSE"; shift 1;;
       -p) __password="TRUE"; shift 1;;
       -s) __sanitized="TRUE"; shift 1;;
       -t) __cardtype="$2"; shift 2;;
       -L) location="location $2"; all_cards="location $2"; shift 2;;
       *)  default_parser_function "$@"; shift $#;;
  esac
  
done

check_platform_type=`get_platform_type`
__parm1=`sysmgr_show -o -p exec | grep PID`
__parm2=`echo ${__parm1#*PID:}`
export EXEC_PID=$__parm2

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

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


# List each set of show commands to be run. Each set must finish with an empty
# string. Note that it is important to use single quotes rather than double 
# quotes for the strings containing your commands; showtech infra expects the command
# exactly the way it was entered.
# Use "\" ahead of any special character (eg. |) used in the command line.
Common_exec[1]='show bfd all session'
Common__ksh[1]='bfd_show_command -o 0x1 -x 0x4'
Common_exec[2]='show bfd all'
Common__ksh[2]='bfd_show_command -o 0x3 -x 0x4'
Common_exec[3]='show process bfd'
Common__ksh[3]='sysmgr_show -o -p bfd'
if [ "$platform" == "panini" ]; then
    Common_exec[4]='show install active'
    Common__ksh[4]='sdr_instcmd show install active'
    Common_exec[5]='show install inactive'
    Common__ksh[5]='sdr_instcmd show install inactive'
else
    Common_exec[4]='show install active'
    Common__ksh[4]='instcmd show install active'
    Common_exec[5]='show install which component ip-bfd'
    Common__ksh[5]='instcmd show install which component ip-bfd detail'
fi
Common_exec[6]='show bfd lpts detail verbose'
Common__ksh[6]='bfd_show_command -o 0x11 -d -v'
Common_exec[7]='show bfd all multipath'
Common__ksh[7]='bfd_show_command -o 0x13 -x 0x4'
Common_exec[8]='show bfd all session detail'
Common__ksh[8]='bfd_show_command -o 0x1 -x 0x4 -d'
Common_exec[9]='show bfd bootstrap history'
Common__ksh[9]='bfd_show_command -o 0x18 -y'
Common_exec[10]='show bfd gsp detail'
Common__ksh[10]='bfd_show_command -o 0x19 -d'
if [ "$platform" == "hfr" ]; then    
    Common_exec[11]='show hfr'
    Common__ksh[11]='shelfmgr_show_hfr -e'
elif [ "$platform" == "prp" ]; then
    Common_exec[11]='show platform'
    Common__ksh[11]='show_platform'
elif [ "$platform" == "viking" ]; then
    Common_exec[11]='show platform'
    Common__ksh[11]='show_platform_vkg -e'
elif [ "$platform" == "panini" ]; then 
    Common_exec[11]='show platform' 
    Common__ksh[11]='show_platform_sysdb' 
fi 
Common_exec[12]='show mpls lsd forwarding application bfd detail'
Common__ksh[12]='mpls_lsd_fwd_show -d -Z -o 0xb'
Common_exec[13]='show running-config bfd'
Common__ksh[13]='nvgen -c -q gl/ip_bfd/'
Common_exec[14]='show arm conflicts'
Common__ksh[14]='ip_arm_show -v 4 -f default -l -1 -c'
Common_exec[15]='show running-config'
Common__ksh[15]='nvgen -c -l 1 -t 1 -o 1'
Common_exec[16]='show logging' 
Common__ksh[16]='show_logging' 
Common_exec[17]='show_version'
if [ "$platform" == "panini" ]; then 
    Common__ksh[17]='ng_show_version'
else
    Common__ksh[17]='show_version'
fi
Common_exec[18]=''
Common__ksh[18]=''

# Commands for All Nodes to execute on both RP and LC
AllNodes_exec[1]='show cef drop location $location'
AllNodes__ksh[1]='fib_statistics_show_command -P 0x0 -d -N $fq_nodeid'
AllNodes_exec[2]='show bfd index-mgrs location $location'
AllNodes__ksh[2]='bfd_show_command -o 0x6 -b -l $fq_nodeid'
AllNodes_exec[3]='show bfd statistics private brief location $location'
AllNodes__ksh[3]='bfd_show_command -o 0xf -p -s -b -l $fq_nodeid'
AllNodes_exec[4]=''
AllNodes__ksh[4]=''

# Commands for All Nodes to execute on RP
# these command are not loaded on LC so they must be called from the RP 

# We need to exec 'show bfd bundles detail' commands for all the location
# on the RP node. Please get detail in DDTS CSCtc30835.
# Do not use the variable __i since it's used in get_node_list. See
# CSCua01078 for details.

#Note: The important thing is platform variable
#holds the value panini for Scapa as well as RSP4(NCS560) 
#If the platform variable is changed in 
#future according to platform we need to do 
#necessary checks as well

#Commands on RSP4(aka NCS560 or UEA) platform
#When the platform type is UEA(i.e RSP4 or NCS560)
#We get the card type as "RP\nLC\n" as node_type -a
#is being used.So we are checking for expression 
#RP in cardtype and populate the required commands
#in AllNodesRP_exec and AllNodesRP__ksh

if [ "$platform" == "panini" ]; then
    __bfd_i=1
    check_for_string="RP"
    if [ "$__cardtype" == "RP" ] || [[ "$__cardtype" == $check_for_string* ]]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show bfd bundles detail location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0xa -b -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
 
    if [ "$__cardtype" == "RP" ] || [[ "$__cardtype" == $check_for_string* ]]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show bfd bundles echo detail location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0x12 -d -b -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
 
    if [ "$__cardtype" == "RP" ] || [[ "$__cardtype" == $check_for_string* ]]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show bfd trace location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="show_bfd_trace -i $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
else
    __bfd_i=1
    if [ "$__cardtype" == "RP" ]; then
        get_node_list $__node_regex
        __bfd_j=0; while [ "$__bfd_j" -le "$(($__number_of_nodes-1))" ]; do
            location="${__location[$__bfd_j]}"
            nodeid="${__nodeid[$__bfd_j]}" 
            AllNodesRP_exec[$__bfd_i]="show bfd bundles detail location $location"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0xa -b -l $nodeid"
            __bfd_i=$(($__bfd_i + 1))
            __bfd_j=$(($__bfd_j + 1))
        done
    fi
    if [ "$__cardtype" == "RP" ]; then
        get_node_list $__node_regex
        __bfd_j=0; while [ "$__bfd_j" -le "$(($__number_of_nodes-1))" ]; do
            location="${__location[$__bfd_j]}"
            nodeid="${__nodeid[$__bfd_j]}" 
            AllNodesRP_exec[$__bfd_i]="show bfd bundles echo detail location $location"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0x12 -d -b -l $nodeid"
            __bfd_i=$(($__bfd_i + 1))
            __bfd_j=$(($__bfd_j + 1))
        done
    fi

    if [ "$__cardtype" == "RP" ]; then
        get_node_list $__node_regex
        __bfd_j=0; while [ "$__bfd_j" -le "$(($__number_of_nodes-1))" ]; do
            location="${__location[$__bfd_j]}"
            nodeid="${__nodeid[$__bfd_j]}" 
            AllNodesRP_exec[$__bfd_i]="show bfd trace location $location"
            AllNodesRP__ksh[$__bfd_i]="show_bfd_trace -i $nodeid"
            __bfd_i=$(($__bfd_i + 1))
            __bfd_j=$(($__bfd_j + 1))
        done
    fi
fi

if [ "$check_platform_type" == "SKYWARP" ]; then    
    if [ "$__cardtype" == "RP" ]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show udp brief location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="udp_cmd_client show brief -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
    if [ "$__cardtype" == "RP" ]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show udp statistics pcb all location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="udp_cmd_client show statistics -a -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
    if [ "$__cardtype" == "RP" ]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show bfd statistics private brief location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0xf -p -s -b -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
    if [ "$__cardtype" == "RP" ]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show bfd ha server detail location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0x16 -W -d -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
    if [ "$__cardtype" == "RP" ]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show bfd issu server detail location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0x17 -W -d -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
    if [ "$__cardtype" == "RP" ]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show bfd client history location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0x2 -y -b -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
    if [ "$__cardtype" == "RP" ]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show bfd all session status history location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0x1 -f -h -x 0x4 -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
    if [ "$__cardtype" == "RP" ]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show bfd session pending server location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0xd -W -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
    if [ "$__cardtype" == "RP" ]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show bfd agents location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0x15 -b -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
    if [ "$__cardtype" == "RP" ]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show bfd lpts detail verbose location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="bfd_show_command -o 0x11 -d -v -b -l $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
    if [ "$__cardtype" == "RP" ]; then
        __node_list=`node_list_generation -f ALL`
        for nodeid in $__node_list
        do
            fq_nodeid=`/pkg/bin/node_conversion -i $nodeid`
            AllNodesRP_exec[$__bfd_i]="show process bfd location $nodeid"
            AllNodesRP__ksh[$__bfd_i]="sysmgr_show -o -p bfd -n $fq_nodeid"
            __bfd_i=$(($__bfd_i + 1))
        done
    fi
else
    AllNodesRP_exec[$__bfd_i]='show udp brief location $location'
    AllNodesRP__ksh[$__bfd_i]='udp_cmd_client show brief -l $fq_nodeid'
    AllNodesRP_exec[$__bfd_i+1]='show udp statistics pcb all location $location'
    AllNodesRP__ksh[$__bfd_i+1]='udp_cmd_client show statistics -a -l $fq_nodeid'
    AllNodesRP_exec[$__bfd_i+2]='show bfd statistics private brief location $location'
    AllNodesRP__ksh[$__bfd_i+2]='bfd_show_command -o 0xe -p -s -b -l $fq_nodeid'
    AllNodesRP_exec[$__bfd_i+3]='show bfd ha server detail location $location'
    AllNodesRP__ksh[$__bfd_i+3]='bfd_show_command -o 0x16 -W -d -l $fq_nodeid'
    AllNodesRP_exec[$__bfd_i+4]='show bfd issu server detail location $location'
    AllNodesRP__ksh[$__bfd_i+4]='bfd_show_command -o 0x17 -W -d -l $fq_nodeid'
    AllNodesRP_exec[$__bfd_i+5]='show bfd client history location $location'
    AllNodesRP__ksh[$__bfd_i+5]='bfd_show_command -o 0x2 -y -b -l $fq_nodeid'
    AllNodesRP_exec[$__bfd_i+6]='show bfd session pending server location $location'
    AllNodesRP__ksh[$__bfd_i+6]='bfd_show_command -o 0xd -W -l $fq_nodeid'
    AllNodesRP_exec[$__bfd_i+7]='show bfd agents location $location'
    AllNodesRP__ksh[$__bfd_i+7]='bfd_show_command -o 0x15 -b -l $fq_nodeid'
    AllNodesRP_exec[$__bfd_i+8]='show bfd lpts detail verbose location $nodeid'
    AllNodesRP__ksh[$__bfd_i+8]='bfd_show_command -o 0x11 -d -v -b -l $fq_nodeid'
    AllNodesRP_exec[$__bfd_i+9]='show process bfd location $location'
    AllNodesRP__ksh[$__bfd_i+9]='sysmgr_show -o -p bfd -n $fq_nodeid'
    AllNodesRP_exec[$__bfd_i+10]=''
    AllNodesRP__ksh[$__bfd_i+10]=''
fi

# Commands for All Nodes to execute on LCs
AllNodesLC_exec[1]='show bfd all location $location'
AllNodesLC__ksh[1]='bfd_show_command -o 0x3 -x 0x4 -l $fq_nodeid'
AllNodesLC_exec[2]='show process bfd_agent location $location'
AllNodesLC__ksh[2]='sysmgr_show -o -p bfd_agent -n $fq_nodeid'
AllNodesLC_exec[3]='show bfd ha agent detail location $location'
AllNodesLC__ksh[3]='bfd_show_command -o 0x16 -b -d -l $fq_nodeid'
AllNodesLC_exec[4]='show bfd issu agent detail location $location'
AllNodesLC__ksh[4]='bfd_show_command -o 0x17 -b -d -l $fq_nodeid'
AllNodesLC_exec[5]='show bfd session pending agent location $location'
AllNodesLC__ksh[5]='bfd_show_command -o 0xd -b -l $fq_nodeid'
AllNodesLC_exec[6]=''
AllNodesLC__ksh[6]=''

# Commands for All Nodes to execute on c12k LCs
PRPAllNodesLC_exec[1]='show controllers pse ingress statistics location $location'
PRPAllNodesLC__ksh[1]='hfa_show -l $fq_nodeid -s rx -u'
PRPAllNodesLC_exec[2]='show controllers pse egress statistics location $location'
PRPAllNodesLC__ksh[2]='hfa_show -l $fq_nodeid -s tx -u'
PRPAllNodesLC_exec[3]='show controllers fwd stats location $location'
PRPAllNodesLC__ksh[3]='fab_lc_dbg -d -n $fq_nodeid '
PRPAllNodesLC_exec[4]=''
PRPAllNodesLC__ksh[4]=''

# Commands for All Nodes to execute on CRS LCs
HFRAllNodesLC_exec[1]='show controllers pse statistics ingress location $location'
HFRAllNodesLC__ksh[1]='pse_cli -t 0x4 -i 0x0 -n $fq_nodeid'
HFRAllNodesLC_exec[2]='show controllers pse statistics egress location $location'
HFRAllNodesLC__ksh[2]='pse_cli -t 0x4 -i 0x1 -n $fq_nodeid'
HFRAllNodesLC_exec[3]='show bfd platform trace event location $location'
HFRAllNodesLC__ksh[3]='bfd_pd_show_ltrace -i $fq_nodeid -V'
HFRAllNodesLC_exec[4]='show bfd platform trace error location $location'
HFRAllNodesLC__ksh[4]='bfd_pd_show_ltrace -i $fq_nodeid -E'
HFRAllNodesLC_exec[5]='show bfd platform context location $location'
HFRAllNodesLC__ksh[5]='platform_bfd_fwd_show -o 0x0 -l $fq_nodeid'
HFRAllNodesLC_exec[6]='show lpts pifib hardware entry type bfd statistics location $location'
HFRAllNodesLC__ksh[6]='show_platform_pifib -z 0x3 -r 0x3 -i $fq_nodeid'
HFRAllNodesLC_exec[7]='show captured packets ingress location $location'
HFRAllNodesLC__ksh[7]='pak_capture_show_command -I -N $fq_nodeid'
HFRAllNodesLC_exec[8]='show captured packets egress location $location'
HFRAllNodesLC__ksh[8]='pak_capture_show_command -E -N $fq_nodeid'
HFRAllNodesLC_exec[9]='show controllers cpuctrl clients pdma bfd active location $location'
HFRAllNodesLC__ksh[9]='cpuctrl_edm_show_hfr -n $fq_nodeid -c 0x7 pdma 0x0'
HFRAllNodesLC_exec[10]='show controller ingressq statistics location $location'
HFRAllNodesLC__ksh[10]='iqm_show -n $fq_nodeid -S'
HFRAllNodesLC_exec[11]='show controller fabricq statistics location $location'
HFRAllNodesLC__ksh[11]='fqm_show packet-stats -n $fq_nodeid -l $location -d 0x0'
HFRAllNodesLC_exec[12]='show controllers pse statistics ingress location $location'
HFRAllNodesLC__ksh[12]='pse_cli -t 0x4 -i 0x0 -n $fq_nodeid'
HFRAllNodesLC_exec[13]='show controllers pse statistics egress location $location'
HFRAllNodesLC__ksh[13]='pse_cli -t 0x4 -i 0x1 -n $fq_nodeid'
HFRAllNodesLC_exec[14]='show controllers pse statistics ingress location $location'
HFRAllNodesLC__ksh[14]='pse_cli -t 0x4 -i 0x0 -n $fq_nodeid'
HFRAllNodesLC_exec[15]='show controllers pse statistics egress location $location'
HFRAllNodesLC__ksh[15]='pse_cli -t 0x4 -i 0x1 -n $fq_nodeid'
HFRAllNodesLC_exec[16]=''
HFRAllNodesLC__ksh[16]=''

# Commands for All Nodes to execute on Viking LCs
ASRAllNodesLC_exec[1]='show controllers np counters all location $location'
ASRAllNodesLC__ksh[1]='prm_np_show counters -s $fq_nodeid'
ASRAllNodesLC_exec[2]='show controllers fabric fia drops ingress location $location'
ASRAllNodesLC__ksh[2]='fsi_show -n $fq_nodeid -f -d -N'
ASRAllNodesLC_exec[3]='show controllers fabric fia drops egress location $location'
ASRAllNodesLC__ksh[3]='fsi_show -n $fq_nodeid -f -d -E'
ASRAllNodesLC_exec[4]='show controllers fabric fia stats location $location'
ASRAllNodesLC__ksh[4]='fsi_show -n $fq_nodeid -f -s' 
ASRAllNodesLC_exec[5]='show lpts pifib hardware bfd discriminator table location $location'
ASRAllNodesLC__ksh[5]='platform_show_pifib -z 0xa -i $fq_nodeid'
ASRAllNodesLC_exec[6]='show bfd hw-offload trace events location $location'
ASRAllNodesLC__ksh[6]='bfd_offload_show_ltrace -V -i $fq_nodeid'
ASRAllNodesLC_exec[7]='show bfd hw-offload trace error location $location'
ASRAllNodesLC__ksh[7]='bfd_offload_show_ltrace -E -i $fq_nodeid'
ASRAllNodesLC_exec[8]='show bfd hw-offload trace info location $location'
ASRAllNodesLC__ksh[8]='bfd_offload_show_ltrace -N -i $fq_nodeid'
ASRAllNodesLC_exec[9]='show bfd hw-offload trace packet location $location'
ASRAllNodesLC__ksh[9]='bfd_offload_show_ltrace -P -i $fq_nodeid'
ASRAllNodesLC_exec[10]='show controllers np counters all location $location'
ASRAllNodesLC__ksh[10]='prm_np_show counters -s $fq_nodeid'
ASRAllNodesLC_exec[11]='show controllers np ports all location $location'
ASRAllNodesLC__ksh[11]='prm_np_show ports -s $fq_nodeid'
ASRAllNodesLC_exec[12]='show controllers np counters all location $location'
ASRAllNodesLC__ksh[12]='prm_np_show counters -s $fq_nodeid'
ASRAllNodesLC_exec[13]=''
ASRAllNodesLC__ksh[13]=''

# Commands for All Nodes to execute on SSE/Panini LCs
SSEAllNodesLC_exec[1]='show controllers pse statistics ingress location $location'
SSEAllNodesLC__ksh[1]='npu_show_static_stats -d 0x0 -i 0x10 -n $fq_nodeid'
SSEAllNodesLC_exec[2]='show controllers pse statistics egress location $location'
SSEAllNodesLC__ksh[2]='npu_show_static_stats -d 0x1 -i 0x10 -n $fq_nodeid'
SSEAllNodesLC_exec[3]='show controllers pse summary location $location'
SSEAllNodesLC__ksh[3]='npu_asic_statistics -i 0x10 -n $fq_nodeid -s 0x1'
SSEAllNodesLC_exec[4]='show controllers cpuctrl clients pdma bfd active location $location'
SSEAllNodesLC__ksh[4]='cpuctrl_edm_show -n $fq_nodeid -c 0x7 pdma 0x0'
SSEAllNodesLC_exec[5]='show controllers plim asic statistics summary location $location'
SSEAllNodesLC__ksh[5]='plim_ether_show statistics -r -s $fq_nodeid'
SSEAllNodesLC_exec[6]='show lpts pifib hardware entry type bfd statistics location $location'
SSEAllNodesLC__ksh[6]='show_platform_pifib -z 0x3 -r 0x3 -i $fq_nodeid'
SSEAllNodesLC_exec[7]='show controllers fia statistics instance all location $location'
SSEAllNodesLC__ksh[7]='fia_driver_show -s a -b 0x30 -f 0x30 -i 0xff -n 0 -t n -p 0xffffffff'
SSEAllNodesLC_exec[8]='show memory summary location $location'
SSEAllNodesLC__ksh[8]='show_memory_ng -n $fq_nodeid -s'
SSEAllNodesLC_exec[9]='show spp buffer location $location'
SSEAllNodesLC__ksh[9]='spp_sysdb_get -L $fq_nodeid buffer_analysis'
SSEAllNodesLC_exec[10]='show captured packets ingress hexdump location $location'
SSEAllNodesLC__ksh[10]='pak_capture_show_command -I -H -N $fq_nodeid'
SSEAllNodesLC_exec[11]='show captured packets egress hexdump location $location'
SSEAllNodesLC__ksh[11]='pak_capture_show_command -E -H -N $fq_nodeid'
SSEAllNodesLC_exec[12]='show bfd platform trace event location $location'
SSEAllNodesLC__ksh[12]='bfd_pd_show_ltrace -i $fq_nodeid -V'
SSEAllNodesLC_exec[13]='show bfd platform trace error location $location'
SSEAllNodesLC__ksh[13]='bfd_pd_show_ltrace -i $fq_nodeid -E'
SSEAllNodesLC_exec[14]='show bfd platform trace info location $location'
SSEAllNodesLC__ksh[14]='bfd_pd_show_ltrace -i $fq_nodeid -I'
SSEAllNodesLC_exec[15]='show plim plim-ether trace pla all location $location'
SSEAllNodesLC__ksh[15]='plim_ether_show_ltrace -i $fq_nodeid all pla'
SSEAllNodesLC_exec[16]='show controllers pse statistics ingress location $location'
SSEAllNodesLC__ksh[16]='npu_show_static_stats -d 0x0 -i 0x10 -n $fq_nodeid'
SSEAllNodesLC_exec[17]='show controllers pse statistics egress location $location'
SSEAllNodesLC__ksh[17]='npu_show_static_stats -d 0x1 -i 0x10 -n $fq_nodeid'
SSEAllNodesLC_exec[18]='show controllers pse summary location $location'
SSEAllNodesLC__ksh[18]='npu_asic_statistics -i 0x10 -n $fq_nodeid -s 0x1'
SSEAllNodesLC_exec[19]='show controllers cpuctrl clients pdma bfd active location $location'
SSEAllNodesLC__ksh[19]='cpuctrl_edm_show -n $fq_nodeid -c 0x7 pdma 0x0'
SSEAllNodesLC_exec[20]='show controllers plim asic statistics summary location $location'
SSEAllNodesLC__ksh[20]='plim_ether_show statistics -r -s $fq_nodeid'
SSEAllNodesLC_exec[21]='show lpts pifib hardware entry type bfd statistics location $location'
SSEAllNodesLC__ksh[21]='show_platform_pifib -z 0x3 -r 0x3 -i $fq_nodeid'
SSEAllNodesLC_exec[22]='show controllers fia statistics instance all location $location'
SSEAllNodesLC__ksh[22]='fia_driver_show -s a -b 0x30 -f 0x30 -i 0xff -n 0 -t n -p 0xffffffff'
SSEAllNodesLC_exec[23]=''
SSEAllNodesLC__ksh[23]=''

# These commands are to be executed on both RP and  LCs
# the following are regularly cisco-support commands.
# they must be executed directly at this time, to avoid cisco-support
# restrictions.
#
#SupportAllNodes__ksh[1]=''
#SupportAllNodes_exec[1]=''

# These commands are also only to be executed on the LCs
# the following are regularly cisco-support commands.
# they must be executed directly at this time, to avoid cisco-support
# restrictions.
Support__ksh[1]='bfd_show_command -o 0x1 -d -b -x 0x4 -l $fq_nodeid'
Support_exec[1]='show bfd all session agent detail location $location'
Support__ksh[2]='bfd_show_command -o 0x5 -b -l $fq_nodeid'
Support_exec[2]='show bfd timer-groups location $location'
Support__ksh[3]='bfd_show_command -o 0x7 -b -l $fq_nodeid'
Support_exec[3]='show bfd session-array location $location'
Support__ksh[4]='bfd_show_command -o 0x8 -b -l $fq_nodeid'
Support_exec[4]='show bfd interfaces location $location'
Support__ksh[5]='bfd_show_command -o 0x4 -c 0x3 -b -x 0x4 -l $fq_nodeid'
Support_exec[5]='show bfd counters all packet invalid location $location'
Support__ksh[6]='bfd_show_command -o 0x4 -c 0x2 -d -x 0x4 -l $fq_nodeid'
Support_exec[6]='show bfd counters all packet private detail location $location'
Support__ksh[7]='bfd_show_command -o 0x1 -d -f -x 0x4 -l $fq_nodeid'
Support_exec[7]='show bfd all session status detail location $location'
Support__ksh[8]='bfd_show_command -o 0x1 -f -h -x 0x4 -l $fq_nodeid'
Support_exec[8]='show bfd all session status history location $location'
Support__ksh[9]='bfd_show_command -o 0x1 -h -k -f -x 0x4 -l $fq_nodeid'
Support_exec[9]='show bfd all session status non-active history location $location'
Support__ksh[10]=''
Support_exec[10]=''

# the following are regularly cisco-support commands.
# they must be executed directly at this time, to avoid cisco-support
# restrictions.
SupportNoLoc__ksh[1]='bfd_show_command -o 0x2 -y'
SupportNoLoc_exec[1]='show bfd client history'
SupportNoLoc__ksh[2]='bfd_show_command -o 0x14 -p'
SupportNoLoc_exec[2]='show bfd summary private'
SupportNoLoc__ksh[3]=''
SupportNoLoc_exec[3]=''


# Set debug_level_str
case "$debug_level_nb" in
    "0x1") debug_level_str="Brief Summary";;
    "0x2") debug_level_str="Detail";;
    "0x3") debug_level_str="Detail with Event traces";;
    *) echo "Invalid Debug level entered: $debug_level_nb"; exit;;
esac

# 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 the output heading 
    print_main_heading "show tech-support bfd \($debug_level_str\) "
     
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands SupportNoLoc
        exec_commands Common
    else
        print_heading "after intnode $int_node_name extnode $ext_node_name location $location fq_nodeid $fq_nodeid" 

        case "$__cardtype" in
        "LC")
            # execute the command specific to a LC node
            print_heading "Executing specific commands on an LC node" 
            exec_commands AllNodes
            exec_commands Support
            exec_commands AllNodesLC
            if [ "$check_platform_type" == "PRP" ]; then
                print_heading "Executing specific commands on c12k LC node"
                exec_commands PRPAllNodesLC
            elif [ "$check_platform_type" == "HFR" ]; then
                print_heading "Executing specific commands on CRS LC node"
                exec_commands HFRAllNodesLC
            elif [ "$check_platform_type" == "ASR9k" ]; then
                print_heading "Executing specific commands on Viking LC node"
                exec_commands ASRAllNodesLC
            elif [ "$check_platform_type" == "PANINI" ]; then
                print_heading "Executing specific commands on SSE/Panini LC node"
                exec_commands SSEAllNodesLC
            fi
                  ;;
        
        "RP")
            print_heading "Executing specific commands on an RP node"
            # Execute commands
            exec_commands AllNodes
            exec_commands AllNodesRP
            # Currently show tech don't support for ASR14k RSP node
            # if [ "$platform" == "hfr" ]; then
                # print_heading "Executing specific commands on CRS RP node"
                # bfd_platform_show_tech
                # "bfd_platform_show_tech" is a file for executing commands
                # on hfr RP node. 
                # ./platforms/hfr/lc/feature/bfd/scripts/bfd_platform_show_tech 
                # Have removed the file execution here, but didn't remove 
                # the file because we probably would have commands run on hfr 
                # RP node and we might use the file in the future.
            # fi
            ;;
        esac

    fi

    # Print the closing heading.
    print_main_heading "show tech-support bfd complete"
}

# This function calls the display() function and sends the output to file if
# the file option has been set. 
. /pkg/bin/show_tech_file_fragment
