#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# isis_techsupport_mc - ISIS specific show tech commands - fast mode
#
# April 2014, Siddhesh M. Divekar
#
# Copyright (c) 2013-2019 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment

__cardtype="unspecified"
### Required argument parsing
### All local options must be upper-case.
while [ "$#" -gt "0" ]; do
  case "$1" in
     -t) __cardtype="$2"; shift 2;;
      *) default_parser_function "$@"; shift $# ;;
  esac
done

if [ "$__filename" = "unspecified" ]; then
    echo "show_tech_routing_isis: output file not specified"
    exit
fi
if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi

# **********************************************************************
# List of show commands for show tech-support routing isis
# **********************************************************************

# Commands run for the system as a whole.

cmd_index=1

System_exec[$cmd_index]='show version'
if [[ "$platform" = "viking" ]]; then
     System__ksh[$cmd_index]='show_version -b' 
elif [[ "$platform" = "panini" ]]; then
     System__ksh[$cmd_index]='ng_show_version'
else
     System__ksh[$cmd_index]='show_version -b' 
fi
cmd_index=$((cmd_index + 1)) 

System_exec[$cmd_index]="show redundancy"
System__ksh[$cmd_index]='show_rmf_sysdb'
cmd_index=$((cmd_index + 1)) 

System_exec[$cmd_index]='show running-config inheritance detail'
System__ksh[$cmd_index]='isis_show_run'
cmd_index=$((cmd_index + 1)) 

System_exec[$cmd_index]='show platform'
if [[ "$platform" = "viking" ]]; then
     System__ksh[$cmd_index]='show_platform_vkg -e' 
elif [[ "$platform" = "panini" ]]; then
     System__ksh[$cmd_index]='show_platform_sysdb -v' 
else
     System__ksh[$cmd_index]='show_platform -a' 
fi
cmd_index=$((cmd_index + 1)) 

System_exec[$cmd_index]='show isis all afi-all safi-all topology all'
System__ksh[$cmd_index]='isis_show -a -d -v -B -5 -# -F -M -1 -2 all'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show isis database graph ipv4'
System__ksh[$cmd_index]='isis_show --db-dot -J 0x0 -K 0x0 -2________'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show isis database graph ipv6'
System__ksh[$cmd_index]='isis_show --db-dot -J 0x1 -K 0x0 -2________'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show isis private all'
System__ksh[$cmd_index]='isis_show -a -P'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show isis standby all'
System__ksh[$cmd_index]='isis_show -a -Q -d -v -B -5 -# -F -M -1 -2 all'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show isis standby private all'
System__ksh[$cmd_index]='isis_show -a -Q -P'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show isis trace all location all'
System__ksh[$cmd_index]='isis_show_ltrace -A -B -C -D -i all'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show logging'
System__ksh[$cmd_index]='show_logging'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show isis uber-verifier trace all location all'
System__ksh[$cmd_index]='isis_uv_show_ltrace -A -B -C -i all'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show clns trace location all'
System__ksh[$cmd_index]='clns_show_ltrace -i all'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show segment-routing trace'
System__ksh[$cmd_index]='xostrace srms'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show ipv4 int brief'
System__ksh[$cmd_index]='show_ip_interface -b -v default'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show ipv6 int brief'
System__ksh[$cmd_index]='show_ipv6_interface -b -v default'
cmd_index=$((cmd_index + 1))

System_exec[$cmd_index]='show route afi-all safi-all topology all isis'
System__ksh[$cmd_index]='show_all_afi_rib -X 0x0 -Y 0x3 -Z ________ -V all -P isis all ________'
cmd_index=$((cmd_index + 1))
System_exec[$cmd_index]='show route afi-all safi-all topology all'
System__ksh[$cmd_index]='show_all_afi_rib -X 0x0 -Y 0x3 -Z ________ -V all -s all ________'
cmd_index=$((cmd_index + 1))

System__ksh[$cmd_index]=''


# Commands run on RP nodes.

cmd_index=1

RP_nodes_exec[$cmd_index]="show install active"
if [[ "$platform" = "panini" ]]; then
     RP_nodes__ksh[$cmd_index]='sdr_instcmd show install active'
else
     RP_nodes__ksh[$cmd_index]='instcmd show install active'
