#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_cef_fast - CEF specific show tech commands - fast mode
#
# April 2008, Tomasz Kalkowski
# September 2015, Oscar Jajalla  "show tech cef" consolidation
#
# Copyright (c) 2007-2019 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment
. /pkg/bin/show_tech_cef_helper

###########################################
# Set the default values of the variables
# ipv4, non VRF, brief
###########################################

fib_tmpfile_dir="/dev/shmem"
protocol="unspecified"
isVrf=2
vrf="all"
default_node=$showtech_node_name
default_node_id=`node_conversion --2nodeid $default_node`
__location=""
loc=0
level=2
isPrefix=0
prefix=""
isMask=0
mask=""
net=""
route_recursion=0
cef_recursion=0
max_recursion=4
isIf=0
internal_if=""
external_if=""
__cardtype="unspecified"
IS_VRF=1
NOT_VRF=0
shared_path=""
# Parse the arguments to the script.
while [ "$#" -gt "0" ]; do
    case "$1" in
        -vrf*) vrf="${1#-vrf}"; isVrf=1; shift 1;;
        -v4) protocol="ipv4"; level=1; shift 1;; 
        -v6) protocol="ipv6"; level=1; shift 1;; 
        -mpls) protocol="mpls"; level=1; shift 1;;
        -d) level=2; shift 1;;
        -P*) prefix="${1#-P}"; isPrefix=1; shift 1;;
        -M*) mask_string="${1#-M}"; mask=$((16#${mask_string#0x})); typeset -i10 mask; isMask=1; shift 1;;
        -T*) net="${1#-T}"; shift 1;; 
        -t) __cardtype="$2"; shift 2;;
        -i*) internal_if="${1#-i}"; isIf=1; shift 1;;
        -loc*) __location="${1#-loc}"; shift 1;;
        -rack*) shift 1;;
        *)  default_parser_function "$@"; shift $#;;
    esac
done

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

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

if [ "$__location" == "" ]; then
    rsi_node_id=$default_node_id
else
    __location_converted=`node_conversion -N $__location`
    rsi_node_id=`node_conversion --2nodeid $__location_converted`
fi


# **********************************************************************
# List of show commands for show tech-support cef
# **********************************************************************



# ####################################################
# Level 1 (brief) SYS Commands
# These commands are run once per system on the dSC
# ####################################################
com1_SYS_exec[1]='show version'
if [[ "$platform" = "panini" ]]; then
    com1_SYS__ksh[1]='ng_show_version'
else
    com1_SYS__ksh[1]='show_version'
fi
if [[ "$platform" = "panini" ]]; then
    com1_SYS_exec[2]='show install active'
    com1_SYS__ksh[2]='sdr_instcmd show install active'
else
    com1_SYS_exec[2]='show install active summary'
    com1_SYS__ksh[2]='instcmd show install active'
fi
com1_SYS_exec[3]='show log'
com1_SYS__ksh[3]='show_logging'
com1_SYS_exec[4]='show redundancy location all'
com1_SYS__ksh[4]='redcon_show -n all'
com1_SYS__ksh[5]=''

index=1
if [[ $isVrf = 0 || $isVrf = 2 ]]; then
    if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
        com2_SYS_exec[index]='show route ipv4 summary'
        com2_SYS__ksh[index]='show_ipv4_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -S ipv4 ________'
        ((index++))
        com2_SYS_exec[index]='show rib ipv4 clients'
        com2_SYS__ksh[index]='show_ipv4_rib -X 0x1 -r 0x0'
        ((index++))
    fi
    if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then
        com2_SYS_exec[index]='show route ipv6 summary'      
        com2_SYS__ksh[index]='show_ipv6_rib -X 0x2 -Y 0x1 -Z ________ -V ________ -S ipv6 ________'
        ((index++))
        com2_SYS_exec[index]='show rib ipv6 clients'
        com2_SYS__ksh[index]='show_ipv6_rib -X 0x1 -r 0x0'
        ((index++))
  fi
fi
if [[ $isVrf = 1 || $isVrf = 2 ]]; then
  com2_SYS_exec[index]='show rsi vrf $vrf location $location'
  com2_SYS__ksh[index]='show_rsi_agent -c 0x17 -t $vrf -l $rsi_node_id'     
  ((index++))
  if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
      com2_SYS_exec[index]='show route vrf $vrf ipv4 summary' 
      com2_SYS__ksh[index]='show_ipv4_rib -X 0x1 -Y 0x1 -Z $vrf -V ________ -S ipv4 $vrf'
      ((index++))
  fi
  if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then  
      com2_SYS_exec[index]='show route vrf $vrf ipv6 summary' 
      com2_SYS__ksh[index]='show_ipv6_rib -X 0x2 -Y 0x1 -Z $vrf -V ________ -S ipv6 $vrf'
      ((index++))
      com2_SYS_exec[index]='show rib vrf $vrf ipv6 opaques tunnel-nexthop'
      com2_SYS__ksh[index]='show_ipv6_rib -X 0x2 -Y 0x1 -Z $vrf -V ________ -W 0x0' 
      ((index++))
      com2_SYS_exec[index]='show rib vrf $vrf ipv6 opaques ipfrr'
      com2_SYS__ksh[index]='show_ipv6_rib -X 0x2 -Y 0x1 -Z $vrf -V ________ -J 0x0'
      ((index++))
  fi
fi
if [ "$CEF_COFO" == "1" ]; then
    #opaque always in ipv4 in rib
    com2_SYS_exec[index]='show rib opaque cofo-intf'
    com2_SYS__ksh[index]='show_ipv4_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -"\(" 0x0'
    ((index++))
    com2_SYS_exec[index]='show rib opaque cofo-slabel'
    com2_SYS__ksh[index]='show_ipv4_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -"\)" 0x0'
    ((index++))
fi
com2_SYS__ksh[index]=''


# MPLS brief SYS commands
com6_SYS_exec[1]='show mpls forwarding summary'
com6_SYS__ksh[1]='fib_mpls_show_fwding -S'
com6_SYS__ksh[4]=''


