basic_fc_script.tcl

来自「smartbits二次开发示例代码」· TCL 代码 · 共 605 行 · 第 1/2 页

TCL
605 行
字号
			    4 { puts " - Service parameter receive size"}
			    5 { puts " - Service parameter concurrent seqs"}
			    6 { puts " - Service parameter credit"}
			    7 { puts " - Invalid port name"}
			    8 { puts " - Invalid node or fabric name"}
			    9 { puts " - Invalid common service parameters"}
			    10 { puts " - Command already in progress"}
			    11 { puts " - Out of resources"}
			    12 { puts " - Port identifier not registered"}
			    13 { puts " - Port name not registered"}
			    14 { puts " - Node name not registered"}
			    15 { puts " - Class of Service not registered"}
			    16 { puts " - IP Address not registered"}
			    17 { puts " - Initial Process Association not registered"}
			    18 { puts " - Fibre Channel 4 types not registered"}
			    19 { puts " - Symbolic port name not registered"}
			    20 { puts " - Symbolic node name not registered"}
			    21 { puts " - Port type not registered"}
			    22 { puts " - Port IP address not registered"}
			    23 { puts " - Fabric port name not registered"}
			    24 { puts " - Hard address not registered"}
			    25 { puts " - Access denied"}
			    26 { puts " - Unacceptable port identifier"}
			    27 { puts " - Database empty"}
			    28 { puts " - No object registered in scope"}
			    default { puts "EXPLANATION $explanation NOT DEFINED"}
			}
		}	;# end of if print out info
	puts "---------------------------------------------------------------"
	
	set ::Result 1
	puts "** ERROR ** Port $H $S $P did not complete $action!\n\n"
	unset status
	return -1
}

#################################################################
# startCapture
#
# Start capture and wait
#################################################################
proc startCapture {H S P} {
   puts "Setting Capture"
   struct_new CapSetup NSCaptureSetup
   set CapSetup(ulCaptureLength) $::CAPTURE_LENGTH_ENTIRE_FRAME
   set CapSetup(ulCaptureEvents) $::CAPTURE_EVENTS_ALL_FRAMES
   LIBCMD HTSetStructure $::NS_CAPTURE_SETUP 0 0 0 CapSetup 0 $H $S $P
   LIBCMD HTSetCommand $::NS_CAPTURE_START 0 0 0 "" $H $S $P
   after 2000
}

#################################################################
# stopCapture
#
# Stop capture and display results
#################################################################
proc stopCapture {H S P {numToDisplay 5}} {
   puts "Stopping Capture"
   LIBCMD HTSetCommand $::NS_CAPTURE_STOP 0 0 0 "" $H $S $P
   
   puts "Checking Capture Count"
   struct_new CapCount NSCaptureCountInfo
   LIBCMD HTGetStructure $::NS_CAPTURE_COUNT_INFO 0 0 0 CapCount 0 $H $S $P
   puts "Capture count is $CapCount(ulCount)"
   
   if {$CapCount(ulCount) < $numToDisplay} {
   	puts "Setting the number of packets to display to $CapCount(ulCount)"
   	set numToDisplay	$$CapCount(ulCount)
   }
   
   puts "Getting Captured Packets"
   struct_new CapData NSCaptureDataInfo
   for {set i 0} {$i < $numToDisplay} {incr i} {
      puts ""
      set CapData(ulFrameIndex) $i
      LIBCMD HTGetStructure $::NS_CAPTURE_DATA_INFO $i 1 0 CapData 0 $H $S $P
      puts -nonewline "Frame index = $CapData(ulFrameIndex)"
      for {set j 0} {$j < $CapData(ulRetrievedLength)} {incr j} {
         if {[expr $j % 16] == 0} {
            puts ""
            puts -nonewline [format "%4i:   " $j]
         }
         puts -nonewline " [format "%02X" $CapData(ucData.$j)]"
      }
      puts ""
   }
   puts ""
}

