码迷,mamicode.com
首页 > Windows程序 > 详细

使用Tcl脚本调用STC平台的Native API实现测试对象、Device、StreamBlock的创建和配置

时间:2015-05-28 21:39:10      阅读:589      评论:0      收藏:0      [点我收藏+]

标签:测试   脚本   native   api   

使用Tcl脚本调用STC平台的Native API实现测试对象、Device、StreamBlock的创建和配置


环境配置如下:

在Windows的Conmand下操作


#
# Configuration file(CommonConFig.tcl)
#
# Initializing the Script.

# This script is used to set common configuration paramters used with the STC-300 class.



#Step 1: Load Spirent TestCenter Automation API.
# Type in the code that will load in the Spirent TestCenter Automation API
# using the package require Tcl command.

puts ""
puts "Loading the SpirentTestCenter API Package"

  #Place your code after this line.



source "C:/Program Files/Spirent Communications/Spirent TestCenter 3.70/Spirent TestCenter Application/SpirentTestCenter.tcl"
puts "Spirent TestCenter API is Loaded."
puts ""


#Step 2: Variable declaration
# Note: Check with the Instructor to Obtain your Chassis IP Address as well as the Slot and Port Pair.
# Replace the xxx‘s with your Equipment Information.


  set chassis_ip 10.132.238.190
  set TxSlot 1
  set RxSlot 1
  set TxPort 7
  set RxPort 8
  set chassis_invalidip 10.88.20.8
  set portList "//$chassis_ip/$TxSlot/$TxPort //$chassis_ip/$RxSlot/$RxPort"

puts "Chassis/Slot/Port Variables have been declared."
puts "This script is using Chassis:$chassis_ip  Slot:$TxSlot  Port:$TxPort"
puts "             Chassis:$chassis_ip  Slot:$RxSlot  Port:$RxPort"
puts " "


1、  使用Tcl脚本调用STC平台的Native API实现机框的连接、端口占用等功能


#########################################################################
#
#      
#      Template Tcl File for Lab: Initialization/Connection/Reservation(Connect.tcl)
#
#     The CommonConfig.tcl file must be properly configured with the
#     Spirent TestCenter Chassis IP Address and Slot/Port Pairs
#     in order for this lab to run properly.
#
#########################################################################
# Source in CommonConfig.tcl file
#  1: Source in the Common Config.tcl file that contains the Load and System Variable information.
#
# Connect:
#  1: Connect to given chassis_ip using stc::connect API Function.
#  Note: Try using chassis_invaldiip and check the output.
#
# Port Reservation:
#  1: Reserve Physical Ports
#  2: Check that the Physical Ports are Reserved using the GUI.
#
# Release Ports:
#  1: Release the Reserved Physical Ports.
#  2: Check that the Physical Ports are Released using the GUI.
#
# Disconnect from the Chassis:
#  1: Disconnect the script from the Spirent TestCenter Chassis using stc::disconnect API Function.
#
#  Note: Please check the following variables before using the script
#        IP address of chassis "chassis_ip"
#        Ports to be used in the chassis "portList"
#
#########################################################################

## Source in CommonConfig.tcl
#Step1: Sourcing in CommonConfig.tcl file
 puts ""
 puts "Sourcing in CommonConfig.tcl file."

 source CommonConFig.tcl


 #
 # Place Code Here
 #
 


## Connect
#Step 1: Connecting to chassis
  puts "\n*** Connecting to Chassis ***\n"
 
puts "Syntax stc::connect $chassis_ip\n"
set result [stc::connect $chassis_ip ]

  #
  # Place Code Here
  #
 
  puts "The return value of stc::connect api is ->\" $result\" \n"

  #
  # Note: Please uncomment the stc::connect $chassis_invalidip line..
  # STC::connect api will not return any error but will display exception as follows:
  #
  #19:59:48.017 ERROR - in connect: CStcRunTimeError Failed to connect to chassis 1
  #0.88.22.18.  Please check that equipment is online/up.
  #stcerror in connect: CStcRunTimeError Failed to connect to chassis 10.88.22.18.
  #Please check that equipment is online/up.
  #

#  puts "Note: Invalid ip wont return error. But connect API throws exception"
#  set result [stc::connect $chassis_invalidip ]
#  puts "The status is $result.This line is never executed incase of invalid ip."



## Port Reservation
#Step 1: Reserve the Physical Ports
 foreach port $portList {
  stc::reserve $port
  puts "**** Reserving port $port ***"
}

 #
 # Place Code Here
 #

#Step 2: Check Ports in the GUI
puts ""
puts "Check if the ports are Reserved within the Reservation Window of the GUI."
puts ""
puts "Press enter to continue..."
flush stdout
gets stdin pause


## Release Ports  
#Step 1: Release the ports
 

 #
 # Place Code Here
 #

#Step 2: Check Ports in the GUI
puts ""
puts "Check if the ports are Released within the Reservation Window of the GUI."
puts "The status of the Ports should be Available or Rebooting. "
puts ""
puts "Press enter to continue..."
flush stdout
gets stdin pause

## Release Ports  
#Step 1: Release the ports
foreach port $portList {
  stc::release $port
  puts "**** Releasing port $port ***"
}

## Disconnecting
#Step 1: Disconnecting from the Chassis.
  puts "\n*** Disconnecting from the chassis ***\n"

set result [stc::disconnect $chassis_ip ]
puts "The return value of stc::disconnect api is:\" $result\" \n"
 #
 # Place Code Here
 #



# End

2、  使用Tcl脚本调用STC平台的Native API实现测试对象的创建和配置


 proc p {node} {
  puts "[stc::get $node]"
  foreach n [stc::get $node -children] {
  p $n
  }
}

source CommonConFig.tcl

puts "\n*** Connecting to Chassis ***\n"
set result [stc::connect $chassis_ip ]
puts "Chassis: $chassis_ip is now Connected.\n"


## Port Reservation
#Reserve the Physical Ports
foreach port $portList {
  stc::reserve $port
  puts "**** Reserving port $port ***"
}


#Step 1: Displaying the System Object using the stc::get API Function."
set abc [stc::get system1]
puts "The System Children and Attributes using the stc::get API Function are:"
puts "$abc"
puts "Please press enter to contine the script: <enter>"
gets stdin a

puts "Creating Project Object"
set hProject [stc::create "Project" \
            -TestMode "L2L3" \
            -SelectedTechnologyProfiles "Layer2_and_Layer3" ]

puts "The Project Object has been created and configured."

#Step 2:Displaying all Project Attributes by Calling Procedure p.
p $hProject


#Step 1: Create the First Logical Port Object
puts "Creating Port 1"
set hPort(1) [ stc::create "Port" \
                  -under $hProject \
                  -Location [lindex $portList 0] \
                  -Layer3Type "IPV4"]

