#!/pkg/bin/ksh
# --------------------------------------------------------------------------
# dhcpc_client_show_tech - Show tech-support script for dhcp client
#
# June 2013, Madhusudanan S
#
# Copyright (c) 2013-2015 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 variables
__cardtype="unspecified"
int_node_name=`uname -n`
ext_node_name=`node_conversion -E $int_node_name`
fq_nodeid=`node_conversion -i $int_node_name`
location=$ext_node_name

# Parse the arguments to the script.
# None needed for dhcp client at this time.

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

#Platform specific commands
# Detect on which platform are we goin to exec cmd
uname -a | grep hfr > /dev/null 2>&1;  RC=$?
uname -a | grep prp > /dev/null 2>&1;  RC1=$?
uname -a | grep enxr > /dev/null 2>&1; RC2=$?
uname -a | grep asr9k > /dev/null 2>&1; RC3=$?
uname -a | grep xrvr > /dev/null 2>&1; RC4=$?

if [[ "$RC" -eq "0" ]]; then
    platform="hfr"
elif [[ "$RC1" -eq "0" ]]; then
    platform="prp"
elif [[ "$RC2" -eq "0" ]]; then
    platform="enxr"
elif [[ "$RC3" -eq "0" ]]; then
    platform="viking"
elif [[ "$RC4" -eq "0" ]]; then
    platform="xrvr"
else
    platform="panini"
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.
#
# For all of these the __ksh variable is the process that will actually be
# spawned, the _exec variable is just a string that is printed in the output to
# describe it.
#

#######################################################################
###              Show dhcpv4 client system level info               ###
#######################################################################
if [[ "$platform" = "panini" ]]; then
    show_dhcpv4_client_sys_exec[1]="show version"
    show_dhcpv4_client_sys__ksh[1]="ng_show_version"
else 
    show_dhcpv4_client_sys_exec[1]="show version"
    show_dhcpv4_client_sys__ksh[1]="show_version"
fi

if [[ "$platform" = "panini" ]]; then
    show_dhcpv4_client_sys_exec[2]="show install active"
    show_dhcpv4_client_sys__ksh[2]="sdr_instcmd show install active"
else 
    show_dhcpv4_client_sys_exec[2]="show install active"
    show_dhcpv4_client_sys__ksh[2]="instcmd show install active"
fi

show_dhcpv4_client_sys_exec[3]="show running-config"
show_dhcpv4_client_sys__ksh[3]="nvgen -c -l 1 -t 1 -o 1"

show_dhcpv4_client_sys_exec[4]="show process dhcpcd location all"
show_dhcpv4_client_sys__ksh[4]="sysmgr_show -o -p xr_dhcpcd -n all"

show_dhcpv4_client_sys_exec[5]="show ipv4 vrf all interface brief"
show_dhcpv4_client_sys__ksh[5]="show_ip_interface -b -v all"

show_dhcpv4_client_sys_exec[6]=""
show_dhcpv4_client_sys__ksh[6]=""

#######################################################################
###               Show dhcpv4 client with location                  ###
#######################################################################
show_dhcpv4_client_rplc_exec[1]="show dhcp ipv4 client location $location detail debug"
show_dhcpv4_client_rplc__ksh[1]="dhcpcd_show_client -d -g -L $fq_nodeid"

show_dhcpv4_client_rplc_exec[2]="show dhcp ipv4 client location $location statistics-all debug"
show_dhcpv4_client_rplc__ksh[2]="dhcpcd_show_client -s -g -L $fq_nodeid"

show_dhcpv4_client_rplc_exec[3]="show dhcp ipv4 client trace location $location"
show_dhcpv4_client_rplc__ksh[3]="dhcpcd_show_client_ltrace -A"

show_dhcpv4_client_rplc_exec[4]="show ipv4 ma trace location $location"
show_dhcpv4_client_rplc__ksh[4]="show_ipv4_ma_ltrace -i $fq_nodeid"

show_dhcpv4_client_rplc_exec[5]="show ipv4 ma trace error location $location"
show_dhcpv4_client_rplc__ksh[5]="show_ipv4_ma_ltrace -i $fq_nodeid -E"

show_dhcpv4_client_rplc_exec[6]=""
show_dhcpv4_client_rplc__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 dhcp ipv4 client"

     if [ "$__cardtype" = "SYS" ]; then
          exec_commands show_dhcpv4_client_sys
     else
          case "$__cardtype" in
           "DRP"|"RP"|"LC")
           exec_commands show_dhcpv4_client_rplc
         ;;
        esac
     fi

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

