#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# ospf_show_tech - OSPF show tech-support script
#
# Oct 2004, Larus Maxwell
# Jul 2014, Balaji Venkatraman
#
# Copyright (c) 2004-2005, 2007, 2009, 2014, 2016 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

### Required by show_tech
. /pkg/bin/show_tech_main_fragment


### List the sets of show commands to 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.

    index=1
## Command set 1 - configuration & other basic info
### Variable initialization
standby=""
rp_role="active"
process_name=""
process_args="+"
__cardtype="unspecified"
showtech_argv="" 
showtech_argc="0"
skip_traces="0"
skip_active="0"
skip_standby="0"
# Read in the arguments to the script, setting mode
# according to these arguments.
# Note that it is important for security reasons that users can only enter
# alphanumeric filenames and nodes and that anywhere calling this script must
# enforce this.
  
while [ $# -gt 0 ]; do
  case "$1" in
     -P) process_name="$2"; shift 2;;
     -ST) skip_traces=1; shift 1;;
     -SA) skip_active=1; shift 1;;
     -SS) skip_standby=1; shift 1;;
     -t) __cardtype="$2"; shift 2;;
      *)  showtech_argv="$showtech_argv $1"; (( showtech_argc+=1 )); shift 1;;
    esac
  done
  
config_exec[$index]="show version"
if [[ "$platform" = "panini" ]]; then
  config__ksh[$index]="ng_show_version"
else
  config__ksh[$index]="show_version"
fi
    index=$((index + 1))

config_exec[$index]="show install active"
if [[ "$platform" = "panini" ]]; then
  config__ksh[$index]="sdr_instcmd show install active"
else
  config__ksh[$index]="instcmd show install active"
fi
    index=$((index + 1))
 
config_exec[$index]="show redundancy"
config__ksh[$index]="redcon_show"
    index=$((index + 1))

config_exec[$index]="show running router ospf $process_name"
config__ksh[$index]="nvgen -c -q gl/ipv4-ospf/proc/"
    index=$((index + 1))
 
config_exec[$index]="show process ospf location all"
config__ksh[$index]="sysmgr_show -o -p ospf -n all"
    index=$((index + 1))
if [ "$process_name" = "" ]; then
   config__ksh[$index]="nvgen -c -q gl/ipv4-ospf/proc/"
else
   config__ksh[$index]="nvgen -c -q gl/ipv4-ospf/proc/$process_name/"
fi
    index=$((index + 1))
 
config_exec[$index]=""
config__ksh[$index]=""
    index=1  
## Command set 2 - ospf commands
for rp_role in "active" "standby"
    do
    if [[ "$skip_active" == 1 ]]  && [[ "$rp_role" == "active" ]]; then
        continue
    fi

    if [[ "$skip_standby" == 1 ]]  && [[ "$rp_role" == "standby" ]]; then
        continue
    fi

    if [ "$rp_role" == "active" ] ; then
        standby=""
    else
        standby="standby"
    fi    

    ospf_exec[$index]="show ospf $process_name $standby"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -i"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby summary"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -U"
    index=$((index + 1))

    ospf_exec[$index]="show ospf $process_name $standby vrf all summary"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role -U"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby interface"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -I -X 0x0 -Y 0x0 -f 0x0  -b 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all interface"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role -I -X 0x0 -Y 0x0 -f 0x0 -b 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby statistics interface summary"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -c -X 0x0 -Y 0x0 -f 0x0 -p 0x0 -s 0x1"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all statistics interface summary"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role -c -X 0x0 -Y 0x0  -f 0x0 -p 0x0 -s 0x1"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby virtual-links"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -V"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all virtual-links"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role -V"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all sham-links"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role -X"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby neighbor detail"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role  -N -X 0x0 -Y 0x0 -f 0x0 -i 0x0 -a 0x0 -d 0x1 -j 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all neighbor detail"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role  -N -X 0x0 -Y 0x0 -f 0x0 -i 0x0 -a 0x0 -d 0x1 -j 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby database database-summary count-self"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role  -D -X 0x0 -Y 0x0 -f 0x0 -s 0x1 -q 0x1"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all database database-summary count-self"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role  -D -X 0x0 -Y 0x0 -f 0x0 -s 0x1 -q 0x1"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby database router self-originate"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role  -D -X 0x0 -Y 0x0 -f 0x0 -t 0x1 -o 0x1 -a 0x0 -r 0x0 -i 0x0 -l 0x0 -m 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all database router self-originate"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role  -D -X 0x0 -Y 0x0 -f 0x0 -t 0x1 -o 0x1 -a 0x0 -r 0x0 -i 0x0 -l 0x0 -m 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby database network self-originate"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role  -D -X 0x0 -Y 0x0 -f 0x0 -t 0x2 -o 0x1 -a 0x0 -r 0x0 -i 0x0 -l 0x0 -m 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all database network self-originate"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role  -D -X 0x0 -Y 0x0 -f 0x0 -t 0x2 -o 0x1 -a 0x0 -r 0x0 -i 0x0 -l 0x0 -m 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby statistics prot"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -P"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby statistics raw-io"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -O"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby statistics te"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -E"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby statistics spf"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -S"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby statistics rib-thread"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -r"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby statistics rib-batch"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -b"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby statistics nsr"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -n"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby message-queue"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -Q"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby border-routers"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -B"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all border-routers"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role -B"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby retransmission-list"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role  -R -X 0x0 -Y 0x0 -f 0x0 -i 0x0 -p 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all retransmission-list"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role  -R -X 0x0 -Y 0x0 -f 0x0 -i 0x0 -p 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby request-list"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role  -L -X 0x0 -Y 0x0 -f 0x0 -i 0x0 -p 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all request-list"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role  -L -X 0x0 -Y 0x0 -f 0x0 -i 0x0 -p 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby flood-list"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role  -F -X 0x0 -Y 0x0 -f 0x0 -p 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all flood-list"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role  -F -X 0x0 -Y 0x0 -f 0x0 -p 0x0"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby maxage-list"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -M"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all maxage-list"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role -M"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby bad-checksum"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -C"
    index=$((index + 1))
 
    ospf_exec[$index]="show ospf $process_name $standby vrf all bad-checksum"
    ospf__ksh[$index]="ospf_show -T $process_args -v all -l $rp_role -C"
    index=$((index + 1))

    ospf_exec[$index]="show ospf $process_name $standby statistics issu"
    ospf__ksh[$index]="ospf_show -T $process_args -v + -l $rp_role -s"
    index=$((index + 1))

