rammbock库关键字学习

rammbock库关键字学习

本文是从官方文档中直译过来,由于本人的英文水平有限(大部分借助百度翻译),某些地方肯定翻译的不好,希望大家多多指正修改,多谢!!!

库简介:rammbock:通用的网络协议测试库;提供简单的方法来指定网络数据包,并检查发送和接收数据包的结果。

1.Accept Connection
参数:[name=None | alias=None]

1.如果名称为空,则接受到由名称标识的服务器或最新服务器的连接。
2.如果给定一个别名,则连接将被命名,稍后可以使用该名称引用

Examples:
Accept connection
Accept connectionServer1my_connection

2.Array
参数:[size | type | name | *parameters ]
定义一个给定大小的包含类型字段的新数组

1.如果数组中的元素中有叫name的,则为name
2.type类型,是作为数组内容执行的关键字的名称
3.*parameters,可选的额外参数作为参数传递给此关键字

Examples:
Array8u16myArray
u32length
ArraylenthsomeStructmyArrayargument for someStruct

3.Bin
参数:[size | name| value=None ]
向模板添加新的二进制字段

1.必须在二进制容器中调用此关键字.具体看New Binary Container

4.Bin To Hex
参数:[bin_value]
将给定的二进制转换为十六进制字符串

Examples:
${hex}=Bin to hexHello!
${hex}=Bin to hex${binary}

5.Case
参数:[size| kw | *parameters]
包里的元素开始于Start Bag

1.size,可以是绝对值,如1、或者一个范围1-3,、或者是“*”(接受任何数字)

Examples:
Start bagintBag
case0-1u8foo42
case0-2u8bar1
End bag

6.Chars
参数:[length| name| value=None | terminator=None]
像模板中添加一个char数组

1.长度以字节为单位,可以引用模板中的之前的数字字段
2.特殊值,长度中的“*”表示长度编码为值的长度,并解码为所有可用字节(包括终结字符),直到匹配终结字符terminator=${terminator}(ascii编码)

Examples:
chars16fieldHello World!
u8charLength
charscharLengthfield
chars*fieldHello World!

7.Clear Message Streams
参数:[ 无 ]
重置传入sockets和流的消息
1.你可以使用该关键字在几个连续的case使用相同的连接

8.Client Receives Binary
参数:[name=None | timeout=None | label=None ]
接收原始的二进制消息

1.如果没指定客户端,则使用最新的客户端
2.可选的消息标签显示在logs中

Examples:
${binary} =Client receives binary
${binary} =Client receives binaryClient1timeout=5

9.Client Receives Message
参数:[*parameters ]

1.使用模板接收一个消息
2.模板由New Message定义,并校验字段值
3.在调用此模板之前,必须使用New Message定义消息模板

可选参数:

  • 命名客户端名称(默认使用最新的),example:name=Client1
  • 接收消息的超市时间,example:timeout=0.1
  • lates,如果设置为true,则首先从缓冲区获取最新的消息。默认为False,example:latest=True
  • 用冒号分隔的验证消息字段值,example:some_field:0xaf05
Examples:
${msg} =Client receives message
${msg} =Client receives messagename=Client1timeout=5
${msg} =Client receives messagemessage_field:(0|1)

10.Client Receives Without Validation
参数:[*parameters ]

1.使用模板接收一个消息
2.模板由New Message定义
3.在调用此模板之前,必须使用New Message定义消息模板

可选参数:

  • 命名客户端名称(默认使用最新的),example:name=Client1
  • 接收消息的超市时间,example:timeout=0.1
  • lates,如果设置为true,则首先从缓冲区获取最新的消息。默认为False,example:latest=True
Examples:
${msg} =Client receives message
${msg} =Client receives messagename=Client1timeout=5

11.Client Sends Binary
参数:[message| name=None | label=None]
发送一个原始的二进制消息

1.如果没指定客户端,则使用最新的客户端
2.可选的消息标签显示在logs中

Examples:
Client sends binaryHello!
Client sends binary${some binary}Client1label=DebugMessage

12.Client Sends Message
参数:[*parameters ]
发送一个由New Message定义的消息

1.可选参数是客户端名称,用等号分隔
2.消息字段值用冒号分隔
3.协议头的值,可以用语法设置协议头值 header:header_field_name:value

Examples:
Client sends message
Client sends messagefield_name:valuefield_name2:value
Client sends messagename=Client1header:message_code:0x32

