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

本文档演示如何在Windows环境下使用Tcl脚本调用Spirent TestCenter的Native API,实现对测试对象、Device、StreamBlock的创建和配置。通过连接、端口占用、释放等步骤,详细展示了STC平台自动化操作的过程。
摘要由CSDN通过智能技术生成

使用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 conf
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值