#################################
#Level 2 (detail) SYS commands
#################################
#
# Protocol and VRF Independent Level 2 (detail) SYS commands
#
com9_SYS_exec[1]='show bcdlv2 consumers'
com9_SYS__ksh[1]='show_bcdlv2 -C 0x6'
com9_SYS_exec[2]='show bcdl table'
com9_SYS__ksh[2]='show_bcdl -t'
com9_SYS_exec[3]='show cef fast-reroute-db'
com9_SYS__ksh[3]='fib_show_command -L -O 0x0'
com9_SYS_exec[4]='show cef fast-reroute-log'
com9_SYS__ksh[4]='fib_show_command -6 -O 0x0'
com9_SYS__ksh[5]=''

#
# IPv6 detailed SYS commands
#
if [[ $isVrf = 1 || $isVrf = 2 ]]; then
  com12_SYS_exec[2]='show rib vrf $vrf ipv6 opaques ip-nexthop'
  com12_SYS__ksh[2]='show_ipv6_rib -X 0x2 -Y 0x1 -Z $vrf -V ________ -K 0x0'
  com12_SYS_exec[3]=''
else
  com12_SYS__ksh[2]=''
fi

#
#ipv4 detailed SYS commands
#
com15_SYS_exec[2]='show rib ipv4 opaques ipfrr'  
com15_SYS__ksh[2]='show_ipv4_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -J 0x'
if [[ $isVrf = 1 || $isVrf = 2 ]]; then 
  com15_SYS_exec[3]='show rib vrf $vrf ipv4 opaques tunnel-nexthop'
  com15_SYS__ksh[3]='show_ipv4_rib -X 0x1 -Y 0x1 -Z $vrf -V ________ -W 0x0'
  com15_SYS__ksh[4]=''
else
  com15_SYS__ksh[3]=''
fi

#################################################
# End of SYS commands       
###############################################

#
# Protocol and VRF Independent, Location specific Level 1 (brief) Commands
#
com2_exec[1]='show proc blocked location $location'
if [[ "$platform" = "panini" ]]; then
    com2__ksh[1]='sh_proc_ng_blocked'
else
    com2__ksh[1]='show_processes -b'
fi
com2_exec[2]='show cef resource detail location $location'
com2__ksh[2]='fib_show_command -K -O 0x0 -d'
com2_exec[3]='show mem summary location $location'
if [[ "$platform" = "panini" ]]; then
    com2__ksh[3]='show_memory_ng -s'
else
    com2__ksh[3]='show_memory -s'
fi
com2_exec[4]='show cef external location $location'
com2__ksh[4]='fib_show_command -t -O 0x0 -e'
com2__ksh[5]=''

# show shmwin summary
com5_exec[1]='show shmwin summary'
com5__ksh[1]='shmwin_show -N all -S'
com5__ksh[2]=''

com18_exec[1]='show cef proc-fsm location $location'
com18__ksh[1]='fib_show_command --proc_fsm'
com18_exec[2]='show cef message-queue location $location'
com18__ksh[2]='fib_show_command --msg_q'
com18_exec[3]='show cef misc location $location'
com18__ksh[3]='fib_show_command -s -O 0x0'
com18_exec[4]='show cef imdr location $location'
com18__ksh[4]='fib_show_command -1 -O 0x0'
com18__ksh[5]=''

com19_exec[1]='show cef exceptions location $location'
com19__ksh[1]='fib_statistics_show_command -P 0x0 -e'
com19_exec[2]='show cef drops location $location'
com19__ksh[2]='fib_statistics_show_command -P 0x0 -d'
cidx=3
#COFO related
if [ "$CEF_COFO" == "1" ]; then
    com19_exec[cidx]='show cef global cofo tables summary location $location'
    com19__ksh[cidx]='fib_show_command -s --global --cofo-tbl-id-summary'
    ((cidx++))
    com19_exec[cidx]='show cef global cofo tables location $location'
    com19__ksh[cidx]='fib_show_command -s --global --cofo-tbls'
    ((cidx++))
    com19_exec[cidx]='show cef global cofo interface location $location'
    com19__ksh[cidx]='fib_show_command -s --global --cofo-idb-tbl'
    ((cidx++))
fi
com19__ksh[cidx]=''

com20_exec[1]='show cef summary location $location'
com20__ksh[1]='fib_show_command -S -O 0x0'
com20__ksh[2]=''

#
# IPv4/IPv6 Level 1 (brief) VRF Independent commands
if [ -d /net ] ; then
shared_path="/net"
elif [ -d /shared ] ; then
shared_path="/shared"
fi

index=1
if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
    com3_exec[index]='show cef ipv4 drops location $location'
    com3__ksh[index]='fib_statistics_show_command -P 0x0 -d'
    ((index++))
    com3_exec[index]='show cef ipv4 exceptions'
    com3__ksh[index]='fib_statistics_show_command -P 0x0 -e'
    ((index++))
    com3_exec[index]='show cef ipv4 retry-db location $location'
    com3__ksh[index]='fib_show_command -O 0x0 --retry_db'
    ((index++))
    com3_exec[index]='show cef fast-reroute-db location $location'
    com3__ksh[index]='fib_show_command -L -O 0x0'
    ((index++))
    com3_exec[index]='show cef ipv4 pathlist-db shared detail location $location'
    com3__ksh[index]='fib_show_command -O 0x0 --pathlist_db shared -d'
    ((index++))
    com3_exec[index]='show cef ipv4 pathlist-db exclusive detail location $location'
    com3__ksh[index]='fib_show_command -O 0x0 --pathlist_db exclusive -d'
    ((index++))
    if [ "$shared_path" != "" ]; then
        com3_exec[index]='run cat $shared_path/$default_node/$fib_tmpfile_dir/fib_idb_recycle_ipv4.log'
        com3__ksh[index]='cat $shared_path/$default_node/$fib_tmpfile_dir/fib_idb_recycle_ipv4.log'
        ((index++))
    fi
fi
if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then
    com3_exec[index]='show cef ipv6 drops location $location'
    com3__ksh[index]='fib_statistics_show_command -P 0x1 -d'
    ((index++))
    com3_exec[index]='show cef ipv6 exceptions'
    com3__ksh[index]='fib_statistics_show_command -P 0x1 -e'
    ((index++))
    com3_exec[index]='show cef ipv6 retry-db location $location'
    com3__ksh[index]='fib_show_command -O 0x1 --retry_db'
    ((index++))
    com3_exec[index]='show cef ipv6 fast-reroute-db location $location'
    com3__ksh[index]='fib_show_command -L -O 0x1'
    ((index++))
    com3_exec[index]='show cef ipv6 pathlist-db shared detail location $location'
    com3__ksh[index]='fib_show_command -O 0x1 --pathlist_db shared -d'
    ((index++))
    com3_exec[index]='show cef ipv6 pathlist-db exclusive detail location $location'
    com3__ksh[index]='fib_show_command -O 0x1 --pathlist_db exclusive -d'
    ((index++))
    if [ "$shared_path" != "" ]; then
        com3_exec[index]='run cat $shared_path/$default_node/$fib_tmpfile_dir/fib_idb_recycle_ipv6.log'
        com3__ksh[index]='cat $shared_path/$default_node/$fib_tmpfile_dir/fib_idb_recycle_ipv6.log'
        ((index++))
    fi
