atmppp.tcl
来自「smartbits二次开发示例代码」· TCL 代码 · 共 569 行 · 第 1/2 页
TCL
569 行
# atmppp.tcl
# Sets up multiple PPP sessions on two cards then starts and
# stops the streams as a group. Displays Tx Rx counts
# on both cards.
#
# Creates numberofPPPSessions starting at 0/32 (0/20 hex)
# and incrementing upward on each card.
#
# Program will work with two cards connected back to
# back without a DUT.
#
# ASSUMES:
# AT-9155C ATM Cards are installed in slot 1 and slot 3.
###################################################
# If smartlib.tcl is not loaded, attempt to locate it at the default location.
# The actual location is different on different platforms.
if {$tcl_platform(platform) == "windows"} {
set libPath "../../../../tcl/tclfiles/smartlib.tcl"
} else {
set libPath "../../../../include/smartlib.tcl"
}
# if "smartlib.tcl" is not loaded, try to source it from the default path
if { ! [info exists __SMARTLIB_TCL__] } {
if {[file exists $libPath]} {
source $libPath
} else {
#Enter the location of the "smartlib.tcl" file or enter "Q" or "q" to quit
while {1} {
puts "Could not find the file $libPath."
puts "Enter the path of smartlib.tcl, or q to exit."
gets stdin libPath
if {$libPath == "q" || $libPath == "Q"} {
exit
}
if {[file exists $libPath]} {
source $libPath
break
}
}
}
}
# If chassis is not currently linked prompt for IP and link
if {[ETGetLinkStatus] < 0} {
puts "SmartBits not linked - Enter chassis IP address"
gets stdin ipaddr
set retval [NSSocketLink $ipaddr 16385 $RESERVE_ALL]
if {$retval < 0 } {
puts "Unable to connect to $ipaddr. Please try again."
exit
}
}
#cards in slots 1...
set iHub 0
set iSlot 0
set iPort 0
#... and 3
set iHub2 0
set iSlot2 2
set iPort2 0
set firstStream 0
set numberOfPPPSessions 4
set burstSize 200
# ip addresses (passed in by function call below)
set ip1 10.10.1.10
set ip2 10.10.2.10
# create global frame definition structure
catch {unset Frame}
struct_new Frame ATMFrameDefinition
##########################################################
################## PROCEDURES #######################
##########################################################
##########################################################
# LIBCMD error handler
##########################################################
proc LIBCMD {args} {
set iResponse [uplevel $args]
if {$iResponse < 0} {
puts "$args : $iResponse"
}
}
#########################################################
#########################################################
# waitForInput
# Simple wait until ENTER is pressed routine
#########################################################
proc waitForInput {} {
puts "\nPress ENTER to continue"
gets stdin response
}
#########################################################
#########################################################
# connectToSmartBits
#
# Checks for link with chassis. If not linked, will link to IP
# address if one was passed in, will prompt user for IP otherwise
#########################################################
proc connectToSmartBits { {ipaddr 0} } {
# Check for link state, connect if not linked
if {[ETGetLinkStatus] < 1} {
if {$ipaddr == 0} {
puts "Chassis not linked, Enter SmartBits chassis IP address"
gets stdin ipaddr
}
set retval [NSSocketLink $ipaddr 16385 $RESERVE_ALL]
}
}
#########################################################
#########################################################
# setATMOC3
# Set line parameters for ATM OC-3 (AT-9155) card.
#########################################################
proc setATMOC3 { H S P } {
struct_new LineParams ATMLineParams
set LineParams(ucFramingMode) $::ATM_OC3_FRAMING
set LineParams(ucTxClockSource) $::ATM_INTERNAL_CLOCK
set LineParams(ucCellScrambling) $::TRUE
set LineParams(ucHecCoset) $::TRUE
set LineParams(ucRxErroredCells) $::ATM_CORRECT_ERRORED_CELLS
set LineParams(ucLoopbackEnable) $::ATM_LOOPBACK_DISABLED
for {set i 0} {$i < 4} {incr i} {
set LineParams(ucIdleCellHeader.$i) 0
}
LIBCMD HTSetStructure $::ATM_LINE 0 0 0 LineParams 0 $H $S $P
}
#########################################################
#########################################################
# getMaxStreamCount
# Queries card for the maximum number of streams it can
# support and returns value to caller
#########################################################
proc getMaxStreamCount {H S P} {
struct_new CardCapabilities ATMCardCapabilities
LIBCMD HTGetStructure $::ATM_CARD_CAPABILITY 0 0 0 CardCapabilities 0 $H $S $P
return $CardCapabilities(uiMaxStream)
}
##########################################################
#########################################################
# getMaxBandwidth
# Queries card for the maximum bandwidth of card
#########################################################
proc getMaxBandwidth {H S P} {
struct_new CardCapabilities ATMCardCapabilities
LIBCMD HTGetStructure $::ATM_CARD_CAPABILITY 0 0 0 CardCapabilities 0 $H $S $P
return $CardCapabilities(ulLineCellRate)
}
##########################################################
##########################################################
# clearATMStream
# disconnects and resets all streams on target card
##########################################################
proc clearATMStream {H S P} {
struct_new ATM ATMStreamControl
set maxStreamsOnCard [getMaxStreamCount $H $S $P]
#Disconnect all streams
set ATM(ucAction) $::ATM_STR_ACTION_DISCONNECT
set ATM(ulStreamIndex) 0
set ATM(ulStreamCount) $maxStreamsOnCard
LIBCMD HTSetStructure $::ATM_STREAM_CONTROL 0 0 0 ATM 0 $H $S $P
# Reset All Streams
set ATM(ucAction) $::ATM_STR_ACTION_RESET
set ATM(ulStreamIndex) 0
set ATM(ulStreamCount) $maxStreamsOnCard
LIBCMD HTSetStructure $::ATM_STREAM_CONTROL 0 0 0 ATM 0 $H $S $P
}
##########################################################
##########################################################
# setPPPCfg
# sets PPP parameters for the target card. Local IP
# address is either passed in or defaults to 10.1.1.1
# Peer IP is passed as second argument or defaults to
# 10.1.2.1.
#
# For simplicity running back to back we use no authorization
# The auth enabling code is commented out,
##########################################################
proc setPPPCfg {H S P streams {localip 10.1.1.1} {peerip 10.1.2.1} } {
set enable 1
set disable 0
struct_new pppCfg PPPParamCfg
set pppCfg(ulpppInstance) 0
set pppCfg(ulpppCount) $streams
# LCP Negotiation options
# set pppCfg(uipppWeWish) $::PPPO_USECHAPAUTH
# set pppCfg(uipppWeMust) $::PPPO_USECHAPAUTH
# set pppCfg(uipppWeCan) $::PPPO_USECHAPAUTH
set pppCfg(uipppWeWish) $::PPPO_USENONE
set pppCfg(uipppWeMust) $::PPPO_USENONE
set pppCfg(uipppWeCan) $::PPPO_USENONE
# LCP parameters
set pppCfg(ucpppEnablePPP) $enable
set pppCfg(ucpppCHAPAlgo) $::PPP_CHAPMS
set pppCfg(uipppMRU) $::PPP_CONFIGURE_MRU
set pppCfg(uipppMaxFailure) $::PPP_CONFIGURE_MAXFAILURE
set pppCfg(uipppMaxConfigure) $::PPP_CONFIGURE_MAXCONFIGURE
set pppCfg(uipppMaxTerminate) $::PPP_CONFIGURE_MAXTERMINATE
set pppCfg(ulpppMagicNumber) $::PPP_CONFIGURE_MAGICNUMBER
# login and password we will authenticate
set pppCfg(ucpppOurID.0._char_) "l"
set pppCfg(ucpppOurID.1._char_) "o"
set pppCfg(ucpppOurID.2._char_) "g"
set pppCfg(ucpppOurID.3._char_) "i"
set pppCfg(ucpppOurID.4._char_) "n"
set pppCfg(ucpppOurPW.0._char_) "p"
set pppCfg(ucpppOurPW.1._char_) "a"
set pppCfg(ucpppOurPW.2._char_) "s"
set pppCfg(ucpppOurPW.3._char_) "s"
set pppCfg(ucpppOurPW.4._char_) "w"
set pppCfg(ucpppOurPW.5._char_) "o"
set pppCfg(ucpppOurPW.6._char_) "r"
set pppCfg(ucpppOurPW.7._char_) "d"
# login and password we will send to peer
set PPPCfg(ucpppPeerID.0._char_) "l"
set PPPCfg(ucpppPeerID.1._char_) "o"
set PPPCfg(ucpppPeerID.2._char_) "g"
set PPPCfg(ucpppPeerID.3._char_) "i"
set PPPCfg(ucpppPeerID.4._char_) "n"
set PPPCfg(ucpppPeerPW.0._char_) "p"
set PPPCfg(ucpppPeerPW.1._char_) "a"
set PPPCfg(ucpppPeerPW.2._char_) "s"
set PPPCfg(ucpppPeerPW.3._char_) "s"
set PPPCfg(ucpppPeerPW.4._char_) "w"
set PPPCfg(ucpppPeerPW.5._char_) "o"
set PPPCfg(ucpppPeerPW.6._char_) "r"
set PPPCfg(ucpppPeerPW.7._char_) "d"
# IP parameters
set pppCfg(ucpppIPEnable) $enable
set pppCfg(ucpppNegotiateIPAddr) $enable
set pppCfg(uipppIPCompress) $disable
# set local IP address
for {set i 0} {$i < 4} {incr i} {
set pppCfg(ucpppOurIPAddr.$i) [lindex [split $localip .] $i]
}
set pppCfg(uipppRestartTimer) 0x03
set pppCfg(uipppRetryCount) 0x05
# set peer IP address
for {set i 0} {$i < 4} {incr i} {
set pppCfg(ucpppPeerIPAddr.$i) [lindex [split $peerip .] $i]
}
LIBCMD HTSetStructure $::PPP_SET_CONFIG 0 0 0 pppCfg 0 $H $S $P
# copy parameters to all of the streams
struct_new pppCopy PPPParamsCopy
set pppCopy(uipppSrcStrNum) 0
set pppCopy(uipppDstStrNum) 1
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?