Blame TestTools/switch_methods.exp

Packit 857059
# BEGIN_ICS_COPYRIGHT8 ****************************************
Packit 857059
# 
Packit 857059
# Copyright (c) 2015, Intel Corporation
Packit 857059
# 
Packit 857059
# Redistribution and use in source and binary forms, with or without
Packit 857059
# modification, are permitted provided that the following conditions are met:
Packit 857059
# 
Packit 857059
#     * Redistributions of source code must retain the above copyright notice,
Packit 857059
#       this list of conditions and the following disclaimer.
Packit 857059
#     * Redistributions in binary form must reproduce the above copyright
Packit 857059
#       notice, this list of conditions and the following disclaimer in the
Packit 857059
#       documentation and/or other materials provided with the distribution.
Packit 857059
#     * Neither the name of Intel Corporation nor the names of its contributors
Packit 857059
#       may be used to endorse or promote products derived from this software
Packit 857059
#       without specific prior written permission.
Packit 857059
# 
Packit 857059
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 857059
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 857059
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit 857059
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
Packit 857059
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 857059
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit 857059
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Packit 857059
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Packit 857059
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 857059
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 857059
# 
Packit 857059
# END_ICS_COPYRIGHT8   ****************************************
Packit 857059
Packit 857059
#[ICS VERSION STRING: unknown]
Packit 857059
#########################################################################################
Packit 857059
# Name        : get_switch_lids_to_ports_map
Packit 857059
# Input       : cmd_host (where can opa commands be run to query SM)
Packit 857059
# Return      . A dict mapping LID to list of ports.
Packit 857059
# Description : Queries fabric return a dict with all lids of switches and ports that are enabled on them.  Only ports with LINK will be returned (no disconnected ports)
Packit 857059
#########################################################################################
Packit 857059
Packit 857059
Packit 857059
proc get_switch_lids_to_ports_map { cmd_host }  {
Packit 857059
Packit 857059
    # Build DOM from XML
Packit 857059
    set lids_dom [ run_opareport $cmd_host "-o lids" ]
Packit 857059
    set links_dom [ run_opareport $cmd_host "-o links" ]
Packit 857059
Packit 857059
    # Get all switches 
Packit 857059
    set lidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='SW']} ]
Packit 857059
    #puts "found [ llength $lidsList ] switch lids"
Packit 857059
Packit 857059
Packit 857059
    set lid_port_map [dict create]
Packit 857059
Packit 857059
    # For each switch node
Packit 857059
    foreach item $lidsList {
Packit 857059
	set lid [ $item getAttribute "LID"]
Packit 857059
	set guid [ [ $item selectNodes NodeGUID/text() ] nodeValue ]
Packit 857059
	#puts "lid:$lid; guid:$guid"	
Packit 857059
Packit 857059
	# Now, using guid as the key, poke into linksDOM to find the ports for this guid.
Packit 857059
	set portList [ $links_dom selectNodes /Report/LinkSummary/Link/Port\[NodeGUID='$guid'\]/PortNum/text() ]   
Packit 857059
	# Now you have a list of ports for specific LID/GUID.
Packit 857059
	#puts "found [ llength $portList ] ports"
Packit 857059
Packit 857059
	# List of ports per lid
Packit 857059
	set ports {} 
Packit 857059
	foreach port $portList {
Packit 857059
	    set portNum [ $port nodeValue ]
Packit 857059
Packit 857059
	    # If don't care about port 1 - skip it
Packit 857059
	    #` if { $portNum == 1 } {
Packit 857059
	    #    continue
Packit 857059
	    # }
Packit 857059
	    #puts "lid:$lid->port num:$portNum"
Packit 857059
Packit 857059
	    lappend ports $portNum
Packit 857059
Packit 857059
	    # I would have a data structure that is a map of lists, i.e.  
Packit 857059
	    #	LID1: port1, port2, port3
Packit 857059
	    #	LID2: port5,port6,port7
Packit 857059
	    #	…….                                        	    
Packit 857059
	}
Packit 857059
	#puts "Added [ llength $ports ] ports"
Packit 857059
Packit 857059
	dict set lid_port_map $lid $ports
Packit 857059
	#puts "lid_port_map size: [dict size $lid_port_map]"
Packit 857059
    }
Packit 857059
    
Packit 857059
    # Free memory
Packit 857059
    $lids_dom delete 
Packit 857059
    $links_dom delete
Packit 857059
Packit 857059
    return $lid_port_map
