#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# platform_show_tech_mcast -- Runs ASR9K specific commands for 'show
#                             tech-support multicast' command.
#
# December 2003 - Adam Yeung
#
# Copyright (c) 2003-2010, 2012-2020 by Cisco Systems, Inc.
# All rights reserved.
#----------------------------------------------------------------------

#
# This script runs all the HFR specific mutlicast commands for show
# tech-support multicast. The script is invoked by show_tech_mcast.
# 
# Options:
#   -n nodeid         Run commands on specified node id.
#   -m nodename       Specify the printable node name of the node id.
#   -g group          Run route commands for specified group addr. (optional)
#   -s source         Run route commands for specified source addr. (optional)
#


# *****************************************************************
#  Functions for formatting
#
#  All inherited from infra/showtech. They are supposed to convert
#  some command libraries into script module, so the formatting
#  will be in sync with other show tech output.#
# *****************************************************************

#
# This function prints a row of a specified character.
#
# Argument $1: Number of times to print the character
# Argument $2: Character to print
#
#print_char() {
#    j=1; while [ "$j" -le "$1" ]; do
#        echo "$2\c"
#        j=$(($j + 1))
#    done;
#}

#
# This function prints a string centered with a row of a character each side
# of it with one space between each end of the string and the characters.
#
# Argument $1: String to print
# Argument $2: Character to print round string
#
# Note: This function assumes that each line is 79 characters long.
#
#print_heading() {
#    title="$1"
#    title_length=${#title}
#
#    # There is a space each side of the sting, so the remaining
#    # number of spaces to be filled with the string and characters is 77.
#    twice_char_length=$((77 - $title_length))
#    char_length=$(($twice_char_length / 2))
#    echo "\n"
#    print_char $char_length "$2"
#    echo  " $title \c"
#    print_char $char_length "$2"
#    echo "\n"
#}

# Set address-family specific multicast addresses
# Also set address-family specific show commands.
ip2hex()
{
   set -A n2h 0 1 2 3 4 5 6 7 8 9 a b c d e f
   nib2hex() { echo -n ${n2h[$1]}; }

   for octet in $(IFS=.; echo $1); do
     nib2hex $((octet / 16))
     nib2hex $((octet % 16))
   done
   echo
}

ipv62hex()
{
   str=$1
   hex=""
        # blkptr and blkptr_end is used to point to the begining and end of
        # a 4 hex digit block
        typeset -i blkptr=1
        typeset -i blkptr_end

        # For each set of 4 digits
        while [ blkptr -lt 39 ] ; do
            blkptr_end=$blkptr+3
            v6_addr_part=$(echo ${str} | cut -c ${blkptr}-${blkptr_end})
            v6_hex="$hex$v6_addr_part"
            blkptr=$blkptr+5
        done

    # Strip all trailing :
    hex=${hex%%:*}
    echo $hex
}

#
# Attempts to determine what type of linecard we are executing
# on.
#
set_lc_type() {

    is_np_card=`pidin | grep prm_server | wc -l`
    is_cpp_card=`pidin | grep cpp_driver | wc -l`

    if [[ $is_np_card -gt 0 ]]; then
        lc_type="LC_NP"
    elif [[ $is_cpp_card -gt 0 ]]; then
        lc_type="LC_CPP"
    else
        lc_type="UNKNOWN"
    fi

    # Need logic to id an AVSM if we ever have any
    # AVSM specific cards to run
}

# ***************************
#  Function to run commands
# ***************************

#
# execute_lc_command() prints the command description and issues the command.
# Commands with group option will get executed only if group is specified.
#

exec_lc_command() {
    cmd=$1
    node_id=$2
    group_hex=$3
    source_hex=$4
    cmd_vrf_option=$5
    addr_family=$6

    fretta_cmd=""
    if [[ $group != "" && $group != "unspecified" ]]; then
       fretta_cmd="$fretta_cmd -g $group_hex"
    fi
    if [[ $source != "" && $source != "unspecified" ]]; then
       fretta_cmd="$fretta_cmd -s $source_hex"
    fi
    if [[ -n "$cmd_vrf_option" ]]; then
       fretta_vrf="$fretta_vrf $cmd_vrf_option"
       fretta_cmd="$fretta_cmd $cmd_vrf_option"
    fi

    eval "$cmd $node_id $fretta_cmd"
    echo "\n##### end clock: \c"; iosclock -d 0
}


