关注作者了解更多精彩内容
我们在使用Spirent TestCenter进行自动化或者手工操作的时候,会查看、保存、分析流量结果。接下来我将在前文的基础上,给大家讲解一下使用Spirent TestCenter的客户端与TCL自动化脚本,进行流量结果的查询、刷新、清除与保存。在这之前我们先要进行一些初始化操作,脚本如下:
# import package
puts "导入SpirentTestCenter包"
package require SpirentTestCenter
# creat project
puts "创建项目"
set hProject [stc::create project]
# create port
puts "创建端口"
set szChassisIp 10.61.32.98
set hPortTx [stc::create port -under $hProject -location //$szChassisIp/4/5 -useDefaultHost False ]
set hPortRx [stc::create port -under $hProject -location //$szChassisIp/4/6 -useDefaultHost False ]
# attach Port
puts "占用端口"
stc::perform attachPorts -portList [list $hPortTx $hPortRx] -autoConnect TRUE
stc::subscribe -parent handle -ConfigType resultParentType -ResultType resultType -FileNamePrefix filenamePrefix -Interval seconds -ViewAttributeList allrList -RecordsPerPage 256
我们常用的订阅代码,主要分为两类,一类是对端口进行统计,一类是对stream进行统计。对应的GUI图片展示也一同放在下方。
端口统计(Generator与Analyzer的不同在于Generator是对发送流量统计,Analyzer是对接收流量统计):
set result1 [stc::subscribe -parent project1 -ConfigType Generator -ResultType GeneratorPortResults]
set result2 [stc::subscribe -parent project1 -ConfigType Analyzer -ResultType AnalyzerPortResults]
端口-GUI界面:我们通过红色标记的观察模式,对端口查看通过Analyzer与Generator订阅产生的结果。
stream统计(同样TxStreamResults统计发送流量,RxStreamSummaryResults统计接收流量):
set result3 [stc::subscribe -parent project1 -ConfigType StreamBlock -ResultType TxStreamResults ]
set result4 [stc::subscribe -parent project1 -ConfigType StreamBlock -ResultType RxStreamSummaryResults]
stream-GUI界面:我们通过红色标记的观察模式,对端口查看通过streamblock订阅产生的结果。
subscribe代码执行结果:
Parent | 填写的参数必须是Porject对象,可以填写自己创建的Project类或者使用system下自动创建的Project类(上面代码使用project对象就是后者) |
ConfigType | ConfigType是ResultType的父类,是既定参数,在文档里面可查到每个ResultType对应的父类,例如AnalyzerPortResults的父类就是Analyzer。常用的configtype参数有Analyzer,Generator,streamblock。 |
ResultType | 结果类型是已经创建好的数据对象,不需要您单独创建,只需要根据已有的参数填入其中。ResultType可以在文档中通过对应的ConfigType查看其ResultChild,或者通过代码使用Spirent TestCenter获取configtype下的ResultChild。 |
Analyzer | AnalyzerPortResults, DiffServResults, FilteredStreamResults, InterestingStreamsResults, OverflowResults, PortAvgLatencyResults, RxCpuPortResults, RxStreamResults, StreamThresholdResults |
Generator | GeneratorPortResults, TxCpuPortResults |
streamblock | RxStreamBlockResults, RxStreamSummaryResults, RxStream,TxStreamBlockResults, TxStreamResults |
tips:我们上面提到的Interval设置获取数据间隔的时间,同样也可以在Project下的ResultOptions里面设置。我们需要设置TimedRefreshResultViewMode与TimedRefreshInterval参数
参数名称 | 定义 | 参数 |
TimedRefreshInterval | 当TimedRefreshResultViewMode 选择 PERIODIC 模式为时,以秒为单位定义刷新间隔 | Default: 10 Range: 1 - 65535 |
TimedRefreshResultViewMode | 自动刷新不实时更新结果的结果视图。 | Default: MANUAL MANUAL:不会自动刷新结果视图。 CONTINUOUS:结果视图不断刷新。 PERIODIC: 根据 TimedRefreshInterval 中定义的时间间隔刷新结果视图。 |
set hProject [stc::create project]
set ResultOptions(1) [lindex [stc::get $hProject(1) -children -ResultOptions]0]
stc::config $ResultOptions(1) -TimedRefreshResultViewMode "PERIODIC" TimedRefreshintterval "1"
0
2
A方法执行代码如下:
#通过设置的变量result获取结果
set Generator_List [stc::get $result1 -resultchild]
foreach element $Generator_List {
puts "Generator发送:[stc::get $element -GeneratorSigFrameCount] 端口:[stc::get [stc::get $element -parent] -parent]"
}
set Anlyzer_List [stc::get $result2 -resultchild]
foreach element $Anlyzer_List {
puts "Anlyzer接收:[stc::get $element -SigFrameCount] 端口:[stc::get [stc::get $element -parent] -parent]"
}
set TxRsult [stc::get [stc::get $result3 -resultchild] -FrameCount]
set RxRsult [stc::get [stc::get $result4 -resultchild] -SigFrameCount]
set streamBlock_1 [stc::get [stc::get $result4 -resultchild] -parent]
puts "流量名称:[stc::get $streamBlock_1 -Name] 接收流量大小:$TxRsult 发送流量大小:$RxRsult "
B方法执行代码如下:
#我们在卡面创建一个streamblock 设置为StreamBlock1
puts "获取本次端口$txport, $rxport Tx和Rx结果统计"
array set port1_Tx_result [stc::get $hPortTx.generator.generatorportresults]
array set port1_Rx_result [stc::get $hPortTx.analyzer.analyzerportresults]
array set port2_Tx_result [stc::get $hPortRx.generator.generatorportresults]
array set port2_Rx_result [stc::get $hPortRx.analyzer.analyzerportresults]
puts "TxPort统计信息:发送:$port1_Tx_result(-GeneratorSigFrameCount),接收:$port1_Rx_result(-SigFrameCount)"
puts "RxPort统计信息:发送:$port2_Tx_result(-GeneratorSigFrameCount),接收:$port2_Rx_result(-SigFrameCount)"
puts "获取本次流量$StreamBlock1,Tx和Rx结果统计"
array set streamblock1_Tx_result [stc::get $StreamBlock1.TxStreamResults]
array set streamblock1_Rx_result [stc::get $StreamBlock1.RxStreamSummaryResults]
puts "流量名称:[stc::get $StreamBlock1-name],接收端口:$streamblock1_Rx_result(-RxPort),发送:$streamblock1_Tx_result(-FrameCount),接收:$streamblock1_Rx_result(-SigFrameCount)"
Port获取结果:
puts "刷新本次结果数据"
set hSubscribe [stc::subscribe -parent project1 -ResultType GeneratorPortResults -ConfigType Generator]
stc::perform RefreshResultView -ResultDataSet $hSubscribe
#清除数据移动有三种方法
puts "清除所有数据统计"
stc::perform ResultsClearAll -ExecuteSynchronous True -portList [stc::get project1 -children-Port]
stc::perform ResultsClearView -ResultDataset desultdataset1
stc::perform ResultsClearView -ResultList rxstreamsummaryresultsX
set dbfile "C:/Users/**/Desktop/ResultData/SavedbResult.db"
stc::perform SaveResults -ResultFileName $dbfile -SaveDetailedResults True -loopMode "append"
set pacpfile "C:/Users/**/Desktop/ResultData/SavePacpResult.pacp"
stc::perform CaptureDataSaveCommand
Tips1:保存抓包文件,分步骤为先去配置抓包参数,开始抓包,打流(然后停流),停止抓包,保存pacp文件。
#配置抓包参数
set hCapture [stc::get $hPortTx -children-Capture]
stc::config $hCapture -mode "REGULAR_MODE" -srcMode "TX_RX_MODE"
#开始抓包
stc::perform CaptureStartCommand -CaptureProxyId $hCapture
#停止抓包
stc::perform CaptureStopCommand -CaptureProxyId $hCapture
#保存pacp文件
set pacpfile "C:/Users/**/Desktop/ResultData/SavePacpResult.pacp"
stc::perform CaptureDataSaveCommand -CaptureProxyId $hCapture -FileName $pacpfile
Tips2:保存结果中会,如果不设置保存路径,会有一个默认路径,我们可以提供过命令查看默认路径。
array set sysPaths [stc::perform GetSystemPaths]
set userDataPath $sysPaths(-UserDataPath)
set commonDataPath $sysPaths(-CommonDataPath)
set sessionDataPath $sysPaths(-SessionDataPath)
#输出结果
-UserDataPath {C:/Users/user/Documents/Spirent/TestCenter x.xx/}
-CommonDataPath {C:/ProgramData/Spirent/TestCenter x.xx/}
-SessionDataPath {C:/Users/Qhan/Documents/Spirent/TestCenter x.xx/Logs/2024-03-07_10-06-23/}
Tips3:如果我们想要修改或者配置log文件的设置,可以修改stcbll.ini文件。在windows系统下,默认位置为:
C:\Program Files\Spirent Communications\Spirent TestCenter <version>\Spirent TestCenter Application
#举例,要想定期删除日志
#打开stcbll.ini
#找到[logger]
#添加 maxLifeTimeInDays=1
主要可以添加修改参数如下:
maxLifeTimeInDays:在记录后日志保存天数
maxFileSizeInMB:-日志文件的最大大小。当达到文件大小限制时,当前的bll.log将被备份到一个新的文件中(例如bll.log.1),并且当前的日志消息将继续写入bll.log中。(单位)
maxBackup:创建的最大备份文件数,如果达到限制,则删除最旧的备份。outputDirectory:保存日志文件的目录。举例:
outputDirectory=D:/mydir/mylogs
代码总流程:
# 导入SpirentTestCenter包
puts "导入SpirentTestCenter包"
package require SpirentTestCenter
#创建项目
puts "创建项目"
set hProject [stc::create project]
#创建端口
puts "创建端口"
set szChassisIp 10.61.32.98
set hPortTx [stc::create port -under $hProject -location //$szChassisIp/4/5 -useDefaultHost False ]
set hPortRx [stc::create port -under $hProject -location //$szChassisIp/4/6 -useDefaultHost False ]
#占用端口
puts "占用端口"
stc::perform attachPorts -portList [list $hPortTx $hPortRx] -autoConnect TRUE
#订阅结果数据
puts "订阅结果数据"
set result1 [stc::subscribe -parent project1 -ConfigType Analyzer -ResultType AnalyzerPortResults]
set result2 [stc::subscribe -parent project1 -ConfigType Generator -ResultType GeneratorPortResults]
set result3 [stc::subscribe -parent project1 -ConfigType StreamBlock -ResultType TxStreamResults ]
set result4 [stc::subscribe -parent project1 -ConfigType StreamBlock -ResultType RxStreamSummaryResults]
#创建device1
puts "创建device1"
set TEmulatedDevice [stc::create "EmulatedDevice" -under $hProject -AffiliatedPort $hPortTx -Name {Tdevice}]
#创建以太协议
puts "创建以太协议"
set eth2 [stc::create "EthIIIf" -under $TEmulatedDevice]
#set eth2 [stc::create "EthIIIf" -under $TEmulatedDevice -SourceMac "00:10:94:00:00:02" -SrcMacStep " 00:00:00:00:00:01" -SrcMacStepMask "00:00:FF:FF:FF:FF" -SrcMacRepeatCount 0]
#Generated values will be 00:10:94:00:00:02, 00:10:94:00:00:03, 00:10:94:00:00:02, 00:10:94:00:00:03, and so on.
# Create Vlan
#set TVlan [stc::create "VlanIf" -under $TEmulatedDevice -VlanId "100" -StackedOn $eth2]
# Create Ipv4If
puts "创建IPV4协议"
set Ip2 [stc::create "Ipv4If" -under $TEmulatedDevice -StackedOnEndpoint-targets $eth2 -Address "192.168.11.2" -Gateway "192.168.11.1"]
#expample
#set Ip2 [stc::create "Ipv4If" -under $TEmulatedDevice -StackedOn $TVlan -Address "192.168.11.2" -Gateway "192.168.11.1"]
#Address = 1.1.1.1, AddrRepeatCount = 0, AddrStep = 0.0.0.1, AddrStepMask = 0.0.0.255, IfRecycleCount = 3
#The generated values for Address will be 1.1.1.1, 1.1.1.2, 1.1.1.3, 1.1.1.1, 1.1.1.2, 1.1.1.3, and so on.
#load Config
puts "加载配置"
stc::config $TEmulatedDevice -TopLevelIf "$Ip2"
stc::config $TEmulatedDevice -PrimaryIf-targets "$Ip2"
stc::apply
# Create EmulatedDevice2
set REmulatedDevice [stc::create "EmulatedDevice" -under $hProject -AffiliatedPort $hPortRx -Name {Rdevice}]
# Create EthIIIf
set eth3 [stc::create "EthIIIf" -under $REmulatedDevice]
# Create Vlan
#set TVlan [stc::create "VlanIf" -under $REmulatedDevice -VlanId "100" -StackedOn $eth3]
# Create Ipv4If
set Ip3 [stc::create "Ipv4If" -under $REmulatedDevice -StackedOnEndpoint-targets $eth3 -Address "192.168.11.1" -Gateway "192.168.11.2"]
#load Config
stc::config $REmulatedDevice -TopLevelIf "$Ip3"
stc::config $REmulatedDevice -PrimaryIf-targets "$Ip3"
stc::apply
# Create StreamBlock
puts "创建stream流"
set StreamBlock1 [stc::create "StreamBlock" -under $hPortTx]
stc::config $StreamBlock1 -SrcBinding-targets " $Ip2 "
stc::config $StreamBlock1 -DstBinding-targets " $Ip3 "
#Load Configuration
stc::apply
puts "清除所有结果记录"
stc::perform ResultsClearAll
puts "启动流量"
stc::perform GeneratorStart
#set streamList
#set hStreams [StreamBlock1]
#puts "启动流量"
#stc::perform StreamBlockStartCommand -StreamBlockList $hStreams
#puts "停止流量"
#stc::perform StreamBlockStopCommand -StreamBlockList $hStreams
puts "等待10s"
stc::sleep 10
puts "停止流量"
stc::perform GeneratorStop
puts "等待2s"
stc::sleep 2
#get Generator_List Result
puts "获取端口发送的流量"
set Generator_List [stc::get $result2 -resultchild]
foreach element $Generator_List {
puts "Generator发送:[stc::get $element -GeneratorSigFrameCount] 端口:[stc::get [stc::get $element -parent] -parent]"
}
#get Anlyzer_List Result
puts "获取端口接收的流量"
set Anlyzer_List [stc::get $result1 -resultchild]
foreach element $Anlyzer_List {
puts "Anlyzer接收:[stc::get $element -SigFrameCount] 端口:[stc::get [stc::get $element -parent] -parent]"
}
set TxRsult [stc::get [stc::get $result3 -resultchild] -FrameCount]
set RxRsult [stc::get [stc::get $result4 -resultchild] -SigFrameCount]
set streamBlock_1 [stc::get [stc::get $result4 -resultchild] -parent]
puts "流量名称:[stc::get $streamBlock_1 -Name] 接收流量大小:$TxRsult 发送流量大小:$RxRsult "
puts "保存配置文件在执行路径下$env(TCL_RUNNING_DIR)stc_demo.xml"
stc::perform SaveAsXmlCommand -FileName $env(TCL_RUNNING_DIR)stc_demo.xml
puts "断开机框连接"
stc::disconnect $szChassisIp
puts "退出进程"
exit
以上就是Spirent TestCenter关于Result的自动化代码,讲解到此结束,谢谢大家观看。
Spirent TestCenter 自动化中文版教程(六)门道初探之Device和绑定流
Spirent TestCenter 自动化中文版教程(七)门道初探之Generator基础
Spirent TestCenter 自动化中文版教程(八)门道初探之基础实践
思博伦官方网站: www.spirent.cn
技术中心热线:400-810-9529
支持邮箱:support@spirent.com
售后网站:support.spirent.com
版权归思博伦通信科技(北京)有限公司所有,思博伦技术中心(SpirentServices)原创发布,转载请联系授权。
长按识别二维码,关注思博伦技术中心