Packit 857059
}
Packit 857059
#########################################################################################
Packit 857059
# Name        : get_switch_lids_to_hfi_ports_map
Packit 857059
# Input       : cmd_host (where can opa commands be run to query SM)
Packit 857059
# Return      . A dict mapping LID to list of ports that are connect to HFIs.
Packit 857059
# Description : Queries fabric return a dict with all lids of switches and ports that are enabled and connected to HFIs on them.  Only ports with LINK will be returned (no disconnected ports)
Packit 857059
#########################################################################################
Packit 857059
Packit 857059
Packit 857059
proc get_switch_lids_to_hfi_ports_map { cmd_host }  {
Packit 857059
    # Build DOM from XML
Packit 857059
    set lids_dom [ run_opareport $cmd_host "-o lids" ]
Packit 857059
    set links_dom [ run_opareport $cmd_host "-o links" ]
Packit 857059
Packit 857059
    set lidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='SW']} ]
Packit 857059
#    puts "found [ llength $lidsList ] switch lids"
Packit 857059
#    puts "[$lidsList selectNodes NodeGUID/text()]"
Packit 857059
Packit 857059
    set lid_port_map [dict create]
Packit 857059
Packit 857059
    # For each switch node
Packit 857059
    foreach item $lidsList {
Packit 857059
	set lid [ $item getAttribute "LID"]
Packit 857059
	set guid [ [ $item selectNodes NodeGUID/text() ] nodeValue ]
Packit 857059
	#puts "lid:$lid; guid:$guid"	
Packit 857059
Packit 857059
	# Now, using guid as the key, poke into linksDOM to find the ports for this guid.
Packit 857059
        
Packit 857059
#	set portList [ $links_dom selectNodes /Report/LinkSummary/Link/Port\[NodeGUID='$guid'\]/PortNum/text() ]          
Packit 857059
	set linkList [ $links_dom selectNodes /Report/LinkSummary/Link ]
Packit 857059
        #puts "found [ llength $linkList ] links"
Packit 857059
        foreach link $linkList {
Packit 857059
          set portNodes [ $link getElementsByTagName Port ]
Packit 857059
          set port1 [lindex $portNodes 0]
Packit 857059
          set port2 [lindex $portNodes 1]
Packit 857059
          set port1_NodeType [[$port1 child all NodeType] asText]
Packit 857059
          set port2_NodeType [[$port2 child all NodeType] asText]
Packit 857059
          set port1_GUID [[$port1 child all NodeGUID] asText]
Packit 857059
          set port2_GUID [[$port2 child all NodeGUID] asText]
Packit 857059
          set port1_PortNum [[$port1 child all PortNum] asText]
Packit 857059
          set port2_PortNum [[$port2 child all PortNum] asText]
Packit 857059
          if { ([string compare $port1_GUID $guid]==0) || ([string compare $port2_GUID $guid]==0) } {
Packit 857059
            if { ([string compare $port1_NodeType SW]==0) && ([string compare $port2_NodeType FI]==0) } {
Packit 857059
	      lappend ports $port1_PortNum
Packit 857059
            } elseif {([string compare $port1_NodeType FI] == 0) && ([string compare $port2_NodeType SW] == 0)} {
Packit 857059
	      lappend ports $port2_PortNum
Packit 857059
            } 
Packit 857059
          } 
Packit 857059
           
Packit 857059
        }
Packit 857059
	#puts "Added [ llength $ports ] ports"
Packit 857059
Packit 857059
	dict set lid_port_map $lid $ports
Packit 857059
	#puts "lid_port_map size: [dict size $lid_port_map]"
Packit 857059
    }
Packit 857059
    
Packit 857059
    # Free memory
Packit 857059
    $lids_dom delete 
Packit 857059
    $links_dom delete
Packit 857059
Packit 857059
    return $lid_port_map
