posppp.tcl

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

TCL
517 行
字号
#####################################################################
# posppp.tcl                                                        #
#                                                                   #
# Program tested against two POS-3500As in a SmartBits 600          #
#                                                                   #
# Sets up PPP on POS                                                #
# ASSUMES:                                                          #
# SmartLib.tcl has been sourced                                     #
# You will need to set ipaddr to the address of the local box       #
# POS cards connected back to back                                  #
#                                                                   #
# NOTE: This script works on the following cards:                   #
#       - POS-6500/6502                                             #
#                                                                   #
#####################################################################


if  {$tcl_platform(platform) == "windows"} {
      set libPath "../../../../tcl/tclfiles/smartlib.tcl"
} else {
         set libPath "../../../../include/smartlib.tcl"
}

# if it is not loaded, try to source it at 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
     }
}

# SET CONSTANTS

set iHub 0
set iSlot 0
set iPort 0

set iHub2 0
set iSlot2 1
set iPort2 0

# address of card stack
set ppp_ip1 "10.1.1.[expr $iSlot + 1]"
set ppp_ip2 "10.1.1.[expr $iSlot2 + 1]"

# address of SmartMetricsStreams
set stream1ip 10.1.1.100
set stream2ip 10.1.1.200

# 10,000 packets
set burst_count 10000

# number of captured packets to display
set packets_per_display 5

# packet length
set data_length 120

    ################################################################################
    ################################################################################
    ############################   PROCEDURES   ####################################
    ################################################################################
    ################################################################################

################### LIBCMD ####################################
# LIBCMD error handler (from misc.tcl)
###############################################################
proc LIBCMD {args} {
	set iResponse [uplevel $args]
	if {$iResponse < 0} {
	   puts "$args :  $iResponse"
	}
}
#################### END LIBCMD ###############################

#####################################################################
# wait_for_input
# Pause routine that allows user to view error messages
#####################################################################
proc wait_for_input {} {

   puts "Press ENTER to continue"
   gets stdin response
   return $response
}
#####################################################################

#####################################################################
# reset_capture   stop and restart capture
#####################################################################
proc reset_capture { H S P } {

#LIBCMD HTSetCommand $::L3_CAPTURE_OFF_TYPE 0 0 0 "" $H $S $P
#LIBCMD HTSetCommand $::L3_CAPTURE_ALL_TYPE 0 0 0 "" $H $S $P

# Capture set up
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 $H $S $P
after 2000

# Start capture
LIBCMD HTSetCommand $::NS_CAPTURE_START 0 0 0 0 $H $S $P

}
#####################################################################

#####################################################################
# show_packet 
# displays the contents of num_packets formatted in readable form
#####################################################################
proc show_packet { H S P num_packets } {

global data_length NS_CAPTURE_DATA_INFO NS_CAPTURE_COUNT_INFO

# Stop capture
LIBCMD HTSetCommand $::NS_CAPTURE_STOP 0 0 0 0 $H $S $P

struct_new CapCount NSCaptureCountInfo
LIBCMD HTGetStructure $NS_CAPTURE_COUNT_INFO 0 0 0 CapCount 0 $H $S $P
   if {$CapCount(ulCount) < 1} {
       puts "No packets captured on card [expr $S + 1]"
   } else {
      if {$CapCount(ulCount) < $num_packets} {
      set num_packets $CapCount(ulCount)
      }
    struct_new CapData NSCaptureDataInfo
    for {set i 0} {$i < $num_packets} {incr i} {
         set capData(ulFrameIndex)         $i
         set capData(ulRequestedLength)    2048
         LIBCMD HTGetStructure $NS_CAPTURE_DATA_INFO 0 0 0 CapData 0 $H $S $P
#         for {set j 0} {$j < [expr $data_length + 4]} {incr j} {}
         for {set j 0} {$j < $CapData(ulRetrievedLength)} {incr j} {
         set iData 0
                  if {[expr $j % 16] == 0} {
                        puts ""
                        puts -nonewline [format "%4i:   " $j]
                  }
                  puts -nonewline " "
                  puts -nonewline [format "%02X" $CapData(ucData.$j._ubyte_)]                     
         }
         puts ""
	 if {$i < [expr $num_packets - 1]} {
	 puts ""
	 puts "Press ENTER to display packet [expr $i + 2]"
	 gets stdin response
	 } else {
	 puts "End of captured data!"
	 }
    }
 }
}
#####################################################################

####################################################################
#
#####################################################################
proc set_line_cfg {H S P} {
struct_new MyLineCfg POSCardLineConfig
   set MyLineCfg(ucCRC32Enabled) 0
   set MyLineCfg(ucScramble) 1
LIBCMD HTSetStructure $::POS_CARD_LINE_CONFIG 0 0 0 MyLineCfg 0 $H $S $P
}

####################################################################
# set_encap
#####################################################################
proc set_encap {H S P} {
struct_new MyEncap POSCardPortEncapsulation
   set MyEncap(ucEncapStyle) $::PROTOCOL_ENCAP_TYPE_STD_PPP
  LIBCMD HTSetStructure $::POS_CARD_PORT_ENCAP 0 0 0 MyEncap 0 $H $S $P
}
####################################################################

############################################################################
# PPP Configuration
#
############################################################################
proc ppp_config {H S P our_ip peer_ip} {

  struct_new MyPPPParamCfg PPPParamCfg

  set MyPPPParamCfg(ulpppInstance) 0
  set MyPPPParamCfg(ulpppCount) 1

  # From PPPItems.h
  # * Current PPP negotiation options:
  # *	PPPO_MRU          		0x0001
  # * PPPO_USECHAPAUTH  		0x0010
  # * PPPO_USEPAPAUTH   		0x0020
  # * PPPO_USEMAGIC     		0x0080
  # * PPPO_USENONE			0x0000
  #
  # Use OR to combine options as shown.
  # We ask for MRU negotiation and Magic Number
  set MyPPPParamCfg(uipppWeWish) [expr $::PPPO_USEMAGIC + $::PPPO_MRU]
  # We MUST get at least Magic Number (will fail without)
  set MyPPPParamCfg(uipppWeMust) $::PPPO_USEMAGIC
  # But we CAN support any of the options
  set MyPPPParamCfg(uipppWeCan) [expr $::PPPO_USEMAGIC + $::PPPO_MRU]
  set MyPPPParamCfg(ucpppEnablePPP) 1

  set MyPPPParamCfg(uipppMRU) 1500
  set MyPPPParamCfg(uipppMaxFailure) 5
  set MyPPPParamCfg(uipppMaxConfigure) 10
  set MyPPPParamCfg(uipppMaxTerminate) 2
  # 0 generates random Magic Number
  set MyPPPParamCfg(ulpppMagicNumber) 2
  set MyPPPParamCfg(uipppRestartTimer) 3
  set MyPPPParamCfg(uipppRetryCount) 1
  set MyPPPParamCfg(ucpppIPEnable) 1
  for {set i 0} {$i < 4} {incr i} {
    set octet [lindex [split $our_ip .] $i]
    set MyPPPParamCfg(ucpppOurIPAddr.$i) $octet
  }
  # Default Gateway is the same as the peer ip in 
  for {set j 0} {$j < 4} {incr j} {
    set octet [lindex [split $peer_ip .] $j]
    set MyPPPParamCfg(ucpppPeerIPAddr.$j) $octet
  }
  LIBCMD HTSetStructure $::PPP_SET_CONFIG 0 0 0 MyPPPParamCfg 0 $H $S $P
}

############################################################################


####################################################################

⌨️ 快捷键说明

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