tcltk控制chariot进行测试,并将批量数据输出成excel
来源:互联网 发布:caffe translator 编辑:程序博客网 时间:2024/06/10 05:18
直接上源码,都加了备注,应该很容易看懂
test4.tcl
另存为 print4.tcl
桌面新建文件夹TCL
需要使用bat来驱动tcl文件
tclsh test4.tcl
test4.tcl
建立4条pair 来进行流量测试,测试时间为1小时
set array1(1) "D2B"set array1(2) "72083C"set array1(3) "v1.0.29"set array1(4) "Polden"set array1(5) "lklk"set array1(6) "1.0.25.7"#工具函数,获取系统时间################################################################################################proc tcl_get_system_time {{type dt} } { switch $type { "dt" {set t [clock format [clock seconds] -format %Y-%m-%d-%H-%M-%S]} "d" {set t [clock format [clock seconds] -format %Y-%m-%d]} "t" {set t [clock format [clock seconds] -format %H:%M:%S]} "H" {set t [clock format [clock seconds] -format %H]} default {puts "ERROR:Invali parameter $type"} }}#初始化参数################################################################################################# Windows 32位环境使用set ixchariot_installation_dir "C:/Program Files/Ixia/IxChariot"# 设置 script 为Throughput脚本set script "c:/Program Files/Ixia/IxChariot/Scripts/Throughput_change.scr"#首先进入IxChariot安装目录cd $ixchariot_installation_dir#读取Chariot一些函数包,以便后续进行调用load ChariotExtpackage require ChariotExtglobal auto_index#工作目录,存放测试脚本和结果文件set work_dir "C:/Users/Administrator/Desktop/TCL/proc/"#设置超时时间,如果超时则会自动退出。##################################################################################################***************************************************************# 测试数据配置:# 根据真实的组网配置e1, e2的IP地址.# 测试结果文件为lbtest.tst# 超时为120秒#***************************************************************set log 1set e1 "192.168.1.100"set e2 "1.1.1.2"set script "c:/Program Files/Ixia/IxChariot/Scripts/Throughput_change.scr"#set testFile "C:/Users/Administrator/Desktop/TCL/proc/lbtest.tst"set timeout 4000set result $work_dir[tcl_get_system_time],$array1(3).tst #***************************************************************## 脚本主要部分# ----------------# 每一步都用括号()说明,演示Chariot API编程指南##***************************************************************# (1)# 加载Chariot软件包。如果这一步不通过,原因会打印出来并添加到$errorInfo。load ChariotExtpackage require ChariotExt# (2)# 创建一个测试对象来定义测试。或者从磁盘中加载一个测试。puts "Create the test..."set test [chrTest new]# 加载系统设置################################################################################################# 首先,创建一个runOpts也就是系统设置if {$log} {puts "Create the Opts..." }set runOpts [chrTest getRunOpts $test]# 读取当前的TEST_END 结束测试的条件,默认为WHEN_FIRST_COMPLETES 等待所有的数据包跑完#puts "Test End Conditions : [chrRunOpts get $runOpts TEST_END ]"# 然后指定 TEST_END 值 FIXED_DURATION 固定持续时间chrRunOpts set $runOpts TEST_END FIXED_DURATIONif {$log} {puts "Test End Conditions : [chrRunOpts get $runOpts TEST_END ]" }#接下来我们指定的时间在几秒钟内chrRunOpts set $runOpts TEST_DURATION 3600# (3)# 建立一个测试对.puts "Create the pair..."set pair [chrPair new]# (4)# 给测试对添加地址属性.puts "Set required pair attributes..."chrPair set $pair E1_ADDR $e1 E2_ADDR $e2# (5)# 给测试对定义测试脚本puts "Use a script..."chrPair useScript $pair $script# (6)# 把测试对添加到测试对象中.puts "Add the pair to the test..."chrTest addPair $test $pair################################################# (3)# 建立一个测试对.puts "Create the pair..."set pair1 [chrPair new]# (4)# 给测试对添加地址属性.puts "Set required pair attributes..."chrPair set $pair1 E1_ADDR $e1 E2_ADDR $e2# (5)# 给测试对定义测试脚本puts "Use a script..."chrPair useScript $pair1 $script# (6)# 把测试对添加到测试对象中.puts "Add the pair to the test..."chrTest addPair $test $pair1################################################################################################# (3)# 建立一个测试对.puts "Create the pair..."set pair2 [chrPair new]# (4)# 给测试对添加地址属性.puts "Set required pair attributes..."chrPair set $pair2 E1_ADDR $e1 E2_ADDR $e2# (5)# 给测试对定义测试脚本puts "Use a script..."chrPair useScript $pair2 $script# (6)# 把测试对添加到测试对象中.puts "Add the pair to the test..."chrTest addPair $test $pair2################################################################################################# (3)# 建立一个测试对.puts "Create the pair..."set pair3 [chrPair new]# (4)# 给测试对添加地址属性.puts "Set required pair attributes..."chrPair set $pair3 E1_ADDR $e1 E2_ADDR $e2# (5)# 给测试对定义测试脚本puts "Use a script..."chrPair useScript $pair3 $script# (6)# 把测试对添加到测试对象中.puts "Add the pair to the test..."chrTest addPair $test $pair3################################################# (7)# 运行测试puts "Run the test..."chrTest start $test# (8)# 等测试结束才能拿到结果,默认等2分钟。如果2分钟后没有结束,就认为出错。puts "Wait for the test to stop..."if {![chrTest isStopped $test $timeout]} { puts "ERROR: Test didn't stop in 2 minutes!" chrTest delete $test force return}# (9)# 配置打印# 测试对直接从前文的定义中取出,# 在其他场景下如果没有测试对变量,则测试结果中也可以取到。#puts "================================================="#puts "Test setup:\n----------"#puts "Number of pairs = [chrTest getPairCount $test]"#puts "E1 address : [chrPair get $pair E1_ADDR]"#puts "E2 address : [chrPair get $pair E2_ADDR]"# 前文没有设置脚本协议,但是也同样的打印出来.#puts "Protocol : [chrPair get $pair PROTOCOL]"# 显示脚本磁盘文件名称和和应用程序脚本名称# the application script name.#puts "Script filename : [chrPair get $pair SCRIPT_FILENAME]"#puts "Appl script name: [chrPair get $pair APPL_SCRIPT_NAME]"# (10)# 结果打印:# 结果点的数目,吞吐量大小(平均,最小,最大)#puts ""#puts "Test results:\n------------"#puts "Number of timing records = \#[chrPair getTimingRecordCount $pair]# (11)# 因为是入门例子,下面的代码片段没有包含"No such value"检查,# 这个值在界面上显示为"n/a"。# 在这个例子中,我们通常可以拿到吞吐量结果。其他的值都处理为出错。# set throughput [chrPairResults get $pair THROUGHPUT]# 输出格式美化#set avg [format "%.3f" [lindex $throughput 0]]#set min [format "%.3f" [lindex $throughput 1]]#set max [format "%.3f" [lindex $throughput 2]]#puts "Throughput:"#puts " avg $avg min $min max $max"# (12)# 保存结果到测试文件.puts "=========="puts "Save the test..."chrTest save $test $result# (13)# 释放资源# (测试对象会自动释放相关的测试对)chrTest delete $test force# 搞定!return
读取出4条pair的平均流量,并将它们打印输出。
需要使用bat来驱动tcl文件
bat命令如下,黏贴另存为*.bat
@echo offcd cd C:\Users\Administrator\Desktop\TCLtclsh print4.tcl >test4.csv
另存为 print4.tcl
#首先进入IxChariot安装目录set ixchariot_installation_dir "C:/Program Files/Ixia/IxChariot"#set ixchariot_installation_dir "C:/Program Files/Ixia/IxChariot"cd $ixchariot_installation_dirload ChariotExtpackage require ChariotExt# 设置工作目录set work_dir "C:/Users/Administrator/Desktop/TCL/proc/"set work_dir_length [string length $work_dir]# 结果文件匹配#set files [glob -nocomplain -- $work_dir/*Edge*.tst]set files [glob -nocomplain -- $work_dir/*.tst]for { set i 0 } { $i < [llength $files] } { incr i } { #set long [llength $files] #puts "files $long" #puts "work_dir_length $work_dir_length " set tt [chrTest new] set f [lindex $files $i] set record_time [string range $f $work_dir_length [string length $f]] set record_time [string range $record_time 0 38] set script [string range $record_time 40 $work_dir_length] puts -nonewline "$record_time, " chrTest load $tt $f chrTest getPairCount $tt chrTest getPair $tt 0 set p1 [chrTest getPair $tt 0] #puts "Number of timing records = [chrPair getTimingRecordCount $p1]" # 提取MLR和DF文件 # 根据不同的测试需求,也可以读取吞吐量,时延,抖动,丢包率等指标 #set mlr [chrPairResults get $p1 MEDIA_LOSS_RATE ] #set df [chrPairResults get $p1 DELAY_FACTOR] set th [chrPairResults get $p1 THROUGHPUT ] #puts "mlr, [lindex $mlr 0], [lindex $mlr 1], [lindex $mlr 2],\ # df, [lindex $df 0], [lindex $df 1], [lindex $df 2]" set avg [format "%.3f" [lindex $th 0]] #set min [format "%.3f" [lindex $th 1]] #set max [format "%.3f" [lindex $th 2]] #puts "$avg,$min,$max " ################################### #chrTest getPair $tt 0 set p2 [chrTest getPair $tt 1] set th2 [chrPairResults get $p2 THROUGHPUT ] set avg1 [format "%.3f" [lindex $th2 0]] ################################### set p2 [chrTest getPair $tt 2] set th2 [chrPairResults get $p2 THROUGHPUT ] set avg2 [format "%.3f" [lindex $th2 0]] ################################################## set p2 [chrTest getPair $tt 3] set th2 [chrPairResults get $p2 THROUGHPUT ] set avg3 [format "%.3f" [lindex $th2 0]] ################################################## puts "$avg,$avg1,$avg2,$avg3" ################################################## chrTest delete $tt force}exit
0 0
- tcltk控制chariot进行测试,并将批量数据输出成excel
- tcltk控制chariot进行测试,并将批量数据输出成excel
- 用Delphi将数据导入到Excel并控制Excel
- 用Delphi将数据导入到Excel并控制Excel
- 用Delphi将数据导入到Excel并控制Excel
- 用Delphi将数据导入到Excel并控制Excel
- 套用模板输出Excel,并对数据进行分页
- C#套用模板输出Excel,并对数据进行分页
- 套用模板输出Excel,并对数据进行分页
- 批量将报表导成excel文件并打包下载
- 将在txt中的点数据批量arcgis插值后再输出为excel格式--未完
- Powershell调用Excel批量读取指定单元格数据并输出csv结果文件
- 用Delphi将数据导入到Excel并控制Excel(转载)
- 给出excel模板,进行数据批量上传
- DataGrid输出Excel并进行格式化处理
- 将excel批量添加数据导入sql
- 将数据绑定DataGrid并输出Excel文档的数据模型问题
- CHARIOT测试流量1
- 企业级应用程序开发的技术概览
- Android ListView应用
- SOAP协议
- 用ASP.NET构建完整E-mail发送系统
- opencv2.2.0源代码(include文件)分析(3)--上部分
- tcltk控制chariot进行测试,并将批量数据输出成excel
- 设计模式浅谈--单例模式
- 115个Java面试题和答案——终极列表(上)
- android:shape的使用
- 提高IIS的安全性
- 嵌入式linux系统中的tftp配置
- 部署引擎时候,出现大量TIME_WAIT解决办法
- javascript利用setInterval进行轮询操作一例
- Oracle 几个服务各代表什么作用