0


性能测试工具 IxChariot:Tcl脚本调用方法介绍

ixChariot是一款功能强大的性能测试软件,可用来测试有线和无线性能,可以模拟真实应用程序流量,并提供关键性能指标,包括吞吐量、丢包、抖动、延迟、MOS等。本文简单介绍如何使用IxChariot Tcl API来实现自动化跑流。

目录

IxChariot测试网络

一个基本的IxChariot测试网络主要包括三个部分:

  • IxChariot控制端:可以安装IxChariot软件的Windows PC
  • Endpoint 1:接收IxChariot控制端的测试脚本和数据,与Endpoint 2 进行跑流测试,并将所有测试结果返回到IxChariot控制端。
  • Endpoint 2:与Endpoint 1通信,接收Endpoint 1的测试脚本和数据,并将测试结果返回给Endpoint 1

通常在IxChariot控制端电脑的IxChariot软件配置跑流脚本,在

  1. Endpoint 1

  1. Endpoint 2

两个电脑上安装并启动Endpoint。然后就可以在IxChariot控制端运行跑流脚本,测试结果会返回到控制端。

IxChariot软件页面的手动配置这里就不介绍了,下面主要介绍如何使用Chariot API来实现自动化跑流。

IxChariot API简介

IxChariot API支持使用C语言和Tcl脚本来驱动IxChariot跑流,我们可以通过IxChariot API来创建、执行、保存和提取测试结果。

下图是IxChariot包与IxChariot API、endpoint之间的工作流程。

IxChariot API中的对象是分层的,其包含的分层结构如下图:

以下对象在测试对象中单独实例化,然后添加到测试对象示例中:

pair

hardware pair

VoIP pair

VoIP hardware pair

application group

video pair

multicast group

video multicast group

multicast pair

channel

receiver

IxChariot测试必须至少包含一个 pair 对象:pair,hardware pair, VoIP pair, video pair, multicast group, 或者 video multicast group对象实例。当测试开始执行时,会自动创建时间记录(timing record)对象实例。

IxChariot Tcl包提供的方法可在帮助文档中查看。

IxChariot环境安装

本文主要介绍IxChariot Tcl API的简单使用,这里介绍Tcl跑流的环境安装步骤。

1. 安装IxChariot

在IxChariot控制端电脑(Windows系统)上安装,我使用的是默认安装路径:

  1. C:\Program Files (x86)\Ixia\IxChariot

2. 安装endpoint

安装系统平台对应的endpoint,支持Windows、Linux和macOS系统。

1、Windows系统安装

Windows系统双击安装即可。

启动endpoint的cmd命令:

  1. $ net start IxiaEndpoint

停止endpoint进程的cmd命令:

  1. $ net stop IxiaEndpoint

2、Linux系统安装

Linux rpm包安装方法:

  1. $ rpm -ivh pelinux_amd64_95.rpm

Linux 源码包安装方法:

  1. $ cd endpoint
  2. $ tar -xvzf pelinux_amd64_730.tar.gz
  3. $ ./endpoint.install accept_license

启动endpoint:

  1. $ setsid /usr/local/Ixia/endpoint

停止endpoint进程:

  1. $ /usr/local/Ixia/endpoint k

3. 安装Tcl

使用IxChariot Tcl API时,建议在命令行执行Tcl脚本来运行IxChariot:

  1. $ tclsh myTest.tcl

因此需要安装一下Tcl环境,Tcl下载地址:https://www.tcl.tk/software/tcltk/download.html

安装完成后,需要将tcl安装bin目录添加到环境变量。

IxChariot Tcl API

下面列举一些 IxChariot Tcl 包创建普通 pair 的一些常用方法。

chrRunOpts

用于定义和获取测试运行选项,比如设置跑流时间:

  1. set test [chrTest new]
  2. #设置测试时间值
  3. set runOpts [chrTest getRunOpts $test]
  4. chrRunOpts set $runOpts TEST_END FIXED_DURATION
  5. chrRunOpts set $runOpts TEST_DURATION 30

必须将

  1. TEST_END

设置为

  1. FIXED_DURATION

时,

  1. TEST_DURATION

