dot1x_copyfill.tcl

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

TCL
403 行
字号
proc FillSupplicant {H S P } {

    struct_new supplicantFill NSDOT1XSupplicantFill
    
    set supplicantFill(ulBaseIndex) 0
    set supplicantFill(ulDestinationIndex) 1
    set supplicantFill(ulCount) 9
    set supplicantFill(uiField) $::DOT1X_SUPPLICANT_SRC_MAC
    for {set i 0} {$i < 6} {incr i} {
        set supplicantFill(ucDelta.$i) 1
    }
    
    puts "Changing Source MAC with Fill command ..."
    LIBCMD HTSetStructure $::NS_DOT1X_SUPPLICANT_FILL 0 0 0 supplicantFill 0 $H $S $P
    unset supplicantFill
}

################################################################################
# CreateU64String - Creates a U64 or double long string by appending the ulong #
#                   values $high and $low                                      #
#                                                                              #
# inputs:  high: the first 32 bits of the double long value                    #
#           low: the last 32 bits of the double long value                     #
#                                                                              #
# returns:  The string created by appending the values $high and $low.         #
################################################################################
proc CreateU64String {high low} {
    switch -- $high {
        0 {return $low}
        default {
            return "$high$low"
    }
    } 
}

#################################################################################
# - Retrieve Statistics                                                         #
#	                                                                        #
#################################################################################

proc DisplayPortStats {H S P } {

    struct_new stats NSDOT1XSupplicantSessionStatsInfo
    
    puts "\nDisplaying Port Statistics for Supplicants "
    LIBCMD HTGetStructure $::NS_DOT1X_SUPPLICANT_SESSION_STATS_INFO 0 0 0 stats 0 $H $S $P
    
    puts "\n-----------------------------------------------------------------------------------"
    puts " Setup Rate for Supplicants                   :  $stats(ulSetupRate) "
    puts " Authentications Attempted                    :  $stats(ulAuthenticationAttempted) "
    puts " Authentications Successful                   :  $stats(ulAuthenticationSuccessful) "
    puts " Authentications Failed                       :  $stats(ulAuthenticationFailed) "
    puts " Authentication Retries                       :  $stats(ulAuthenticationRetries) "
    puts " Supplicants being Retried                    :  $stats(ulRetried) "
    puts " Failed Supplicants (retries exhausted)       :  $stats(ulFailed) "
    puts " Supplicants Configured                       :  $stats(ulConfigured) "
    puts " Supplicants being Authenticated              :  $stats(ulAuthenticating) "
    puts " Supplicants Authenticated                    :  $stats(ulAuthenticated)  "
    puts " Supplicants Configured, but Idle             :  $stats(ulIdle)"
    puts " Supplicants being Retried or being Started   :  $stats(ulPending)"
    puts " Supplicants being Stopped (in Pending State) :  $stats(ulTerminatedPending)"
    puts " Time when Statistics was Collected           :  $stats(SessionRetrievedTime.ulSecond) seconds\
        $stats(SessionRetrievedTime.ulMicrosecond) microseconds"
    puts " Time when Statistics was Updated             :  $stats(SessionUpdateTime.ulSecond) seconds \
        $stats(SessionUpdateTime.ulMicrosecond) microseconds"
    puts " Total Time for Supplicant Authentication     :  [CreateU64String $stats(u64SetupTime.high) \
        $stats(u64SetupTime.low)]"
    puts "\n-----------------------------------------------------------------------------------"
    
    unset stats
	
}

#################################################################################
# - Check the state of Supplicants                                              #
#	 Verify if both Supplicants have been Authenticated                     #
#################################################################################