puts "Port 1 Created."
p $hPort(1)

puts "Creating Port 2"
set hPort(2) [ stc::create "Port" \
                  -under $hProject \
                  -Location [lindex $portList 1] ]

puts "Port 2 Created."
p $hPort(2)

#Step 5:Displaying the Active Physical Port using the PortSetupGetActivePhy command.  
array set x [stc::perform PortSetupGetActivePhy -Port $hPort(1)]
puts ""
puts "This will display the Active Phy for the first Port "
puts "before Port Mapping is performed."
puts "Active Phy using PortSetupGetActivePhy is: $x(-ActivePhy)"
puts "Please press enter to continue the script: <enter>"
gets stdin a


#Step 8: Setup Port Mappings.
puts "Performing Port Mapping."
stc::perform setupPortMappings
puts "The Ports are now Mapped (logical to physical port)."
puts "Please press enter to contine the script: <enter>"
gets stdin a


#Step 11:Setting EthernetCopper Phy Attributes using the stc:get API Function.
puts ""
puts "Setting EthernetCopper Phy Attributes using the stc:get API Function."
set hMedia1 [stc::get $hPort(1) -children-EthernetCopper]
stc::config $hMedia1 -LineSpeed SPEED_100M -AutoNegotiation FALSE
 
set hMedia2 [stc::get $hPort(2) -children-EthernetCopper]
stc::config $hMedia2 -LineSpeed SPEED_100M -AutoNegotiation FALSE
puts "Please press enter to contine the script: <enter>"
gets stdin a


#Step 12: Applying the Configuration to the Hardware.
puts "Applying the PHY Attributes to the Ports."
stc::apply


#Step 1: Delete Project
puts ""
puts "Deleteing the Project."
stc::delete $hProject
puts "Project Deleted."
puts ""



3、  使用Tcl脚本调用STC平台的Natvie API实现Device的创建和配置



#########################################################################
#
#      
#      Solution for Lab: Device Objects(Devices.sol)
#
#     The CommonConfig.sol file must be properly configured with the
#     Spirent TestCenter Chassis IP Address and Slot/Port Pairs
#     in order for this lab to run properly.
#
#########################################################################
#
# In this lab you will:
# - Create/Configure Device and Interface Objects for 1st Host.
# - Create/Configure Device and Interface Objects for 2nd Host.
# - Set up Device/Port Relationships.
# - Apply the Test Configuration to the Hardware.
# - Enable Ping on Host 1 and ensure that Ping was successful to the attached DUT Gateway.
#
#########################################################################
#
# All of the items in this section have been already scripted for you:
#
# Source in CommonConfig.tcl file
#
# Connect to given chassis_ip using stc::connect API Function.
#
# Port Reservation.
#
# Configure the System Object.
#
# Create/Configure a Project Object.
#
# Create/Configure/View two Port Objects.
#
# Release Ports.
#
# Disconnect from the Chassis:
#
########################################################################################
########################################################################################
#
# Procedure to Display all Object Attributes.
  proc p {node} {
    puts "[stc::get $node]"
    foreach n [stc::get $node -children] {
    p $n
  }
  }


## Source in CommonConfig.tcl
#Sourcing in CommonConfig.tcl file
 puts ""
 puts "Sourcing in CommonConFig.tcl file."
 source "CommonConFig.tcl"
 

## Connect
#Connecting to chassis
  puts "\n*** Connecting to Chassis ***\n"
  set result [stc::connect $chassis_ip ]
  puts "Chassis: $chassis_ip is now Connected.\n"

 
## Port Reservation
#Reserve the Physical Ports
  foreach port $portList {
    stc::reserve $port
    puts "**** Reserving port $port ***"
  }

  puts ""
  puts "*******************Configuring/Viewing System Object*************************"
 

 ##Configure System Object
  puts ""
  puts "The System Object has been created and configured."

 
 ##Displaying Chassis Model and Chassis Firmware Version
  set hPChassisMan [stc::get system1 -children-physicalchassismanager]
  set hPChassis [stc::get $hPChassisMan -children-physicalchassis]
  set abc [stc::get $hPChassis -Model -FirmwareVersion]
  puts ""
  puts "Displaying the Chassis Model and Chassis Firmware Version."
  puts "$abc"
 

  puts ""
  puts ""
  puts "*******************Creating/Configuring Project Object*****************"
  puts ""

 ##Create Project Object
  catch {stc::delete $hProject} err
  puts ""
  puts "Creating Project Object"
  set hProject [stc::create "Project" \
                      -TestMode "L2L3" \
                      -Active "TRUE" \
                      -Name "Project Object1"]

  puts "The Project Object has been created and configured."

  puts ""
  puts ""
  puts "************Creating/Configuring/Viewing Port Objects***********************"
  puts ""

 ##Create the First Logical Port Object
  puts ""
  puts "Creating Port 1"
  set hPort(1) [ stc::create "Port" \
                  -under $hProject \
                  -Location [lindex $portList 0] \
                  -Active "TRUE" \
                  -Name "Port 1"]

  puts "Port 1 Created."

 ##Creating Second Logical Port Object
  puts ""
  puts ""
  puts "Creating Port 2"
  set hPort(2) [ stc::create "Port" \
                  -under $hProject \
                  -Location [lindex $portList 1] \
                  -Active "TRUE" \
                  -Name "Port 2"]

  puts "Port 2 Created."

 
 ##Setup Port Mappings.
  puts "Performing Port Mapping."
  stc::perform setupPortMappings
  puts "The Ports are now Mapped (logical to physical port)."
 


 ##Setting Auto Negotiation to False and Line Speed to 100M for both Ports.
 ##Setting  EthrenetCopper Phy Attributes using the stc:get API Function.
 ##获取port1的以太铜缆属性,并进行线速和自协商属性的设置
  set hMedia1 [stc::get $hPort(1) -children-EthernetCopper]
  stc::config $hMedia1 -LineSpeed SPEED_100M -AutoNegotiation FALSE
 
  set hMedia2 [stc::get $hPort(2) -children-EthernetCopper]
  stc::config $hMedia2 -LineSpeed SPEED_100M -AutoNegotiation FALSE
 
 ##Setting port configure to physical port
  stc::apply


