#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# macsec_show_techsupport - Fretta specific Show tech-support macsec
#
# Dec 2015, Srivathsan S
#
# Copyright (c) 2014-2018 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------
. /pkg/bin/show_tech_main_fragment

    i=1
    #Determining card type to run the CLI  
    cardtype=`node_type`
    
    if [ $cardtype == "LC" ]; then
	
    	msc_clis_exec[i]='show processes secy_driver location $ext_node_name'
    	msc_clis__ksh[i]='sysmgr_show -o -p secy_driver -n $fq_nodeid'
    	i=$(($i + 1))
    
	# Xilinx FPGA specific macsec controller info  
    	msc_clis_exec[i]='show controllers macsec hardware location $ext_node_name'
    	msc_clis__ksh[i]='platform_secy_show -m -h -l $fq_nodeid'
    	i=$(($i + 1))
    
    	msc_clis_exec[i]='show controllers macsec idb location $ext_node_name'
    	msc_clis__ksh[i]='platform_secy_show -o -l $fq_nodeid'
	i=$(($i + 1))
	
    	msc_clis_exec[i]='show macsec platform idb location $ext_node_name'
    	msc_clis__ksh[i]='platform_macsec_show_ea -n -l $fq_nodeid'
	i=$(($i + 1))
    
    	# convert location of form for ex :  0/1/CPU0 to 0/1/
	node_loc=$(echo $ext_node_name | awk -F"/" '{print $1"/"$2"/"}')
	
	# Get the list of interfaces registered in this node from IM.
	intf_list_arr=$(im_show database | grep ^Interface| sed 's/,//' \
	| cut -d" " -f2)
	
	# Get the list of interfaces in which we have macsec running.
	# These cannot be used directly for passing to client processes.
	# Store the interface in the form R/S/I/P  only.
	# They will be compared with interfaces on this node obtained from IM
    	macsec_interfaces_from_mka=`show_macsec_mka -m -i all | tail -n+4 | \
	tr -s ' '  | cut -d' ' -f2 | sed '/^$/d' | sed "s|.*$node_loc|$node_loc|"`

	# Iterate mka list of interfaces and compare with IM interface 
	for msc_if in $macsec_interfaces_from_mka; do
	   msc_if_str=$(echo $intf_list_arr | sed 's/ /#\n/g' | \
	   grep $msc_if# | sed 's/#//')
	
	   if [[ $msc_if_str ]]; then
	      msc_if_str_internal=`convert_interface_fmt '-i' $msc_if_str`
	      
	      msc_clis_exec[i]="show macsec mka statistics interface $msc_if_str"
	      msc_clis__ksh[i]="show_macsec_mka -m -t intf -f $msc_if_str_internal"
	      i=$(($i + 1))

              msc_clis_exec[i]="show controllers $msc_if_str stats"
	      msc_clis__ksh[i]="ethernet_show_controller -i $msc_if_str_internal -s stats"
	      i=$(($i + 1))
	    
	      msc_clis_exec[i]="show controllers macsec hardware interface $msc_if_str status"
	      msc_clis__ksh[i]="platform_secy_show -m -h -i $msc_if_str_internal -t"
	      i=$(($i + 1))
		  
              msc_clis_exec[i]="show controllers macsec stats interface $msc_if_str"
	      msc_clis__ksh[i]="platform_secy_show -s -i $msc_if_str_internal -h -d"
	      i=$(($i + 1))
		  
	      msc_clis_exec[i]="show macsec platform hardware sa interface $msc_if_str"
	      msc_clis__ksh[i]="platform_macsec_show_ea -j -i $msc_if_str_internal -h"
	      i=$(($i + 1))

	      msc_clis_exec[i]="show macsec platform hardware stats interface $msc_if_str"
	      msc_clis__ksh[i]="platform_macsec_show_ea -s -i $msc_if_str_internal -h"
	      i=$(($i + 1))

	      msc_clis_exec[i]="show macsec secy stats interface $msc_if_str"
	      msc_clis__ksh[i]="show_macsec_secy -s -f $msc_if_str_internal"
	      i=$(($i + 1))
	
          fi
	done
        msc_clis_exec[i]='show controllers macsec trace sdk reverse  location $ext_node_name'
        msc_clis__ksh[i]='xlfpga_show_ltrace -r -i $fq_nodeid'
	i=$(($i + 1))
	
        msc_clis_exec[i]='show controllers macsec trace es200-sdk reverse  location $ext_node_name'
        msc_clis__ksh[i]='es200_show_ltrace -r -i $fq_nodeid'
	i=$(($i + 1))
	
        msc_clis_exec[i]='show controllers macsec trace event reverse  location $ext_node_name'
        msc_clis__ksh[i]='easy_debug_ltrace -r -i $fq_nodeid -W 1 -X 0x1 -Y 0x0 -Z secy_combined'
	i=$(($i + 1))
	
        msc_clis_exec[i]='show controllers macsec trace error reverse location $ext_node_name'
        msc_clis__ksh[i]='easy_debug_ltrace -r -i $fq_nodeid -W 1 -X 0x0 -Y 0x0 -Z secy_combined'
	i=$(($i + 1))
        
        msc_clis_exec[i]='show macsec platform trace event reverse  location $ext_node_name'
        msc_clis__ksh[i]='easy_debug_ltrace -r -i $fq_nodeid -W 1 -X 0x0 -Y 0x0 -Z macsec_combined'
	i=$(($i + 1))
	
        msc_clis_exec[i]='show macsec platform trace error reverse  location $ext_node_name'
        msc_clis__ksh[i]='easy_debug_ltrace -r -i $fq_nodeid -W 1 -X 0x1 -Y 0x0 -Z macsec_combined'
	i=$(($i + 1))
        
        msc_clis_exec[i]='Secy Driver FPD client ctrace logs'
        msc_clis__ksh[i]='ctracedec -ktgAL secy_driver/fpdmgr'
	i=$(($i + 1))
	
     else
	# Card type is RP
	node_loc=$(echo $ext_node_name | awk -F"/" '{print $1"/"$2"/"}')
        intf_list_arr=$(im_show database | grep ^Interface| sed 's/,//' \
        | cut -d" " -f2)
        macsec_interfaces_from_mka=`show_macsec_mka -m -i all | tail -n+4 | \
        cut -d' ' -f1 |sed '/^$/d' | sed "s|.*$node_loc|$node_loc|"`
        # Iterate mka list of interfaces and compare with IM interface 
        for msc_if in $macsec_interfaces_from_mka; do
		#Getting port num of macsec interface
        	port_num=$(echo $msc_if | grep -o -E '[0-9/]+')
         	msc_if_str=`IFS=$'\n' ; echo "${intf_list_arr[*]}" | grep "$port_num"`
          	msc_if_str_internal=`convert_interface_fmt '-i' $msc_if_str`
          	if [[ $msc_if_str ]]; then
                	msc_clis_exec[i]="show interfaces $msc_if_str"
			msc_clis__ksh[i]="show_interface -i $msc_if_str_internal"
                	i=$(($i + 1))
                fi
	done
     fi
     
     msc_clis_exec[i]=''
     msc_clis__ksh[i]=''
     exec_commands msc_clis

. /pkg/bin/show_tech_main_fragment