# disp_lc_cmd_title() prints the command description.
# Commands with group/source option will get executed with group/source specified.
#
# Argument $1: command_desc
# Argumnet $2: printable node name in the form of x/x/x
# Argument $3: group
# Argument $4: source
# Argument $5: vrf option
disp_lc_cmd_title() {
    cmd_desc=$1
    node_name=$2
    group=$3
    source=$4
    cmd_vrf_option=$5

    fretta_cmd=""
    if [[ $group != "" && $group != "unspecified" ]]; then
       fretta_cmd="$fretta_cmd -g $group"
    fi
    if [[ $source != "" && $source != "unspecified" ]]; then
       fretta_cmd="$fretta_cmd -s $source"
    fi
    if [[ -n "$cmd_vrf_option" ]]; then
       fretta_cmd="$fretta_cmd $cmd_vrf_option"
    fi
    echo "$cmd_desc $node_name $fretta_cmd"
    print_heading "$cmd_desc $node_name $fretta_cmd" "-"
    echo "##### start clock: \c"; iosclock -d 0
}

# ******************
#  Main starts here
# ******************

. /pkg/bin/show_tech_main_fragment
. /pkg/bin/show_tech_dpa_util

#
# Set the default values for the argument variables.
#
card_type=$(node_type)
addr_type="unspecified"
node_id="unspecified"
node_name="unspecified"
group="unspecified"
source="unspecified"
vrf_name="unspecified"
group_hex="unspecified"
source_hex="unspecified"
vrf_opt=""
vrf_with_tag=""

#
# Read in the arguments to the script. Node id must be in integer, node
# name must be in x/x/x format, group addr in dotted decimal format.
#
while [ $# -gt 0 ]; do
  case "$1" in
     -c) card_type="$2"; shift 2;;
     -i) addr_type="$2"; shift 2;;
     -n) node_id="$2"; shift 2;;
     -m) node_name="$2"; shift 2;;
     -g) group="$2"; shift 2;;
     -s) source="$2"; shift 2;;
     -v) vrf_name="$2"; shift 2;;
     -x) source_hex="$2"; shift 2;;
     -y) group_hex="$2"; shift 2;;
     -u) __tar_file_directory_on_node="$2"; shift 2;;
     -f) __tar_file_directory_on_node="$2"; shift 2;;
     node*) shift 1;;
###     *)  echo "Invalid arguments to platform_show_tech_mcast _$2_"; exit;;
     *)  echo "Invalid arguments to platform_show_tech_mcast _$2_"; shift 2;;
  esac
done


if [[ $addr_type == "unspecified" ]]; then
    echo "platform_show_tech_mcast: address family is not specified, use ipv4"
    addr_type="ipv4"
fi

if [[ $node_id == "unspecified" || $node_name == "unspecified" ]]; then
    echo "platform_show_tech_mcast: node name and node id are required args"
    exit
fi

if [[ $group != "unspecified" ]]; then
    if [[ $addr_type = "ipv6" ]]; then
        if [[ $group != @(*:*:*:*:*:*:*:*) ]]; then
        echo "platform_show_tech_mcast: invalid ipv6 group format $group"
        exit
        fi
    else
        if [[ $group != @(*.*.*.*) ]]; then
        echo "platform_show_tech_mcast: invalid ipv4 group format $group"
        exit
        fi
    fi
fi

if [[ $source != "unspecified" ]]; then
    if [[ $addr_type = "ipv6" ]]; then
        if [[ $source != @(*:*:*:*:*:*:*:*) ]]; then
        echo "platform_show_tech_mcast: invalid ipv6 group format $source"
        exit
        fi
    else
        if [[ $source != @(*.*.*.*) ]]; then
        echo "platform_show_tech_mcast: invalid ipv4 group format $source"
        exit
        fi
    fi
fi