13.Conditional
参数:[condition | name]
当name这个元素存在、condition条件为true,定义一个“condition(条件)”

Examples:
Conditionalmycondition == 1foo
u8myelement42
End conditional

14.Connect
参数:[ host | port | name=None]
将客户机连接到给定的主机和端口

1.如果没指定客户端,则使用最新的客户端

Examples:
Connect127.0.0.18080
Connect127.0.0.18080Client1

15.Container
参数:[ name | length| type | *parameters]
通过给定的长度,定义一个容器

1.通过这个关键字,可以方便的创建一个长度包含类型中定义的字段的结构。

16.Embed Seqdiag Sequence
参数:[ 无 ]
创建消息序列图PNG文件到输出文件夹,并嵌入图像目录文件
1.需要安装seqdiag才能创建序列图,see http://blockdiag.com/en/seqdiag/

17.End Bag
参数:[ 无 ]
从Start Bag开始,结束一个包

18.End Binary Container
参数:[ 无 ]
结束二进制容器,see New Binary Container

19.End Conditional
参数:[ 无 ]
结束条件的定义,see Conditional

20.End Protocol
参数:[ 无 ]
结束协议的定义

21.End Struct
参数:[ 无 ]
结束结构体的定义,see New Struct

22.End Tbcd Container
参数:[ 无 ]
官方文档无解释

23.End Union
参数:[ 无 ]
结束 union 定义,see New Union

24.Get Client Protocol
参数:[ name=None]
*返回客户端使用的协议,如果客户端不使用协议,则返回空

25.Get Client Unread Messages Count
参数:[ client_name=None ]
获取客户端未读消息的个数

26.Get Message
参数:[ *parameters ]
获取编码信息

1.Send Message 关键字是方便的,它会调用这个(Get Message)来获取消息对象,然后发送它
2.可选参数是用冒号分隔的消息字段值

Examples:
${msg} =Get message
${msg} =Get messagefield_name:value

27.Get Server Unread Messages Count
参数:[ server_name=None ]
获取服务器端未读消息的个数

28.Hex To Bin
参数:[ hex_value ]
将给定的16进制值转换为二进制

Examples:
${bin}=Hex to bin0xcafe

29.I 32
参数:[ name | value=None | align=None ]
向模板中添加一个32位的整形字段

1.只需调用具有预定义长度的int关键字

30.I 8
参数:[ name | value=None | align=None ]
向模板中添加一个1位(官方文档上写的是1,可能有误)的整形字段

1.只需调用具有预定义长度的int关键字

31.Int
参数:[ Length | name | value=None | align=None ]
向模板中添加一个带符号的整数

1.Length以字节为长度,value是可选的,align可用于将字段与较长的字节长度对齐
2.带符号整数使用两个二进制补码

Examples:
int2foo
int2foo42
int2fourByteFoo42align=4

32.Load Copy Of Template
参数:[ name | *parameters ]
*加载一个消息模板副本,通过Save template保存(当最初保存的值从一个case保存到另一个case时),parameters是用冒号分隔的消息头的默认值

Examples:
Load Copy Of TemplateMyMessageheader_field:value

33.Load Template
参数:[ name | *parameters ]
*加载一个消息模板,通过Save template保存,parameters是用冒号分隔的消息头的默认值

Examples:
Load TemplateMyMessageheader_field:value

34.Log Handler Messages
参数:[ 无 ]
官方文档无解释

35.New Binary Container
参数:[ name ]
定义一个新的二进制容器模板

1.二进制容器只能包含二进制字段,由Bin 这个关键字定义

Examples:
New binary containerflags
bin2foo
bin6bar
End binary container

36.New Message
参数:[ message_name | protocol=None |*parameters ]
定义一个名为message_name的消息模板

1.protocol必须通过 Start Protocol Description预先定义好
2.*parameters是用冒号分隔的消息头的默认值

Examples:
New messageMyMessageMyProtocolheader_field:value
bin2foo

37.New Protocol
参数:[ protocol_name ]
开始定义一个新的协议模板

1.使用协议的连接,该连接的所有发送和接收都必须符合此协议模板

38.New Struct
参数:[ type | name |*parameters ]
定义一个新的结构体模板

1.你必须调用End Struct去结束结构体的定义
2.type是通用类型的名称
3.name是包含结构体的字段名
4.*parameters的 值是用冒号分隔的
5.可选结构体的长度通过length=.Length定义,用于接收以验证结构是否匹配预设长度
6.当发送时,结构体长度可以引用其他消息字段,然后动态设置该字段

