atmbasic.tcl

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

TCL
421 行
字号
#############################################################################################
# atmbasic.tcl                                                                              #
#                                                                                           #
# - Sets up two streams each on two cards then starts, stops the streams on card 1.         #
# - Displays Tx Rx counts on both cards.                                                    #
#                                                                                           #
# - Creates numStreams PVC streams starting at 0/32 (0/20 hex) and incrementing upward.     #
#                                                                                           #
# - Program will work with two cards connected back to back without a DUT.                  #
# - AT-9155 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_NONE]
     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 numStreams 2


##################    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 for per stream counts"
	gets stdin response
}


#######################################################################
# connectToSmartBits                                                  #
#                                                                     #
# - Checks that SmartLib.tcl is loaded, exits if not found.           #
# - 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 library load
   if {[uplevel #0 info exists __SMARTLIB_TCL__] < 1} {
        puts "SmartLibrary not loaded - source SmartLib.tcl before starting program"
        gets stdin response
        exit
   }

   # 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

}


########################################################################
# createATMStream                                                      #
#                                                                      #
# - Sets up the stream parameters such as type encapsulation,          #
#   rate class, PCR and cell header.  Equivalent to the values         #
#   set on the top part of the Stream Setup window in                  #
#   SmartWindows                                                       #
#                                                                      #
# - Accpets params for encapsulation (either SNAP or 1577) VPI/VCI     #
#   and CLP values                                                     #
#                                                                      #
# - If you are sending the traffic through a device                    #
#   you will need to create VCCs with the corresponding VPI:VCI        #
########################################################################

⌨️ 快捷键说明

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