atmtmbasic.tcl
来自「smartbits二次开发示例代码」· TCL 代码 · 共 459 行 · 第 1/2 页
TCL
459 行
struct_new ext L3StreamExtension
# Calculate frame rate based on the PCR (353207) of the configured port speed OC3
#
# All the VCs have PCR of [expr 353207 / $VCCount], as configured above. This calculation is
# based on this VC PCR and evenly distributed it to the streams which are bound to the VC -
# and use its equivalent frame rate as the frame rate of the streams
# NOTE:
# It is not necessary to always set the stream frame rate as as this equivalent VC PCR frame rate
# as long as the summation of the frame rate of all the streams bound on the VC is equal or smaller
# than the allocated VC PCR.
#
set CellsPerFrame [expr floor(($DataLength + 5) / 48) + 1 ]
set PCRPerVC [expr 353207 / $VCCount]
set PCRPerStream [expr $PCRPerVC / $StreamCountPerVC ]
set PFRPerStream [expr round( floor($PCRPerStream / $CellsPerFrame)) ]
#Define stream extension contents
set ext(ulFrameRate) $PFRPerStream
#Set frame rate for stream of index 1
LIBCMD HTSetStructure $L3_DEFINE_STREAM_EXTENSION 0 0 0 ext 0 $TxHub $TxSlot $TxPort
unset ext
#################################################################################################
# Setup frame rate for the next [$StreamCountTotal - 1] more streams based on the first stream. #
# Since the ulFrameRate is delta value in the structure below, with zero value below, the same #
# frame rate of the first stream is set for all the next [$StreamCountTotal - 1] more streams. #
# #
# NOTE: #
# The frame rate must be the same for all the streams if they are bound to one single VC #
#################################################################################################
#Declare Stream Extension
struct_new ext L3StreamExtension
#Define stream extension contents
set ext(ulFrameRate) 0
#Set frame rate based on the frame rate of stream of index 1
LIBCMD HTSetStructure $L3_DEFINE_MULTI_STREAM_EXTENSION 1 [expr $StreamCountTotal - 1] \
0 ext 0 $TxHub $TxSlot $TxPort
unset ext
###########################################################################################
#Stream binding -- binding streams to VCs, and set ATM flags (CLP on or off). #
# #
#Streams 1 to 3 are bound to VC 0; #
#Streams 4 to 6 are bound to VC 1; #
#Streams 7 to 9 are bound to VC 2; #
#Streams 10 to 12 are bound to VC 3; #
###########################################################################################
puts "Binding Streams to VCs ..."
struct_new streambind L3StreamBinding*$StreamCountTotal
for {set i 0; set j 0} {$i < $StreamCountTotal } {incr i} {
if { $i % $StreamCountPerVC == 0 && $i != 0 } {
incr j
}
set streambind($i.ucBindMode) $STREAM_BIND_VC
set streambind($i.uiBindIndex) $j; # This is the VC index, which is to be bound
set streambind($i.uiATMFlags) $atmFlag
}
LIBCMD HTSetStructure $L3_DEFINE_STREAM_BINDING 0 0 0 streambind 0 $TxHub $TxSlot $TxPort
unset streambind
###########################################################################################
# Commit ATM configuration #
# Commit is to commit all the stream configurations #
# NOTE: #
# NS_COMMIT_CONFIG is always required before run the test #
###########################################################################################
puts "Committing the configurations ..."
LIBCMD HTSetCommand $NS_COMMIT_CONFIG 0 0 0 0 $TxHub $TxSlot $TxPort
###########################################################################################
# Capture setup & start #
###########################################################################################
puts "Setting up capture ..."
struct_new cap NSCaptureSetup
set cap(ulCaptureMode) $CAPTURE_MODE_FILTER_ON_EVENTS
set cap(ulCaptureLength) $CAPTURE_LENGTH_ENTIRE_FRAME
set cap(ulCaptureEvents) $CAPTURE_EVENTS_ALL_FRAMES
LIBCMD HTSetStructure $NS_CAPTURE_SETUP 0 0 0 cap 0 $RxHub $RxSlot $RxPort
unset cap
puts "Start capture"
LIBCMD HTSetCommand $NS_CAPTURE_START 0 0 0 0 $RxHub $RxSlot $RxPort
###########################################################################################
#Transmit PacketCount packets to the Rx Card, and read counters after transmition. #
#Note: the current transmit mode is set to single burst of $PacketCount packets. Therefore#
# we don't need to use "HTRun $HTSTOP $TxHub $TxSlot $TxPort" to stop the traffic. #
###########################################################################################
puts "Tranmsitting $PacketCount packets ..."
LIBCMD HTRun $HTRUN $TxHub $TxSlot $TxPort
# Wait for one second to allow packets to transmit, and counters to be updated.
LIBCMD NSDelay 2
###########################################################################################
#Stop capture #
###########################################################################################
LIBCMD HTSetCommand $NS_CAPTURE_STOP 0 0 0 0 $RxHub $RxSlot $RxPort
#LIBCMD HTRun $HTSTOP $TxHub $TxSlot $TxPort
#after 2000
puts "Stop capture"
###########################################################################################
#Display Counters (HTGetCounters). #
###########################################################################################
#Get Counters from both Tx Card and Rx Card.
puts "Reading counters ..."
struct_new TxCounters HTCountStructure
struct_new RxCounters HTCountStructure
LIBCMD HTGetCounters TxCounters $TxHub $TxSlot $TxPort
LIBCMD HTGetCounters RxCounters $RxHub $RxSlot $RxPort
puts ""
puts "---------------------------------------------------------------"
puts "TX transmitted: $TxCounters(TmtPkt) "
puts "RX received: $RxCounters(RcvPkt) "
puts "---------------------------------------------------------------"
unset TxCounters
unset RxCounters
###########################################################################################
#Display Counters (AT_PORT_COUNTER_INFO). #
###########################################################################################
puts ""
puts "Reading port counters ..."
struct_new pc ATPortCounterInfo
LIBCMD HTGetStructure $AT_PORT_COUNTER_INFO 0 0 0 pc 0 $TxHub $TxSlot $TxPort
puts ""
puts "---------------------------------------------------------------"
puts "TX port: txFrames=$pc(u64TxAAL5Frames.low), rxFrames=$pc(u64RxAAL5Frames.low), \
txCells=$pc(u64TxAssignedCells.low), rxCells=$pc(u64RxCells.low)"
LIBCMD HTGetStructure $AT_PORT_COUNTER_INFO 0 0 0 pc 0 $RxHub $RxSlot $RxPort
puts "RX port: txFrames=$pc(u64TxAAL5Frames.low), rxFrames=$pc(u64RxAAL5Frames.low), \
txCells=$pc(u64TxAssignedCells.low), rxCells=$pc(u64RxCells.low)"
puts "---------------------------------------------------------------"
unset pc
###########################################################################################
#Display Counters (AT_VC_COUNTER_INFO). #
###########################################################################################
puts ""
puts "Reading VC counters ..."
struct_new vc ATVCCounterInfo
puts ""
puts "---------------------------------------------------------------"
for {set i 0} {$i < $VCCount} {incr i} {
LIBCMD HTGetStructure $AT_VC_COUNTER_INFO $i 0 0 vc 0 $TxHub $TxSlot $TxPort
puts "TX VC $i: txCells=$vc(u64TxCells.low), txFrames=$vc(u64TxAAL5Frames.low), \
rxCells=$vc(u64RxCells), rxFrames=$vc(u64RxAAL5Frames)"
LIBCMD HTGetStructure $AT_VC_COUNTER_INFO $i 0 0 vc 0 $RxHub $RxSlot $RxPort
puts "RX VC $i: txCells=$vc(u64TxCells.low), txFrames=$vc(u64TxAAL5Frames.low), \
rxCells=$vc(u64RxCells), rxFrames=$vc(u64RxAAL5Frames)"
}
puts "---------------------------------------------------------------"
unset vc
###########################################################################################
#Display Packets captured by Rx card. #
###########################################################################################
#Get number of packets captured by Rx card.
struct_new CapCount NSCaptureCountInfo
LIBCMD HTGetStructure $NS_CAPTURE_COUNT_INFO 0 0 0 CapCount 0 $RxHub $RxSlot $RxPort
set PacketCount $CapCount(ulCount)
unset CapCount
#Display packets.
puts ""
for {set i 1} {$i <= $PacketCount} {incr i} {
puts "Displaying packet number $i of $PacketCount: "
puts "---------------------------------------------------------------"
#Define a structure to store captured data
struct_new CapData NSCaptureDataInfo
#Get captured data, starting at index 0.
LIBCMD HTGetStructure $NS_CAPTURE_DATA_INFO [expr $i-1] 0 0 CapData 0 $RxHub $RxSlot $RxPort
#Display captured data: the length of a packet = DataLength + 4-byte CRC.
for {set j 0} {$j < [expr $DataLength ]} {incr j} {
if {[expr $j % 16] == 0} {
puts ""
puts -nonewline [format "%4i: " $j]
}
puts -nonewline [format " %02X" $CapData(ucData.$j._ubyte_)]
}
puts ""
puts "---------------------------------------------------------------"
puts ""
if {$i < [expr $PacketCount]} {
puts "Press ENTER to display next packet, or q to Stop."
gets stdin response
if {$response == "q" || $response == "Q"} {
unset CapData
exit
}
} else {
puts "DONE."
}
unset CapData
}
# Release the slot
LIBCMD HTSlotRelease $TxHub $TxSlot
LIBCMD HTSlotRelease $RxHub $RxSlot
#Unlink Chassis
puts "UnLinking from the chassis now.."
LIBCMD ETUnLink
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?