#!/pkg/bin/ksh

# -----------------------------------------------------------------------------
# show_config_sram - Provides output for 'show_config_sram' for the 
#                    'Show tech-support bundle'
#
# Sept 2018, Ben Tamer
#
# Copyright (c) 2018-2019 by cisco Systems, Inc.
# All rights reserved.
#------------------------------------------------------------------------------

# This script  will be called by 'show_tech_fast_bundle_common'. This script is passed
# the node number as a parameter and will call 'uidb_show configsram' for each bundle
# member (per NPU)
  
#
# Load the script provided by show-tech infra, which provides worker functions
#
. /pkg/bin/show_tech_main_fragment

node_number="$1" 
        
#
# The display() function is the one that does all the work - called by us as 
# this is a worker script.
#
display() {
    if [[ -x `which prm_np_show 2>/dev/null` ]]; then
            
        #get the list of ports (with port 'type') per NPU and output the mapping
        portmap=$(prm_np_show portmap -s "$node_number")
        bundle_lines=$(echo "$portmap" | grep -E '(bundle|NP: [0-9])')
        echo "Bundle Port to NPU Mapping:"
        echo "$bundle_lines"
        echo ""

        # search throught the list of ports for any port type of 'bundle'
        for line in ${bundle_lines[@]}; do

            # get the NPU number
            if [[ "$line" == *"NP"* ]] 
            then
                mynp=$(echo "$line" | grep -o '[0-9]\{1,2\}')
            else
                #get the port number of any port type of 'bundle'
                if [[ "$line" == *"bundle"* ]] 
                then
                    myport=$(echo "$line" |  grep -o '[0-9]\{1,5\}')
                    
                    #call 'uidb_show configsram' to dump the SRAM data for the 'bundle' member
                    uidb_show configsram -p "$myport" -e "$mynp" -s "$node_number"
                fi
            fi
        done
    else
        echo 'Not available for this platform.'
    fi
}

display
