T-Rex STL STLVmWrFlowVar支持ICMP Packet类型。可以使用offset参数来指定写入FlowVar的偏移量。
以下是示例代码:
from trex_stl_lib.api import *
class STLS1(object):
def create_stream (self):
return STLStream(packet = STLPktBuilder(pkt = Ether()/IP(dst="16.0.0.1", ttl=64)/ICMP()),
flow_var = {
'ip.id': '1,2,3',
'icmp.type': '0,1,2,3',
'icmp.seq': '10,20,30',
'icmp.id': STLVmFlowVar(name="my_icmp_id", min_value=1, max_value=1000, size=2, op="dec"),
'icmp.chksum': STLVmFlowVar(name="my_icmp_chksum", min_value=0, max_value=65535, size=2, op="random"),
},
vm = [STLVmWrFlowVar(fv_name='my_icmp_id', pkt_offset=36),
STLVmWrFlowVar(fv_name='my_icmp_chksum', pkt_offset=38, offset_fixup=True)],
mode = STLTXSingleBurst(total_pkts = 1))
def get_streams (self, direction = 0, **kwargs):
return [self.create_stream()]
在此示例中,我们使用STLVmWrFlowVar将icmp.id和icmp.chksum被写入到ICMP packet中的指定偏移量。icmp.id将被写入到第36个字节,icmp.chksum将被写入到第38个字节。注意,注意offset_fixup参数的用法,它指示T-Rex 流量生成器在使用icmp.checksum计算校验和之前将补偿值添加到icmp.checksum前面。