使用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

时间: 05-27

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

Tcl脚本调用高层API实现仪表使用和主机创建配置的自己主动化測试用例

#设置Chassis的基本參数,包含IP地址.port的数量等等 set chassisAddr 10.132.238.190 set islot 1 set portList {11 12} ;#端口的排列顺序是port1, port2 if { [catch { #载入STC API Lib cd ../Source #载入HLAPI Lib source ./CSTC.tcl SetLogOption -Debug Enable # 開始连接机器 TestDevice chassis1 $

Native Application 开发详解(直接在程序中调用 ntdll.dll 中的 Native API,有内存小、速度快、安全、API丰富等8大优点)

文章目录:                   1. 引子: 2. Native Application Demo 展示: 3. Native Application 简介: 4. Native Application 有何妙用: 5. MJ0011 关于 Native Application 的文章整理: 6. 互联网上其他关于 Native Application 的文章整理: 7. 小结: 1. 引子: 其实在好久以前就看了 MJ0011 翻译的那个<Native 应用程序详细>系列的文

Unity在Android和iOS中如何调用Native API

本文主要是对unity中如何在Android和iOS中调用Native API进行介绍. 首先unity支持在C#中调用C++ dll,这样可以在Android和iOS中提供C++接口在unity中调用.利用这一特性,可以扩展unity的功能.例如集成和调用第三方库.同时为了满足对unity接口的一致性,可以考虑在android和iOS上提供相同的接口供C#调用. 这里列举以下两个例子. 1. 1. 以弹出一个覆盖部分屏幕的webview为例来说明如何从C#调用Native接口. 2. 2. 简

Modelsim中使用TCL脚本编写do文件实现自动化仿真

通常我们使用Modelsim进行仿真,是通过图形界面点点点来进行操作,殊不知Modelsim完美支持TCL脚本语言及批处理命令do文件.简单来说就是从你修改完代码后到你重新编译把需要的信号拉出来查看,现在只需要一个动作即可完成.大大提高了工作效率,博主之前也是点点点了好久,最后发现有这么好的仿真技巧,真是相见恨晚. 下面列举一些常见的TCL脚本命令 Run do文件的一些常用命令 #打开现有工程 project open C:/Users/jayash/Desktop/sim/ImageProc

1 TCL脚本基本语法(概要)

TCL常用基本语法 一个TCL脚本可以包含一个或多个命令.命令之间必须用换行符或分号隔开. 第一个单词代表命令名,另外的单词则是这个命令的参数,用空格或TAB键隔开. 变量置换$. 命令置换[] 反斜杠置换\ ,例如set msg multiple\ space ,如果没有\则有报警. 双引号将各种分隔符将不作处理,对换行符及$和[]两种置换符会照常处理. 花括号中所有特殊字符成为普通字符,失去其意义. 注释符 '#' $符号往后直到第一个不是字母.数字或下划线的字符之间的单词符号作为要被置换的

tcl脚本环境搭建——windows下

? 以下内容整理自网络,试验可用 1.下载tcl解释器,并安装http://www.activestate.com/activetcl 2.tclsh85.exe运行bin/tclsh85.exe(wish85.exe:包含了tclsh 和 tk两部分) 3.创建一个简单的tcl脚本:E:/tcl/hello.tcl,输入内容如下:package require Tclpackage require Tkset a "hello world!"puts $a然后在tclsh85.exe

Perl脚本调用的优缺点

Perl脚本在运行时作为一个独立的进程,调用另一个脚本意味着创建一个子进程,这和函数调用有着本质的区别,函数调用是一个进程中执行了一段独立代码.这是特别需要注意的前提,下面总结了这种机制的优缺点. 优点 并行性.进程之间是独立的.并发的,因此脚本调用脚本时,这两个脚本可以是并行工作的,子脚本又可以调用子脚本,并行性可以无限扩展,运行效率高. 兼容性.一行命令就能调用其它脚本语言,甚至是系统命令,简洁方便. 缺点 传参数需要特别检查.调用脚本时传入参数相当于敲命令时加参数,被调用的脚本不会自己主动

使用Tcl脚本分配FPGA管脚

自动生成Tcl文件 Project -> Generate Tcl File for Project... 弹出如下对话框,设置脚本路径. 编辑引脚 使用set_location_assignment分配管脚如下: 第一次配制时,没有set_location_assignment语句,自已在set_global_assignment语句下一行添加即可. 执行Tcl脚本 Tools -> Tcl Scripts... 选中刚新建的Tcl文件,点击Run运行即可! 答疑解惑 1. 为什么Tcl中没

使用shell脚本调用mysql数据库存储过程,并设置定时任务

本来是要mysql数据库中创建事件任务来,定时执行存储过程,做数据传输的...后来由于种种原因,就使用crontab来定时执行,调用存储过程. 实现这个数据传输分为两步: 第一步:编写shell脚本调用mysql数据库存储过程,如下: #!/bin/bash#0 1 * * * sh /home/drmTrans3/rj_proc.shhost1=127.0.0.1user=systempasswd=linuxport=3306mysql -h${host1} -u${user} -p${pas