1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
|
# BEGIN_ICS_COPYRIGHT8 ****************************************
#
# Copyright (c) 2015, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Intel Corporation nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# END_ICS_COPYRIGHT8 ****************************************
#[ICS VERSION STRING: unknown]
#########################################################################################
# Name : get_switch_lids_to_ports_map
# Input : cmd_host (where can opa commands be run to query SM)
# Return . A dict mapping LID to list of ports.
# 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)
#########################################################################################
proc get_switch_lids_to_ports_map { cmd_host } {
# Build DOM from XML
set lids_dom [ run_opareport $cmd_host "-o lids" ]
set links_dom [ run_opareport $cmd_host "-o links" ]
# Get all switches
set lidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='SW']} ]
#puts "found [ llength $lidsList ] switch lids"
set lid_port_map [dict create]
# For each switch node
foreach item $lidsList {
set lid [ $item getAttribute "LID"]
set guid [ [ $item selectNodes NodeGUID/text() ] nodeValue ]
#puts "lid:$lid; guid:$guid"
# Now, using guid as the key, poke into linksDOM to find the ports for this guid.
set portList [ $links_dom selectNodes /Report/LinkSummary/Link/Port\[NodeGUID='$guid'\]/PortNum/text() ]
# Now you have a list of ports for specific LID/GUID.
#puts "found [ llength $portList ] ports"
# List of ports per lid
set ports {}
foreach port $portList {
set portNum [ $port nodeValue ]
# If don't care about port 1 - skip it
#` if { $portNum == 1 } {
# continue
# }
#puts "lid:$lid->port num:$portNum"
lappend ports $portNum
# I would have a data structure that is a map of lists, i.e.
# LID1: port1, port2, port3
# LID2: port5,port6,port7
# …….
}
#puts "Added [ llength $ports ] ports"
dict set lid_port_map $lid $ports
#puts "lid_port_map size: [dict size $lid_port_map]"
}
# Free memory
$lids_dom delete
$links_dom delete
return $lid_port_map
}
#########################################################################################
# Name : get_switch_lids_to_hfi_ports_map
# Input : cmd_host (where can opa commands be run to query SM)
# Return . A dict mapping LID to list of ports that are connect to HFIs.
# 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)
#########################################################################################
proc get_switch_lids_to_hfi_ports_map { cmd_host } {
# Build DOM from XML
set lids_dom [ run_opareport $cmd_host "-o lids" ]
set links_dom [ run_opareport $cmd_host "-o links" ]
set lidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='SW']} ]
# puts "found [ llength $lidsList ] switch lids"
# puts "[$lidsList selectNodes NodeGUID/text()]"
set lid_port_map [dict create]
# For each switch node
foreach item $lidsList {
set lid [ $item getAttribute "LID"]
set guid [ [ $item selectNodes NodeGUID/text() ] nodeValue ]
#puts "lid:$lid; guid:$guid"
# Now, using guid as the key, poke into linksDOM to find the ports for this guid.
# set portList [ $links_dom selectNodes /Report/LinkSummary/Link/Port\[NodeGUID='$guid'\]/PortNum/text() ]
set linkList [ $links_dom selectNodes /Report/LinkSummary/Link ]
#puts "found [ llength $linkList ] links"
foreach link $linkList {
set portNodes [ $link getElementsByTagName Port ]
set port1 [lindex $portNodes 0]
set port2 [lindex $portNodes 1]
set port1_NodeType [[$port1 child all NodeType] asText]
set port2_NodeType [[$port2 child all NodeType] asText]
set port1_GUID [[$port1 child all NodeGUID] asText]
set port2_GUID [[$port2 child all NodeGUID] asText]
set port1_PortNum [[$port1 child all PortNum] asText]
set port2_PortNum [[$port2 child all PortNum] asText]
if { ([string compare $port1_GUID $guid]==0) || ([string compare $port2_GUID $guid]==0) } {
if { ([string compare $port1_NodeType SW]==0) && ([string compare $port2_NodeType FI]==0) } {
lappend ports $port1_PortNum
} elseif {([string compare $port1_NodeType FI] == 0) && ([string compare $port2_NodeType SW] == 0)} {
lappend ports $port2_PortNum
}
}
}
#puts "Added [ llength $ports ] ports"
dict set lid_port_map $lid $ports
#puts "lid_port_map size: [dict size $lid_port_map]"
}
# Free memory
$lids_dom delete
$links_dom delete
return $lid_port_map
}
#########################################################################################
# Name : get_lid_from_guid
# Input : guid
# Return : output of opasaquery -o lid -n $guid
# Description : get lid from guid
#########################################################################################
proc get_lid_from_guid { guid } {
##
## get_lid_from_guid
## --------------
## Obtain my guid
## assumes that target_root_sh has already been called for the host
set cmd "lid=`opasaquery -o lid -n $guid`"
#debug_message "running: $cmd"
unix_cmd 60 "" $cmd
send_unix_cmd { echo "XXX${lid}XXX"; echo DONE }
expect_list 60 { "DONE" "XXX" "DONE" } { "exiting" "No such" "Error" "ERROR" "VAPI" "THH" } tmp
check_exit_status 60 0
regexp {DONE.*XXX *(.*) *XXX.*DONE} $tmp trash lid
return "$lid"
}
#########################################################################################
# Name : get_switchport_from_lid
# Input : cmd_host lid *** LID must be in format 0x0001 (the same format as provided by opareport -o lids)
# 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
# Description : For the lid of an HFI return the switch lid and port that that HFI is connected to
#########################################################################################
proc get_switchport_from_lid { cmd_host mylid } {
set lids_dom [ run_opareport $cmd_host "-o lids" ]
set links_dom [ run_opareport $cmd_host "-o links" ]
#################################################
#debug/dev only
#set lids_file "lids.xml"
#set links_file "links.xml"
#################################################
# Open lids XML files
#set size [file size $lids_file]
#set fp [open $lids_file r]
#set lidsXML [read $fp $size]
#################################################
# Open links XML files
#set size [file size $links_file]
#set fp [open $links_file r]
#set linksXML [read $fp $size]
##################################################
#set lids_dom [dom parse $lidsXML]
#set links_dom [dom parse $linksXML]
set switchLidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='SW']} ]
set hfiLidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='FI']} ]
set myguid "none"
set return_lid "none"
set return_port "none"
foreach item $hfiLidsList {
set lid [ $item getAttribute "LID"]
set guid [ [ $item selectNodes NodeGUID/text() ] nodeValue ]
if { [string compare $lid $mylid] == 0 } {
set myguid $guid
}
}
if { [string compare $myguid "none"] == 0 } {
error "Lid $mylid not found"
}
# For each switch node
foreach item $switchLidsList {
set lid [ $item getAttribute "LID"]
set guid [ [ $item selectNodes NodeGUID/text() ] nodeValue ]
set linkList [ $links_dom selectNodes /Report/LinkSummary/Link ]
#puts "found [ llength $linkList ] links"
foreach link $linkList {
# puts "processing link [$link asXML] [$link asText]"
set portNodes [ $link getElementsByTagName Port ]
set port1 [lindex $portNodes 0]
set port2 [lindex $portNodes 1]
set port1_NodeType [[$port1 child all NodeType] asText]
set port2_NodeType [[$port2 child all NodeType] asText]
set port1_GUID [[$port1 child all NodeGUID] asText]
set port2_GUID [[$port2 child all NodeGUID] asText]
set port1_PortNum [[$port1 child all PortNum] asText]
set port2_PortNum [[$port2 child all PortNum] asText]
target_root_sh $cmd_host
if { ([string compare $port1_GUID $myguid]==0) } {
#set return_lid $lid
set return_lid [get_lid_from_guid $port2_GUID]
set return_port $port2_PortNum
} elseif { ([string compare $port2_GUID $myguid]==0) } {
#set return_lid $lid
set return_lid [get_lid_from guid $port1_GUID]
set return_port $port1_PortNum
}
}
}
$lids_dom delete
$links_dom delete
return [list $return_lid $return_port]
}
#########################################################################################
# Name : get_switchport_from_guid
# Input : cmd_host guid
# 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
# Description : For the lid of an HFI return the switch lid and port that that HFI is connected to
#########################################################################################
proc get_switchport_from_guid { cmd_host myguid } {
set lids_dom [ run_opareport $cmd_host "-o lids" ]
set links_dom [ run_opareport $cmd_host "-o links" ]
#################################################
#debug/dev only
#set lids_file "lids.xml"
#set links_file "links.xml"
#################################################
# Open lids XML files
#set size [file size $lids_file]
#set fp [open $lids_file r]
#set lidsXML [read $fp $size]
#################################################
# Open links XML files
#set size [file size $links_file]
#set fp [open $links_file r]
#set linksXML [read $fp $size]
##################################################
#set lids_dom [dom parse $lidsXML]
#set links_dom [dom parse $linksXML]
set switchLidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='SW']} ]
set hfiLidsList [ $lids_dom selectNodes {/Report/LIDSummary/LIDs/Value[NodeType='FI']} ]
set return_lid "none"
set return_port "none"
# For each switch node
foreach item $switchLidsList {
set lid [ $item getAttribute "LID"]
set guid [ [ $item selectNodes NodeGUID/text() ] nodeValue ]
set linkList [ $links_dom selectNodes /Report/LinkSummary/Link ]
#puts "found [ llength $linkList ] links"
foreach link $linkList {
#puts "processing link [$link asXML] [$link asText]"
set portNodes [ $link getElementsByTagName Port ]
set port1 [lindex $portNodes 0]
set port2 [lindex $portNodes 1]
set port1_NodeType [[$port1 child all NodeType] asText]
set port2_NodeType [[$port2 child all NodeType] asText]
set port1_GUID [[$port1 child all NodeGUID] asText]
set port2_GUID [[$port2 child all NodeGUID] asText]
set port1_PortNum [[$port1 child all PortNum] asText]
set port2_PortNum [[$port2 child all PortNum] asText]
#puts "myguid is $myguid port1guid = $port1_GUID port2guid= $port2_GUID lid = $lid"
if { ([string compare $port1_GUID $myguid]==0) } {
set return_lid $lid
set return_lid [get_lid_from_guid $port2_GUID]
set return_port $port2_PortNum
} elseif { ([string compare $port2_GUID $myguid]==0) } {
set return_lid $lid
set return_lid [get_lid_from_guid $port1_GUID]
set return_port $port1_PortNum
}
}
}
$lids_dom delete
$links_dom delete
return [list $return_lid $return_port]
}
|