#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# fsync_show_tech - Frequency synchronization show tech script
#
# February 2009, Rob James
#
# Copyright (c) 2009, 2016-2017, 2019 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment


# Parse the arguments to the script.
while [ "$#" -gt "0" ]; do
    case "$1" in
        *)  default_parser_function "$@"; shift $#;;
    esac
done

#
# Collect showtechs from neighbouring components
#
enable_techs "$arg_string" show_tech_ptp_main syncec_show_tech show_tech_gsp /pkg/bin/sysdb_show_tech_support_fast
set_max_depth 1

#
# get platform we are running on in order to make sure that the right version
# of certain commands gets run. Note that all spirit platforms set platform
# to panini.
#
get_platform

if [[ "$platform" = "flexr-asr9k" ]]; then
      #Setting platform as panini
      platform="panini"
fi

#
# Work out the platform dependant commands
#
if [[ "$platform" = "panini" ]]; then
    show_version_command='ng_show_version'
    show_proc_blocked_command='sh_proc_ng_blocked'
else
    show_version_command='show_version'
    show_proc_blocked_command='show_processes -b'
fi

# ***********************************************************
#  Show commands to be run by the show tech-support commands
# ***********************************************************

#############################################################
# Show commands that run once per system
sys_show_exec[1]='show frequency synchronization configuration-errors'
sys_show__ksh[1]='fsync_show_config_errors'
sys_show_exec[2]='show frequency synchronization interfaces brief'
sys_show__ksh[2]='fsync_show_interface -b'
sys_show_exec[3]='show frequency synchronization clock-interfaces brief'
sys_show__ksh[3]='fsync_show_clock -b'
sys_show_exec[4]='show frequency synchronization selection summary'
sys_show__ksh[4]='fsync_show_selection -s'
sys_show_exec[5]='show frequency synchronization selection'
sys_show__ksh[5]='fsync_show_selection'
sys_show_exec[6]='show frequency synchronization interfaces'
sys_show__ksh[6]='fsync_show_interface'
sys_show_exec[7]='show frequency synchronization interfaces summary'
sys_show__ksh[7]='fsync_show_interface -s'
sys_show_exec[8]='show frequency synchronization clock-interfaces'
sys_show__ksh[8]='fsync_show_clock'
sys_show_exec[9]='show logging'
sys_show__ksh[9]='show_logging'
sys_show_exec[10]='show running-config'
sys_show__ksh[10]='nvgen -c -l 1 -t 1 -o 1 '
sys_show_exec[11]='show configuration history'
sys_show__ksh[11]='cfgmgr_show_history -s -f -n 0x5dc -t all -b'
sys_show_exec[12]='show configuration commit changes - for each commit ID'
sys_show__ksh[12]='show_tech_config_history'
sys_show_exec[13]='show version'
sys_show__ksh[13]=$show_version_command
sys_show_exec[14]='show interfaces summary'
sys_show__ksh[14]='show_interface -a -o 0x3'
sys_show_exec[15]='show interfaces brief'
sys_show__ksh[15]='show_interface -a -o 0x2'
sys_show_exec[16]='show configuration failed startup'
sys_show__ksh[16]='cfgmgr_show_failed -l'
sys_show_exec[17]='show frequency synchronization internal-database'
sys_show__ksh[17]='fsync_show_db'
sys_show__ksh[18]=''


#############################################################
# Commands that run on RP and LC nodes

# Trace
rplc_trace_exec[1]='show frequency synchronization trace'
rplc_trace__ksh[1]='fsync_show_ltrace'
rplc_trace__ksh[2]=''

# Show commands
rplc_show_exec[1]='show process blocked'
rplc_show__ksh[1]=$show_proc_blocked_command
rplc_show_exec[2]='show processes fsyncmgr'
rplc_show__ksh[2]='sysmgr_show -o -p fsyncmgr'
rplc_show__ksh[3]=''


#############################################################
# Commands that run on all SCs
sc__ksh[1]=''

#############################################################
# Commands that run on all SPs
sp__ksh[1]=''

#############################################################
# Commands that run on all RPs and DRPs
rp_exec[1]='show processes fsyncglobal'
rp__ksh[1]='sysmgr_show -o -p fsyncglobal'
rp_exec[2]='show gnss-receiver'
rp__ksh[2]='gnssmgr_show_receiver'
rp_exec[3]='show gnss-receiver trace'
rp__ksh[3]='gnss_show_ltrace'
rp__ksh[4]=''

#############################################################
# Script

display() {
    print_main_heading "show tech-support frequency synchronization"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys_show
    else
        case "$__cardtype" in
        "RP")
            exec_commands rplc_trace
            exec_commands rplc_show
            exec_commands rp
            ;;
        "DRP")
            exec_commands rplc_trace
            exec_commands rplc_show
            exec_commands rp
            ;;
        "LC")
            exec_commands rplc_trace
            exec_commands rplc_show
            ;;
        esac
    fi

    print_main_heading "show tech-support frequency synchronization complete"
}


. /pkg/bin/show_tech_file_fragment

