#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_timing - Shared show tech-support for RSP4 timing
# Cisco_user: Gaurav Sharma(gaurash6)
# Copyright (c) 2016-2019 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

# Load the script fragment containing 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

# Parse the arguments to the script.
__cardtype="unspecified"

while [ "$#" -gt "0" ]; do
   case "$1" in
        -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

################################################################################
# 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.
###############################################################################

#####################################################################
#  Commands that run on SYS node (i.e. the node where the show tech
#  command is issued from).
#####################################################################


cmd_index=1
sys_exec[$cmd_index]='show platform'
sys__ksh[$cmd_index]='show_platform_sysdb'
((cmd_index++))

sys_exec[$cmd_index]='show spp node-counters location $location'
sys__ksh[$cmd_index]='spp_sysdb_get -L $fq_nodeid node_counters'
((cmd_index++))

sys_exec[$cmd_index]='show spp node'
sys__ksh[$cmd_index]='spp_sysdb_get -M node_stats'
((cmd_index++))

sys_exec[$cmd_index]='show spp graph'
sys__ksh[$cmd_index]='spp_sysdb_get -M node_graph '
((cmd_index++))

sys_exec[$cmd_index]='show spp offload lib trace'
sys__ksh[$cmd_index]='swoff_show_trace'
((cmd_index++))

sys_exec[$cmd_index]='show frequency synchronization selection'
sys__ksh[$cmd_index]='fsync_show_selection'
((cmd_index++))

sys_exec[$cmd_index]='show frequency synchronization interfaces'
sys__ksh[$cmd_index]='fsync_show_interface'
((cmd_index++))

sys_exec[$cmd_index]='show frequency synchronization clock-interfaces'
sys__ksh[$cmd_index]='fsync_show_clock'
((cmd_index++))

sys_exec[$cmd_index]='show ptp platform servo'
sys__ksh[$cmd_index]='ptp_pd_show_servo'
((cmd_index++))

sys_exec[$cmd_index]='show ptp dataset time-properties'
sys__ksh[$cmd_index]='ptp_show_datasets -t '
((cmd_index++))

sys_exec[$cmd_index]='show ptp platform trace'
sys__ksh[$cmd_index]='ptp_pd_show_ltrace'
((cmd_index++))

sys_exec[$cmd_index]='show ptp trace'
sys__ksh[$cmd_index]='ptp_show_ltrace'
((cmd_index++))

sys_exec[$cmd_index]='show ptp dataset parent'
sys__ksh[$cmd_index]='ptp_show_datasets -p'
((cmd_index++))

sys_exec[$cmd_index]='show ptp dataset current'
sys__ksh[$cmd_index]='ptp_show_datasets -c'
((cmd_index++))

sys_exec[$cmd_index]='show ptp dataset default'
sys__ksh[$cmd_index]='ptp_show_datasets -d'
((cmd_index++))

sys_exec[$cmd_index]='show ptp packet-counters location $location'
sys__ksh[$cmd_index]='ptp_show_packets -h $fq_nodeid'
((cmd_index++))

sys_exec[$cmd_index]='show ptp advertised-clock'
sys__ksh[$cmd_index]='ptp_show_advertized'
((cmd_index++))

sys_exec[$cmd_index]='show controllers timing controller clock'
sys__ksh[$cmd_index]='syncctrl_show clock'
((cmd_index++))

sys_exec[$cmd_index]='show controllers timing controller src'
sys__ksh[$cmd_index]='syncctrl_show src'
((cmd_index++))

sys_exec[$cmd_index]='show controllers timing input-clock status location $location'
sys__ksh[$cmd_index]='tmgctrl_core_show_ctrl -C -H $fq_nodeid'
((cmd_index++))

sys_exec[$cmd_index]='show controllers timing pll status location $location'
sys__ksh[$cmd_index]='tmgctrl_core_show_ctrl -P -H $fq_nodeid'
((cmd_index++))

sys_exec[$cmd_index]='show controllers timing tod snapshot location $location'
sys__ksh[$cmd_index]='tmgctrl_core_show_ctrl -T -H $fq_nodeid'
((cmd_index++))

sys_exec[$cmd_index]='show controllers timing controller trace all location $location'
sys__ksh[$cmd_index]='show_sync_common_trace -D -h $fq_nodeid'
((cmd_index++))

sys_exec[$cmd_index]='show controllers gnssea ltrace location $location'
sys__ksh[$cmd_index]='show_gnss_ea_ltrace -I .* -i $fq_nodeid -T .*'
((cmd_index++))

sys_exec[$cmd_index]='show gnss-receiver 0 location $location'
sys__ksh[$cmd_index]='gnssmgr_show_receiver -r 0 -h $fq_nodeid'
((cmd_index++))

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

sys_exec[$cmd_index]=''
sys__ksh[$cmd_index]=''

platform_specific_clis() {
    if [ -f /pkg/bin/show_tech_platform_specific_timing ]; then
        enable_techs ""  /pkg/bin/show_tech_platform_specific_timing
    fi
}

##################################################################
# Run show tech commands
##################################################################
display() {

    print_main_heading "show tech-support  platform timing"

    # Get the card_type: SYS|RP|DRP|LC.
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
        platform_specific_clis
    else
        case "$__cardtype" in
        "DRP"|"RP")
            exec_commands rp
            platform_specific_clis
            ;;
        esac
    fi

    print_main_heading "show tech-support  platform timing 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
