dot1x_copyfill.tcl

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

TCL
403 行
字号
################################################################################################
# dot1x_copyfill.tcl                                                                           #
#                                                                                              #
# - Demonstrates the configuration of Supplicants for Terametrics XD and Xenpak cards.         #
# - Configures the Port for Supplicant Configuration                                           #
# - Configures one supplicant.      																			  #
# - Use copy command (NS_DOT1X_SUPPLICANT_COPY) to create 9 additional supplicants.            #
# - Use fill command (NS_DOT1X_SUPPLICANT_FILL) to change and increment Source MAc   			  #
# - Displays Port Statistics of Supplicants.                                                   #
# - This script assumes that an Authenticator is on the Rx, and the ID and Password            #
#   expected by the Authenticator is "tom" and "tom123" respectively.                          #
################################################################################################

# 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 address and then 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
    }
}

#################################################################################
# - Start Supplicant Subprocess                                                 #
#	                                                                             #
#################################################################################

proc StartSubprocess {H S P } {

    struct_new subProcess NSCreateSubprocess
    set subProcess(ulUserID) 	0
    set subProcess(ulGroupID)  0
    set subProcess(uiModuleID) 51968
    set subProcess(ulSharedMemKey)    	1684108910
    set subProcess(ucCommand.0) [ConvertCtoI "d"]
    set subProcess(ucCommand.1) [ConvertCtoI "o"]
    set subProcess(ucCommand.2) [ConvertCtoI "t"]
    set subProcess(ucCommand.3) [ConvertCtoI "1"]
    set subProcess(ucCommand.4) [ConvertCtoI "x"]
    set subProcess(ucCommand.5) [ConvertCtoI "d"]
    LIBCMD HTSetStructure $::NS_CREATE_SUBPROCESS 0 0 0 subProcess 0 $H $S $P
    return  $subProcess(ulSubprocessHandle)
}


#################################################################################
# - Configure the Port for Supplicant Configuration                             #
#   Configure the Port for Supplicants to be started at an even interval.       #
#                                                                               #
#################################################################################

proc ConfigurePort {SetupInterval H S P } {

    struct_new portConfig NSDOT1XSupplicantPortConfig
    set portConfig(ulSessionSetupDelay) 	$SetupInterval
    set portConfig(ulSessionTearDownDelay) 20
    set portConfig(ulSessionBurstSize) 	100
    set portConfig(uiSessionMaxPending) 	100
    set portConfig(ucSessionControlMode)     $::DOT1X_SESSION_CONTROL_EVEN_BURST
    set portConfig(ucPortAuthenticationMode) $::DOT1X_MAC_BASED_AUTHENTICATION_MODE
    
    puts "\nConfiguring Port ..."
    LIBCMD HTSetStructure $::NS_DOT1X_SUPPLICANT_PORT_CONFIG 0 0 0 portConfig 0 $H $S $P
    unset portConfig
}


#################################################################################
# - Configure Supplicant                                                        #
#   Configure 1 Supplicants.                                                    #
#################################################################################

proc ConfigureSupplicant {AuthenticationTime HeldTime RetryTimes H S P } {

    struct_new supplicantConfigure NSDOT1XSupplicantConfig
    set supplicantConfigure(ulIndex) 0
    set supplicantConfigure(ulCount) 1
    set supplicantConfigure(ucSourceMAC) {2 2 2 2 2 2}
    set supplicantConfigure(ucDestinationMAC) {1 2 3 4 5 6}
    set supplicantConfigure(ucAuthenticationMode) $::DOT1X_AUTHENTICATION_MODE_ACTIVE
    set supplicantConfigure(uiMaxStart) 3
    set supplicantConfigure(uiStartTime) 30
    set supplicantConfigure(uiAuthenticationTime) $AuthenticationTime
    set supplicantConfigure(uiHeldTime) $HeldTime
    set supplicantConfigure(ucAuthenticationMethod) $::DOT1X_AUTHENTICATION_METHOD_EAPMD5
    set supplicantConfigure(ucAuthenticationID._char_) "tom"
    set supplicantConfigure(ucAuthenticationPassword._char_) "tom123"
    set supplicantConfigure(uiRetryCount) $RetryTimes
    
    puts "Configuring Supplicant ..."
    LIBCMD HTSetStructure $::NS_DOT1X_SUPPLICANT_CONFIG 0 0 0 supplicantConfigure 0 $H $S $P
    unset supplicantConfigure
}



#################################################################################
# - Start Supplicant                                                            #
#	 Start Supplicant with index 0 to index 9                               #
#################################################################################

proc StartSupplicant {H S P } {

    struct_new startSupplicant NSDOT1XSupplicantControl
    
    set startSupplicant(ulIndex) 0
    set startSupplicant(ulCount) 10
    set startSupplicant(ulAction) $::DOT1X_SUPPLICANT_START
    
    puts "Starting Supplicant to begin Authenticating ..."
    LIBCMD HTSetStructure $::NS_DOT1X_SUPPLICANT_CONTROL 0 0 0 startSupplicant 0 $H $S $P
    unset startSupplicant
}


#################################################################################
# - Stop Supplicants                                                            #
#	 Stop all Supplicants                                                        #
#################################################################################

proc StopSupplicant {H S P } {

    struct_new stopSupplicant NSDOT1XSupplicantControl
    
    set stopSupplicant(ulIndex) 0
    set stopSupplicant(ulCount) $::DOT1X_ALL
    set stopSupplicant(ulAction) $::DOT1X_SUPPLICANT_STOP
    
    puts "Stopping Supplicants ..."
    LIBCMD HTSetStructure $::NS_DOT1X_SUPPLICANT_CONTROL 0 0 0 stopSupplicant 0 $H $S $P
    unset stopSupplicant

}


#################################################################################
# - Copy Supplicant                                                             #
# - Copy Supplicant at index 0 and create 9 new Supplicants with the same       #
#   configuration as Supplicant at index 0                                      #
#################################################################################

proc CopySupplicant {H S P } {

    struct_new supplicantCopy NSDOT1XSupplicantCopy
    
    set supplicantCopy(ulBaseIndex) 0
    set supplicantCopy(ulDestinationIndex) 1
    set supplicantCopy(ulCount) 9
    
    puts "Copying Supplicant ..."
    LIBCMD HTSetStructure $::NS_DOT1X_SUPPLICANT_COPY 0 0 0 supplicantCopy 0 $H $S $P
    unset supplicantCopy
}

#################################################################################
# - Fill Supplicant                                                             #
# - Increment Source MAC for Supplicants with index 1 to 9                      #
#   Source MAC for Supplicant 1 will be 3.3.3.3.3.3, Supplicant 2 will be       #
#   4.4.4.4.4.4 and so on.                                                      #
#################################################################################

⌨️ 快捷键说明

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