if [[ $vrf_name != "" && $vrf_name != "unspecified" ]]; then
   vrf_opt="-v $vrf_name"
   vrf_with_tag="vrf $vrf_name"
   echo "vrf_opt = $vrf_opt, group = $group, source = $source, node_name=$node_name, node_id=$node_id, addr_type=$addr_type, card_type=$card_type"
fi

if [[ $addr_type == "ipv4" ]] ;then
    mfwd_proc_name="ipv4_mfwd_partner"
else
    mfwd_proc_name="ipv6_mfwd_partner"
fi

mfwd_proc_pid=`sysmgr_show -o -p $mfwd_proc_name | grep -e PID | cut -c 27-`


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

#
# For each command in the list, two mandatory variables are defined as:
# 1. <component>_command_desc[i] is the command that would be entered at the
#    CLI. This is used as the headline for the command in the script output.
# 2. <component>_command[i] is the executable obtained from "describe
#    <show command>" at the CLI. Note that the location filter option must
#    be the last option in the string.
#
# The group filter is optional:
#
# 3. <component>_command_group[i] is the group filter option of the command.
#    Command with the group option will get executed only if a group addr
#    is specified, otherwise the show command is skipped.
#
# New commands may be added at any point in the list but the list must
# remain numbered consecutively from 1 and must end with an empty command.
#
# To add a new command, first pick the right group it should go in --
# RP commands, LC commands that need a VRF option, LC commands that
# don't need VRF option, etc.  There are also sections for specific
# LC types.
#
# As described above, commands are specified in pairs of parallel
# arrays.  The *_command_desc[i] array has the command that the user
# would type at the CLI and the *command[i] is the actual program
# and options that would get executed as a result of the user typing
# in that command at the CLI.
#
# So, find the right group to add to, copy/paste one of the existing
# pairs for that group, then update it for you new command.  Put it
# wherever you want the command output to appear within that group
# of commands.  Then, make sure that all of the pairs in that group
# are numbered consecutively and that the last entry in the
# *_command[last] entry is empty (it needs no companion description
# array entry.  It is simply the terminator of the list.
#
# Look for some commands similar to the one that you are adding
# and just mimic what is already there.
#

# Commands for sys
cmd_index=1
sys_exec[$cmd_index]='show running-config'
sys__ksh[$cmd_index]='nvgen -c -l 1 -t 1 -o 1'

((cmd_index++))
sys_exec[$cmd_index]='show logging'
sys__ksh[$cmd_index]='show_logging'

((cmd_index++))
sys_exec[$cmd_index]=''
sys__ksh[$cmd_index]=''

# Commands for RP only
cmd_index=1
rp_exec[$cmd_index]="show platform"
rp__ksh[$cmd_index]="show_platform_sysdb"

((cmd_index++))
rp_exec[$cmd_index]="show version"
rp__ksh[$cmd_index]="ng_show_version"

((cmd_index++))
rp_exec[$cmd_index]="show install active"
rp__ksh[$cmd_index]="sdr_instcmd show install active"

((cmd_index++))
rp_exec[$cmd_index]="show running-config"
rp__ksh[$cmd_index]="nvgen -c -l 1 -t 1 -o 1"

((cmd_index++))
rp_exec[$cmd_index]="admin show inventory"
rp__ksh[$cmd_index]="show_inventory -a"

((cmd_index++))
rp_exec[$cmd_index]="admin show running-config"
rp__ksh[$cmd_index]="nvgen -b /admin/cfg/"

((cmd_index++))
rp_exec[$cmd_index]="show logging"
rp__ksh[$cmd_index]="show_logging"