fi
cmd_index=$((cmd_index + 1)) 

RP_nodes_exec[$cmd_index]="show placement"
RP_nodes__ksh[$cmd_index]='placed_show'
cmd_index=$((cmd_index + 1)) 

RP_nodes_exec[$cmd_index]='show processes blocked location $location'
if [[ "$platform" = "panini" ]]; then
 RP_nodes__ksh[$cmd_index]='sh_proc_ng_blocked -l $fq_nodeid'
else
 RP_nodes__ksh[$cmd_index]='show_processes -b $fq_nodeid'
fi
cmd_index=$((cmd_index + 1))

RP_nodes_exec[$cmd_index]='show processes isis'
if [[ "$platform" = "enxr" ]]; then
 RP_nodes__ksh[$cmd_index]='sysmgr_show_enxr -o -p isis'
else
 RP_nodes__ksh[$cmd_index]='sysmgr_show -o -p isis'
fi
cmd_index=$((cmd_index + 1))

RP_nodes_exec[$cmd_index]='show imds interface all'
RP_nodes__ksh[$cmd_index]='im_show database -v 0x2'
cmd_index=$((cmd_index + 1))

RP_nodes_exec[$cmd_index]='show lpts bindings client-id clnl brief'
RP_nodes__ksh[$cmd_index]='show_lpts_pa -a -B -j 0x4'
cmd_index=$((cmd_index + 1))

RP_nodes_exec[$cmd_index]='show clns statistics'
RP_nodes__ksh[$cmd_index]='show_clns_traffic'
cmd_index=$((cmd_index + 1))

RP_nodes_exec[$cmd_index]='show clns pcb location $location'
RP_nodes__ksh[$cmd_index]='lpts_show_pcb -p 0x4 -f 0x0 -N $fq_nodeid -e /oper/clns/'
cmd_index=$((cmd_index + 1))

RP_nodes_exec[$cmd_index]='show isis xipc'
RP_nodes__ksh[$cmd_index]='isis_show_xipc'
cmd_index=$((cmd_index + 1))

RP_nodes__ksh[$cmd_index]=''


# Commands run on linecard nodes.

cmd_index=1

if [ -x /pkg/bin/show_platform_pifib ]; then
 LC_nodes_exec[$cmd_index]='show lpts pifib hardware entry type isis location $location'
 LC_nodes__ksh[$cmd_index]='show_platform_pifib -z 0x1 -r 0x2 -i $fq_nodeid'
 cmd_index=$((cmd_index + 1))
elif [ -x /pkg/bin/platform_show_pifib ]; then
 LC_nodes_exec[$cmd_index]='show lpts pifib hardware entry type isis location $location'
 LC_nodes__ksh[$cmd_index]='platform_show_pifib -z 0x1 -r 0x2 -i $fq_nodeid'
 cmd_index=$((cmd_index + 1))
fi

LC_nodes__ksh[$cmd_index]=''


# Commands run on both RP and Linecard nodes.

cmd_index=1

All_nodes_exec[$cmd_index]='show netio clients location $location'
All_nodes__ksh[$cmd_index]='netio_show -L $fq_nodeid'
cmd_index=$((cmd_index + 1))

All_nodes_exec[$cmd_index]='show lpts pifib entry type isis brief location $location'
All_nodes__ksh[$cmd_index]='show_lpts_pifib -z 0x0 -k 0x0 -a 0x1 -i $fq_nodeid'
cmd_index=$((cmd_index + 1))

All_nodes_exec[$cmd_index]='show lpts pifib entry type isis location $location'
All_nodes__ksh[$cmd_index]='show_lpts_pifib -z 0x0 -k 0x0 -a 0x0 -i $fq_nodeid'
cmd_index=$((cmd_index + 1))

All_nodes__ksh[$cmd_index]=''


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

display() {
  
    print_main_heading "show tech-support routing isis - Card:$__cardtype Node:$node_name"
    
    case "$__cardtype" in
    SYS)
        exec_commands System
        ;;
    RP|DRP)
        exec_commands RP_nodes
        exec_commands All_nodes
        ;;
    LC)
        exec_commands LC_nodes
        exec_commands All_nodes
        ;;
    esac        

    print_main_heading "show tech-support routing isis 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