Examples:
New structPairmyPair
u8first
u8second
End Struct

39.New Tbcd Container
参数:[ name ]

40.New Union
参数:[ type,name ]
通过type和name定义一个新联合的新模板

1.字段插入union是可选择的
2.union的长度,就是它最长的一个字段的长度

Examples:
New unionIntOrAddressfoo
Chars16ipAddress
u32int
End union

41.Pdu
参数:[ length ]
在协议模板中定义消息

1.长度必须是模板定义中前一个字段的名称,或固定长度协议的静态值

Examples:
pdu5
u8length
pdulength-1

42.Reset Handler Messages
参数:[ 无 ]

43.Reset Rammbock
参数:[ 无 ]
关闭所有连接,删除所有服务端、客户端和协议

1.你需要调用该关键字,在退出测试之前
2.将关闭所有的连接,所以端口可以更快的重新使用

44. Save Template
参数:[ name | unlocked=False]
保存消息模板供Load template以后使用

1.如果保存的模板被标记为unlocked,那么之后对其进行更改(也就是后面的还可以继续添加字段),默认为locked

Examples:
Save TemplateMyMessage
Save TemplateMyOtherMessageunlocked=True

45.Server Receives Binary
参数:[ name=None | timeout=None| connection=None |label=None]
接收一个原始的二进制消息

1.如果未制定服务器,则使用最新的那个
2.可选的消息标签显示在logs中

Examples:
${binary} =Server receives binary
${binary} =Server receives binaryServer1connection=my_connectiontimeout=5

46.Server Receives Binary From
参数:[ name=None | timeout=None| connection=None |label=None]
接收一个原始的二进制消息.并返回消息、ip、和端口值

1.如果未制定服务器,则使用最新的那个
2.可选的消息标签显示在logs中

Examples:
${binary} =${ip}${port}Server receives binary
${binary} =${ip}${port}Server receives binaryServer1connection=my_connectiontimeout=5

47.Server Receives Message
参数:[ *parameters]
通过New Message定义的消息模板接收一个消息,并验证字段的值

1.调用此关键字之前,消息模板必须由New Message定义好

可选的参数:

  • name,命名客户端的名称(默认使用最新的),example:name=Client1
  • 连接的别名,example:connection=connection1
  • 接收消息的超时时间,example:timeout=0.1
  • latest,如果设置latest为true,则首先从缓冲区获取最新的消息,默认为False,example:latest=True
  • 消息字段的值由冒号进行分割,example:some_field:0xaf05
Examples:
${msg}=Server Receives Message
${msg}=Server Receives Messagename=Server1alias=my_connectiontimeout=5
${msg}=Server Receives Messagemessage_field:(0|1)

48.Server Receives Without Validation
参数:[ *parameters]
通过New Message定义的消息模板接收一个消息

1.调用此关键字之前,消息模板必须由New Message定义好

可选的参数:

  • name,命名客户端的名称(默认使用最新的),example:name=Client1
  • 连接的别名,example:connection=connection1
  • 接收消息的超时时间,example:timeout=0.1
  • latest,如果设置latest为true,则首先从缓冲区获取最新的消息,默认为False,example:latest=True
Examples:
${msg}=Server Receives Message
${msg}=Server Receives Messagename=Server1alias=my_connectiontimeout=5

49.Server Sends Binary
参数:[ message |name=None|connection=None|label=None]
发送一个原始的二进制消息

1.如果未指定服务器,则使用最新的
2.可选的消息标签显示在logs中

Examples:
Server sends binaryHello!
Server sends binary${somebinary}Server1label=DebugMessage
Server sends binary${somebinary}name=Server1connection=my_connection

50.Server Sends Message
参数:[ *parameters]
发送一个由New Message定义的消息

1.可选的参数是服务器名和可能的连接别名,用“=”进行分割,消息字段的值用冒号”:"进行分割,协议头的值可以使用语法设置 header:header_field_name:value.

Examples:
Server sends message
Server sends messagefield_name:valuefield_name2:value
Server sends messagename=Server1connection=my_connection

51.Set Client Handler
参数:[ handler_func |name=None| header_filter=None | header_filter=None | interval=0.5]
为当前加载的消息模板类型设置自动处理程序