if [[ $addr_type == "ipv4" ]] ;then
    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib $vrf_with_tag platform trace all "
    rp__ksh[$cmd_index]="mrib_show_ltrace_platf -A"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib fgid info all"
    rp__ksh[$cmd_index]="mrib_show_stats -i 0x0"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib fgid stats"
    rp__ksh[$cmd_index]="mrib_show_stats -x"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib fgid ostats"
    rp__ksh[$cmd_index]="mrib_show_stats -o"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib fgid intdb all"
    rp__ksh[$cmd_index]="mrib_show_stats -d 0x0"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib route detail"
    rp__ksh[$cmd_index]="mrib_show -e ,,, -i ,,,,,,,,,, -O -D $vrf_opt"

    ((cmd_index++))
    rp_exec[$cmd_index]="show igmp snooping summary"
    rp__ksh[$cmd_index]="igmpsn_show -S"

    ((cmd_index++))
    rp_exec[$cmd_index]="show igmp snooping group"
    rp__ksh[$cmd_index]="igmpsn_show -G"

    ((cmd_index++))
    rp_exec[$cmd_index]="show igmp $vrf_with_tag group"
    rp__ksh[$cmd_index]="igmp_show -g"

    ((cmd_index++))
    rp_exec[$cmd_index]="show igmp snooping summary statistics"
    rp__ksh[$cmd_index]="igmpsn_show -S -y"

    ((cmd_index++))
    rp_exec[$cmd_index]="show igmp snooping trace all"
    rp__ksh[$cmd_index]="igmpsn_show_ltrace -A"
else
    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib ipv6 $vrf_with_tag platform trace all "
    rp__ksh[$cmd_index]="mrib6_show_ltrace_platf -A"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib ipv6 fgid info all"
    rp__ksh[$cmd_index]="mrib6_show_stats -i 0x0"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib ipv6 fgid stats"
    rp__ksh[$cmd_index]="mrib6_show_stats -x"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib ipv6 fgid ostats"
    rp__ksh[$cmd_index]="mrib6_show_stats -o"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib ipv6 fgid intdb all"
    rp__ksh[$cmd_index]="mrib6_show_stats -d 0x0"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mrib ipv6 route detail"
    rp__ksh[$cmd_index]="mrib6_show -e ,,, -i ,,,,,,,,,, -O -D $vrf_opt"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mld snooping summary"
    rp__ksh[$cmd_index]="mldsn_show -S"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mld snooping group"
    rp__ksh[$cmd_index]="mldsn_show -G"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mld $vrf_with_tag group"
    rp__ksh[$cmd_index]="mld_show -g"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mld snooping summary statistics"
    rp__ksh[$cmd_index]="mldsn_show -S -y"

    ((cmd_index++))
    rp_exec[$cmd_index]="show mld snooping trace all"
    rp__ksh[$cmd_index]="mldsn_show_ltrace -A"
fi

((cmd_index++))
rp_exec[$cmd_index]="show igmp snooping l2fib-trace rp"
rp__ksh[$cmd_index]="fretta_l2fib_trace -s R -l"

((cmd_index++))
rp_exec[$cmd_index]="show igmp snooping l2fib-trace lc"
rp__ksh[$cmd_index]="fretta_l2fib_trace -s L -l A"

((cmd_index++))
rp_exec[$cmd_index]="show l2vpn bridge-domain"
rp__ksh[$cmd_index]="l2vpn_show 0x9"

((cmd_index++))
rp_exec[$cmd_index]="show ether-ea trace all location all"
rp__ksh[$cmd_index]="dpa_ether_ea_show_ltrace -i all -E -V"

((cmd_index++))
rp_exec[$cmd_index]="show spp node-counters"
rp__ksh[$cmd_index]="spp_sysdb_get -M node_counters"

((cmd_index++))
rp_exec[$cmd_index]="show controllers npu voq-usage interface all instance 0 location all"
rp__ksh[$cmd_index]="dpa_qosea_voq_show -v x -i 0x10 -n A -t n -p 0x0"

((cmd_index++))
rp_exec[$cmd_index]=''
rp__ksh[$cmd_index]=''

# Commands to display state of the mfwd_partner process (All linecards)
hw_lc_all_mfwd_proc_command_desc[1]="show processes blocked location"
hw_lc_all_mfwd_proc_command[1]="show_processes -b -n"

hw_lc_all_mfwd_proc_command_desc[2]="show process $mfwd_proc_name location"
hw_lc_all_mfwd_proc_command[2]="sysmgr_show -o -p $mfwd_proc_name -n"

