posppp.tcl
来自「smartbits二次开发示例代码」· TCL 代码 · 共 517 行 · 第 1/2 页
TCL
517 行
# POS_set_stream
# Sets up IP stream on card. Caller passes in Hub Slot Port of Tx card
# (H S P) and Hub Slot Port of Rx card (H2 S2 P2). Procedure uses slot
# numbers to set IP addresses (second octet is derived from card slot number.
#####################################################################
proc POS_set_stream {H S P source_ip dest_ip} {
struct_new streamIP StreamIP
set streamIP(ucActive) 1
set streamIP(ucProtocolType) $::L3_STREAM_IP
set streamIP(uiFrameLength) $::data_length
set streamIP(ucTagField) 1
set streamIP(TypeOfService) 0
set streamIP(TimeToLive) 10
# Source IP
for {set i 0} {$i < 4} {incr i} {
set octet [lindex [split $source_ip .] $i]
set streamIP(SourceIP.$i) $octet
}
# Destination IP
for {set j 0} {$j < 4} {incr j} {
set octet [lindex [split $dest_ip .] $j]
set streamIP(DestinationIP.$j) $octet
}
set streamIP(Netmask.0) 255
set streamIP(Netmask.1) 255
set streamIP(Netmask.2) 255
set streamIP(Netmask.3) 0
set streamIP(Protocol) 4
LIBCMD HTSetStructure $::L3_DEFINE_IP_STREAM 0 0 0 streamIP 0 $H $S $P
###########################################
# Define stream extension
# Multiburst mode with Burst Count of 10,000
# and an MBurstCount of 2 sends two 10,000 packet bursts
###########################################
struct_new extensionIP L3StreamExtension
set extensionIP(ulFrameRate) 5000
set extensionIP(ulTxMode) $::L3_SINGLE_BURST_MODE
set extensionIP(ulBurstCount) $::burst_count
set extensionIP(ulMBurstCount) 0
set extensionIP(ulBGPatternIndex) 0
set extensionIP(ulBurstGap) 0
set extensionIP(uiInitialSeqNumber) 0
LIBCMD HTSetStructure $::L3_DEFINE_STREAM_EXTENSION 0 0 0 extensionIP 0 $H $S $P
}
############################################################################
# LCP Control
# Passing open as an argument opens LCP; anything else closes LCP
############################################################################
proc lcp_control {H S P action } {
struct_new MyPPPControlCfg PPPControlCfg
set MyPPPControlCfg(ulpppInstance) 0
set MyPPPControlCfg(ulpppCount) 1
if {$action == "open"} {
puts "Opening LCP"
set MyPPPControlCfg(ucpppAction) $::PPP_OPEN_LCP
} else {
puts "Closing LCP"
set MyPPPControlCfg(ucpppAction) $::PPP_CLOSE_LCP
}
LIBCMD HTSetStructure $::PPP_SET_CTRL 0 0 0 MyPPPControlCfg 0 $H $S $P
}
############################################################################
####################################################################
# lcp_status
# Uses while loop to poll until LCP status is UP
############################################################################
proc lcp_status {H S P} {
struct_new MyPPPStatusInfo PPPStatusInfo
LIBCMD HTGetStructure $::PPP_STATUS_INFO 0 1 0 MyPPPStatusInfo 0 $H $S $P
set timeout_count 20
set loop_count 0
while {$MyPPPStatusInfo(ucppplcpState) > 0} {
puts "Current LCP status on card [expr $S + 1] is $MyPPPStatusInfo(ucppplcpState)"
after 2500
LIBCMD HTGetStructure $::PPP_STATUS_INFO 0 1 0 MyPPPStatusInfo 0 $H $S $P
incr loop_count
if {$loop_count > $timeout_count} {
break
}
}
if {$MyPPPStatusInfo(ucppplcpState) == 0} {
puts "Final LCP State on card [expr $S + 1] is UP"
} elseif {$MyPPPStatusInfo(ucppplcpState) == 1} {
puts "Final LCP State on card [expr $S + 1] is DOWN"
} else {
puts "Final LCP State on card [expr $S + 1] is an interim or undefined state"
}
}
############################################################################
#################################################################
# show_counter_data
#################################################################
proc show_lcp_counts {H S P} {
struct_new MyPPPStatsInfo PPPStatsInfo
LIBCMD HTGetStructure $::PPP_STATS_INFO 0 1 0 MyPPPStatsInfo 0 $H $S $P
puts "================================================================="
puts " LCP Counts Card [expr $S + 1] "
puts "================================================================="
puts " LCP Configure Requests Sent[format "%10d" $MyPPPStatsInfo(ullcpConfReqSent)]"
puts " LCP Configure Ack Sent [format "%10d" $MyPPPStatsInfo(ullcpConfAckSent)]"
puts " LCP Configure Nak Sent [format "%10d" $MyPPPStatsInfo(ullcpConfNakSent)]"
puts " LCP Configure Reject Sent [format "%10d" $MyPPPStatsInfo(ullcpConfRejectSent)]"
puts " LCP Terminate Requests Sent[format "%10d" $MyPPPStatsInfo(ullcpTermReqSent)]"
puts " LCP Terminate Ack Sent [format "%10d" $MyPPPStatsInfo(ullcpTermAckSent)]"
puts " LCP Protocol Reject Sent [format "%10d" $MyPPPStatsInfo(ullcpTermReqSent)]"
puts " LCP Discard Requests Sent [format "%10d" $MyPPPStatsInfo(ullcpDiscardReqSent)]"
puts " LCP Code Reject Sent [format "%10d" $MyPPPStatsInfo(ullcpCodeRejectSent)]"
puts " LCP Reset Request Sent [format "%10d" $MyPPPStatsInfo(ullcpResetReqSent)]"
puts " LCP Reset Ack Sent [format "%10d" $MyPPPStatsInfo(ullcpResetAckSent)]"
puts "================================================================="
}
##################################################################
##############################################################
# wait_for_stop
# loop checks Tx Rate (packets/sec) and waits until it is zero
# Failure to wait until transmission is complete can result
# in false counter readings.
##############################################################
proc wait_for_txstop {H S P} {
struct_new count HTCountStructure
after 1000
HTGetCounters count $H $S $P
while {($count(TmtPktRate) != 0)} {
HTGetCounters count $H $S $P
after 200
}
}
##############################################################
proc show_counts { } {
struct_new cs HTCountStructure*2
LIBCMD HGGetCounters cs
puts "------------------------------------------------------------"
puts " Test Packet Counts"
puts "------------------------------------------------------------"
puts " Card [expr $::iSlot + 1] Card [expr $::iSlot2 +1]"
puts "------------------------------------------------------------"
puts "Tx Packets $cs(0.TmtPkt) | $cs(1.TmtPkt)"
puts "Rx Packets $cs(0.RcvPkt) | $cs(1.RcvPkt)"
puts "------------------------------------------------------------"
}
###############################################################################
###############################################################
###############################################################
#################### MAIN ###########################
###############################################################
###############################################################
# Check link state and prompt for connect IP if not already linked
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
}
} else {
puts "Smartbits already linked"
}
# Explicitly reserve cards
LIBCMD HTSlotReserve $iHub $iSlot
LIBCMD HTSlotReserve $iHub2 $iSlot2
###################
# Set up group
###################
HGSetGroup ""
HGAddtoGroup $iHub $iSlot $iPort
HGAddtoGroup $iHub2 $iSlot2 $iPort2
# reset card and erase any streams
HGResetPort $RESET_FULL
###########################################
# Check both cards belong to group before
# testing.
###########################################
if {([HGIsHubSlotPortInGroup $iHub $iSlot $iPort] < 1) || ([HGIsHubSlotPortInGroup $iHub2 $iSlot2 $iPort2] < 1)} {
puts "Group not configured correctly"
gets stdin response
exit
}
set_line_cfg $iHub $iSlot $iPort
set_line_cfg $iHub2 $iSlot2 $iPort2
set_encap $iHub $iSlot $iPort
set_encap $iHub2 $iSlot2 $iPort2
POS_set_stream $iHub $iSlot $iPort $stream1ip $stream2ip
POS_set_stream $iHub2 $iSlot2 $iPort2 $stream2ip $stream1ip
ppp_config $iHub $iSlot $iPort $ppp_ip1 $ppp_ip2
ppp_config $iHub2 $iSlot2 $iPort2 $ppp_ip2 $ppp_ip1
lcp_control $iHub $iSlot $iPort open
lcp_control $iHub2 $iSlot2 $iPort2 open
lcp_status $iHub $iSlot $iPort
lcp_status $iHub2 $iSlot2 $iPort2
###########################################
# Clear counters with HGClearPort and
# create Counter Strucutres to hold count data
###########################################
LIBCMD HGClearPort
# reset capture on card 2
reset_capture $iHub2 $iSlot2 $iPort2
#####################################################
# Start transmission with HGStart
# wait_for_txstop waits until burst is done
####################################################
LIBCMD HGStart
wait_for_txstop $iHub $iSlot $iPort
wait_for_txstop $iHub2 $iSlot2 $iPort2
puts "Displaying Counts"
show_counts
puts "Displaying LCP Counts"
wait_for_input
show_lcp_counts $iHub $iSlot $iPort
wait_for_input
show_lcp_counts $iHub2 $iSlot2 $iPort2
puts "Displaying Capture Data from card [expr $iSlot2 + 1]"
wait_for_input
show_packet $iHub2 $iSlot2 $iPort2 $packets_per_display
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?