proc getFCCounters {H S P} {
   struct_new cs FCCounterInfo 
   LIBCMD  HTGetStructure $::FC_COUNTER_INFO 0 0 0 cs 0 $H $S $P

   puts "======================================================="
   puts "	  Counter Data = > Card [expr $S +1]  Port [expr $P + 1]  |"
   puts "======================================================="
   puts "    	   Events (Total)    |     Rates (Per Second) |"
   puts "======================================================="
   puts "Tx Packets 	[format "%12d" $cs(ulTmtPkt)] | 		 [format "%12d" $cs(ulTmtPktRate)] |"
   puts "Rx Packets 	[format "%12d" $cs(ulRcvPkt)] | 		 [format "%12d" $cs(ulRcvPktRate)] |"
   puts "Rx Bytes 	[format "%12d" $cs(ulRcvByte)] | 		 [format "%12d" $cs(ulRcvByteRate)] |"
   puts "-------------------------------------------------------"
   puts "Recvd Trigger	[format "%12d" $cs(ulRcvTrig)] | 		 [format "%12d" $cs(ulRcvTrigRate)] |"
   puts "-------------------------------------------------------"
   puts "CRC Errors	[format "%12d" $cs(ulCRC)] | 		 [format "%12d" $cs(ulCRCRate)] |"
   puts "-------------------------------------------------------"
   puts "Oversize	[format "%12d" $cs(ulOversize)] | 		 [format "%12d" $cs(ulOversizeRate)] |"
   puts "Undersize	[format "%12d" $cs(ulUndersize)] | 		 [format "%12d" $cs(ulUndersizeRate)] |"
   puts "-------------------------------------------------------"
   puts "Press ENTER to continue"
   gets stdin response

}


#########################################################################################
#########################################################################################
#########################################################################################
############################	     MAIN PROGRAM	    #####################################
#########################################################################################
#########################################################################################
#########################################################################################
source smartlib.tcl
#source show.tcl

# status checker variable
global Result
set Result 	0
set numTrys 5	;# how many times to ask for status before giving up

# capture
set numPacketsDiplay	1 ;# could be any #

# port 1
set TxHub  0
set TxSlot 0
set TxPort 0
# port 2
set RxHub  0
set RxSlot 0
set RxPort 1

# Port configuration parameteres
set topology 	$::TOPOLOGY_PT_2_PT		;# TOPOLOGY_LOOP
set speed 		$::SPEED_1GHZ				;# SPEED_2GHZ
set bbCredit 	32

# Stream parameters
set numStreams 	1
set frameLength	124
set connMode		$::PUBLIC_MODE		;# PRIVATE_MODE

# link to the chassis here
if {[ETGetLinkStatus] < 0} {
     puts "SmartBits not linked - Enter chassis IP address"
     gets stdin ipaddr
     set retval [NSSocketLink ipaddr 16385 $RESERVE_NONE]  
     if {$retval < 0 } {
	  puts "Unable to connect to $ipaddr. Please try again."
	  exit
     }
}

# Reserve the 2 slots
LIBCMD HTSlotReserve $TxHub $TxSlot  
LIBCMD HTSlotReserve $RxHub $RxSlot 

puts "Reset Fibre Channel ports ... "
LIBCMD HTResetPort $::RESET_FULL $TxHub $TxSlot $TxPort
LIBCMD HTResetPort $::RESET_FULL $RxHub $RxSlot $RxPort
after 2000


# 1st configure the ports using topology speed bbCredit (defined above)
puts "Configure Fibre Channel ports ... "
PortConfig $TxHub $TxSlot $TxPort
PortConfig $RxHub $RxSlot $RxPort

# Configure the WWNs, set up the streams and create the FC header
#	Stream parameters are the Source and Dest WWNs
puts "Create streams and define WWNs ...\n"
Stream $TxHub $TxSlot $TxPort 100 200
Stream $RxHub $RxSlot $RxPort 200 100

# Go through the process of linking, logging in, discover & commit