hw_lc_all_mfwd_proc_command_desc[3]="follow process $mfwd_proc_pid iteration 1 location"
hw_lc_all_mfwd_proc_command[3]="attach_process -p $mfwd_proc_pid -i 1 -n"

hw_lc_all_mfwd_proc_command[4]=''


# MFIB PD per-VRF commands at LC (All linecards)
hw_lc_all_mfwd_vrf_command_desc[1]="show mfib hardware aggregator location"
hw_lc_all_mfwd_vrf_command[1]="$show_mfwd_hw_fretta_ksh -Z -l"

hw_lc_all_mfwd_vrf_command[2]=''


# MFIB PD commands at LC (All linecards)
hw_lc_all_mfwd_command_desc[1]="show mfib hardware connections location"
hw_lc_all_mfwd_command[1]="$show_mfwd_hw_fretta_ksh -N -l"

hw_lc_all_mfwd_command_desc[2]="show mfib hardware resource-counter detail location"
hw_lc_all_mfwd_command[2]="$show_mfwd_hw_fretta_ksh -R -d -l"

hw_lc_all_mfwd_command[3]=''

# MFIB PD commands at LC
cmd_index=1

if [[ $addr_type == "ipv4" ]] ;then
    lc_mfwd_exec[$cmd_index]="show mfib $vrf_with_tag hardware route detail location $node_name"
    lc_mfwd__ksh[$cmd_index]="show_ipv4_mfwd_fretta_client -O -l $node_id $vrf_opt"

    ((cmd_index++))
    lc_mfwd_exec[$cmd_index]="show mfib $vrf_with_tag hardware route internal location $node_name"
    lc_mfwd__ksh[$cmd_index]="show_ipv4_mfwd_fretta_client -e -l $node_id $vrf_opt"

    ((cmd_index++))
    lc_mfwd_exec[$cmd_index]="show mfib $vrf_with_tag hardware route summary location $node_name"
    lc_mfwd__ksh[$cmd_index]="show_ipv6_mfwd_fretta_client -B -l $node_id $vrf_opt"

    ((cmd_index++))
    lc_mfwd_exec[$cmd_index]="show mfib $vrf_with_tag hardware trace all location $node_name"
    lc_mfwd__ksh[$cmd_index]="show_ipv4_mfwd_fretta_ltrace -J -i $node_id $vrf_opt"
else
    lc_mfwd_exec[$cmd_index]="show mfib $vrf_with_tag ipv6 hardware route detail location $node_name"
    lc_mfwd__ksh[$cmd_index]="show_ipv6_mfwd_fretta_client -O -l $node_id $vrf_opt"

    ((cmd_index++))
    lc_mfwd_exec[$cmd_index]="show mfib $vrf_with_tag ipv6 hardware route internal location $node_name"
    lc_mfwd__ksh[$cmd_index]="show_ipv6_mfwd_fretta_client -e -l $node_id $vrf_opt"

    ((cmd_index++))
    lc_mfwd_exec[$cmd_index]="show mfib $vrf_with_tag ipv6 hardware route summary location $node_name"
    lc_mfwd__ksh[$cmd_index]="show_ipv6_mfwd_fretta_client -B -l $node_id $vrf_opt"

    ((cmd_index++))
    lc_mfwd_exec[$cmd_index]="show mfib $vrf_with_tag ipv6 hardware trace all location $node_name"
    lc_mfwd__ksh[$cmd_index]="show_ipv6_mfwd_fretta_ltrace -J -i $node_id $vrf_opt"
fi

((cmd_index++))
lc_mfwd_exec[$cmd_index]=''
lc_mfwd__ksh[$cmd_index]=''

# IGMPSN PD commands at LC (All linecards)
cmd_index=1
lc_igmp_exec[$cmd_index]="show l2vpn forwarding bridge-domain mroute ipv4 detail location all"
lc_igmp__ksh[$cmd_index]="l2fib_show_client -BridgeDomainAll -d -t -l"

((cmd_index++))
lc_igmp_exec[$cmd_index]=''
lc_igmp__ksh[$cmd_index]=''

((cmd_index++))
lc_mfwd_route_exec[$cmd_index]=''
lc_mfwd_route__ksh[$cmd_index]=''

