#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# ospf_show_tech_database - OSPFv3 show tech-support database script
#
# Feb 2017, Manish Kumar
# Copyright (c) 2017-2018 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_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;;
     -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]=""
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 ospfv3 $process_name $standby database"
    ospf__ksh[$index]="ospfv3_show_dbase -T $process_args -v + -L $rp_role -X 0x0 -Y 0x0 -f 0x0 -s 0x0 -o 0x0 -a 0x0 -r 0x0 -i 0x0 -l 0x0 -m 0x0 -n 0x0 -d 0x0 -g 0x0 -k 0x0 -w 0x0"
    index=$((index + 1))

    ospf_exec[$index]="show ospfv3 $process_name $standby vrf all database"
    ospf__ksh[$index]="ospfv3_show_dbase -T $process_args -v all -L $rp_role -X 0x0 -Y 0x0 -f 0x0 -s 0x0 -o 0x0 -a 0x0 -r 0x0 -i 0x0 -l 0x0 -m 0x0 -n 0x0 -d 0x0 -g 0x0 -k 0x0 -w 0x0"
    index=$((index + 1))

done
    ospf_exec[$index]=""
    ospf__ksh[$index]=""
    index=1
  
 
#
# 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 ospfv3 databases"
 
   if [ "$__cardtype" == "SYS" ]; then
           exec_commands ospf 
   fi    
      
       # Print the closing heading. 
       print_main_heading "show tech-support routing ospfv3 databases"
  }
  
### This mandatory bit calls display() and handles output redirection.
. /pkg/bin/show_tech_file_fragment
 
