ttproto 是一个用于实现测试工具的实验性工具,主要用于一致性和互操作性测试。
项目描述
TTProto(测试工具原型)
ttproto 是一个用于实现测试工具、一致性和互操作性测试的实验性工具。首次实施它是为了探索 TTCN-3 标准的新功能和概念,但我们也使用它来实施我们为 2012 年 3 月在巴黎举行的 CoAP 互操作性活动提供的被动互操作性测试套件。
ttproto 现在被用于为f-interop 欧洲项目开发测试工具(用于互操作性和一致性测试) 该工具在 python3 中实现,其设计主要受 TTCN-3(抽象模型、模板、快照、行为树、通信端口、日志记录)和 Scapy(语法、灵活性、可定制性) 其目的是促进快速原型设计和实验(而不是生产使用)。我们选择最大化其模块化和可读性,而不是性能和实时考虑。
从 CLI 使用 TTProto
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 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 进行 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 分析,互操作测试用例事后分析,例如 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 文档
- 关于源代码gitlab repo
git 存储库包含以下测试工具:
TAT_COAP - 测试分析工具
用于测试 2 个 IUT 之间的 CoAP 互操作性的被动测试分析工具。它使用通用 TAT 结构(以简单的方式将工具扩展到其他协议的接口)。
基于 HTTP 的接口
HTTP API 由 HTTP RPC 样式的方法组成:
- 获取 /api/v1/analyzer_getTestCases
- 获取 /api/v1/analyzer_getTestcaseImplementation
- POST /api/v1/analyzer_testCaseAnalyze
- 获取 /api/v1/analyzer_getFrames
- POST /api/v1/dissector_dissectFile(必须提供TOKEN)
- GET /api/v1/dissector_getFrames(必须提供TOKEN)
- GET /api/v1/dissector_getFramesSummary
有关详细信息/参数,请参阅 tat_coap/webserver.py 文件
AMQP 接口
TAT_COAP 还实现了 AMQP 接口。有关 API 端点和 AMQP 连接的配置,请参阅文档。
TS_COAP - 分析后验 PCAP 分析器(稳定)
无源测试分析工具,用于测试 2 个 IUT 之间的互操作性。这个工具只提供了一个分析网络阵营的功能,可以通过基于 python 的网络服务器进行访问。
基于 HTTP 的接口
在127.0.0.1:2080作为网络服务器运行 CoAP TAT
cd ttproto
python3 -m ttproto.ts_coap
在 127.0.0.1:2080 打开网络浏览器并上传您的 PCAP 文件进行分析!
TS_6LoWPAN_ND - 一致性测试工具 (WIP)
用于测试 6LoWPAN ND 的一致性测试工具
运行单元测试
python3 -m pytest 测试/ --ignore=tests/test_webserver/tests.py --ignore=tests/test_tat/test_webserver.py