# Misc commands for LC (All linecards)
hw_lc_all_command_desc[1]="show lpts pifib hardware entry statistics location"
hw_lc_all_command[1]="platform_show_pifib -z 0x3 -i"

hw_lc_all_command_desc[2]="show im database brief location"
hw_lc_all_command[2]="im_show database -l 0x1 -h"

hw_lc_all_command[3]=''

# NP (Trident/Typhoon) LC specific commands
hw_lc_np_command_desc[1]="show controller np ports all location"
hw_lc_np_command[1]="prm_np_show ports -s"

hw_lc_np_command_desc[2]="show controller np counters all location"
hw_lc_np_command[2]="prm_np_show counters -s"

hw_lc_np_command_desc[3]="show prm stats summary location"
hw_lc_np_command[3]="prm_stats_show summary -s"

hw_lc_np_command_desc[4]="show prm stats client all location"
hw_lc_np_command[4]="prm_stats_show client -c 0x0 -s"

hw_lc_np_command_desc[5]="show prm server trace error location"
hw_lc_np_command[5]="show_prm_server_ltrace -E -i"

hw_lc_np_command_desc[6]="show uidb index all location"
hw_lc_np_command[6]="uidb_show index -s"

hw_lc_np_command_desc[7]="ship_show -c asr9k-ipmcast"
hw_lc_np_command[7]="ship_show -c asr9k-ipmcast"

hw_lc_np_command[8]=''

# NP (Thor) LC specific commands
hw_lc_cpp_command_desc[1]="Stat-1-show controllers pse qfp statistics drop location"
hw_lc_cpp_command[1]="sh_cpp_stat -h"

hw_lc_cpp_command_desc[2]="Sum-1-show controllers pse qfp statistics summary location"
hw_lc_cpp_command[2]="sh_cpp_stat_summary -h"

hw_lc_cpp_command_desc[3]="Stat-2-show controllers pse qfp statistics drop location"
hw_lc_cpp_command[3]="sh_cpp_stat -h"

hw_lc_cpp_command_desc[4]="Sum-2-show controllers pse qfp statistics summary location"
hw_lc_cpp_command[4]="sh_cpp_stat_summary -h"

hw_lc_cpp_command_desc[5]="Stat-3-show controllers pse qfp statistics drop location"
hw_lc_cpp_command[5]="sh_cpp_stat -h"

hw_lc_cpp_command_desc[6]="Sum-3-show controllers pse qfp statistics summary location"
hw_lc_cpp_command[6]="sh_cpp_stat_summary -h"

hw_lc_cpp_command[7]=''

# DPA commands at LC (All linecards)
cmd_index=1
lc_dpa_exec[$cmd_index]="dpa_ipmcolist_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_ipmcolist_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_ipmctxintf_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_ipmctxintf_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_l3intfmctxstats_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_l3intfmctxstats_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_l2intf_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_l2intf_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_ip6mcroute_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_ip6mcroute_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_ip6mcrxstats_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_ip6mcrxstats_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_ipmcroute_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_ipmcroute_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_ipmcrxstats_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_ipmcrxstats_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_mplsmdtbud_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_mplsmdtbud_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_meshmc_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_meshmc_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_l2port_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_l2port_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_l1port_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_l1port_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_l3intf_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_l3intf_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_tmport_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_tmport_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_lagport_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_lagport_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_l2ipmcroute_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_l2ipmcroute_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_l2mcolist_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_l2mcolist_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_l2bridge_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_l2bridge_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_l2bridgeport_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_l2bridgeport_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]="dpa_l2intf_show_client -b"
lc_dpa__ksh[$cmd_index]="dpa_l2intf_show_client -b"

((cmd_index++))
lc_dpa_exec[$cmd_index]=''
lc_dpa__ksh[$cmd_index]=''


#
# Execute commands for the RP only.
#
#do_rp_commands() {
    #i=1; while [ -n "${hw_rp_command[i]}" ]; do
    #    print_heading "${hw_rp_command_desc[i]} $node_name " "-"
    #    echo  "${hw_rp_command_desc[i]}"
    #    echo "##### start clock: \c"; iosclock -d 0
    #    eval "${hw_rp_command[i]}"
    #    echo "\n##### end clock: \c"; iosclock -d 0
    #    i=$(($i + 1))
    #done
