basic_fc_script.tcl
来自「smartbits二次开发示例代码」· TCL 代码 · 共 605 行 · 第 1/2 页
TCL
605 行
#####################################################################################
# NAME
# BasicFCScript.tcl
# DESCRIPTION
# This Script uses the FBC 3601A/3602B module of SmartBits to setup a number of
# streams and transmit them. It is required of the Script to be Linked Up,
# Logged In and have Discovered the other devices before reaching the Commit state
# to transmit traffic.
# USAGE
# This script is to be used with the latest released FW and 3.14ver Library or higher
#
# AUTHOR/REVISION HISTORY
# PJ Yedidsion -Created (Tab set to 3 spaces)
#
#####################################################################################
########################
# Procedures Section #
########################
###########################################################
# procNAME
# PortConfig
# DESCRIPTION
# Configure Fibre Channel Port Parameters
###########################################################
proc PortConfig {H S P} {
struct_new fc_port FCPortConfig
# use the global parameters and configure the ports
set fc_port(ucSpeed) $::speed
set fc_port(ucTopology) $::topology
set fc_port(uiBBCreditConfigRx) $::bbCredit
LIBCMD HTSetStructure $::FC_PORT_CONFIG 0 0 0 fc_port 0 $H $S $P
}
###########################################################
# procNAME
# DefineStream
# DESCRIPTION
# Configure WWN and Define Fibre Channel Streams
# PARAMETERS
# Source and Destination WWNs
###########################################################
proc Stream {H S P SWWN DWWN} {
# two WWN wndpoints for each stream
struct_new wwnConfig FCWWN*[expr $::numStreams * 2]
struct_new stream StreamFC*$::numStreams
# Loop through and populate arrays for stream, FC header and WWN endpoints
for {set i 0} {$i < $::numStreams} {incr i} {
#puts -nonewline "\nConfig stream [expr $i+1] on $H $S $P ... "
set stream($i.uiFrameLength) $::frameLength
set stream($i.ucActive) 1
set stream($i.ucProtocolType) $::STREAM_PROTOCOL_FC
set stream($i.ucTagField) 1
set stream($i.ucRandomData) 1
set stream($i.u64SourceWWN.high) [expr $SWWN / 0x010000]
set stream($i.u64SourceWWN.low) [expr $SWWN & 0x0FFFF]
set stream($i.u64DestWWN.high) [expr $DWWN / 0x010000]
set stream($i.u64DestWWN.low) [expr $DWWN & 0x0FFFF]
set stream($i.ucCOS) $::FC_STREAM_COS_3
set stream($i.ucR_CTL) 0
set stream($i.ulF_CTL) 0
set stream($i.uiCS_CTL) 0
set stream($i.ucDF_CTL) 0
set stream($i.ucEnableSeqCnt) 1
set stream($i.ucDuplexMode) $::FULLDUPLEX_MODE
set stream($i.ucVerifyAL_PD) 1
set stream($i.ucVerifyAL_PS) 1
set stream($i.ulSOF) 0
set stream($i.ucFCType) 0
set stream($i.uiSeqCnt) 0
set stream($i.uiOX_ID) 0
set stream($i.uiRX_ID) 0
set stream($i.ulParameter) 0
set stream($i.ulEOF) 0
set stream($i.ucSeqID) 1
set stream($i.uiPayLoadLength) 28
set stream($i.ProtocolHeader._char_) "PayLoad Goes Here see John!"
#
#################################################################
# Now set up a pair of endpoints for each stream.
# expr $i * 2 will give 0,2,4,6 sequence
# expr ($i * 2) + 1 will give 1,3,5,7 sequence
#################################################################
#puts -nonewline "\nConfig 2 WWN endpoints for stream [expr $i+1] on $H $S $P ... "
# local
set wwnConfig([expr $i * 2].u64WWN.high) [expr $SWWN / 0x10000]
set wwnConfig([expr $i * 2].u64WWN.low) [expr $SWWN & 0x0FFFF]
set wwnConfig([expr $i * 2].ucRemote) $::LOCAL_MODE
set wwnConfig([expr $i * 2].ucSupportedCOS) 1
set wwnConfig([expr $i * 2].ucPublic) $::connMode
# remote
set wwnConfig([expr ($i * 2) + 1].u64WWN.high) [expr $DWWN / 0x10000]
set wwnConfig([expr ($i * 2) + 1].u64WWN.low) [expr $DWWN & 0x0FFFF]
set wwnConfig([expr ($i * 2) + 1].ucRemote) $::REMOTE_MODE
set wwnConfig([expr ($i * 2) + 1].ucSupportedCOS) 1
set wwnConfig([expr ($i * 2) + 1].ucPublic) $::connMode
# increment the WWNs
incr SWWN
incr DWWN
}
# make the call to define the steams
LIBCMD HTSetStructure $::FC_WWN 0 0 0 wwnConfig 0 $H $S $P
LIBCMD HTSetStructure $::FC_DEFINE_STREAM 0 $::numStreams 0 stream 0 $H $S $P
}
###########################################################
# procNAME
# LinkUp
# DESCRIPTION
# Link up the ports
###########################################################
proc LinkUp {H S P} {
# Send LinkUp command
LIBCMD HTSetCommand $::FC_LINKUP 0 0 0 "" $H $S $P
}
###########################################################
# procNAME
# Login
# DESCRIPTION
# Login the ports
###########################################################
proc Login {H S P} {
# Send Login command
LIBCMD HTSetCommand $::FC_WWN_LOGIN 0 0 0 "" $H $S $P
}
###########################################################
# procNAME
# PublicDisc
# DESCRIPTION
# Do a public discovery to the switch to find out about
# other ports that are logged in
###########################################################
proc PublicDisc {H S P} {
# Send Discovery command
LIBCMD HTSetCommand $::FC_PUBLIC_DISCOVERY 0 0 0 "" $H $S $P
}
###########################################################
# procNAME
# PrivateDisc
# DESCRIPTION
# Do a private discovery to the switch to find out about
# other ports that are logged in
###########################################################
proc PrivateDisc {H S P} {
# Send Discovery command
LIBCMD HTSetCommand $::FC_PRIVATE_DISCOVERY 0 0 0 "" $H $S $P
}
###########################################################
# procNAME
# Commit
# DESCRIPTION
# Get ports to being Ready To Test
###########################################################
proc Commit {H S P} {
# Complete the initialization and configuration process and put ports to Ready to Test
LIBCMD HTSetCommand $::FC_COMMIT 0 0 0 "" $H $S $P
}
###########################################################
# display current port status - will expand error info
# if error is non-zero
###########################################################
proc Status {H S P fc_status stateBit} {
upvar $fc_status status
LIBCMD HTGetStructure $::FC_STATUS_INFO 0 0 0 status 0 $H $S $P
# Check if State is True
if { $stateBit & $status(ulState) } {
return 1
}
# see if we totally lost link (can be used later to bring ports back up)
if { $stateBit != $::PORT_LINK_UP } {
if { $status(ulState) & $::PORT_LINK_UP } {
# do nothing
} else {
#puts "LINK HAS GONE DOWN!"
return 0
}
}
return -1
}
proc checkStatus {H S P value action waiting} {
struct_new status FCStatus
while {$waiting > 0} {
set retval [Status $H $S $P status $value]
if {$status(ulState) & $value} {
puts "==> Port $H $S $P successfully completed $action!\n"
return 1
} else {
puts "Please wait for port status updating to $action:$waiting"
after 1000
incr waiting -1
}
}
##
## We know that as many times as we tried, the port did not get the correct state
## so dump the error info to the screen
##
#puts " RAW ulState Value 0x[format %04X $status(ulState)]"
puts "---------------------------------------------------------------"
puts -nonewline "Fibre Channel Port ($H,$S,$P) Status ==>"
if {$status(ulState) & 0x01 } {
puts " LINK DOWN "
} elseif {$status(ulState) & 0x02} {
puts " LINK INITIALIZING "
} elseif {$status(ulState) & 0x04} {
puts " LINK UP "
puts -nonewline "Fabric specific Status ==> "
if {$status(ulState) & 0x08 } {
puts "LOGIN"
} elseif {$status(ulState) & 0x10 } {
puts "LOGIN COMPLETE"
} elseif {$status(ulState) & 0x20 } {
puts "PUBLIC DISCOVERY"
} elseif {$status(ulState) & 0x40 } {
puts "PUBLIC DISCOVERY COMPLETE"
} elseif {$status(ulState) & 0x80 } {
puts "PRIVATE DISCOVERY"
} elseif {$status(ulState) & 0x100 } {
puts "PRIVATE DISCOVERY COMPLETE"
} elseif {$status(ulState) & 0x200 } {
puts "READY TO TEST"
} else {
puts "NO SPECIFIC DEFINITION"
}
}
#puts "ERROR CODE RAW [format %X $status(ulError)]"
# if error is set, print out the error info
if {$status(ulError) != 0} {
#puts "------------ Fibre Channel Error Info ------------------------"
#puts " RAW ulError Value 0x[format %04X $status(ulError)]"
if {$status(ulError) & 0x01 } {
puts -nonewline "LOSS OF SYNC"
}
if {$status(ulError) & 0x02 } {
puts -nonewline "LOSS OF SIGNAL"
}
if {$status(ulError) & 0x04 } {
puts -nonewline "LINK RESET"
}
if {$status(ulError) & 0x08 } {
puts -nonewline "PORT TX FAULT"
}
if {$status(ulError) & 0x010 } {
puts -nonewline "FABRIC LOGIN ERROR"
}
if {$status(ulError) & 0x020 } {
puts -nonewline "PORT LOGIN ERROR"
}
if {$status(ulError) & 0x040 } {
puts -nonewline "NAME SERVER ERROR"
}
if {$status(ulError) & 0x080 } {
puts -nonewline "INVALID STATE ERROR"
}
# Extended error reason
switch $status(ulErrorExtendedInfo) {
0 { puts -nonewline " - NO REASON CODE"}
1 { puts -nonewline " - INVALID LS COMMAND"}
2 { puts -nonewline " - LOGICAL ERROR"}
3 { puts -nonewline " - LOGICAL INVALID IU SIZE"}
4 { puts -nonewline " - LOGICAL BUSY"}
5 { puts -nonewline " - PROTOCOL ERROR"}
6 { puts -nonewline " - UNABLE TO PERFORM COMMAND"}
7 { puts -nonewline " - COMMAND NOT SUPPORTED"}
8 { puts -nonewline " - TIMEOUT"}
9 { puts -nonewline " - CLASS OF SERVICE 2 NOT SUPPORTED"}
10 { puts -nonewline " - CLASS OF SERVICE 3 NOT SUPPORTED"}
default { puts -nonewline " - REASON CODE $reason NOT DEFINED"}
}
# Detailed error explanation
switch $status(ulErrorDetailedInfo) {
0 { puts " - No additional information"}
1 { puts " - Service parameter options"}
2 { puts " - Service parameter init control"}
3 { puts " - Service parameter recp control"}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?