#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# secy_driver_show_techsupport - Show tech-support script for secy_driver
#
# Jan 2017, Sreejith Sreekumaran
#
# Copyright (c) 2017-2021 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

# 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.

__cardtype="unspecified"

# Set the default values of the file name for which show tech-support macsec 
# is to run and the file it is to write to.
# 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
        -t) __cardtype="$2"; shift 2;;
        *)  default_parser_function "$@"; shift $#;;
    esac
done

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

 # global commands on RP


###############################################################################
# Show commands that run once per LR                                          #
###############################################################################


sys_exec[1]='show install active'
sys__ksh[1]='sdr_instcmd show install active'

sys_exec[2]='show install repository'
sys__ksh[2]='sdr_instcmd show install repository'

sys_exec[3]='show version'
sys__ksh[3]='ng_show_version'

sys_exec[4]='show platform'
sys__ksh[4]='show_platform_sysdb'

sys_exec[5]=''
sys__ksh[5]=''


###############################################################################
# Show commands that run on every RP                                          #
###############################################################################


rp_exec[1]='show logging'
rp__ksh[1]='show_logging'

rp_exec[2]='show redundancy location all'
rp__ksh[2]='redcon_show -n all'

rp_exec[3]='show context location all'
rp__ksh[3]='corehelper_context -c 0x1 -n all'

rp_exec[4]='show running-config'
rp__ksh[4]='nvgen -c -l 1 -t 1 -o 1'

rp_exec[5]='show ip int brief'
rp__ksh[5]='show_ip_interface -b -v all'

rp_exec[6]='show process secy_driver location all'
rp__ksh[6]='sysmgr_show -o -p secy_driver -n all'

rp_exec[7]=''
rp__ksh[7]=''

###############################################################################
# Show commands of secy_driver that run on every LC                       #
###############################################################################
i=1;

lc_exec[i]='show controllers macsec hardware location $ext_node_name'
lc__ksh[i]='platform_secy_show -m -h -l $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show controllers macsec trace event reverse  location $ext_node_name'
lc__ksh[i]='easy_debug_ltrace -r -i $fq_nodeid -W 1 -X 0x1 -Y 0x0 -Z secy_combined'
i=$(($i + 1))

lc_exec[i]='show controllers macsec trace error reverse location $ext_node_name'
lc__ksh[i]='easy_debug_ltrace -r -i $fq_nodeid -W 1 -X 0x0 -Y 0x0 -Z secy_combined'
i=$(($i + 1))

lc_exec[i]='show controllers macsec trace util-event reverse  location $ext_node_name'
lc__ksh[i]='easy_debug_ltrace -r -i $fq_nodeid -W 1 -X 0x2 -Y 0x0 -Z secy_combined'
i=$(($i + 1))

lc_exec[i]='show controllers macsec trace sdk xilinx-sdk reverse  location $ext_node_name'
lc__ksh[i]='xlfpga_show_ltrace -r -i $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show controllers macsec trace sdk es200-sdk reverse  location $ext_node_name'
lc__ksh[i]='es200_show_ltrace -r -i $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show controllers macsec trace sdk x120-sdk reverse  location $ext_node_name'
lc__ksh[i]='x120_show_ltrace -r -i $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show controllers macsec trace sdk vtss-sdk reverse  location $ext_node_name'
lc__ksh[i]='vsc_show_ltrace -r -i $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show controllers macsec trace sdk meta-dx1-sdk reverse  location $ext_node_name'
lc__ksh[i]='meta_dx1_show_ltrace -r -i $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show controllers macsec trace all location $ext_node_name'
lc__ksh[i]='secy_driver_show_ltrace -i $fq_nodeid -A 0x1 -W 1 -X 0x0 -Y 0x0 -Z secy_combined'
i=$(($i + 1))