#########################################################################################
#########################################################################################
  puts "*****************************************************************************  "
  puts "*************Beginning of the student Coding for this lab.*******************"
  puts ""
  puts ""
  puts "*******************Creating/Configuring Device/Host and Interface Objects for 1st Device/Host*****************"
 ##开始创建Device
 #Step 1: Create Device/Host
  puts "Creating 1st Device/Host Object."
  set hDevice(1) [stc::create "EmulatedDevice" \
                           -under $hProject \
                           -DeviceCount "1" \
                           -Active "TRUE" \
                           -EnablePingResponse "TRUE"\
                           -Name "Host 1" \
               -AffiliationPort-targets " $hPort(1) "]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a
  puts ""


 #Step 2: Create Layer 2 Ethernet Interface for Device/Host 1.
  puts "Creating Ethernet interface for Device/Host 1."
 ##创建以太网帧接口信息
  set hEthIIIf(1) [stc::create "EthIIIf" \
                              -under $hDevice(1) \
                              -SourceMac "00:10:94:00:00:02" \
                              -Active "TRUE" \
                              -Name "EthIIIf 1" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 
 #Step 3: Create Layer 3 IPv4 Interface for Device/Host 1.
 ##创建IP接口信息
  puts "Creating IP interface for Device/Host 1."
  set hIpv4If(1) [stc::create "Ipv4If" \
                             -under $hDevice(1) \
                             -Address "192.168.81.2" \
                             -AddrStep "0.0.0.1" \
                             -AddrStepMask "0.0.0.255" \
                             -PrefixLength "24" \
                             -Gateway "192.168.81.1" \
                             -GatewayMac "00:00:01:00:00:01" \
                             -Active "TRUE" \
                 -Name "Ipv4If 1"]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 
 #Step 4: Defining IP Stack for Device/Host 1.
 ##此步骤是什么意思?需要查阅资料理解,从手册中查询-StackedOnEndpoint-targets
 ##关于StackedOnEndpoint的手册说明:Specifies network endpoint stacking。Obj-ref的1522页
  puts "Defining IP Stack for Device/Host 1."
 
  stc::config $hIpv4If(1) -StackedOnEndpoint-targets " $hEthIIIf(1) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 

  puts ""
  puts "*******************Creating/Configuring Device/Host and Interface Objects for 2nd Device/Host*****************"
  puts ""
 

#Step 1: Create Host 2.
  puts "Creating 2nd Device/Host Object."
  set hDevice(2) [stc::create "EmulatedDevice" \
                           -under $hProject \
                           -DeviceCount "1" \
                           -EnablePingResponse "TRUE"\
                           -Active "TRUE" \
                           -Name "Host 2" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 #Step 2: Affiliating 2nd Device/Host to the Target (Port2) using stc::config API Function.
 ##注意hDevice(2)与Port(2)的关联,方式和hDivice(1)不同,Device(1)一个是直接在创建时参数里指定;Device(2)是通过config函数进行设置
  puts "Affiliating 2nd Device/Host to Target (Port2) using stc::config API Function."
  stc::config $hDevice(2) -AffiliationPort-targets " $hPort(2) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 #Step 3: Create Layer 2 Ethernet Interface for Device/Host 2.
  puts "Creating Ethernet interface for Device/Host 2."
  set hEthIIIf(2) [stc::create "EthIIIf" \
                              -under $hDevice(2) \
                              -SourceMac "00:10:94:00:00:03" \
                              -Active "TRUE" \
                              -Name "EthIIIf 2" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 
 #Step 4: Create Layer 3 IPv4 Interface for Device/Host 2.
  puts "Creating IP interface for Device/Host 2."
  set hIpv4If(2) [stc::create "Ipv4If" \
                             -under $hDevice(2) \
                             -Address "192.168.81.110" \
                             -AddrStepMask "0.0.0.255" \
                             -PrefixLength "24" \
                             -Gateway "192.168.81.1" \
                             -GatewayMac "00:00:01:00:00:01" \
                             -Active "TRUE" \
                             -Name "Ipv4If 2" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 #Step 5: Defining IP Stack for Device/Host 2.
  puts "Defining IP Stack for Device/Host 2."
 
  stc::config $hIpv4If(2) -StackedOnEndpoint-targets " $hEthIIIf(2) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a
  puts ""
  puts ""


  #Step 6: View the State of the Ethernet Interface Object.
  puts "Displaying the State of the Ethernet Interface Object."
  set p [stc::get $hEthIIIf(1)  -IfState]
  puts "This is the Ethernet Interface Status for Device/Host 2: $p"
  puts ""
 

 #Step 7:  View the State of the IPv4 Interface Object.
  puts "Displaying the State of the IPv4 Interface Object."
  set p [stc::get $hIpv4If(1)  -IfState ]
  puts "This is the IPv4 Interface Status for Device/: $p"
  puts ""



  puts ""
  puts "*******************Setting up Device/Port Relationships*****************"
  puts ""
 
 #Step 1: Set up relationships
  puts "Setting up relationships."
  #stc::config $hPort(1) -ActivePhy-targets " $hMedia1 "
  #stc::config $hPort(2) -ActivePhy-targets " $hMedia2 "

 ##可以理解为是协议栈的设置
 ##PrimaryIf:Specifies if a top-level interface is facing the DUT.   Obj-ref的821页
 ##TopLevelIf:Specifies the top-level interface in the interface stack  
  stc::config $hDevice(1) -TopLevelIf-targets " $hIpv4If(1) "
  stc::config $hDevice(1) -PrimaryIf-targets " $hIpv4If(1) "
 
  stc::config $hDevice(2) -TopLevelIf-targets " $hIpv4If(2) "
  stc::config $hDevice(2) -PrimaryIf-targets " $hIpv4If(2) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

  puts ""
  puts ""
 
 

  puts ""
  puts "*******************Applying the Test Configuration to the Hardware*****************"
  puts ""
 
 #Step 1: Applying the Test Configuration to the hardware.
  puts "Applying the Test Configuration to the hardware."
  stc::apply
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 
 
 
  puts ""
  puts "*******************Ping Device/Host 1 Gateway*****************"
  puts ""

 #Step 1: Setting up Ping for Device/Host 1.
  puts "Setting up Ping for Device/Host 1."
  stc::perform PingStart\
    -DeviceList "$hDevice(1)"\
    -FrameCount "4"\
     -PingIpv4DstAddr "192.168.81.110"
    


 #Step 2: Pausing script for 5 seconds.
  puts "Pausing script for 5 seconds."
  stc::sleep 5


 #Step 3: Viewing Ping Results.
  puts "Viewing Ping Results."
  set hPing [stc::get $hPort(1) -children-PingReport]
  set t [stc::get $hPing -AttemptedPingCount ]
  set p [stc::get $hPing -PingResult ]
  puts "Ping Attempts: $t"
  puts "Results from Ping: $p"
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 
   

##Delete Project
  puts ""
  puts "Deleting the Project."
  stc::delete $hProject
  puts "Project Deleted."
  puts ""
  puts ""


##Release the Ports.
  foreach port $portList {
    stc::release $port
    puts "**** Releasing port $port ***"
  }


##Disconnecting
#Disconnecting from the Chassis.
  puts ""
  puts "\n*** Disconnecting from the Chassis ***"
  set result [stc::disconnect $chassis_ip ]
  puts "The Chassis and script are now disconnected."

 

# End

4、  使用Tcl脚本调用STC平台的Natvie API实现Hosts的创建和配置



#########################################################################
#
#      
#      Solution for Lab: System_Project_Port Objects(Project.sol)
#
#     The CommonConfig.sol file must be properly configured with the
#     Spirent TestCenter Chassis IP Address and Slot/Port Pairs
#     in order for this lab to run properly.
#
#########################################################################
#
# In this lab you will:
# - Create/Configure Host and Interface Objects for 1st Host.
# - Create/Configure Host and Interface Objects for 2nd Host.
# - Set up Host/Port Relationships.
# - Apply the Test Configuration to the Hardware.
# - Enable Ping on Host 1 and ensure that Ping was successful to the attached DUT Gateway.
#
#########################################################################
#
# All of the items in this section have been already scripted for you:
#
# Source in CommonConfig.tcl file
#
# Connect to given chassis_ip using stc::connect API Function.
#
# Port Reservation.
#
# Configure the System Object.
#
# Create/Configure a Project Object.
#
# Create/Configure/View two Port Objects.
#
# Release Ports.
#
# Disconnect from the Chassis:
#
########################################################################################
########################################################################################
#
# Procedure to Display all Object Attributes.
  proc p {node} {
    puts "[stc::get $node]"
    foreach n [stc::get $node -children] {
    p $n
  }
  }


## Source in CommonConfig.tcl
#Sourcing in CommonConfig.tcl file
 puts ""
 puts "Sourcing in CommonConfig.tcl file."
 source "../CommonConfig.tcl"
 

## Connect
#Connecting to chassis
  puts "\n*** Connecting to Chassis ***\n"
  set result [stc::connect $chassis_ip ]
  puts "Chassis: $chassis_ip is now Connected.\n"

 
## Port Reservation
#Reserve the Physical Ports
  foreach port $portList {
    stc::reserve $port
    puts "**** Reserving port $port ***"
  }

  puts ""
  puts "*******************Configuring/Viewing System Object*************************"
 

 ##Configure System Object
  puts ""
  puts "The System Object has been created and configured."

 
 ##Displaying Chassis Model and Chassis Firmware Version
  set hPChassisMan [stc::get system1 -children-physicalchassismanager]
  set hPChassis [stc::get $hPChassisMan -children-physicalchassis]
  set abc [stc::get $hPChassis -Model -FirmwareVersion]
  puts ""
  puts "Displaying the Chassis Model and Chassis Firmware Version."
  puts "$abc"
 

  puts ""
  puts ""
  puts "*******************Creating/Configuring Project Object*****************"
  puts ""

 ##Create Project Object
  catch {stc::delete $hProject} err
  puts ""
  puts "Creating Project Object"
  set hProject [stc::create "Project" \
                      -TestMode "L2L3" \
                      -Active "TRUE" \
                      -Name "Project Object1"]

  puts "The Project Object has been created and configured."

  puts ""
  puts ""
  puts "************Creating/Configuring/Viewing Port Objects***********************"
  puts ""

 ##Create the First Logical Port Object
  puts ""
  puts "Creating Port 1"
  set hPort(1) [ stc::create "Port" \
                  -under $hProject \
                  -Location [lindex $portList 0] \
                  -Active "TRUE" \
                  -Name "Port 1"]

  puts "Port 1 Created."

 ##Creating Second Logical Port Object
  puts ""
  puts ""
  puts "Creating Port 2"
  set hPort(2) [ stc::create "Port" \
                  -under $hProject \
                  -Location [lindex $portList 1] \
                  -Active "TRUE" \
                  -Name "Port 2"]

  puts "Port 2 Created."

##Setting Auto Negotiation to False and Line Speed to 100M for both Ports.

 
 ##Setup Port Mappings.
  puts "Performing Port Mapping."
  stc::perform setupPortMappings
  puts "The Ports are now Mapped (logical to physical port)."
 

 ##Setting  EthrenetCopper Phy Attributes using the stc:get API Function.
 
  set hMedia1 [stc::get $hPort(1) -children-EthernetCopper]
  stc::config $hMedia1 -LineSpeed SPEED_100M -AutoNegotiation FALSE
 
  set hMedia2 [stc::get $hPort(2) -children-EthernetCopper]
  stc::config $hMedia2 -LineSpeed SPEED_100M -AutoNegotiation FALSE

  stc::apply

 
#########################################################################################
#########################################################################################
  puts "*****************************************************************************  "
  puts "*************Beginning of the student Coding for this lab.*******************"
  puts ""
  puts ""
  puts "*******************Creating/Configuring Host and Interface Objects for 1st Host*****************"
 
 #Step 1: Create Host
  puts "Creating 1st Host Object."
  set hHost(1) [stc::create "Host" \
                           -under $hProject \
                           -DeviceCount "1" \
               -EnablePingResponse "TRUE"  \
                           -Active "TRUE" \
                           -Name "Host 1" \
               -AffiliationPort-targets " $hPort(1) "]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a
  puts ""


 #Step 2: Create Layer 2 Ethernet Interface for Host 1.
  puts "Creating Ethernet interface for Host 1."

  set hEthIIIf(1) [stc::create "EthIIIf" \
                              -under $hHost(1) \
                              -SourceMac "00:10:94:00:00:02" \
                              -SrcMacStepMask "00:00:ff:ff:ff:ff" \
                              -Active "TRUE" \
                              -Name "EthIIIf 1" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 
 #Step 3: Create Layer 3 IPv4 Interface for Host 1.
  puts "Creating IP interface for Host 1."
  set hIpv4If(1) [stc::create "Ipv4If" \
                             -under $hHost(1) \
                             -Address "192.168.81.2" \
                             -PrefixLength "24" \
                             -Gateway "192.168.81.1" \
                             -Active "TRUE" \
                 -Name "Ipv4If 1"]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 
 #Step 4: Defining IP Stack for Host 1.
  puts "Defining IP Stack for Host 1."
 
  stc::config $hIpv4If(1) -StackedOnEndpoint-targets " $hEthIIIf(1) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


  puts ""
  puts "*******************Creating/Configuring Host and Interface Objects for 2nd Host*****************"
  puts ""
 

#Step 1: Create Host 2.
  puts "Creating 2nd Host Object."
  set hHost(2) [stc::create "Host" \
                           -under $hProject \
                           -DeviceCount "1" \
               -EnablePingResponse "TRUE"  \
                           -Active "TRUE" \
                           -Name "Host 2" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 #Step 2: Affiliating 2nd Host to the Target (Port2) using stc::config API Function.
  puts "Affiliating 2nd Host to Target (Port2) using stc::config API Function."
  stc::config $hHost(2) -AffiliationPort-targets " $hPort(2) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 #Step 3: Create Layer 2 Ethernet Interface for Host 2.
  puts "Creating Ethernet interface for Host 2."
  set hEthIIIf(2) [stc::create "EthIIIf" \
                              -under $hHost(2) \
                              -SourceMac "00:10:94:00:00:03" \
                              -Active "TRUE" \
                              -Name "EthIIIf 2" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 
 #Step 4: Create Layer 3 IPv4 Interface for Host 2.
  puts "Creating IP interface for Host 2."
  set hIpv4If(2) [stc::create "Ipv4If" \
                             -under $hHost(2) \
                             -Address "192.168.81.220" \
                             -PrefixLength "24" \
                             -Gateway "192.168.81.1" \
                             -Active "TRUE" \
                             -Name "Ipv4If 2" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 #Step 5: Defining IP Stack for Host 2.
  puts "Defining IP Stack for Host 2."
 
  stc::config $hIpv4If(2) -StackedOnEndpoint-targets " $hEthIIIf(2) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a
  puts ""
  puts ""


  puts ""
  puts "*******************Setting up Host/Port Relationships*****************"
  puts ""
 
 #Step 1: Set up relationships
  puts "Setting up relationships."
  #stc::config $hPort(1) -ActivePhy-targets " $hMedia1 "
  #stc::config $hPort(2) -ActivePhy-targets " $hMedia2 "

  stc::config $hHost(1) -TopLevelIf-targets " $hIpv4If(1) "
  stc::config $hHost(1) -PrimaryIf-targets " $hIpv4If(1) "
 
  stc::config $hHost(2) -TopLevelIf-targets " $hIpv4If(2) "
  stc::config $hHost(2) -PrimaryIf-targets " $hIpv4If(2) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

  puts ""
  puts ""
 
 

  puts ""
  puts "*******************Applying the Test Configuration to the Hardware*****************"
  puts ""
 
 #Step 1: Applying the Test Configuration to the hardware.
  puts "Applying the Test Configuration to the hardware."
  stc::apply
  puts "Please press enter to contine the script: <enter>"
  gets stdin a



  puts ""
  puts "*******************Ping Host 1 Gateway*****************"
  puts ""

 #Step 1: Setting up Ping for Host 1.
  puts "Setting up Ping for Host 1."
  stc::perform PingStart\
    -DeviceList "$hHost(1)"\
    -FrameCount "5"\
     -PingIpv4DstAddr "192.168.81.220"


 #Step 2: Pausing script for 5 seconds.
  puts "Pausing script for 5 seconds."
  stc::sleep 5


 #Step 3: Viewing Ping Results.
  puts "Viewing Ping Results."
  set hPing [stc::get $hPort(1) -children-PingReport]
  set t [stc::get $hPing -AttemptedPingCount ]
  set p [stc::get $hPing -PingResult ]
  puts "Ping Attempts: $t"
  puts "Results from Ping: $p"
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 

##Delete Project
  puts ""
  puts "Deleteing the Project."
  stc::delete $hProject
  puts "Project Deleted."
  puts ""
  puts ""


##Release the Ports.
  foreach port $portList {
    stc::release $port
    puts "**** Releasing port $port ***"
  }


##Disconnecting
 #Disconnecting from the Chassis.
  puts ""
  puts "\n*** Disconnecting from the Chassis ***"
  set result [stc::disconnect $chassis_ip ]
  puts "The Chassis and script are now disconnected."

 

# End

5、使用Tcl脚本调用STC平台的Natvie API实现StreamBlock的创建和配置


#########################################################################
#
#      
#      Solution for Lab: Bound StreamBlock Objects(StreamBlock1.sol)
#
#     The CommonConfig.sol file must be properly configured with the
#     Spirent TestCenter Chassis IP Address and Slot/Port Pairs
#     in order for this lab to run properly.
#
#########################################################################
#
# In this lab you will:
# - Create/Configure Host and Interface Objects for 1st Host.
# - Create/Configure Host and Interface Objects for 2nd Host.
# - Set up Host/Port Relationships.
# - Apply the Test Configuration to the Hardware.
# - Create/Configure/View two StreamBlocks.
# - Bind the StreamBlocks
#
#########################################################################
#
# All of the items in this section have been already scripted for you:
#
# Source in CommonConfig.tcl file
#
# Connect to given chassis_ip using stc::connect API Function.
#
# Port Reservation.
#
# Configure the System Object.
#
# Create/Configure a Project Object.
#
# Create/Configure/View two Port Objects.
#
# Set up the Generator/Analyzer and Capture
#
# Release Ports.
#
# Disconnect from the Chassis:
#
########################################################################################
########################################################################################
#
# Procedure to Display all Object Attributes.
  proc p {node} {
    puts "[stc::get $node]"
    foreach n [stc::get $node -children] {
    p $n
  }
  }


##Source in CommonConfig.tcl
#Sourcing in CommonConfig.tcl file
 puts ""
 puts "Sourcing in CommonConFig.tcl file."
 source "CommonConfig.tcl"
 

##Connect
#Connecting to chassis
  puts "\n*** Connecting to Chassis ***\n"
  set result [stc::connect $chassis_ip ]
  puts "Chassis: $chassis_ip is now Connected.\n"

 
##Port Reservation
#Reserve the Physical Ports
  foreach port $portList {
    stc::reserve $port
    puts "**** Reserving port $port ***"
  }

  puts ""
  puts "*******************Configuring/Viewing System Object*************************"
 

 ##Configure System Object
  puts ""
  puts "Configuring System Object"
  stc::config system1 \
              -InSimulationMode "FALSE" \
              -UseSmbMessaging "FALSE" \
              -Active "TRUE" \
              -Name "System Object"

  puts "The System Object has been created and configured."

 
 ##Displaying Chassis Model and Chassis Firmware Version
  set hPChassisMan [stc::get system1 -children-physicalchassismanager]
  set hPChassis [stc::get $hPChassisMan -children-physicalchassis]
  set abc [stc::get $hPChassis -Model -FirmwareVersion]
  puts ""
  puts "Displaying the Chassis Model and Chassis Firmware Version."
  puts "$abc"
 

  puts ""
  puts ""
  puts "*********************Creating/Configuring Project Object********************"
  puts ""

 ##Create Project Object
  catch {stc::delete $hProject} err
  puts ""
  puts "Creating Project Object"
  set hProject [stc::create "Project" \
                      -TableViewData "" \
                      -TestMode "L2L3" \
                      -Active "TRUE" \
                      -Name "Project Object1"]

  puts "The Project Object has been created and configured."

  puts ""
  puts ""
  puts "************Creating/Configuring/Viewing Port Objects***********************"
  puts ""

 ##Create the First Logical Port Object
  puts ""
  puts "Creating Port 1"
  set hPort(1) [ stc::create "Port" \
                  -under $hProject \
                  -Location [lindex $portList 0] \
                  -Active "TRUE" \
                  -Name "Port 1"]

  puts "Port 1 Created."

 ##Creating Second Logical Port Object
  puts ""
  puts ""
  puts "Creating Port 2"
  set hPort(2) [ stc::create "Port" \
                  -under $hProject \
                  -Location [lindex $portList 1] \
                  -Active "TRUE" \
                  -Name "Port 2"]

  puts "Port 2 Created."

 
 ##Setup Port Mappings.
  puts "Performing Port Mapping."
  stc::perform setupPortMappings
  puts "The Ports are now Mapped (logical to physical port)."
 


 ##Displaying the Online status for Port 1 and Port 2 after Port Mapping.
  set abc [stc::get $hPort(1) -Online]
  set def [stc::get $hPort(2) -Online]

  puts ""
  puts "This will display the status of the first Port: $abc"
  puts "This will display the status of the second Port: $def"
 


 ##Setting  EthrenetCopper Phy Attributes using the stc:get API Function.
  set hMedia1 [stc::get $hPort(1) -children-EthernetCopper]
  stc::config $hMedia1 -LineSpeed SPEED_100M -AutoNegotiation FALSE
 
  set hMedia2 [stc::get $hPort(2) -children-EthernetCopper]
  stc::config $hMedia2 -LineSpeed SPEED_100M -AutoNegotiation FALSE

  stc::apply

 ##Displaying EthrenetCopper Phy Line Speed Status.
  set abc [stc::get $hMedia1 -LineSpeedStatus]
  puts "Displaying Line Speed Status on Port 1: $abc"

  set abc [stc::get $hMedia2 -LineSpeedStatus]
  puts "Displaying Line Speed Status on Port 2: $abc"
  puts ""
  puts ""
  puts ""





#########################################################################################
#########################################################################################
  puts "*****************************************************************************"
  puts "*************Beginning of the Student Coding for this lab.*******************"
  puts "*****************************************************************************"
#########################################################################################
#########################################################################################

  puts ""
  puts "*********Creating/Configuring Host and Interface Objects for 1st Host********"
  puts ""


 #Step 1: Create Host
 #You must change the Device Count from 1 to 5 within the Lab.
  puts "Creating 1st Host Object."
  set hHost(1) [stc::create "Host" \
                     -under $hProject \
                     -DeviceCount "1" \
                     -AffiliationPort-targets " $hPort(1) "]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a
  puts ""


 #Step 2: Create Layer 2 Ethernet Interface for Host 1.
  puts "Creating Ethernet interface for Host 1."

  set hEthIIIf(1) [stc::create "EthIIIf" \
                    -under $hHost(1) \
                    -SourceMac "00:21:94:00:00:02" \
                    -SrcMacStep "00:00:00:00:00:01" \
                    -SrcMacList "" \
                    -SrcMacStepMask "00:00:ff:ff:ff:ff" \
                    -Name "EthIIIf 1" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 
 #Step 3: Create Layer 3 IPv4 Interface for Host 1.
  puts "Creating IP interface for Host 1."
  set hIpv4If(1) [stc::create "Ipv4If" \
                   -under $hHost(1) \
                   -Address "192.168.21.2" \
                   -AddrStep "0.0.0.1" \
                   -AddrStepMask "0.0.0.255" \
                   -Gateway "192.168.21.1" \
                   -Name "Ipv4If 1"]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 
 #Step 4: Defining IP Stack for Host 1.
  puts "Defining IP Stack for Host 1."
 
  stc::config $hIpv4If(1) -StackedOnEndpoint-targets " $hEthIIIf(1) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 #Step 5: View the State of the Ethernet Interface Object.
  puts "Displaying the State of the Ethernet Interface Object."
  set p [stc::get $hEthIIIf(1)  -IfState]
  puts "This is the Ethernet Interface Status for Host 1: $p"
  puts ""
  puts ""


 #Step 6:  View the State of the IPv4 Interface Object.
  puts "Displaying the State of the IPv4 Interface Object."
  set p [stc::get $hIpv4If(1)  -IfState ]
  puts "This is the IPv4 Interface Status for Host 1: $p"
  puts ""
 

  puts ""
  puts "********Creating/Configuring Host and Interface Objects for 2nd Host*********"
  puts ""
 

#Step 1: Create Host 2.
#You must change the Device Count from 1 to 5 within the Lab.
  puts "Creating 2nd Host Object."
  set hHost(2) [stc::create "Host" \
                     -under $hProject \
                     -DeviceCount "1" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 #Step 2: Affiliating 2nd Host to the Target (Port2) using stc::config API Function.
  puts "Affiliating 2nd Host to Target (Port2) using stc::config API Function."
  stc::config $hHost(2) -AffiliationPort-targets " $hPort(2) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 #Step 3: Create Layer 2 Ethernet Interface for Host 2.
  puts "Creating Ethernet interface for Host 2."
  set hEthIIIf(2) [stc::create "EthIIIf" \
                        -under $hHost(2) \
                        -SourceMac "00:22:94:00:00:02" \
                        -SrcMacStep "00:00:00:00:00:01" \
                        -SrcMacStepMask "00:00:ff:ff:ff:ff" \
                        -Active "TRUE" \
                        -Name "EthIIIf 2" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

 
 #Step 4: Create Layer 3 IPv4 Interface for Host 2.
  puts "Creating IP interface for Host 2."
  set hIpv4If(2) [stc::create "Ipv4If" \
                       -under $hHost(2) \
                       -Address "192.168.21.220" \
                       -AddrStep "0.0.0.1" \
                       -AddrStepMask "0.0.0.255" \
                       -Gateway "192.168.21.1" \
                       -Active "TRUE" \
                       -Name "Ipv4If 2" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 #Step 5: Defining IP Stack for Host 2.
  puts "Defining IP Stack for Host 2."
 
  stc::config $hIpv4If(2) -StackedOnEndpoint-targets " $hEthIIIf(2) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a
  puts ""
  puts ""


  #Step 6: View the State of the Ethernet Interface Object.
  puts "Displaying the State of the Ethernet Interface Object."
  set p [stc::get $hEthIIIf(1)  -IfState]
  puts "This is the Ethernet Interface Status for Host 1: $p"
  puts ""
 

 #Step 7:  View the State of the IPv4 Interface Object.
  puts "Displaying the State of the IPv4 Interface Object."
  set p [stc::get $hIpv4If(1)  -IfState ]
  puts "This is the IPv4 Interface Status for Host 1: $p"
  puts ""



  puts ""
  puts "*******************Setting up Host/Port Relationships************************"
  puts ""
 
 #Step 1: Set up relationships
  puts "Setting up relationships."
  #stc::config $hPort(1) -ActivePhy-targets " $hMedia1 "
  #stc::config $hPort(2) -ActivePhy-targets " $hMedia2 "

  stc::config $hHost(1) -TopLevelIf-targets " $hIpv4If(1) "
  stc::config $hHost(1) -PrimaryIf-targets " $hIpv4If(1) "
 
  stc::config $hHost(2) -TopLevelIf-targets " $hIpv4If(2) "
  stc::config $hHost(2) -PrimaryIf-targets " $hIpv4If(2) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a
  puts ""
 

  puts ""
  puts "************Creating/Configuring StreamBlock Object on 1st Port**************"
  puts ""
######################################创建StreamBlock的关键代码#######################

 #Step 1: Creating StreamBlock.
  puts "Creating StreamBlock on Port 1."
  set hStreamBlock(1) [stc::create "StreamBlock" \
    -under $hPort(1) \
    -frameconfig "" \
    -load 100 \
    -loadunit FRAMES_PER_SECOND \
    -priority 10 \
    -Name "StreamBlock 1" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 #Step 2: Creating the Ethernet PDU for StreamBlock.
  puts "Creating the Ethernet PDU for StreamBlock."
  stc::create ethernet:EthernetII -under $hStreamBlock(1) -name eth_pdu1 \
    -srcMac 00:21:94:00:00:04 \
    -dstMac 00:22:94:00:00:05
  puts "Please press enter to contine the script: <enter>"
  gets stdin a
 

 #Step 3: Creating the IP PDU for StreamBlock.
  puts "Creating the IP PDU for StreamBlock."
  stc::create ipv4:IPv4 -under $hStreamBlock(1) -name ip_pdu1\
    -sourceAddr 192.168.01.2 \
    -destAddr   192.168.02.2 \
    -gateway    192.168.01.1 \
    -prefixlength 24 \
    -destprefixlength 24
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


  puts ""
  puts "************Creating/Configuring StreamBlock Object on 2nd Port**************"
  puts ""



#Step 1: Creating StreamBlock.
  puts "Creating StreamBlock on Port 2."
  set hStreamBlock(2) [stc::create "StreamBlock" \
             -under $hPort(2) \
           -frameconfig "" \
           -load 100 \
           -loadunit FRAMES_PER_SECOND \
           -priority 10 \
           -Name "StreamBlock 2" ]
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


#Step 2: Creating the Ethernet PDU for StreamBlock.
  puts "Creating the Ethernet PDU for StreamBlock."
  stc::create ethernet:EthernetII -under $hStreamBlock(2) -name eth_pdu2\
    -srcMac 00:22:94:00:00:05 \
    -dstMac 00:21:94:00:00:04
  puts "Please press enter to contine the script: <enter>"
  gets stdin a
 

#Step 3: Creating the IP PDU for StreamBlock.
  puts "Creating the IP PDU for StreamBlock."
  stc::create ipv4:IPv4 -under $hStreamBlock(2) -name ip_pdu2\
    -sourceAddr 192.168.02.2 \
    -destAddr   192.168.01.2 \
    -gateway    192.168.02.1 \
    -prefixlength 24 \
    -destprefixlength 24
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 


  puts ""
  puts "***********************Binding the StreamBlocks *****************************"
  puts ""

#Step 1: Set up relationships
  puts "Binding the StreamBlocks to the Host IP Interfaces."
  stc::config $hStreamBlock(1) -SrcBinding-targets " $hIpv4If(1) "
  stc::config $hStreamBlock(1) -DstBinding-targets " $hIpv4If(2) "
  stc::config $hStreamBlock(2) -SrcBinding-targets " $hIpv4If(2) "
  stc::config $hStreamBlock(2) -DstBinding-targets " $hIpv4If(1) "
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 

 puts ""
  puts "**********************Updating the StreamBlocks******************************"
  puts ""


#Step 1: Updating the Streamblock.
  puts "Updating the 1st StreamBlock."
  stc::perform StreamBlockUpdate -streamBlock "$hStreamBlock(1)"
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

#Step 2: Updating the Streamblock.
  puts "Updating the 2nd StreamBlock."
  stc::perform StreamBlockUpdate -streamBlock "$hStreamBlock(2)"
  puts "Please press enter to contine the script: <enter>"
  gets stdin a




  puts ""
  puts "***************Viewing StreamBlock Read-Only Attributes**********************"
  puts ""
 

#Step 1: View StreamBlock Read-Only Attributes.
  puts "Displaying the State of the 1st StreamBlock Object."
  set p [stc::get $hStreamBlock(1)  -StreamCount -FlowCount]
  puts "$p"
  puts ""
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

#Step 2: View StreamBlock Read-Only Attributes.
  puts "Displaying the State of the 2nd StreamBlock Object."
  set p [stc::get $hStreamBlock(2)  -StreamCount -FlowCount]
  puts "$p"
  puts ""
  puts "Please press enter to contine the script: <enter>"
  gets stdin a


 
 

#########################################################################################
#########################################################################################
  puts "*****************************************************************************"
  puts "*****************End of the student Coding for this lab.*********************"
  puts "*****************************************************************************"
#########################################################################################
#########################################################################################
 

  puts " "
  puts " "


##Configure generator
  puts "configure generator and analyzer.."
  set hGenerator(1) [lindex [stc::get $hPort(1) -children-Generator] 0]
  set hGenerator(2) [lindex [stc::get $hPort(2) -children-Generator] 0]
  set hGeneratorConfig(1) [lindex [stc::get $hGenerator(1) -children-GeneratorConfig] 0]
  set hGeneratorConfig(2) [lindex [stc::get $hGenerator(2) -children-GeneratorConfig] 0]

  stc::config $hGeneratorConfig(1) \
              -SchedulingMode "RATE_BASED" -Duration "2" \
              -DurationMode "SECONDS" -LoadUnit "PERCENT_LINE_RATE" \
              -LoadMode "FIXED" -FixedLoad "10.000000" \
              -Name "GeneratorConfig 1"

  stc::config $hGeneratorConfig(2) \
              -SchedulingMode "RATE_BASED" -Duration "2" \
              -DurationMode "SECONDS" -LoadUnit "PERCENT_LINE_RATE" \
              -LoadMode "FIXED" -FixedLoad "10.000000" \
              -Name "GeneratorConfig 2"

  set generatorList "$hGenerator(1) $hGenerator(2)"

##Configure Analyzer results under project handle.

  set hAnalyzer(1) [lindex [stc::get $hPort(1) -children-Analyzer] 0 ]
  set hAnalyzer(2) [lindex [stc::get $hPort(2) -children-Analyzer] 0 ]
  set hAnalyzerConfig(1) [lindex [stc::get $hAnalyzer(1) -children-AnalyzerConfig] 0]
  set hAnalyzerConfig(2) [lindex [stc::get $hAnalyzer(2) -children-AnalyzerConfig] 0]

  set analyzerList "$hAnalyzer(1) $hAnalyzer(2)"

##Subscribe Generator Results under Project Handle.
  puts "Subscribe to generator and analyzer results.."
  stc::subscribe -Parent $hProject \
    -ConfigType Generator \
    -resulttype GeneratorPortResults  \
    -filenameprefix "Generator_Port_Results"

  stc::subscribe -Parent $hProject \
    -ConfigType Analyzer \
    -resulttype AnalyzerPortResults  \
    -filenameprefix "Analyzer_Port_Results"

 ##Capture
  puts "Creating Capture object under port"
  set hCapture(1) [lindex [stc::get $hPort(1) -children-Capture] 0]

  puts "Creating CaptureFilter object to define filtering condition"
  set hCaptureFilter(1) [lindex [stc::get $hCapture(1) -children-CaptureFilter] 0]

  puts "Creating Capture Filter start even and specify the filter criteria and value"
  set hCaptureFilterStartEvent(1) [lindex [stc::get $hCapture(1) -children-CaptureFilterStartEvent] 0]

  stc::config $hCaptureFilterStartEvent(1) \
    -FrameLenMatch "INCLUDE" \
    -FrameLength "128" \
    -Name "CaptureFilterStartEvent 1"

  #Define capture for port 2.
  set hCapture(2) [lindex [stc::get $hPort(2) -children-Capture] 0]
  set hCaptureFilter(2) [lindex [stc::get $hCapture(2) -children-CaptureFilter] 0]
  set hCaptureFilterStartEvent(2) [lindex [stc::get $hCapture(2) -children-CaptureFilterStartEvent] 0]

  stc::config $hCaptureFilterStartEvent(2) \
    -FrameLenMatch "INCLUDE" \
    -FrameLength "128" \
    -Name "CaptureFilterStartEvent 2"

  set captureList "$hCapture(1) $hCapture(2)"
    
##Start capture and display the counters
  puts "Start capture using capture start all command"
  stc::perform CaptureStartAll -CaptureProxyIds $captureList

##Start the Analyzer and generator
  puts "Starting the traffic for 2 sec..."
  stc::perform AnalyzerStart -AnalyzerList $analyzerList
  stc::perform GeneratorStart -GeneratorList $generatorList
  puts ""
  puts ""
 
  puts ""
  puts ""
  puts "wait for 5 seconds for generator to send traffic.."
    
  stc::perform GeneratorWaitForStop \
    -WaitTimeout 5000 \
    -GeneratorList $generatorList

 ##Display the results
  puts "Displaying the tx and rx count."

  after 1000

  stc::get $hGenerator(1)
  set hGenPortResults [lindex [stc::get $hGenerator(1) -children-GeneratorPortResults]]
  array set genResults [stc::get $hGenPortResults]

  stc::get $hAnalyzer(1)
  set hAnaPortResults [lindex [stc::get $hAnalyzer(1) -children-AnalyzerPortResults]]
  array set analyzerResults [stc::get $hAnaPortResults]

  puts "txSigFrameCnt on Port 1 $genResults(-GeneratorSigFrameCount)"
  puts "rxSigFrameCnt on Port 1 $analyzerResults(-SigFrameCount)"

  stc::get $hGenerator(2)
  set hGenPortResults [lindex [stc::get $hGenerator(2) -children-GeneratorPortResults]]
  array set genResults [stc::get $hGenPortResults]

  stc::get $hAnalyzer(2)
  set hAnaPortResults [lindex [stc::get $hAnalyzer(2) -children-AnalyzerPortResults]]
  array set analyzerResults [stc::get $hAnaPortResults]

  puts "txSigFrameCnt on Port 2 $genResults(-GeneratorSigFrameCount)"
  puts "rxSigFrameCnt on Port 2 $analyzerResults(-SigFrameCount)"

  set capturestate [stc::get $hCapture(1) -CaptureState]
  puts "Packet capture state port 1 is $capturestate"

##Stop capturing.
  puts "Stop capturing using capture stop all command"
  stc::perform CaptureStopAll  -CaptureProxyIds $captureList
    
  set capturestate [stc::get $hCapture(1) -CaptureState]
  puts "Packet capture state port 1 is $capturestate"

  set pktcnt [stc::get $hCapture(1) -PktCount]
  puts "Packet count in port 1 is $pktcnt"
  set pktcnt [stc::get $hCapture(2) -PktCount]
  puts "Packet count in port 2 is $pktcnt"

  puts "Now save the packets in memory to Capture1.pcap file"
  stc::perform SaveSelectedCaptureData    -CaptureProxyId $hCapture(1) \
               -FileName "capture1.pcap" \
               -FileNameFormat PCAP

  puts "Now save the packets in memory to Capture2.pcap file"
  stc::perform SaveSelectedCaptureData    -CaptureProxyId $hCapture(2) \
               -FileName "capture2.pcap" \
               -FileNameFormat PCAP
  puts ""
  puts ""

#########################################################################################
#########################################################################################
  puts "*****************************************************************************"
  puts "*************Beginning of the Student Coding for this lab.*******************"
  puts "*****************************************************************************"
#########################################################################################
#########################################################################################

  puts ""
  puts ""
  puts "***************Viewing StreamBlock Read-Only Attributes**********************"
  puts ""
  puts ""

#Step 1: Displaying Stream Count for StreamBlock 1.
  puts "Displaying the State of the 1st StreamBlock Object after sending traffic."
  set p [stc::get $hStreamBlock(1)  -StreamCount -FlowCount]
  puts "$p"
  puts ""
  puts "Please press enter to contine the script: <enter>"
  gets stdin a

#Step 2: View StreamBlock Read-Only Attributes.
  puts "Displaying the State of the 2nd StreamBlock Object after sending traffic."
  set p2 [stc::get $hStreamBlock(2)  -StreamCount -FlowCount]
  puts "$p2"
  puts ""
  puts "Please press enter to contine the script: <enter>"
  gets stdin a
  puts ""
  puts ""

 
#########################################################################################
#########################################################################################
  puts "*****************************************************************************"
  puts "*****************End of the student Coding for this lab.*********************"
  puts "*****************************************************************************"
#########################################################################################
#########################################################################################
 

  puts " "
  puts " "


##Delete Project
  puts ""
  puts "Deleteing the Project."
  stc::delete $hProject
  puts "Project Deleted."
  puts ""
  puts ""


##Release the Ports.
  foreach port $portList {
    stc::release $port
    puts "**** Releasing port $port ***"
  }


##Disconnecting
 #Disconnecting from the Chassis.
  puts ""
  puts "\n*** Disconnecting from the Chassis ***"
  set result [stc::disconnect $chassis_ip ]
  puts "The Chassis and script are now disconnected."

 

# End


使用Tcl脚本调用STC平台的Native API实现测试对象、Device、StreamBlock的创建和配置

标签:测试   脚本   native   api   

原文地址:http://blog.csdn.net/tomstrong_369/article/details/46127665

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!