#!/pkg/bin/ksh
#!/usr/bin/ksh
#
# Copyright (c) 2003-2017 by cisco Systems, Inc.
# All rights reserved.
#----------------------------------------------------------------------

# Find if the current location is standby RP.
# $1: process name (ex: te_control, rsvp)
# $2: location string (ex: 0/0/CPU0, 0/1/CPU0)
is_loc_standby() {
    # We parse the output of show place prog command to extract the 
    # location of active and standby
    local output=""
    # Use "show placement program xtc_agent" to get active/standby RP
    local string=$(placed_show -p $1 | grep -E "CPU.")
    local str
    for str in $string
    do
        output="$output "$(echo $str | grep -E "CPU.")
    done

    index=0
    for __location in $output; do
        nodes_with_trace[$index]=$__location
        index=$index+1
    done

    if [[ $2 = ${nodes_with_trace[1]} ]];then
        #true
        return 0
    else
        #false
        return 1
    fi
}

# Find if the current location is active RP.
# $1: process name (ex: te_control, rsvp)
# $2: location string (ex: 0/0/CPU0, 0/1/CPU0)
is_loc_active() {
    # We parse the output of show place prog command to extract the 
    # location of active and standby
    local output=""
    # Use "show placement program xtc_agent" to get active/standby RP
    local string=$(placed_show -p $1 | grep -E "CPU.")
    local str
    for str in $string
    do
        output="$output "$(echo $str | grep -E "CPU.")
    done

    index=0
    for __location in $output; do
        nodes_with_trace[$index]=$__location
        index=$index+1
    done

    if [[ $2 = ${nodes_with_trace[0]} ]];then
        #true
        return 0
    else
        #false
        return 1
    fi
}

# Return the ksh command according to the platform.
get_ksh_show_platform() {
    
    if [ "$platform" == "HFR" ] || [ "$platform" == "CRS" ]; then
        echo "shelfmgr_show_hfr -e"
    elif [ "$platform" == "ASR9k" ] || [ "$platform" == "ASR9K" ] || 
        [ "$platform" == "viking" ]; then
        echo "show_platform_vkg -e" 
    elif [ "$platform" == "PANINI" ] || [ "$platform" == "panini" ]; then
        echo "show_platform_sysdb"
    else
        echo "show_platform"
    fi
}


# Return the ksh command according to the platform.
get_ksh_show_process_blocked() {
    
    if [[ "$platform" = "PANINI" || "$platform" = "panini" ]]; then
        echo "sh_proc_ng_blocked"
    else
        echo "show_processes -b"
    fi
}


# return the ksh command according to the platform.
# $1: the name of the process to show
get_ksh_show_process_procname() {
    
    if [ "$platform" == "enxr" ]; then
        echo "sysmgr_show_enxr -o -p $1"
    else
        echo "sysmgr_show -o -p $1"
    fi
}


# return the ksh command according to the platform.
get_ksh_show_redundancy() {
    
    if [ "$platform" == "enxr" ]; then
        echo "show_rmf_sysdb"
    else
        echo "redcon_show"
    fi
}


# return the ksh command according to the platform.
get_ksh_show_clock() {
    
    if [ "$platform" == "enxr" ]; then
        echo "iosclock -e 0x0"
    else
        echo "iosclock -d 0x0"
    fi
}


# return the ksh command according to the platform.
get_ksh_show_version() {
    
    if [ "$platform" == "panini" ]; then
        echo "ng_show_version"
    else
        echo "show_version"
    fi    
}



