ttproto是一个实现测试工具的实验工具,主要用于一致性和互操作性测试。
ttproto的Python项目详细描述
TTproto(测试工具原型)
ttproto是一个用于实现测试工具、一致性和互操作性测试的实验工具。 它最初是为了探索TTCN-3标准的新特性和概念而实现的,但我们也使用它来实现我们为2012年3月在巴黎举行的COAP互操作性活动提供的被动互操作性测试套件。
ttproto现在被用于为f-interop european project开发测试工具(用于互操作性和一致性测试)。 该工具在Python 3中实现,其设计主要受TTCN-3(抽象模型、模板、快照、行为树、通信端口、日志记录)和Scapy(语法、灵活性、可定制性)的影响。 其目的是促进快速成型和实验(而不是生产使用)。我们选择最大化其模块性和可读性,而不是性能和实时性考虑。
使用cli中的ttproto
>>> python3 -m ttproto --help
usage: ttproto <command> [<args>]
TTProto CLI accepts the following commands:
dissect Dissects network traces (.pcap file).
analyze Analyses network traces (.pcap file).
service_amqp Launches TTProto as a HTTP service (WIP).
service_http Launches TTProto as an AMQP service.
>>> python3 -m ttproto --help
usage: ttproto <command> [<args>]
TTProto CLI accepts the following commands:
dissect Dissects network traces (.pcap file).
analyze Analyses network traces (.pcap file).
service_amqp Launches TTProto as a HTTP service (WIP).
service_http Launches TTProto as an AMQP service.
此外,您还可以获得每个子域的帮助:
>>> python3 -m ttproto dissect --help
usage: ttproto dissect file [<options>]
Dissection usage examples:
dissect ./tests/test_dumps/6lowpan_hc/TD_6LOWPAN_HC_01.pcap
dissect ./tests/test_dumps/6lowpan_hc/TD_6LOWPAN_HC_01.pcap -o /tmp/dissection.json
dissect ./tests/test_dumps/6lowpan_hc/TD_6LOWPAN_HC_01.pcap -p sixlowpan
dissect ./tests/test_dumps/6lowpan_hc/TD_6LOWPAN_HC_01.pcap -p icmpv6
dissect ./tests/test_dumps/6lowpan_hc/TD_6LOWPAN_HC_01.pcap -p icmpv6echorequest
示例:
python3 -m ttproto dissect ./tests/test_dumps/6lowpan_hc/TD_6LOWPAN_HC_01.pcap
INFO tat|ttproto_api [MainThread] Dissecting PCAP file ./tests/test_dumps/6lowpan_hc/TD_6LOWPAN_HC_01.pcap
INFO tat|ttproto_api [MainThread] PCAP dissected
INFO tat|main [MainThread] ###[ Ieee802154 ]###
FrameType= 1 (Data Frame)
SecurityEnabled= 0
FramePending= 0
AcknowlegeRequest= 1
IntraPan= 1
Reserved= 0
DestinationAddressingMode= 3 (extended)
FrameVersion= 0 (IEEE 802.15.4-2003)
SourceAddressingMode= 3 (extended)
SequenceNumber= 45
DestinationPanId= 0xabcd
DestinationAddress= 00:12:74:00:14:6e:f1:21
SourcePanId= (omit)
SourceAddress= 00:12:74:00:14:65:d8:db
Payload=
###[ SixLowpanIPHC ]###
Dispatch= 0b011
TF= 0b11 (Elided)
NH= 0 (Inline)
HLIM= 0b10 (Compressed hop limit = 64)
CID= 0 (No additional context)
SAC= 0 (Stateless)
SAM= 0b01 (64 bits)
M= 0 (Not Multicast)
DAC= 0 (Stateless)
DAM= 0b11 (0 bits (multicast: 8))
SCI= (omit)
DCI= (omit)
InlineECN= (omit)
InlineDSCP= (omit)
InlineTFPad= (omit)
InlineFL= (omit)
InlineNH= 58
InlineHLIM= (omit)
InlineSourceAddress= 76:00:14:ff:fe:65:d8:db
InlineDestinationAddress= (omit)
CompressedNextHeader= (omit)
Payload=
###[ IPv6 ]###
Version= 6
TrafficClass= 0x00
FlowLabel= 0x00000
PayloadLength= 64
NextHeader= 58 (ICMP for IPv6)
HopLimit= 64
SourceAddress= fe80::7600:14ff:fe65:d8db
DestinationAddress= fe80::212:7400:146e:f121
Payload=
###[ ICMPv6EchoRequest ]###
Type= 128 (Echo Request)
Code= 0
Checksum= 0x9f55
Identifier= 0x5328
SequenceNumber= 43
Payload=
###[ BytesValue ]###
Value= b'\x99\xa1\xa0W\x00\x00\x00\x00\xaf*\n\x00\x00\x00\x00\x00\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./01234567'
FCS=
Encoded as:
61 cc 2d cd ab 21 f1 6e 14 00 74 12 00 db d8 65
14 00 74 12 00 7a 13 3a 76 00 14 ff fe 65 d8 db
80 00 9f 55 53 28 00 2b 99 a1 a0 57 00 00 00 00
af 2a 0a 00 00 00 00 00 10 11 12 13 14 15 16 17
18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27
28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37
(...)
使用ttproto核心api
下面是一些关于如何使用ttproto api进行pcap分析的示例:
使用ttproto控制台:
python3 -i console.py
用于运行PCAP文件的解剖:
>>> capture = Capture('tests/test_dumps/coap_core/TD_COAP_CORE_01_PASS.pcap')
>>> dissection = capture.get_dissection()
>>> print(json.dumps(dissection, indent=4))
[
{
"_type": "frame",
"id": 1,
"timestamp": 1464858393.547275,
"error": null,
"protocol_stack": [
{
"_type": "protocol",
"_protocol": "NullLoopback",
"AddressFamily": "2",
"ProtocolFamily": "0"
},
{
"_type": "protocol",
"_protocol": "IPv4",
"Version": "4",
(...)
"SourceAddress": "127.0.0.1",
"DestinationAddress": "127.0.0.1",
"Options": "b''"
},
{
(...)
},
{
"_type": "protocol",
"_protocol": "CoAP",
"Version": "1",
"Type": "0",
"TokenLength": "2",
"Code": "1",
"MessageID": "0xaa01",
"Token": "b'b\\xda'",
"Options": [
{
"Option": "CoAPOptionUriPath",
"Delta": "11",
"Length": "4",
"Value": "test"
},
{
"Option": "CoAPOptionBlock2",
"Delta": "12",
"Length": "1",
"Number": "0",
"M": "0",
"SizeExponent": "2"
}
],
"Payload": "b''"
}
]
},
{
(...)
}
]
对于运行PCAP分析,Interop测试用例事后分析,对于(例如)td_coap_core_01:
>>> analyzer = Analyzer('tat_coap')
>>> analysis_result = analyzer.analyse('tests/test_dumps/coap_core/TD_COAP_CORE_01_PASS.pcap','TD_COAP_CORE_01')
>>> print(json.dumps(analysis_result, indent=4))
[
"TD_COAP_CORE_01",
"pass",
[],
"<Frame 1: [127.0.0.1 -> 127.0.0.1] CoAP [CON 43521] GET /test>\n [ pass ] <Frame 1: (...)",
[
[
"pass",
"<Frame 1: [127.0.0.1 -> 127.0.0.1] CoAP [CON 43521] GET /test> Match: CoAP(type=0, code=1)"
],
[
"pass",
"<Frame 1: [127.0.0.1 -> 127.0.0.1] CoAP [CON 43521] GET /test> Match: CoAP(type=0, code=1)"
],
[
"pass",
"<Frame 2: [127.0.0.1 -> 127.0.0.1] CoAP [ACK 43521] 2.05 Content > Match: CoAP(code=69, mid=0xaa01, tok=b'b\\xda', pl=Not(b''))"
],
[
"pass",
"<Frame 2: [127.0.0.1 -> 127.0.0.1] CoAP [ACK 43521] 2.05 Content > Match: CoAP(opt=Opt(CoAPOptionContentFormat()))"
]
],
[]
]
查看更多信息
- 关于库检查的详细功能集:ttproto features
- 关于如何为coap或任何其他协议编写测试用例,请参见CONTRIBUTING.rst document
- 关于源代码gitlab repo
git存储库包含以下测试工具:
tat_coap-测试分析工具
用于测试两个iut之间coap互操作性的被动测试分析工具。 它使用通用的tat结构(接口以简单的方式将工具扩展到其他协议)。
基于http的接口
http api由http-rpc样式的方法组成:
- get/api/v1/analyzer获取测试用例
- get/api/v1/analyzer实现
- post/api/v1/analyzer\u测试用例分析
- get/api/v1/analyzer获取框架
- post/api/v1/dissector_dissectfile(必须提供令牌)
- get/api/v1/dissector\u getframes(必须提供令牌)
- get/api/v1/dissector\u getframessummary
有关详细信息/params,请参阅tat_coap/webserver.py文件
AMQP接口
tat_coap还实现了一个amqp接口。API端点和AMQP连接配置见文档。
ts_coap-分析后验pcap分析仪(稳定)
用于测试两个iut之间互操作性的被动测试分析工具。这个工具只提供了一个分析网络结构的特性,可以通过基于python的web服务器进行访问。
基于http的接口
在127.0.0.1:2080将coap tat作为web服务器运行
cd ttproto
python3 -m ttproto.ts_coap
打开网页浏览器127.0.0.1:2080,上传你的PCAP文件进行分析!
ts u6lowpan nd-一致性测试工具(WIP)
用于测试6lowpan nd的一致性测试工具
运行单元测试
python3-m py test tests/--ignore=tests/test_webserver/tests.py--ignore=tests/test_tat/test_webserver.py