proc CheckSupplicantState {SetupInterval AuthenticationTime HeldTime RetryTimes H S P} {

    # Total Maximum Time for each Supplicant to be Authenticated
    set maxAuthenticatingTime [expr $SetupInterval + \
        ($RetryTimes*($AuthenticationTime + $HeldTime))*1000 ]
    set totalAuthenticationTime [expr $maxAuthenticatingTime *10]  ;# for all Supplicants
    set elapsedTotalTime 0
    
    struct_new supplicantStatus NSDOT1XSupplicantStatusInfo*10
    
    puts "Checking for Successful Authentication ..."
    LIBCMD HTGetStructure $::NS_DOT1X_SUPPLICANT_STATUS_INFO 0 10 0 supplicantStatus 0 $H $S $P
    
    for {set i 0} {$i < 10} {incr i} {
        while { ($supplicantStatus($i.ucSupplicantState) != $::DOT1X_SUPPLICANT_AUTHENTICATED) || \
            ($supplicantStatus($i.ucSessionState) != $::DOT1X_SUPPLICANT_SESSION_AUTHENTICATED) } {
            
            after $maxAuthenticatingTime
            LIBCMD HTGetStructure $::NS_DOT1X_SUPPLICANT_STATUS_INFO 0 10 0 supplicantStatus 0 $H $S $P
            incr elapsedTotalTime [expr $maxAuthenticatingTime]
        }
    }
    
    if {$elapsedTotalTime >= $totalAuthenticationTime} {
        puts " *** ERROR Authentication Failed ***"
    }
}


set TxHub 0
set TxSlot 0
set TxPort 0
source show.tcl

struct_new ulSubHandle ULong

set SetupInterval 20         ;# Setup Interval between Supplicants
set AuthenticationTime 30    ;# Authentication time - time that a supplicant waits for a response from the 
                             #Authenticator before timing out
set HeldTime 60              ;# Time to wait after Authenticator Failure in seconds
set RetryTimes 1             ;# Number of Retry attempts after Authentication Failure

# Reserve the cards
LIBCMD HTSlotReserve $TxHub $TxSlot

# Reset the cards to the default values
LIBCMD HTResetPort $RESET_FULL $TxHub $TxSlot $TxPort

#################################################################################
# - Start Subprocess for Supplicant                                             #
#                                                                               #
#################################################################################
set ulSubHandle(ul) [StartSubprocess $TxHub $TxSlot $TxPort]


#################################################################################
# - Delete all supplicants, and clear all the supplicants and session           #
#   statistics on the port.                                                     #
#################################################################################

LIBCMD HTSetCommand $::NS_DOT1X_SUPPLICANT_RESET 0 0 0 "" $TxHub $TxSlot $TxPort


#################################################################################
# - Configure port for Supplicant configuration.                                #
#                                                                               #
#################################################################################
ConfigurePort $SetupInterval $TxHub $TxSlot $TxPort 


#################################################################################
# - Configure Supplicants.                                                      #
#                                                                               #
#################################################################################
ConfigureSupplicant $AuthenticationTime $HeldTime $RetryTimes $TxHub $TxSlot $TxPort 


#################################################################################
# - Copy Supplicant Configuration.                                              #
#                                                                               #
#################################################################################
CopySupplicant $TxHub $TxSlot $TxPort


#################################################################################
# - Fill Parameter Supplicant Configuration.                                    #
#                                                                               #
#################################################################################
FillSupplicant $TxHub $TxSlot $TxPort


#################################################################################
# - Start Supplicant, to begin Authentication                                   #
#                                                                               #
#################################################################################
StartSupplicant $TxHub $TxSlot $TxPort 
after 3000
#################################################################################
# - Check Supplicant State                                                      #
#                                                                               #
#################################################################################
CheckSupplicantState $SetupInterval $AuthenticationTime $HeldTime $RetryTimes \
                     $TxHub $TxSlot $TxPort
                     

#################################################################################
# - Display Port Statistics                                                     #
#                                                                               #
#################################################################################
DisplayPortStats $TxHub $TxSlot $TxPort

#################################################################################
# - Stop Supplicants to end Authentication                                      #
#                                                                               #
#################################################################################
StopSupplicant $TxHub $TxSlot $TxPort 

#Destroy Subporcess
LIBCMD HTSetStructure $::NS_DESTROY_SUBPROCESS 0 0 0 ulSubHandle 0 $TxHub $TxSlot $TxPort  

# Unlink from Chassis
NSUnLink
puts "DONE!"

⌨️ 快捷键说明

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