#!/pkg/bin/ksh
#----------------------------------------------------------------------
# show_tech_pce_fast - Show tech-support script for XTC
#
# August 2016, Samuel Sidor
#
# Copyright (c) 2016 by cisco Systems, Inc.
# All rights reserved.
# Processes: pce_server
#----------------------------------------------------------------------


# 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

# Fast tech-support documentation: EDCS-631313

__cardtype="unspecified"
proc_str="pce_server"

# Parse the arguments to the script.
# Usage: 
# 
#    show_tech_pce_fast
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

# 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; showtech infra expects the command
# exactly the way it was Dentered.
# Use "\" ahead of any special character (eg. |) used in the command line.

# SYS commands
i=1
sys_exec[$i]='show version'
if [[ "$platform" = "panini" ]]; then
    sys__ksh[$i]='ng_show_version'
else
    sys__ksh[$i]='show_version'
fi
((i++))

sys_exec[$i]='show install active'
if [[ "$platform" = "panini" ]]; then
    sys__ksh[$i]='sdr_instcmd show install active'
else
    sys__ksh[$i]='instcmd show install active'
fi
((i++))

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

sys_exec[$i]='show running-config'
sys__ksh[$((i++))]='nvgen -c -l 1 -t 1 -o 1'

sys_exec[$i]='show proc blocked'
if [[ "$platform" = "panini" ]]; then
    sys__ksh[$i]='sh_proc_ng_blocked'
else
    sys__ksh[$i]='show_processes -b'
fi
((i++))

sys_exec[$i]='show processes $proc_str'
sys__ksh[$((i++))]='sysmgr_show -o -p $proc_str'

sys_exec[$i]=''
sys__ksh[$i]=''

# RP commands
i=1
rp_exec[$i]='show pce lsp private'
rp__ksh[$((i++))]='pce_show -a 0x1 -c 0x5 -s -d -t 0x3'
rp_exec[$i]='show pce lsp summary'
rp__ksh[$((i++))]='pce_show -a 0x1 -c 0x5 -s -d -t 0x4'
rp_exec[$i]='show pce ipv4 topology private'
rp__ksh[$((i++))]='pce_show -a 0x1 -c 0x1 -s -d -t 0x3'
rp_exec[$i]='show pce ipv4 topology summary'
rp__ksh[$((i++))]='pce_show -a 0x1 -c 0x1 -s -d -t 0x4'
rp_exec[$i]='show pce ipv4 peer private'
rp__ksh[$((i++))]='pce_show -a 0x1 -c 0x4 -s -d -t 0x3'
rp_exec[$i]='show pce ipv4 peer summary'
rp__ksh[$((i++))]='pce_show -a 0x1 -c 0x4 -s -d -t 0x4'
rp_exec[$i]='show pce ipv4 prefix'
rp__ksh[$((i++))]='pce_show -a 0x1 -c 0x3 -s -d -t 0x1'
rp_exec[$i]='show pce ipv6 topology private'
rp__ksh[$((i++))]='pce_show -a 0x2 -c 0x1 -s -d -t 0x3'
rp_exec[$i]='show pce ipv6 topology summary'
rp__ksh[$((i++))]='pce_show -a 0x2 -c 0x1 -s -d -t 0x4'
rp_exec[$i]='show pce ipv6 prefix'
rp__ksh[$((i++))]='pce_show -a 0x2 -c 0x3 -s -d -t 0x1'
rp_exec[$i]='show pce association'
rp__ksh[$((i++))]='pce_show -a 0x1 -c 0x7 -s -d -t 0x1'

# Traces
rp_exec[$i]='show pce trace'
rp__ksh[$((i++))]='pce_show_ltrace'
rp_exec[$i]=''
rp__ksh[$i]=''

# LC commands
i=1
lc_exec[$i]=''
lc__ksh[$i]=''


# A function called display() must be provided that calls the functions to 
# run the required show commands. The display() function is called in 
# /pkg/bin/show_tech_comp_file_frag

display() {
    # Print the output heading 
    print_main_heading "show tech-support pce"

    case "$__cardtype" in
    "SYS")
        exec_commands sys
    ;;
    "DRP"|"RP")
        exec_commands rp
    ;;
    "LC")
        exec_commands lc
    ;;
    esac

    # Print the closing heading. 
    print_main_heading "show tech-support pce 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