Packit 857059
}
Packit 857059
Packit 857059
Packit 857059
Packit 857059
#########################################################################################
Packit 857059
# Name		: get_lid_from_guid
Packit 857059
# Input		: guid
Packit 857059
# Return	: output of opasaquery -o lid -n $guid
Packit 857059
# Description	: get lid from guid
Packit 857059
#########################################################################################
Packit 857059
Packit 857059
Packit 857059
proc get_lid_from_guid { guid } {
Packit 857059
##
Packit 857059
## get_lid_from_guid
Packit 857059
## --------------
Packit 857059
## Obtain my guid
Packit 857059
## assumes that target_root_sh has already been called for the host
Packit 857059
        set cmd "lid=`opasaquery -o lid -n $guid`"
Packit 857059
        #debug_message "running: $cmd"
Packit 857059
        unix_cmd 60 "" $cmd
Packit 857059
        send_unix_cmd { echo "XXX${lid}XXX"; echo DONE }
Packit 857059
        expect_list 60 { "DONE" "XXX" "DONE" } { "exiting" "No such" "Error" "ERROR" "VAPI" "THH" } tmp
Packit 857059
        check_exit_status 60 0
Packit 857059
        regexp {DONE.*XXX *(.*) *XXX.*DONE} $tmp trash lid
Packit 857059
Packit 857059
        return "$lid"
Packit 857059
}
Packit 857059
Packit 857059
#########################################################################################
Packit 857059
# Name        : get_switchport_from_lid
Packit 857059
# Input       : cmd_host lid  *** LID must be in format 0x0001 (the same format as provided by opareport -o lids)
Packit 857059
# Return      . A list with element 1 being the SWITCH LID and element 2 being the SWITCH PORT where HFI with that LID is directly connected.  If not found the list [ none none ] will be returned
Packit 857059
# Description : For the lid of an HFI return the switch lid and port that that HFI is connected to
Packit 857059
#########################################################################################
Packit 857059
proc get_switchport_from_lid { cmd_host mylid }  {
Packit 857059
    set lids_dom [ run_opareport $cmd_host "-o lids" ]
Packit 857059
    set links_dom [ run_opareport $cmd_host "-o links" ]
Packit 857059
Packit 857059
    #################################################
Packit 857059
    #debug/dev only
Packit 857059
    #set lids_file  "lids.xml"
Packit 857059
    #set links_file "links.xml"
Packit 857059
    #################################################
Packit 857059
    # Open lids XML files
Packit 857059
    #set size [file size $lids_file]
Packit 857059
    #set fp [open $lids_file r]
Packit 857059
    #set lidsXML [read $fp $size]
Packit 857059
    #################################################
Packit 857059
    # Open links XML files
Packit 857059
    #set size [file size $links_file]
Packit 857059
    #set fp [open $links_file r]
Packit 857059
    #set linksXML [read $fp $size]
Packit 857059
    ##################################################
Packit 857059
    #set lids_dom [dom parse $lidsXML]
Packit 857059
    #set links_dom [dom parse $linksXML]
Packit 857059
Packit 857059
    set switchLidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='SW']} ]
Packit 857059
    set hfiLidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='FI']} ]
Packit 857059
Packit 857059
    set myguid "none"
Packit 857059
    set return_lid "none"
Packit 857059
    set return_port "none"
Packit 857059
Packit 857059
    foreach item $hfiLidsList {
Packit 857059
        set lid [ $item getAttribute "LID"]
Packit 857059
        set guid [ [ $item selectNodes NodeGUID/text() ] nodeValue ]
Packit 857059
        if { [string compare $lid $mylid] == 0 } {
Packit 857059
          set myguid $guid
Packit 857059
        }
Packit 857059
    }
Packit 857059
Packit 857059
    if { [string compare $myguid "none"] == 0 } {
Packit 857059
       error "Lid $mylid not found"
Packit 857059
    }
Packit 857059
Packit 857059
    # For each switch node
Packit 857059
    foreach item $switchLidsList {
Packit 857059
        set lid [ $item getAttribute "LID"]
Packit 857059
        set guid [ [ $item selectNodes NodeGUID/text() ] nodeValue ]
Packit 857059
Packit 857059
        set linkList [ $links_dom selectNodes /Report/LinkSummary/Link ]
Packit 857059
        #puts "found [ llength $linkList ] links"
Packit 857059
        foreach link $linkList {
Packit 857059
#          puts "processing link [$link asXML] [$link asText]"
Packit 857059
          set portNodes [ $link getElementsByTagName Port ]
Packit 857059
          set port1 [lindex $portNodes 0]
Packit 857059
          set port2 [lindex $portNodes 1]
Packit 857059
          set port1_NodeType [[$port1 child all NodeType] asText]
Packit 857059
          set port2_NodeType [[$port2 child all NodeType] asText]
Packit 857059
          set port1_GUID [[$port1 child all NodeGUID] asText]
Packit 857059
          set port2_GUID [[$port2 child all NodeGUID] asText]
Packit 857059
          set port1_PortNum [[$port1 child all PortNum] asText]
Packit 857059
          set port2_PortNum [[$port2 child all PortNum] asText]
Packit 857059
          target_root_sh $cmd_host
Packit 857059
          if { ([string compare $port1_GUID $myguid]==0) } {
Packit 857059
            #set return_lid $lid
Packit 857059
	    set return_lid [get_lid_from_guid $port2_GUID]
Packit 857059
            set return_port $port2_PortNum
Packit 857059
          } elseif { ([string compare $port2_GUID $myguid]==0) } {
Packit 857059
            #set return_lid $lid
Packit 857059
	    set return_lid [get_lid_from guid $port1_GUID]
Packit 857059
            set return_port $port1_PortNum
Packit 857059
          }
Packit 857059
Packit 857059
        }
Packit 857059
Packit 857059
    }