值才会生效。

chrPair set

设置pair属性

  1. chrPair set pair1 PROTOCOL $pro; # 设置协议
  2. chrPair set pair1 E1_ADDR IP地址; # 设置Endpoint 1 address
  3. chrPair set pair1 E2_ADDR IP地址; # 设置Endpoint 2 address

chrPair useScript

给pair设置测试脚本

  1. chrPair useScript pair1 Throughput.scr;

chrPair setScriptVar

设置脚本变量,比如

  1. chrPair setScriptVar pair1 file_size $filesize};#发送字节数
  2. chrPair setScriptVar pair1 send_buffer_size $buffersize; # buffer大小
  3. chrPair setScriptVar pair1 send_data_rate $datarate};#发送速率

读取结果

可以使用

  1. chrCommonResults get

  1. chrPairResults get

方法来读取测试结果。

  1. set runingtime [chrCommonResults get pair1 MEAS_TIME; # 运行时间
  2. set throughput [chrPairResults get pair1 THROUGHPUT; # THROUGHPUT结果

更多API用法可参考接口文档,下面列举创建pair和VoIPPair的示例。

Tcl脚本示例

pair创建实例

  1. set e1 "localhost"
  2. set e2 "localhost"
  3. set script "c:/Program Files/Ixia/IxChariot/Scripts/Throughput.scr"
  4. set testFile "c:/Program Files/Ixia/IxChariot/tests/lbtest.tst"
  5. set timeout 60
  6. # (1)加载Chariot包
  7. load ChariotExt
  8. package require ChariotExt
  9. # (2)创建测试对象
  10. set test [chrTest new]
  11. set runOpts [chrTest getRunOpts $test]
  12. chrRunOpts set $runOpts TEST_END FIXED_DURATION
  13. chrRunOpts set $runOpts TEST_DURATION $timeout; #设置测试运行时间
  14. # (3)创建pair对象
  15. set pair [chrPair new]
  16. # (4)设置pair属性
  17. chrPair set $pair E1_ADDR $e1 E2_ADDR $e2
  18. chrPair set $pair PROTOCOL TCP; #设置协议
  19. # (5)设置测试脚本
  20. chrPair useScript $pair $script
  21. chrPair setScriptVar $pair file_size 1000000;#发送字节数
  22. chrPair setScriptVar $pair send_buffer_size 1500;#buffer大小
  23. chrPair setScriptVar $pair send_data_rate "20 Mb";#发送速率
  24. # (6)添加pair到测试对象中
  25. chrTest addPair $test $pair
  26. # (7)运行测试
  27. chrTest start $test
  28. # (8)等待测试结束
  29. set $timeout [expr 10 + $timeout]
  30. if {![chrTest isStopped $test $timeout]} {
  31. puts "ERROR: Test didn’t stop"
  32. chrTest delete $test force
  33. return
  34. }
  35. # (9)打印
  36. puts "==========="
  37. puts "Test setup:\n----------"
  38. puts "Number of pairs = [chrTest getPairCount $test]"
  39. puts "E1 address : [chrPair get $pair E1_ADDR]"
  40. puts "E2 address : [chrPair get $pair E2_ADDR]"
  41. # We didn’t set the protocol, but let’s show it anyway.
  42. puts "Protocol : [chrPair get $pair PROTOCOL]"
  43. # We’ll show both the script filename and
  44. # the application script name.
  45. puts "Script filename : [chrPair get $pair SCRIPT_FILENAME]"
  46. puts "Appl script name: [chrPair get $pair APPL_SCRIPT_NAME]"
  47. # (10)读取测试结果: 吞吐量
  48. puts ""
  49. puts "Test results:\n------------"
  50. puts "Number of timing records = \
  51. [chrPair getTimingRecordCount $pair]"
  52. set throughput [chrPairResults get $pair THROUGHPUT]
  53. set avg [format "%.3f" [lindex $throughput 0]]
  54. set min [format "%.3f" [lindex $throughput 1]]
  55. set max [format "%.3f" [lindex $throughput 2]]
  56. puts "Throughput:"
  57. puts " avg $avg min $min max $max"
  58. # (11)保存测试结果
  59. puts "Save the test..."
  60. chrTest save $test $testFile
  61. # (12)清理
  62. chrTest delete $test force
  63. return

VoIPPair创建实例

  1. set e1 "localhost"
  2. set e2 "localhost"
  3. set timeout 60
  4. # (1)加载Chariot包
  5. load ChariotExt
  6. package require ChariotExt
  7. # (2)创建测试对象
  8. set test [chrTest new]
  9. set runOpts [chrTest getRunOpts $test]
  10. chrRunOpts set $runOpts TEST_END FIXED_DURATION
  11. chrRunOpts set $runOpts TEST_DURATION $timeout; #设置测试运行时间
  12. # (2)创建voippair对象
  13. set voippair1 [chrVoIPPair new]; # VoIP Pair创建
  14. # (3)设置pair属性
  15. chrPair set $voippair1 E1_ADDR $e1 E2_ADDR $e2
  16. chrPair set $voippair1 QOS_NAME "VoIPQoS";
  17. chrVoIPPair set $voippair1 CODEC "G711u";
  18. # (4)添加voippair1到测试对象中
  19. chrTest addPair $test $voippair1
  20. # (5)运行测试
  21. chrTest start $test
  22. # (6)等待测试结束
  23. if {![chrTest isStopped $test $timeout]} {
  24. puts "ERROR: Test didn’t stop in 2 minutes!"
  25. chrTest delete $test force
  26. return
  27. }
  28. # (7)读取测试结果
  29. # MOS
  30. set mos [chrPairResults get $voippair1 MOS_ESTIMATE]
  31. set mos_avg [format "%.3f" [lindex $mos 0]]
  32. puts "MOS_avg $mos_avg"
  33. # 时延
  34. set delay [chrPairResults get $voippair1 END_TO_END_DELAY]
  35. set delay_avg [lindex $delay 0]
  36. set delay_avg [format "%.1f" $delay_avg]
  37. puts "END_TO_END_DELAY $delay_avg"
  38. # 丢包率
  39. set bytes_recv_e2 [chrCommonResults get $voippair1 BYTES_RECV_E2]
  40. # puts ""
  41. # puts "BYTES_RECV_E2: $bytes_recv_e2"
  42. set bytes_sent_e1 [chrCommonResults get $voippair1 BYTES_SENT_E1]
  43. # puts "BYTES_SENT_E1: $bytes_sent_e1"
  44. set bytes_lost_rate [format "%.4f" [expr ($bytes_sent_e1 - $bytes_recv_e2)/$bytes_sent_e1]]
  45. set bytes_lost_rate [expr $bytes_lost_rate*100]
  46. puts "BYTES_LOST_RATE $bytes_lost_rate"
  47. # (11)保存测试结果
  48. puts "Save the test..."
  49. chrTest save $test $testFile
  50. # (12)清理
  51. chrTest delete $test force
  52. return

其它

执行tst文件

可以使用runtst工具来执行创建的tst文件:

  1. $ cd C:\Program Files (x86)\Ixia\IxChariot
  2. $ runtst.exe -t20 C:\\Users\DELL\\Documents\\IxChariot\\TESTS\\demo.tst d:\\test\\demo.tst

Python执行TCL脚本

除了使用Python的

  1. os.popen

或者

  1. subprocess.Popen

调用编写好的Tcl脚本执行测试外,也可以使用Python的Tcl库来执行Tcl命令:

  1. from Tkinter import Tcl
  2. tcl = Tcl()# 加载ChariotExt
  3. tcl.eval("load ChariotExt")
  4. tcl.eval("package require ChariotExt")

注意:

  1. 执行此Python脚本的电脑必须安装好IXChariot控制端软件,否则无法加载ChariotExt.dll动态链接库。
  2. 如果ChariotExt.dll为32位VC++环境编译,Python也需要32位。

--THE END--


本文转载自: https://blog.csdn.net/u010698107/article/details/129971395
版权归原作者 测试开发小记 所有, 如有侵权,请联系我们删除。

“性能测试工具 IxChariot:Tcl脚本调用方法介绍”的评论:

还没有评论