fi

if [ $isIf = 1 ]; then
    external_if=`convert_interface_fmt '-e' $internal_if`
    if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
        com3_exec[index]='show cef $external_if location $location'
        com3__ksh[index]='fib_show_command -t -O 0x0 -i $external_if'
        ((index++))
        com3_exec[index]='show cef adjacency $external_if location $location'
        com3__ksh[index]='fib_show_command -Z -O 0x0 -i $external_if'
        ((index++))
        com3_exec[index]='show cef adjacency $external_if remote detail location $location'
        com3__ksh[index]='fib_show_command -Z -O 0x0 -i $external_if -B -d'
        ((index++))
    fi
    if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then
        com3_exec[index]='show cef $external_if location $location'
        com3__ksh[index]='fib_show_command -t -O 0x1 -i $external_if'
        ((index++))
        com3_exec[index]='show cef adjacency $external_if location $location'
        com3__ksh[index]='fib_show_command -Z -O 0x1 -i $external_if'
        ((index++))
        com3_exec[index]='show cef adjacency $external_if remote detail location $location'
        com3__ksh[index]='fib_show_command -Z -O 0x1 -i $external_if -B -d'
        ((index++))
    fi
fi
com3__ksh[index]=''

#
# IPv4/IPv6 (brief) VRF specific commands
#
index=1
if [[ $isVrf = 0 || $isVrf = 2 ]]; then
    if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
        com4_exec[index]='show cef ipv4 summary location $location'
        com4__ksh[index]='fib_show_command -S -O 0x0'
        ((index++))
        com4_exec[index]='show cef ipv4 unresolved location $location'
        com4__ksh[index]='fib_show_command -t -O 0x0 -u'
        ((index++))
        com4_exec[index]='show cef ipv4 bgp-attribute summary location $location'
        com4__ksh[index]='fib_show_command -O 0x0 -w -0'
        ((index++))
        com4_exec[index]='show cef ipv4 generic-interface-list location $location'
        com4__ksh[index]='fib_show_command -O 0x0 -x'
        ((index++))
        com4_exec[index]='show cef ipv4 tables summary location $location'
        com4__ksh[index]='fib_show_command -t -O 0x0 -3 -4'
        ((index++))
        com4_exec[index]='show cef ipv4 tables location $location'
        com4__ksh[index]='fib_show_command -t -O 0x0 -3'
        ((index++))
    fi
    if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then
        com4_exec[index]='show cef ipv6 summary location $location'
        com4__ksh[index]='fib_show_command -S -O 0x1'
        ((index++))
        com4_exec[index]='show cef ipv6 unresolved location $location'
        com4__ksh[index]='fib_show_command -t -O 0x1 -u'
        ((index++))
        com4_exec[index]='show cef ipv6 bgp-attribute summary location $location'
        com4__ksh[index]='fib_show_command -O 0x1 -w -0'
        ((index++))
        com4_exec[index]='show cef ipv6 generic-interface-list location $location'
        com4__ksh[index]='fib_show_command -O 0x1 -x'
        ((index++))
        com4_exec[index]='show cef ipv6 tables summary location $location'
        com4__ksh[index]='fib_show_command -t -O 0x1 -3 -4'
        ((index++))
        com4_exec[index]='show cef ipv6 tables location $location'
        com4__ksh[index]='fib_show_command -t -O 0x1 -3'
        ((index++))
    fi
fi
if [[ $isVrf = 1 || $isVrf = 2 ]]; then
    if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
        com4_exec[index]='show cef vrf $vrf ipv4 summary location $location'
        com4__ksh[index]='fib_show_command -S -O 0x0 -f $vrf'
        ((index++))
        com4_exec[index]='show cef vrf $vrf ipv4 unresolved location $location'
        com4__ksh[index]='fib_show_command -t -O 0x0 -f $vrf -u'
        ((index++))
        com4_exec[index]='show cef vrf $vrf ipv4 bgp-attribute summary location $location'
        com4__ksh[index]='fib_show_command -O 0x0 -f $vrf -w -0'
        ((index++))
    fi
    if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then
        com4_exec[index]='show cef vrf $vrf ipv6 summary location $location'
        com4__ksh[index]='fib_show_command -S -O 0x1 -f $vrf'
        ((index++))
        com4_exec[index]='show cef vrf $vrf ipv6 unresolved location $location'
        com4__ksh[index]='fib_show_command -t -O 0x1 -f $vrf -u'
        ((index++))
        com4_exec[index]='show cef vrf $vrf ipv6 bgp-attribute summary location $location'
        com4__ksh[index]='fib_show_command -O 0x1 -f $vrf -w -0'
        ((index++))
    fi
fi
com4__ksh[index]=''

#
# MPLS Level 1 (brief) VRF independent commands
#
com6_exec[1]='show cef mpls interface location $location'
com6__ksh[1]='fib_show_command -I -O 0x2'
com6_exec[2]='show cef mpls adjacency location $location'
com6__ksh[2]='fib_show_command -Z -O 0x0 -9 0x2'
com6_exec[3]='show cef mpls unresolved'
com6__ksh[3]='fib_show_command -t -O 0x2 -u'
com6__ksh[4]=''

#
# FIB traces
#
com7_exec[1]='show cef trace location $location'
com7__ksh[1]='show_fib_trace -P 0x3'
com7__ksh[2]=''

#
# Protocol independent, detailed, location specific
#
# com10_exec[1]='show adjacency trace all location $location'
# com10__ksh[1]='show_ltrace_aib -S -F'
# com10__ksh[2]=''