# Link up the ports
LinkUp $TxHub $TxSlot $TxPort
LinkUp $RxHub $RxSlot $RxPort
# Check the status to make sure we got LinkUp 0x04
checkStatus $TxHub $TxSlot $TxPort $::PORT_LINK_UP "Link" $numTrys
checkStatus $RxHub $RxSlot $RxPort $::PORT_LINK_UP "Link" $numTrys

# If in public mode, do Fabric Login followed by Public Discovery
# If in private mode, do Private Discovery only
if {$connMode} {
	#puts "Login..."
	Login $TxHub $TxSlot $TxPort
	Login $RxHub $RxSlot $RxPort
	# Check the status to make sure we loged in 0x10
	checkStatus $TxHub $TxSlot $TxPort $::PORT_DEVICE_LOGIN_COMPLETE "Login" $numTrys
	checkStatus $RxHub $RxSlot $RxPort $::PORT_DEVICE_LOGIN_COMPLETE "Login" $numTrys
	
	#puts "Discovery (Public)..."
	PublicDisc $TxHub $TxSlot $TxPort
	PublicDisc $RxHub $RxSlot $RxPort
	# Check the status to make sure we discovered 0x40
	checkStatus $TxHub $TxSlot $TxPort $::PORT_PUBLIC_DISCOVERY_COMPLETE "Public Discovery" $numTrys
	checkStatus $RxHub $RxSlot $RxPort $::PORT_PUBLIC_DISCOVERY_COMPLETE "Public Discovery" $numTrys

} else {
	#puts "Discovery (Private)..."
	PrivateDisc $TxHub $TxSlot $TxPort
	PrivateDisc $RxHub $RxSlot $RxPort
	# Check the status to make sure we discovered 0x40
	checkStatus $TxHub $TxSlot $TxPort $::PORT_PRIVATE_DISCOVERY_COMPLETE "Private Discovery" $numTrys
	checkStatus $RxHub $RxSlot $RxPort $::PORT_PRIVATE_DISCOVERY_COMPLETE "Private Discovery" $numTrys

}

Commit $TxHub $TxSlot $TxPort
Commit $RxHub $RxSlot $RxPort
# Check the status to make sure we are ready to test 0x200
checkStatus $TxHub $TxSlot $TxPort $::PORT_READY_TO_TEST "Commit" $numTrys
checkStatus $RxHub $RxSlot $RxPort $::PORT_READY_TO_TEST "Commit" $numTrys


    struct_new  wwnConfigInfo		   FCWWN*2

    LIBCMD HTGetStructure $::FC_WWN_INFO 0 0 0 wwnConfigInfo 0 $TxHub $TxSlot $TxPort
    for {set i 0} {$i < 2} {incr i} {                                           
        puts "---------- WWN [expr $i + 1] -----------------------------------------"
        puts "WWN ucPublic              = $wwnConfigInfo($i.ucPublic)"
        puts "WWN ucRemote              = $wwnConfigInfo($i.ucRemote)"
        puts "WWN (high)                = [format %x $wwnConfigInfo($i.u64WWN.high)]"
        puts "WWN (low)                 = [format %x $wwnConfigInfo($i.u64WWN.low)]"
        puts "WWN Address ID            = [format %x $wwnConfigInfo($i.ulAddressID)]"
    }






after 10000


# Start the capture on our receiving port
startCapture $RxHub $RxSlot $RxPort

# Start transmitting on our transmit port
HTRun $HTRUN $TxHub $TxSlot $TxPort
after 1000
# Stop transmit
HTRun $HTSTOP $TxHub $TxSlot $TxPort

# Stop the capture and display the desired # of packets
stopCapture $RxHub $RxSlot $RxPort $numPacketsDiplay

#
getFCCounters $TxHub $TxSlot $TxPort
getFCCounters $RxHub $RxSlot $RxPort



gets stdin
puts "UnLinking from the chassis now"
LIBCMD ETUnLink
puts "DONE!"
































⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?