lc_exec[i]='show sonet-ea trace error location  $ext_node_name'
lc__ksh[i]='sonet_ea_show_ltrace -E -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show sonet-ea trace info location  $ext_node_name'
lc__ksh[i]='sonet_ea_show_ltrace -I -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show sonet-ma trace info location  $ext_node_name'
lc__ksh[i]='sonet_ma_show_ltrace -I -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show sonet-ma trace init location  $ext_node_name'
lc__ksh[i]='sonet_ma_show_ltrace -B -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show sonet-ma trace error location  $ext_node_name'
lc__ksh[i]='sonet_ma_show_ltrace -E -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show sonet-path-ea trace error location  $ext_node_name'
lc__ksh[i]='sonet_path_ea_show_ltrace -E -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show sonet-path-ea trace info location  $ext_node_name'
lc__ksh[i]='sonet_path_ea_show_ltrace -I -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show sonet-path-ma trace info location  $ext_node_name'
lc__ksh[i]='sonet_path_ma_show_ltrace -I -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show sonet-path-ma trace init location  $ext_node_name'
lc__ksh[i]='sonet_path_ma_show_ltrace -B -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show sonet-path-ma trace error location  $ext_node_name'
lc__ksh[i]='sonet_path_ma_show_ltrace -E -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show otu trace all location  $ext_node_name'
lc__ksh[i]='otu_show_ltrace -A -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='show odu trace all location  $ext_node_name'
lc__ksh[i]='odu_show_ltrace -A -i  $fq_nodeid'
i=$(($i + 1))

lc_exec[i]='Secy Driver FPD client ctrace logs'
lc__ksh[i]='ctracedec -ktgAL secy_driver/fpdmgr'
i=$(($i + 1))

lc_exec[i]='Secy Driver OTN SONET client ctrace debug logs'
lc__ksh[i]='ctracedec -ktgAL secy_driver/otn_sonet_lib_debug'
i=$(($i + 1))

lc_exec[i]='Secy Driver OTN SONET client ctrace error logs'
lc__ksh[i]='ctracedec -ktgAL secy_driver/otn_sonet_lib_err'
i=$(($i + 1))

lc_exec[i]='Secy Driver OTN SONET client ctrace info logs'
lc__ksh[i]='ctracedec -ktgAL secy_driver/otn_sonet_lib_info'
i=$(($i + 1))

lc_exec[i]='Secy Driver LibMonitor ctrace logs'
lc__ksh[i]='ctracedec -ktgAL libmonitor_ptah_client'
i=$(($i + 1))

lc_exec[i]='Secy Driver sonet_ea ctrace logs'
lc__ksh[i]='ctracedec -ktgAL sonet_ea'
i=$(($i + 1))

lc_exec[i]='Secy Driver sonet_ma ctrace logs'
lc__ksh[i]='ctracedec -ktgAL sonet_ma'
i=$(($i + 1))

lc_exec[i]='Secy Driver portmode ctrace logs'
lc__ksh[i]='ctracedec -ktgAL portmode'
i=$(($i + 1))

lc_exec[i]=''
lc__ksh[i]=''

secy_driver_interface_clis() {
    #Determining card type to run the CLI  
    cardtype=`node_type`
	node_loc=$(echo $ext_node_name | awk -F"/" '{print $1"/"$2"/"}')
    i=1

#  Interested in 1/10/25/40 and 100G interface only for now    
   intf_list_arr=$(im_show database | grep -E "^Interface (Ten|Twenty|Forty|Hundred|Gigabit).*"$node_loc"" | sed 's/,//g' | cut -d'.' -f1 | uniq | cut -d ' ' -f2)
    if [ $cardtype == "LC" ]; then
        for if_str in $intf_list_arr; do
	      if_str_internal=`convert_interface_fmt '-i' $if_str`
	      msc_clis_exec[i]="show controllers macsec hardware interface $if_str status"
	      msc_clis__ksh[i]="platform_secy_show -m -h -i $if_str_internal -t"
          i=$(($i + 1))
          msc_clis_exec[i]="show controllers $if_str stats"
	      msc_clis__ksh[i]="ethernet_show_controller -i $if_str_internal -s stats"
	      i=$(($i + 1))
        done
    else  
        for if_str in $intf_list_arr; do
            msc_clis_exec[i]="show interfaces $if_str"
            msc_clis__ksh[i]="show_interface -i $if_str"
            i=$(($i + 1))
        done
    fi 

    msc_clis_exec[i]=''
    msc_clis__ksh[i]=''

    exec_commands msc_clis
    return
}


# Parse the arguments to the script.
# Usage:
#
#sys.exit()
# A function called display() must be provided that calls the functions to
# Print the output heading
do_show_command() {
     print_main_heading "show tech-support secy"

     if [ "$__cardtype" == "SYS" ]; then
         exec_commands sys
     else
         case "$__cardtype" in
         "RP"|"DRP")
             exec_commands rp
             secy_driver_interface_clis
             ;;
         "LC")
          if [ -f /pkg/bin/secy_driver ]
          then
              exec_commands lc
              secy_driver_interface_clis
          fi
	     ;;
         esac
     fi

     # Print the closing heading.
     print_main_heading "show tech-support secy complete"
}
# The display function.
display() {
        do_show_command
}

  # 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