#
# IPv6 Level 2 (detail) VRF Independent commands
#
com11_exec[1]='show ipv6 neighbors location $location'  
com11__ksh[1]='show_ipv6_neighbors -a'
com11_exec[2]='show adjacency ipv6 detail location $location' 
com11__ksh[2]='aib_show_command -P ipv6 -D'
com11_exec[3]='show adjacency ipv6 remote detail location $location' 
com11__ksh[3]='aib_show_command -P ipv6 -R -D'
com11_exec[4]='show cef ipv6 adjacency detail location $location'
com11__ksh[4]='fib_show_command -Z -O 0x1 -9 0x1 -d'
com11_exec[5]='show cef ipv6 recursive-nexthop' 
com11__ksh[5]='fib_show_command -O 0x1 -D'
com11_exec[6]='show cef ipv6 local-label conflicts detail' 
com11__ksh[6]='fib_show_command -O 0x1 -d --label-conflicts'
com11_exec[7]='show ipv6 trace ma location $location' 
com11__ksh[7]='show_ltrace_ma'
com11__ksh[8]=''


#
# MPLS Level 2 (detail) commands
#
com14_exec[1]='show cef mpls adjacency detail location $location'
com14__ksh[1]='fib_show_command -Z -O 0x0 -9 0x2 -d'
com14__ksh[2]=''

#
# IPv4 Level 2 (detail) VRF Independent Commands
#
com15_exec[1]='show arp location $location'
com15__ksh[1]='arp_command show -A'
com15_exec[2]='show arp traffic location $location'
com15__ksh[2]='arp_command show -t -A'
com15_exec[3]='show cef ipv4 adjacency detail location $location'
com15__ksh[3]='fib_show_command -Z -O 0x0 -9 0x0 -d'
com15_exec[4]='show cef ipv4 recursive-nexthop'
com15__ksh[4]='fib_show_command -O 0x0 -D'
com15_exec[5]='show cef ipv4 local-label conflicts detail'
com15__ksh[5]='fib_show_command -O 0x0 -d --label-conflicts'
com15_exec[6]='show ipv4 trace location $location'
com15__ksh[6]='show_ipv4_ltrace'
cidx=7
if [ "$CEF_COFO" == "1" ]; then
    com15_exec[cidx]='show cef global cofo tables detail location $location'
    com15__ksh[cidx]='fib_show_command -s --global --cofo-tbls -d'
    ((cidx++))
    com15_exec[cidx]='show cef global cofo interface detail location $location'
    com15__ksh[cidx]='fib_show_command -s --global --cofo-idb-tbl -d'
    ((cidx++))
fi
com15__ksh[cidx]=''



# **********************************************************************
# Functions
# **********************************************************************


######################################################################
#This function converts ip address a.b.c.d into it's hex equivalent 
#This is needed for some ksh cef commands
#For example 1.9.10.255 is converted to 01090aff
######################################################################