1.该关键字允许用户设置一个python处理程序函数,当消息与预期模板匹配时,rammbock消息队列自动调用该函数
2.可选的name参数定义处理程序将绑定到客户端的节点,否则将使用默认的客户端
3.header_filter定义将使用哪个header字段来标识定义消息(否则所有收到的消息都将匹配!)
4.interval=0.5定义了后台调用处理程序的间隔,以秒为单位,默认每0.5s检查一次传入的消息
5.需使用两个参数调用处理程序函数:rammbock库的实例化和收到的消息

Examples:
Load templateSomeMessage
Set client handlermy_module.respond_to_sample

my_module.py:

def respond_to_sample(rammbock, msg):
rammbock.save_template("__backup_template", unlocked=True)
try:
rammbock.load_template("sample response")
rammbock.client_sends_message()
finally:
rammbock.load_template("__backup_template")

52.Set Server Handler
参数:[ handler_func |name=None| header_filter=None | header_filter=None | alias=None|interval=0.5]
为当前加载的消息模板类型设置自动处理程序

1.该关键字允许用户设置一个python处理程序函数,当消息与预期模板匹配时,rammbock消息队列自动调用该函数
2.可选的name参数定义处理程序将绑定到客户端的节点,否则将使用默认的客户端
3.header_filter定义将使用哪个header字段来标识定义消息(否则所有收到的消息都将匹配!)
4.interval=0.5定义了后台调用处理程序的间隔,以秒为单位,默认每0.5s检查一次传入的消息
5.alias,默认将使用活动的连接
6.需使用两个参数调用处理程序函数:rammbock库的实例化和收到的消息

Examples:
Load templateSomeMessage
Set Server handlermy_module.respond_to_sample

my_module.py:

def respond_to_sample(rammbock, msg):
rammbock.save_template("__backup_template", unlocked=True)
try:
rammbock.load_template("sample response")
rammbock.client_sends_message()
finally:
rammbock.load_template("__backup_template")

53.Start Bag
参数:[ name]
包是一组可选元素,具有可选计数

1.可选元素分别为Case作为第一个参数以接收计数
2.接收到的元素按照顺序从Case的列表中匹配
3.如果接收的值对Case无效(举个例子,与期望值不匹配),然后尝试匹配下一个Case,知道找到匹配项
4.请注意,虽然收到的元素与给定的case相匹配,但是元素不需要以与案例相同的顺序到达

This example would match int value 42 0-1 times and in value 1 0-2 times. For example
1, 42, 1 would match, as would 1, 1:

Examples:
Start bagintBag
case0-1u8foo42
case0-2u8bar1
End bag

一个更真实的案例,其中每个AVP条目都有一个带有用于匹配的值的类型字段

Examples:
Start bagavps
case1AVPresultResult-Code
case1AVPoriginHostOrigin-Host
case1AVPoriginRealmOrigin-Realm
case1AVPhostIPHost-IP-Address
case*AVPappIdVendor-Specific-Application-Id
case0-1AVPoriginStateOrigin-State
End bag

有关包的更完整的实例,see:https://github.com/robotframework/Rammbock/blob/master/atest/diameter.robot

54.Start Sctp Client
参数:[ ip=None | port=None | name=None | timeout=None |protocol=None | family=ipv4]
Starts a new SCTP client

1.客户端可以选择ip、port以及名称、默认超时时间和协议进行绑定。
2.family可以是ipv4(默认)或ipv6
3.作为主机,你必须使用Connect 这个关键字去连接客户端

Examples:
Start TCP client
Start TCP clientname=Client1protocol=GTPV2
Start TCP client10.10.10.253name=Server1protocol=GTPV2
Start TCP clienttimeout=5

55.Start Sctp Server
参数:[ ip | port | name=None | timeout=None |protocol=None | family=ipv4]
Starts a new STCP server to given ip and port