Packit 857059
    $lids_dom delete
Packit 857059
    $links_dom delete
Packit 857059
    return [list $return_lid $return_port]
Packit 857059
}
Packit 857059
Packit 857059
Packit 857059
#########################################################################################
Packit 857059
# Name        : get_switchport_from_guid
Packit 857059
# Input       : cmd_host guid
Packit 857059
# Return      . A list with element 1 being the SWITCH LID and element 2 being the SWITCH PORT where HFI with that LID is directly connected.  If not found the list [ none none ] will be returned
Packit 857059
# Description : For the lid of an HFI return the switch lid and port that that HFI is connected to
Packit 857059
#########################################################################################
Packit 857059
proc get_switchport_from_guid { cmd_host myguid }  {
Packit 857059
    set lids_dom [ run_opareport $cmd_host "-o lids" ]
Packit 857059
    set links_dom [ run_opareport $cmd_host "-o links" ]
Packit 857059
Packit 857059
    #################################################
Packit 857059
    #debug/dev only
Packit 857059
    #set lids_file  "lids.xml"
Packit 857059
    #set links_file "links.xml"
Packit 857059
    #################################################
Packit 857059
    # Open lids XML files
Packit 857059
    #set size [file size $lids_file]
Packit 857059
    #set fp [open $lids_file r]
Packit 857059
    #set lidsXML [read $fp $size]
Packit 857059
    #################################################
Packit 857059
    # Open links XML files
Packit 857059
    #set size [file size $links_file]
Packit 857059
    #set fp [open $links_file r]
Packit 857059
    #set linksXML [read $fp $size]
Packit 857059
    ##################################################
Packit 857059
    #set lids_dom [dom parse $lidsXML]
Packit 857059
    #set links_dom [dom parse $linksXML]
Packit 857059
Packit 857059
    set switchLidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='SW']} ]
Packit 857059
    set hfiLidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='FI']} ]
Packit 857059
Packit 857059
    set return_lid "none"
Packit 857059
    set return_port "none"
Packit 857059
Packit 857059
    # For each switch node
Packit 857059
    foreach item $switchLidsList {
Packit 857059
        set lid [ $item getAttribute "LID"]
Packit 857059
        set guid [ [ $item selectNodes NodeGUID/text() ] nodeValue ]
Packit 857059
Packit 857059
        set linkList [ $links_dom selectNodes /Report/LinkSummary/Link ]
Packit 857059
        #puts "found [ llength $linkList ] links"
Packit 857059
        foreach link $linkList {
Packit 857059
          #puts "processing link [$link asXML] [$link asText]"
Packit 857059
          set portNodes [ $link getElementsByTagName Port ]
Packit 857059
          set port1 [lindex $portNodes 0]
Packit 857059
          set port2 [lindex $portNodes 1]
Packit 857059
          set port1_NodeType [[$port1 child all NodeType] asText]
Packit 857059
          set port2_NodeType [[$port2 child all NodeType] asText]
Packit 857059
          set port1_GUID [[$port1 child all NodeGUID] asText]
Packit 857059
          set port2_GUID [[$port2 child all NodeGUID] asText]
Packit 857059
          set port1_PortNum [[$port1 child all PortNum] asText]
Packit 857059
          set port2_PortNum [[$port2 child all PortNum] asText]
Packit 857059
          #puts "myguid is $myguid port1guid = $port1_GUID port2guid= $port2_GUID lid = $lid"
Packit 857059
          if { ([string compare $port1_GUID $myguid]==0) } {
Packit 857059
            set return_lid $lid
Packit 857059
            set return_lid [get_lid_from_guid $port2_GUID]
Packit 857059
Packit 857059
            set return_port $port2_PortNum
Packit 857059
          } elseif { ([string compare $port2_GUID $myguid]==0) } {
Packit 857059
            set return_lid $lid
Packit 857059
            set return_lid [get_lid_from_guid $port1_GUID]
Packit 857059
Packit 857059
            set return_port $port1_PortNum
Packit 857059
          }
Packit 857059
        }
Packit 857059
    }
Packit 857059
   
Packit 857059
    $lids_dom delete
Packit 857059
    $links_dom delete
Packit 857059
    return [list $return_lid $return_port]
Packit 857059
}
Packit 857059