ipv4address_conv() {
  myIP=$1
  d1=$(echo $myIP | cut -d. -f1)
  d2=$(echo $myIP | cut -d. -f2)
  d3=$(echo $myIP | cut -d. -f3)
  d4=$(echo $myIP | cut -d. -f4)

  #convert single dec number to hex
  function convert_number {
        typeset -i${2:-16} x
        x=$1
        echo ${x#16#}
  }

  h1=$(convert_number $d1)
  h2=$(convert_number $d2)
  h3=$(convert_number $d3)
  h4=$(convert_number $d4)

  #add 0 if needed
  prt () {
    dec=$1
    hex=$2
    if [[ $dec -lt 15 ]]; then echo "0$hex"
    else  echo "$hex"
  fi
 }
echo  "$(prt $d1 $h1)$(prt $d2 $h2)$(prt $d3 $h3)$(prt $d4 $h4)"
}


######################################################################
#This function converts IPV6 address to the string of digits needed for cef ksh function
# For example 1:f:ff::ffff will be converted to 0001000f00ff0000000000000000ffff
######################################################################

ipv6address_conv() {
  myIP=$1
  i=0
  while [[ $i -lt 10 ]] ; do
    array[$i]=""
    let i+=1
  done

  #read numbres up till "::" and put in array
  array[1]=$(echo $myIP | cut -d: -f1)
  if  [[ "${array[1]}" = "" ]]; then
     #if address starts with "::"
      i=3
      j=1
  else
      j=1
      i=2
      #read rest of the address up till "::"
      while [[ "${array[$j]}" != "" ]] ; do
        array[$i]=$(echo $myIP | cut -d: -f$i)
        (( i+=1 )); ((j+=1 ))
      done
  fi

 t=0
  while [[ $t -lt 10 ]] ; do
    array1[$t]=""
    let t+=1
  done

  # Read all numbres after "::" and place them in separate array1
  array1[1]=$(echo $myIP | cut -d: -f$i)
  ((i+=1))
  k=1
  l=2
  while [[ "${array1[$k]}" != "" ]] ; do
      array1[$l]=$(echo $myIP | cut -d: -f$i)
      (( l+=1 )); ((k+=1 )); (( i+=1 ));
  done

  #fill up missing zeros up till "::"
  let m=10-$k
  while [[ $j -ne m ]] ; do
      array[$j]=0
      let j+=1
  done

 # Combine array and array1
 i=1
 while [[ $m -lt 9 ]] ; do
      array[$m]=${array1[$i]}
      let m+=1; let i+=1
  done

  add_zeros() {
     k=$1
     if [[ $((16#${array[$k]})) -eq 0 ]]; then echo "0000"
     elif [[ $((16#${array[$k]})) -lt $((16#10)) ]]; then echo "000${array[$k]}"
     elif [[ $((16#${array[$k]})) -lt $((16#100)) ]]; then echo "00${array[$k]}"
     elif [[ $((16#${array[$k]})) -lt $((16#1000)) ]]; then echo "0${array[$k]}"
     else echo "${array[$k]}"
     fi
     (( i+=1 ))
  }
echo "$(add_zeros 1)$(add_zeros 2)$(add_zeros 3)$(add_zeros 4)$(add_zeros 5)$(add_zeros 6)$(add_zeros 7)$(add_zeros 8)"
}




#####################################################################
# The funtion do_show_route_command() takes 2 arguments. 
# It outputs show route command and if find to be a recursive route,
# it recursively outputs the show route command.
#####################################################################

do_show_route_command() {
    typeset route_next
    # SET ARGUMENT VARIABLES
    route_ip_version=$1
    route_prefix=$2
    route_isvrf=$3
    route_vrf=$4
    route_result_loop_count=0
    route_vrf_loop_count=0
    route_next=""
    nexthop_afi=""


    # SET COMMAND STRING ACCORDING TO PREFIX AND MASK OPTIONS PROVIDED
    if [ $route_isvrf = "0" ]; then
        if [[ $isPrefix = 0 ]]; then
            route_command_exec="show route $route_ip_version summary detail"
            if [ $route_ip_version = "ipv4" ]; then
                route_command="show_"$route_ip_version"_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -D "$route_ip_version" ________"
            else
                route_command="show_"$route_ip_version"_rib -X 0x2 -Y 0x1 -Z ________ -V ________ -D "$route_ip_version" ________"
            fi
        else
            if [[ $route_recursion = 0 ]] && [[ $isMask = 1 ]]; then
                route_command_exec="show route $route_ip_version unicast $route_prefix/$mask detail"
                if [ $route_ip_version = "ipv4" ]; then     
                    route_command="show_"$route_ip_version"_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -p $route_prefix -l $mask_string -3 "$route_ip_version" ________"
                else
                    route_command="show_"$route_ip_version"_rib -X 0x2 -Y 0x1 -Z ________ -V ________ -p $route_prefix -l $mask_string -3 "$route_ip_version" ________"
                fi
            else
                route_command_exec="show route $route_ip_version unicast $route_prefix detail"
                if [ $route_ip_version = "ipv4" ]; then     
                    route_command="show_"$route_ip_version"_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -p $route_prefix -3 "$route_ip_version" ________"
                else
                    route_command="show_"$route_ip_version"_rib -X 0x2 -Y 0x1 -Z ________ -V ________ -p $route_prefix -3 "$route_ip_version" ________"                
                fi
            fi
        fi
    else
        if [[ $isPrefix = 0 ]]; then
            route_command_exec="show route vrf $route_vrf $route_ip_version summary detail"
            if [ $route_ip_version = "ipv4" ]; then     
                route_command="show_"$route_ip_version"_rib -X 0x1 -Y 0x1 -Z "$route_vrf" -V ________ -D "$route_ip_version" "$route_vrf""
            else
                route_command="show_"$route_ip_version"_rib -X 0x2 -Y 0x1 -Z "$route_vrf" -V ________ -D "$route_ip_version" "$route_vrf""            
            fi
        else
            if [[ $route_recursion = 0 ]] && [[ $isMask = 1 ]]; then
                route_command_exec="show route vrf $route_vrf $route_ip_version unicast $route_prefix/$mask detail"
                if [ $route_ip_version = "ipv4" ]; then     
                    route_command="show_"$route_ip_version"_rib -X 0x1 -Y 0x1 -Z "$route_vrf" -V ________ -p $route_prefix -l $mask_string -3 "$route_ip_version" "$route_vrf""
                else
                    route_command="show_"$route_ip_version"_rib -X 0x2 -Y 0x1 -Z "$route_vrf" -V ________ -p $route_prefix -l $mask_string -3 "$route_ip_version" "$route_vrf""                
                fi
            else
                route_command_exec="show route vrf $route_vrf $route_ip_version unicast $route_prefix detail"
                if [ $route_ip_version = "ipv4" ]; then     
                    route_command="show_"$route_ip_version"_rib -X 0x1 -Y 0x1 -Z "$route_vrf" -V ________ -p $route_prefix -3 "$route_ip_version" "$route_vrf""
                else
                    route_command="show_"$route_ip_version"_rib -X 0x2 -Y 0x1 -Z "$route_vrf" -V ________ -p $route_prefix -3 "$route_ip_version" "$route_vrf""                
                fi
            fi
        fi
    fi
    echo " \n++++++ $route_command_exec ++++++++\n"
    # Get show route output and if it is a recursive route, run it recursively
    $route_command
    if [[ $isPrefix = 1 ]]; then
        if [ $route_isvrf = "0" ]; then
            $route_command | grep "RIB_PRIORITY_RECURSIVE" | while read LINE; do
                nexthop_string=`$route_command | grep "Nexthop"`
                nexthop=`echo $nexthop_string | cut -f 1 -d' '`
                nexthop_afi=`echo $nexthop_string | cut -f 7 -d' '`
                if [ $route_ip_version = "ipv4" ]; then
                    $route_command | grep '    [0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' |  while read route_result_prefix; do
                        route_result_prefix1=`echo $route_result_prefix | cut -f 1 -d','`
                        route_recursion=$route_recursion+1
                        if [[ $route_recursion -lt max_recursion ]]; then
                            do_show_route_command $route_ip_version $route_result_prefix1 $NOT_VRF 
                        fi
                    done
                else
                    # For Normal/recursive, non vrf IPv6 routes
                    if [[ "$nexthop_afi" != "IPv4" ]]; then                
                        $route_command | grep '    [0-f]\{1,4\}:*:[0-f]\{1,4\}' |  while read route_result_prefix; do
                            route_result_prefix1=`echo $route_result_prefix | cut -f 1 -d','`
                            route_recursion=$route_recursion+1
                            if [[ $route_recursion -lt max_recursion ]]; then
                                do_show_route_command $route_ip_version $route_result_prefix1 $NOT_VRF
                            fi
                        done
                    fi
                    # For IPv6 routes going over IPv4 routes
                    route_result_prefix1=""
                    $route_command  | grep '    ::ffff:' | while read route_result_prefix1; do
                        #route_result_prefix=`perl -e '$a=shift; $a =~ m/::ffff:(.*?), from ::ffff:/; print $1;' "$route_result_prefix1"`
                        route_result_prefix=`awk '{ $a = shift; if ($a ~ /::ffff:(.*?), from ::ffff:/) print $1 }' "$route_result_prefix1"`
                        oldMask=isMask
                        isMask=0
                        do_show_route_command "ipv4" $route_result_prefix $NOT_VRF
                        isMask=oldMask
                    done                           
                fi
            done
        else
            # If it is VRF output, look for which vrf next hop is in, assuming nexthop vrf is in same vrf for all equal paths
            $route_command | grep "RIB_PRIORITY_RECURSIVE" | while read LINE; do
                nexthop_string=`$route_command | grep "Nexthop"`
                nexthop=`echo $nexthop_string | cut -f 1 -d' '`
                nexthop_afi=`echo $nexthop_string | cut -f 7 -d' '`
                if [ $route_ip_version = "ipv4" ]; then
                    $route_command | grep '    [0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | while read route_result_prefix; do
                        route_result_prefix1=`echo $route_result_prefix | cut -f 1 -d','`
                        route_recursion=$route_recursion+1
                        if [[ $route_recursion -lt max_recursion ]]; then
                            if [ "$nexthop" = "Nexthop"  ]; then
                                route_vrf_new=`echo $nexthop_string | cut -f 2 -d'"'`
                                if [ $route_vrf_new = "default" ]; then
                                    do_show_route_command $route_ip_version $route_result_prefix1 $NOT_VRF
                                else
                                    do_show_route_command $route_ip_version $route_result_prefix1 $IS_VRF $route_vrf_new
                                fi
                            else
                                do_show_route_command $route_ip_version $route_result_prefix1 $IS_VRF $route_vrf
                            fi
                        fi
                    done
                else
                    if [[ "$nexthop_afi" != "IPv4" ]]; then
                        $route_command | grep "  [0-f]\{1,4\}:*:[0-f]\{1,4\}" |  while read route_result_prefix; do
                            route_result_prefix1=`echo $route_result_prefix | cut -f 1 -d','`
                            route_recursion=$route_recursion+1
                            if [[ $route_recursion -lt max_recursion ]]; then
                                if [ "$nexthop" = "Nexthop"  ]; then
                                    route_vrf_new=`echo $nexthop_string | cut -f 2 -d'"'`
                                    if [ $route_vrf_new = "default" ]; then
                                        do_show_route_command $route_ip_version $route_result_prefix1 $NOT_VRF
                                    else
                                        do_show_route_command $route_ip_version $route_result_prefix1 $IS_VRF $route_vrf_new
                                    fi
                                else
                                    do_show_route_command $route_ip_version $route_result_prefix1 $IS_VRF $route_vrf
                                fi
                            fi
                        done
                    fi                
                    # For ipv6 going over ipv4 routes
                    route_result_prefix1=""
                    route_vrf_new=`echo $nexthop_string | cut -f 2 -d'"'`
                    $route_command  | grep '    ::ffff:' | while read route_result_prefix1; do
                        #route_result_prefix=`perl -e '$a=shift; $a =~ m/::ffff:(.*?), from ::ffff:/; print $1;' "$route_result_prefix1"`
                        route_result_prefix=`awk '{ $a = shift; if ($a ~ /::ffff:(.*?), from ::ffff:/) print $1 }' "$route_result_prefix1"`
                        oldMask=isMask
                        isMask=0
                        do_show_route_command "ipv4" $route_result_prefix $NOT_VRF
                        isMask=oldMask
                    done
                fi
            done
        fi
    fi
}

#####################################################################
# The funtion do_show_cef_command() takes ip version and prefix as arguments. 
# It outputs show cef command and if it is found to be a recursive route,
# it recursively outputs the show cef command.
#####################################################################

do_show_cef_command() {
    # SET ARGUMENT VARIABLES
    cef_ip_version=$1
    cef_prefix=$2
    cef_isvrf=$3
    cef_vrf=$4
    cef_line=0
    last_cef_prefix=$cef_prefix

    if [ "$cef_ip_version" == "ipv4" ]; then
       cef_prefix_conv=$(ipv4address_conv $cef_prefix)
    elif [ "$cef_ip_version" == "ipv6" ]; then
       cef_prefix_conv=$(ipv6address_conv $cef_prefix)
    fi
    # SET COMMAND STRING ACCORDING TO PREFIX AND MASK OPTIONS PROVIDED
    if [ $cef_isvrf = "0" ]; then
        if [[ $isPrefix = 0 ]]; then
            cef_string_exec="show cef $cef_ip_version summary"
            if [ "$cef_ip_version" == "ipv4" ]; then
               cef_string="fib_show_command -S -O 0x0"
            else
               cef_string="fib_show_command -S -O 0x1"
            fi
        else
            if [[ $cef_recursion = 0 ]] && [[ $isMask = 1 ]]; then
                cef_string_exec="show cef $cef_ip_version $cef_prefix/$mask"
                if [ "$cef_ip_version" == "ipv4" ]; then
                   cef_string="fib_show_command -t -O 0x0 -P $cef_prefix_conv -M $mask_string -T 0x2"
                   if [[ $level = 2 ]]; then
                       cef_string_hw_ingress="fib_show_command -t -O 0x0 -H ingress -P $cef_prefix_conv -M $mask_string -T 0x2"
                       cef_string_hw_egress="fib_show_command -t -O 0x0 -H egress -P $cef_prefix_conv -M $mask_string -T 0x2"
                   fi
                else
                   cef_string="fib_show_command -t -O 0x1 -P $cef_prefix_conv -M $mask_string -T 0x1a"
                   if [[ $level = 2 ]]; then
                       cef_string_hw_ingress="fib_show_command -t -O 0x1 -H ingress -P $cef_prefix_conv -M $mask_string -T 0x1a"
                       cef_string_hw_egress="fib_show_command -t -O 0x1 -H egress -P $cef_prefix_conv -M $mask_string -T 0x1a"
                   fi
                fi
            else
                cef_string_exec="show cef $cef_ip_version $cef_prefix"
                if [ "$cef_ip_version" == "ipv4" ]; then
                   cef_string="fib_show_command -t -O 0x0 -P $cef_prefix_conv -T 0x2"
                   if [[ $level = 2 ]]; then
                       cef_string_hw_ingress="fib_show_command -t -O 0x0 -H ingress -P $cef_prefix_conv -T 0x2"
                       cef_string_hw_egress="fib_show_command -t -O 0x0 -H egress -P $cef_prefix_conv -T 0x2"
                   fi
                else
                   cef_string="fib_show_command -t -O 0x1 -P $cef_prefix_conv -T 0x1a"
                   if [[ $level = 2 ]]; then
                       cef_string_hw_ingress="fib_show_command -t -O 0x1 -H ingress -P $cef_prefix_conv -T 0x1a"
                       cef_string_hw_egress="fib_show_command -t -O 0x1 -H egress -P $cef_prefix_conv -T 0x1a"
                   fi
                fi
            fi
        fi
    else
        #for VRF case
        if [[ $isPrefix = 0 ]]; then
            cef_string_exec="show cef vrf $cef_vrf $cef_ip_version summary $loc_string"
            if [ "$cef_ip_version" == "ipv4" ]; then
               cef_string="fib_show_command -S -O 0x0 -f $cef_vrf"
            else
               cef_string="fib_show_command -S -O 0x1 -f $cef_vrf"
            fi
        else
            if [[ $cef_recursion = 0 ]] && [[ $isMask = 1 ]]; then
                cef_string_exec="show cef vrf $cef_vrf $cef_ip_version $cef_prefix/$mask"
                if [ "$cef_ip_version" == "ipv4" ]; then
                   cef_string="fib_show_command -t -O 0x0 -f $cef_vrf -P $cef_prefix_conv -M $mask_string -T 0x2 "
                   if [[ $level = 2 ]]; then
                       cef_string_hw_ingress="fib_show_command -t -O 0x0 -f $cef_vrf -H ingress -P $cef_prefix_conv -M $mask_string -T 0x2 "
                       cef_string_hw_egress="fib_show_command -t -O 0x0 -f $cef_vrf -H egress -P $cef_prefix_conv -M $mask_string -T 0x2 "
                   fi
                else
                   cef_string="fib_show_command -t -O 0x1 -f $cef_vrf -P $cef_prefix_conv -M $mask_string -T 0x1a"
                   if [[ $level = 2 ]]; then
                       cef_string_hw_ingress="fib_show_command -t -O 0x1 -f $cef_vrf -H ingress -P $cef_prefix_conv -M $mask_string -T 0x1a"
                       cef_string_hw_egress="fib_show_command -t -O 0x1 -f $cef_vrf -H egress -P $cef_prefix_conv -M $mask_string -T 0x1a"
                   fi
                fi
            else
                cef_string_exec="show cef vrf $cef_vrf $cef_ip_version $cef_prefix"
                if [ "$cef_ip_version" == "ipv4" ]; then
                       cef_string="fib_show_command -t -O 0x0 -f $cef_vrf -P $cef_prefix_conv -T 0x2"
                       if [[ $level = 2 ]]; then
                           cef_string_hw_ingress="fib_show_command -t -O 0x0 -f $cef_vrf -H ingress -P $cef_prefix_conv -T 0x2"
                           cef_string_hw_egress="fib_show_command -t -O 0x0 -f $cef_vrf -H egress -P $cef_prefix_conv -T 0x2"
                       fi
                else
                   cef_string="fib_show_command -t -O 0x1 -f $cef_vrf -P $cef_prefix_conv -T 0x1a"
                   if [[ $level = 2 ]]; then
                       cef_string_hw_ingress="fib_show_command -t -O 0x1 -f $cef_vrf -H ingress -P $cef_prefix_conv -T 0x1a"
                       cef_string_hw_egress="fib_show_command -t -O 0x1 -f $cef_vrf -H egress -P $cef_prefix_conv -T 0x1a"
                   fi
                fi
            fi
        fi
    fi

    if [[ $__location = "" ]]; then print_location="location all"
    else
        print_location="location $__location"
    fi
    
    #EXECUTE COMMAND AND DO RECURSION IF NEEDED
    echo " \n+++++++ $cef_string_exec $print_location++++++++\n"
    # Get show cef output and if it is a recursive route, run it recursively
    if [[ $isPrefix = 1 ]]; then
        cef_command="$cef_string -d"
    else
        cef_command="$cef_string"
    fi
    $cef_command
    # level 2 disabled due to CSCtb92693
    #if [[ $level = 2 ]]; then
        #echo " \n+++++++ $cef_string_exec hardware ingress $print_location++++++++\n"
        #$cef_string_hw_ingress
        #echo " \n+++++++ $cef_string_exec hardware egresss $print_location++++++++\n"
        #$cef_string_hw_egress 
    #fi
    
    if [ $cef_isvrf = "0" ]; then
        if [ $cef_ip_version = "ipv4" ]; then
            $cef_command | grep '   via [0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' |  while read via cef_result_prefix var3 var4 var5 var6; do
                if [ "$var5" = "recursive" ]; then
                    cef_result_prefix1=`echo $cef_result_prefix | cut -f 1 -d','`
                    cef_recursion=$cef_recursion+1
                    if [[ $cef_recursion -lt max_recursion ]]; then
                        do_show_cef_command $cef_ip_version $cef_result_prefix1 $NOT_VRF
                    fi
                fi
            done
        else
            $cef_command | grep '   via [0-f]\{1,4\}:*:[0-f]\{1,4\}' |  while read via cef_result_prefix var3 var4 var5 var6; do
                if [ "$var5" = "recursive" ]; then
                    cef_result_prefix1=`echo $cef_result_prefix | cut -f 1 -d','`
                    cef_recursion=$cef_recursion+1
                    if [[ $cef_recursion -lt max_recursion ]]; then
                        nexthop_afi=`echo $cef_result_prefix1 | cut -f 3 -d':'`
                        if [[ $nexthop_afi = "ffff" ]]; then
                            cef_result_prefix=${cef_result_prefix1##*:}
                            do_show_cef_command "ipv4" $cef_result_prefix $NOT_VRF
                        else
                            do_show_cef_command $cef_ip_version $cef_result_prefix1 $NOT_VRF
                        fi
                    fi
                fi
            done
        fi
    else
        # If it is VRF output, look for which vrf next hop is in, assuming nexthop vrf is in same vrf for all equal paths
        nexthop_string=`$cef_command | grep " - '"`
        nexthop=`echo $nexthop_string | cut -f 1 -d' '`  
        if [[ $cef_ip_version = "ipv4" ]]; then
             $cef_command | grep '   via [0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' |  while read via cef_result_prefix var3 var4 var5 var6; do
		 cef_result_prefix1=""
                 cef_result_prefix1=`echo $cef_result_prefix | cut -f 1 -d','`
                 cef_recursion=$cef_recursion+1
                 if [[ $cef_recursion -lt max_recursion ]]; then
                    if [ "$nexthop" = "next" ]; then 
                        cef_vrf_new=`echo $nexthop_string | cut -f 2 -d"'"`
                        if [ $cef_vrf_new = "default" ]; then 
                            do_show_cef_command $cef_ip_version $cef_result_prefix1 $NOT_VRF
                        else
                            do_show_cef_command $cef_result_prefix1 $IS_VRF $cef_vrf_new
                        fi
                    else
                        if [[ "$last_cef_prefix" != "$cef_result_prefix1" ]]; then
                            do_show_cef_command $cef_ip_version $cef_result_prefix1 IS_VRF $cef_vrf
                        fi
                    fi
                fi
             done
         else
           # for IPv6 prefixes
           $cef_command | grep '   via [0-f]\{1,4\}:*:[0-f]\{1,4\}' |  while read via cef_result_prefix var3 var4 var5 var6; do          
               cef_result_prefix1=`echo $cef_result_prefix | cut -f 1 -d','`
               cef_recursion=$cef_recursion+1
               if [[ $cef_recursion -lt max_recursion ]]; then
                   if [ "$nexthop" = "next" ]; then
                       cef_vrf_new=`echo $nexthop_string | cut -f 2 -d"'"`
                       # Temporary just for CSCsz70848
                       if [ $cef_vrf_new = "Unknown" ]; then
                           cef_vrf_new="default"
                       fi
                       # For 6VPE - next hop is ipv4 in vrf default
                       if [ $cef_vrf_new = "default" ]; then
                           cef_result_prefix2=`echo $cef_result_prefix1 | cut -c8-`
                           do_show_cef_command "ipv4" $cef_result_prefix2 $NOT_VRF
                       else
                           do_show_cef_command $cef_ip_version $cef_result_prefix1 $IS_VRF $cef_vrf_new
                       fi
                   else
                       if [[ "$last_cef_prefix" != "$cef_result_prefix1" ]]; then
                           do_show_cef_command $cef_ip_version $cef_result_prefix1 IS_VRF $cef_vrf
                       fi   
                   fi
               fi
           done
         fi        
    fi
}


#######################################################################
#Function executing ksh commands in order for RPs and LCs
########################################################################
print_commands_all_nodes() {
        #all nodes; brief

        # Trending commands -- 1st run        
        exec_commands com20
        exec_commands com18
        exec_commands com19

        exec_commands com2
        exec_commands com5
        exec_commands com4
        
        exec_commands com7

        if [[ "$protocol" == "mpls" || "$protocol" == "unspecified" ]]; then
           exec_commands com6
        fi

        if [[ "$protocol" != "mpls" || "$protocol" == "unspecified" ]]; then
           exec_commands com3
        fi     

        # Trending commands -- 2nd run
        exec_commands com20
        exec_commands com18
        exec_commands com19

        #all nodes; detail
        if [[ $level = 2 ]]; then
           exec_commands com10

           if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
              exec_commands com15
           fi

           if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then
              exec_commands com11
           fi

           if [[ "$protocol" == "mpls" || "$protocol" == "unspecified" ]]; then
              exec_commands com14
           fi
        fi

}


#######################################################################
#Function printing header
########################################################################
print_header(){
    
    if [[ $__location = "" ]]; then print_location=all
    else
        print_location=$__location
    fi
    
    if [[ $level = 2 ]]; then print_detail="detail"
    else
        print_detail=""
    fi

    if [[ "$protocol" == "unspecified" ]]; then
        print_main_heading "show tech-support cef"
    elif [[ $isVrf = 1 ]]; then
        if [[ $isMask = 0 ]]; then
            print_main_heading "show tech-support cef vrf $vrf $protocol $prefix $print_detail $external_if location $print_location"
        else 
            print_main_heading "show tech-support cef vrf $vrf $protocol $prefix/$mask $print_detail $external_if location $print_location"
        fi
    else
        if [[ $isMask = 0 ]]; then
            print_main_heading "show tech-support cef $protocol $prefix $print_detail $external_if location $print_location"
        else
            print_main_heading "show tech-support cef $protocol $prefix/$mask $print_detail $external_if location $print_location"
        fi
    fi

}

##################################################################
# This is called from the show tech infra for each card requested
##################################################################

display() {
  
    print_header
    
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands com1_SYS
        if [[ "$protocol" != "mpls" || "$protocol" == "unspecified" ]]; then
           exec_commands com2_SYS
        fi

        if [[ "$protocol" == "mpls" || "$protocol" == "unspecified" ]]; then 
          exec_commands com6_SYS
        fi        
        
        # Print Prefix Specific Commands
        if [[ $isPrefix = 1 ]] && [[ $protocol != "mpls" || "$protocol" == "unspecified" ]]; then
            if [[ $isVrf = 1 || $isVrf = 2 ]]; then
                if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
                    do_show_route_command ipv4 $prefix $IS_VRF $vrf
                    do_show_cef_command ipv4 $prefix $IS_VRF $vrf
                fi

                if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then
                    do_show_route_command ipv6 $prefix $IS_VRF $vrf
                    do_show_cef_command ipv6 $prefix $IS_VRF $vrf
                fi
            fi
            if [[ $isVrf = 0 || $isVrf = 2 ]]; then
                if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
                    do_show_route_command ipv4 $prefix $NOT_VRF
                    do_show_cef_command ipv4 $prefix $NOT_VRF
                fi

                if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then
                    do_show_route_command ipv6 $prefix $NOT_VRF
                    do_show_cef_command ipv6 $prefix $NOT_VRF
                fi
            fi
        fi
        
        if [[ $level = 2 ]]; then
            exec_commands com9_SYS

            if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
                exec_commands com15_SYS
            fi

            if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then
                exec_commands com12_SYS
            fi
        fi       
    else
        case "$__cardtype" in
        "RP"|"DRP")
            print_commands_all_nodes
            ;;
        "LC")
            print_commands_all_nodes
            ;;
        esac
        
        # Print Prefix Specific Commands
        if [[ $isPrefix = 1 ]] && [[ $protocol != "mpls" || "$protocol" == "unspecified" ]]; then
            if [[ $isVrf = 1 || $isVrf = 2 ]]; then
                if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
                    do_show_cef_command ipv4 $prefix $IS_VRF $vrf
                fi

                if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then
                    do_show_cef_command ipv6 $prefix $IS_VRF $vrf
                fi
            fi
            if [[ $isVrf = 0 || $isVrf = 2 ]]; then
                if [[ "$protocol" == "ipv4" || "$protocol" == "unspecified" ]]; then
                    do_show_cef_command ipv4 $prefix $NOT_VRF
                fi

                if [[ "$protocol" == "ipv6" || "$protocol" == "unspecified" ]]; then
                    do_show_cef_command ipv6 $prefix $NOT_VRF
                fi
            fi
        fi
    fi

    enable_techs "" /pkg/bin/aib_show_tech /pkg/bin/mpls_io_show_tech

    set_max_depth 2

    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
