1 from trex_stl_lib.api import *
5 def create_stream(self):
6 # base_pkt = Ether()/IP(dst="2.2.0.1")/UDP(dport=12)
9 # if len(base_pkt) < 64:
10 # pad_len = 64 - len(base_pkt)
11 # pad.load = '\x00' * pad_len
15 # vm.tuple_var(name="tuple", ip_min="10.0.0.3", ip_max="10.0.0.202", port_min=1025, port_max=61124, limit_flows = 100000)
17 # vm.write(fv_name="tuple.ip", pkt_offset="IP.src")
20 # vm.write(fv_name="tuple.port", pkt_offset="UDP.sport")
22 # pkt = STLPktBuilder(pkt=base_pkt/pad, vm=vm)
24 # return STLStream(packet=pkt, mode=STLTXCont())
30 ip_max="10.255.255.254",
38 ip_max="2.255.255.254",
42 limit_flows=100000000,
44 # write ip to packet IP.src
45 STLVmWrFlowVar(fv_name="stuple.ip", pkt_offset="IP.src"),
46 STLVmWrFlowVar(fv_name="dtuple.ip", pkt_offset="IP.dst"),
48 STLVmFixIpv4(offset="IP"),
50 STLVmWrFlowVar(fv_name="stuple.port", pkt_offset="UDP.sport"),
51 STLVmWrFlowVar(fv_name="dtuple.port", pkt_offset="UDP.dport"),
56 Ether() / IP(src="16.0.0.1", dst="2.0.0.1") / UDP(dport=12, sport=1025)
59 if len(base_pkt) < 64:
60 pad_len = 64 - len(base_pkt)
61 pad.load = "\x00" * pad_len
63 pkt = STLPktBuilder(pkt=base_pkt / pad, vm=vm)
65 return STLStream(packet=pkt, mode=STLTXCont())
67 def get_streams(self, direction=0, **kwargs):
68 return [self.create_stream()]
71 # dynamic load - used for trex console or simulator