#}

#
# Execute commands common to all linecards.
#
#do_all_lc_commands() {
#    #
#    # First, do commands related to the mfwd process
#    #
#    i=1; while [ -n "${hw_lc_all_mfwd_proc_command[i]}" ]; do
#       disp_lc_cmd_title "${hw_lc_all_mfwd_proc_command_desc[i]}" "$node_name" \
#         "" "" ""
#        exec_lc_command \
#        "${hw_lc_all_mfwd_proc_command[i]}" "$node_id" \
#        "" "" "" ""
#        i=$(($i + 1))
#    done
#
#    #
#    # Next, do the global mfib hardware commands
#    #
#    i=1; while [ -n "${hw_lc_all_mfwd_command[i]}" ]; do
#       disp_lc_cmd_title "${hw_lc_all_mfwd_command_desc[i]}" "$node_name" \
#         "" "" ""
#       exec_lc_command \
#	"${hw_lc_all_mfwd_command[i]}" "$node_id" \
#	"" "" \
#        "" "$addr_type"
#       i=$(($i + 1))
#    done
#}

#
# Execute commands specific to NP-based cards (Typhoon/Trident)
#
do_lc_np_commands() {
   i=1; while [ -n "${hw_lc_np_command[i]}" ]; do
       disp_lc_cmd_title "${hw_lc_np_command_desc[i]}" "$node_name" \
        "" "" ""
        exec_lc_command \
        "${hw_lc_np_command[i]}" "$node_id" \
	    "" "" "" ""
        i=$(($i + 1))
       done
}

#
# Execute commands specific to CPP-based cards (Thor)
#
do_lc_cpp_commands() {
   i=1; while [ -n "${hw_lc_cpp_command[i]}" ]; do
       disp_lc_cmd_title "${hw_lc_cpp_command_desc[i]}" "$node_name" \
        "" "" ""
        exec_lc_command \
        "${hw_lc_cpp_command[i]}" "$node_id" \
	    "" "" "" ""
        i=$(($i + 1))
       done

}

#
# Execute commands specific AVSM card
#
do_lc_avsm_commands() {

    # Fill in AVSM command processing loop(s) here

    return
}

#
# Determines the platform type
#
set_platform_type() {
    platform_type="UNKNOWN"
    is_rp_type=`ng_show_version | grep -E "NCS-560|NCS540L" | wc -l`
    if [[ $is_rp_type -gt 0 ]]; then
        platform_type="VIRTUAL_LC"
    fi
}


#if [[ $card_type == "RP" ]]; then
    #do_rp_commands
    #set_platform_type
    #if [[ $platform_type == "NCS560" ]]; then
    #
    # Do commands applicable to Linecard as well for NCS560
    # as NCS560 is RP+LC combined
    #
    #    do_all_lc_commands
    #fi
#fi

#if [[ $card_type == "LC" ]]; then
    #
    # Do commands applicable to all linecards
    #
    #do_all_lc_commands

#fi # [[ $card_type == "LC" ]]

execute_lc_commands() {
    exec_commands hw_lc_all_mfwd_proc
    exec_commands lc_mfwd
    exec_commands lc_igmp
    exec_commands lc_dpa
    display_dpa_lc
}

execute_rp_commands() {

    echo "executing rp commands"
    exec_commands rp
}

display() {
    print_main_heading "show tech-support multicast platform"

    # Get the card_type: SYS|RP|DRP|LC.
    if [ $card_type == "SYS" ]; then
        exec_commands sys
    else
        case $card_type in
        "RP")
            execute_rp_commands
            set_platform_type
            if [[ $platform_type == "VIRTUAL_LC" ]]; then
                # Do commands applicable to Linecard as well for NCS560
                # as NCS560 is RP+LC combined
                #
                echo "executing lc commands"
	    	execute_lc_commands
            fi
            ;;
        "DRP")
            execute_rp_commands
            ;;
        "LC")
            execute_lc_commands
            ;;
        esac
    fi

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