#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_ipsub - Show tech-support script for Ipsub
#
# February 2011, Mahesh Kelkar
# August 2012, Deepak Naik
#
# Copyright (c) 2011-2014, 2017 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

# Initialise any variables used. 
                                                       
summary=0
__cardtype="unspecified"

# Parse the arguments to the script.
# Usage: 
# 
# -b  : Run commands that display summary information
#     -N) location="$2"; shift 2;;
while [ $# -gt 0 ]; do
  case "$1" in
     -B) summary=1; shift 1;;
     -t) __cardtype="$2"; shift 2;;
     *)  default_parser_function "$@"; shift $#;;
  esac
done

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

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

node_name_internal=`uname -n`
node_number=`node_conversion -i $node_name_internal`

PLATFORM_TYPE=`uname -m`

rplc_summary_option=""
if [ $summary -eq 1 ]; then
    rplc_summary_option="-b"
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. 

###############################################################################
# Show commands that run once per LR                                          #
###############################################################################
sys_exec[1]='show version'

sys_exec[2]='show install active'

if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
   sys__ksh[1]='ng_show_version'
   sys__ksh[2]='sdr_instcmd show install active'
else
   sys__ksh[1]='show_version'
   sys__ksh[2]='instcmd show install active'
fi

sys_exec[3]=''
sys__ksh[3]=''


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


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

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

rp_exec[3]='show cli history detail'
rp__ksh[3]='show_parser_history -h 0x2'

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

rp_exec[5]='show context location all'
if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
   rp__ksh[5]='corehelper_context -c 0x1 -n all'
else
   rp__ksh[5]='dumper_context -c 0x1 -n all'
fi

rp_exec[6]='show clock'
rp__ksh[6]='iosclock -d 0x0'

rp_exec[7]='show ipsubscriber ma disconnect-history'
rp__ksh[7]='show_ipsub_ma_discon_hist'

rp_exec[8]=''
rp__ksh[8]=''

###############################################################################
# Show commands that run on all RP or LC                                      #
###############################################################################
# Command  - show local
rplc_exec[1]='show processes blocked location $location'
if [[ "${PLATFORM_TYPE}" == "x86_64" ]]; then
   rplc__ksh[1]='sh_proc_ng_blocked -l $node_number'
else
   rplc__ksh[1]='show_processes -b -n $node_number'
fi

rplc_exec[2]='show ipsubscriber summary location $location internal'
rplc__ksh[2]='show_ipsub_ma_common -S -T -l $node_number'

rplc_exec[3]='show ipsubscriber access-interface location $location internal'
rplc__ksh[3]='show_ipsub_ma_parent_intf -l $node_number -T'

rplc_exec[4]='show ipsubscriber interface location $location internal'
rplc__ksh[4]='show_ipsub_ma_intf -T -l $node_number'

rplc_exec[5]='show ipsubscriber ma internal vrf location $location'
rplc__ksh[5]='show_ipsub_ma_internal -v -l $node_number'

rplc_exec[6]='show ipsubscriber ma internal fsol location $location'
rplc__ksh[6]='show_ipsub_ma_internal -f -l $node_number'

rplc_exec[7]='show ipsubscriber ma internal events location $location'
rplc__ksh[7]='show_ipsub_ma_internal -e -l $node_number'

rplc_exec[8]='show ipsubscriber ma trace location $location'
rplc__ksh[8]='show_ipsub_ma_ltrace -i $node_number'

rplc_exec[9]='show ipsubscriber ea trace location $location'
rplc__ksh[9]='show_ipsub_ea_ltrace -i $node_number'

rplc_exec[10]='show vaccesslib trace location $location'
rplc__ksh[10]='show_vaccess_lib_ltrace -i $node_number'

rplc_exec[11]='show vaccesslib rib-util trace process ipsub_ma location $location'
rplc__ksh[11]='show_vaccess_lib_rib_util_ltrace -P ipsub_ma -A -i $node_number'

rplc_exec[12]='show process ipsub_ma location $location'
rplc__ksh[12]='sysmgr_show -o -p ipsub_ma -n $node_number'

rplc_exec[13]='show process ipsub_ea location $location'
rplc__ksh[13]='sysmgr_show -o -p ipsub_ea -n $node_number'

rplc_exec[14]='show ipsubscriber ma disconnect-history location $location'
rplc__ksh[14]='show_ipsub_ma_discon_hist -L $node_number'

rplc_exec[15]='show ipsubscriber ma internal chunks location $location'
rplc__ksh[15]='show_ipsub_ma_internal -c -l $node_number'

rplc_exec[16]=''
rplc__ksh[16]=''

# Command  - show local (summary)
rplc_summary_exec[1]='show ipsubscriber summary location $location internal'
rplc_summary__ksh[1]='show_ipsub_ma_common -S -T -l $node_number'

rplc_summary_exec[2]='show ipsubscriber access-interface brief location $location'
rplc_summary__ksh[2]='show_ipsub_ma_parent_intf -l $node_number -b'

rplc_summary_exec[3]='show ipsubscriber interface brief location $location'
rplc_summary__ksh[3]='show_ipsub_ma_intf -l $node_number -b'

rplc_summary_exec[4]='show ipsubscriber ma internal location $location'
rplc_summary__ksh[4]='show_ipsub_ma_internal -l $node_number'

rplc_summary_exec[5]='show ipsubscriber ma internal statistics location $location'
rplc_summary__ksh[5]='show_ipsub_ma_internal -t -l $node_number'

rplc_summary_exec[6]=''
rplc_summary__ksh[6]=''


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

display() {

    # Print the output heading 
    print_main_heading "show tech-support ipsubscriber"

    if [ "$__cardtype" == "SYS" ]; then
            exec_commands sys
    else
        case "$__cardtype" in
        "DRP"|"RP")
            exec_commands rp
            exec_commands rplc 
            if [ $summary -eq 0 ]; then
                exec_commands rplc_summary
            fi
            ;;
        "LC")
            exec_commands rplc
            if [ $summary -eq 0 ]; then
                exec_commands rplc_summary
            fi
            ;;
        esac
    fi

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