done
    ospf_exec[$index]=""
    ospf__ksh[$index]=""
    index=1
  
## Command set 3 - non-ospf commands
 other_exec[$index]="show ipv4 interface brief"
 other__ksh[$index]="show_ip_interface -b -v default"
    index=$((index + 1))
 
 other_exec[$index]="show route summary detail"
 other__ksh[$index]="show_ipv4_rib -X 0x1 -Y 0x1 -Z ________ -V ________ -D ipv4  ________"
    index=$((index + 1))
 
 other_exec[$index]="show route ipv4 multicast summary detail"
 other__ksh[$index]="show_ipv4_rib -X 0x1 -Y 0x2 -Z ________ -V ________ -D ipv4  ________"
    index=$((index + 1))
 
 other_exec[$index]="show route vrf all ipv4 summary"
 other__ksh[$index]="show_ipv4_rib -X 0x1 -Y 0x1 -Z all -V ________ -S ipv4 all"
    index=$((index + 1))
 
 other_exec[$index]="show logging process ospf $process_name"
 other__ksh[$index]="show_logging -p ospf $process_name"
    index=$((index + 1))
 
 other_exec[$index]=""
 other__ksh[$index]=""
    index=1
## Command set 4 - ospf traces
trace_exec[$index]="show ospf $process_name active trace all"
trace__ksh[$index]="ospf_get_all_traces -T $process_args -v + -l active -Z"
    index=$((index + 1))
trace_exec[$index]="show ospf $process_name standby trace all"
trace__ksh[$index]="ospf_get_all_traces -T $process_args -v + -l standby -Z"
    index=$((index + 1))
 
trace_exec[$index]=""
trace__ksh[$index]=""
 
 
#
# Call the showtech infra default parser - using set to recreate the $#, $@,
# etc. - "--" is necessary so set doesn"t try to interpret any of the
# arguments we are passing through
#
if [[ $showtech_argc -ne 0 ]]; then
  set -- $showtech_argv
  default_parser_function $@
fi
 
if [ "$__cardtype" == "unspecified" ]; then
  __cardtype=`node_type`
fi
  
### display - run the show commands
### MUST be named display.
### Called by show_tech_file_fragment().
display() {
 
   # Print the output heading
   print_main_heading "show tech-support routing ospf"
 
   if [ "$__cardtype" == "SYS" ]; then
           exec_commands Basic
           exec_commands config
           exec_commands ospf
           exec_commands other
 
           if [ "$skip_traces" == "0" ]; then
               exec_commands trace
           fi
   fi    
      
       # Print the closing heading. 
       print_main_heading "show tech-support routing ospf complete"
  }
  
### This mandatory bit calls display() and handles output redirection.
. /pkg/bin/show_tech_file_fragment
 