1.pysctp (https://github.com/philpraxis/pysctp) need to be installed your system
2.需要注意的是,你必须使用Accept Connection 这个关键字去接收连接
Examples:
Start STCP server 10.10.10.2 53
Start STCP server 10.10.10.2 53 Server1
Start STCP server 10.10.10.2 53 name=Server1 protocol=GTPV2
Start STCP server 10.10.10.2 53 timeout=5

Examples:
Start STCP server
Start STCP server10.10.10.253
Start STCP server10.10.10.253Server1
Start STCP server10.10.10.253name=Server1protocol=GTPV2
Start STCP server10.10.10.253timeout=5

56.Start Tcp Client
参数:[ ip=None | port=None | name=None | timeout=None |protocol=None | family=ipv4]
Starts a new TCP client

1.Client can be optionally given ip and port to bind to, as well as name, default timeout
and a protocol. family can be either ipv4 (default) or ipv6.
2.You should use Connect keyword to connect client to a host

Examples:
Start TCP client
Start TCP clientname=Client1protocol=GTPV2
Start TCP client10.10.10.253name=Server1protocol=GTPV2
Start TCP client10.10.10.253timeout=5
Start TCP client0:0:0:0:0:0:0:153family=ipv6

57.Start Tcp Server
参数:[ ip | port | name=None | timeout=None | protocol=None | family=ipv4]
Starts a new TCP server to given ip and port

1.Server can be given a name, default timeout and a protocol. family can be either ipv4
(default) or ipv6.
2.Notice that you have to use Accept Connection keyword for server to
receive connections.

Examples:
Start TCP server10.10.10.253
Start TCP server10.10.10.253Server1
Start TCP server10.10.10.253name=Server1protocol=GTPV2
Start TCP server10.10.10.253timeout=5
Start TCP server0:0:0:0:0:0:0:153family=ipv6

58.Start Udp Client
参数:[ ip=None | port=None | name=None | timeout=None | protocol=None | family=ipv4]
Starts a new UDP client

1.Server can be given a name, default timeout and a protocol. family can be either ipv4
(default) or ipv6.
2.Notice that you have to use Accept Connection keyword for server to
receive connections.

Examples:
Start UDP client
Start UDP clientname=Client1protocol=GTPV2
Start UDP client10.10.10.253name=Server1protocol=GTPV2
Start UDP clienttimeout=5
Start TCP server0:0:0:0:0:0:0:153family=ipv6

59.Start Udp Server
参数:[ ip| port | name=None | timeout=None | protocol=None | family=ipv4]
Starts a new UDP server to given ip and port

1.Server can be given a name, default timeout and a protocol. family can be either ipv4
(default) or ipv6.

Examples:
Start UDP server10.10.10.253
Start UDP server10.10.10.253Server1
Start UDP server10.10.10.253name=Server1protocol=GTPV2
Start UDP server10.10.10.253timeout=5
Start UDP server0:0:0:0:0:0:0:153family=ipv6

60.Tbcd
参数:[ size| name | value=None]
官方文档无解释

61.U 128
参数:[ name| value=None| align=None]
将无符号的16字节整数字段添加到模板

1.这是一种方便的方法,只需调用具有预定义长度的Uint关键字

62.U 16
参数:[ name| value=None| align=None]
将无符号的2字节整数字段添加到模板

1.这是一种方便的方法,只需调用具有预定义长度的Uint关键字

63.U 24
参数:[ name| value=None| align=None]
将无符号的3字节整数字段添加到模板

1.这是一种方便的方法,只需调用具有预定义长度的Uint关键字

64.U 32
参数:[ name| value=None| align=None]
将无符号的4字节整数字段添加到模板

1.这是一种方便的方法,只需调用具有预定义长度的Uint关键字

65.U 40
参数:[ name| value=None| align=None]
将无符号的5字节整数字段添加到模板

1.这是一种方便的方法,只需调用具有预定义长度的Uint关键字

66.U 64
参数:[ name| value=None| align=None]
将无符号的8字节整数字段添加到模板

1.这是一种方便的方法,只需调用具有预定义长度的Uint关键字

67.U 8
参数:[ name| value=None| align=None]
将无符号的1字节整数字段添加到模板

1.这是一种方便的方法,只需调用具有预定义长度的Uint关键字

68.Uint
参数:[ length| name | value=None | align=None]
将无符号整数字段添加到模板

1.length,以字节为单位
2.value,值是可选的
3.align,可用于将字段与较长的字节长度对齐

Examples:
uint2foo
uint2foo42
uint2fourByteFoo42align=4

69.Validate Message
参数:[ msg| *parameters ]
使用New Message定义的模板,验证给定的消息。字段值作为可选参数

Examples:
Validate message${msg}
Validate message${msg}status:0

70.Value
参数:[ name| value ]
通过name标识一个默认value给模板字段

1.默认头字段的值,可以设置为header:field语法

Examples:
Valuefoo42
Valuestruct.sub_field0xcafe
Valueheader:version0x02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值