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",
33 # name="stuple", limit_flows=10000),
39 ip_max="2.255.255.254",
42 # name="dtuple", limit_flows=100000000),
46 # write ip to packet IP.src
47 STLVmWrFlowVar(fv_name="stuple.ip", pkt_offset="IP.src"),
48 STLVmWrFlowVar(fv_name="dtuple.ip", pkt_offset="IP.dst"),
50 STLVmFixIpv4(offset="IP"),
52 STLVmWrFlowVar(fv_name="stuple.port", pkt_offset="UDP.sport"),
53 STLVmWrFlowVar(fv_name="dtuple.port", pkt_offset="UDP.dport"),
58 Ether() / IP(src="16.0.0.1", dst="2.0.0.1") / UDP(dport=12, sport=1025)
61 if len(base_pkt) < 64:
62 pad_len = 64 - len(base_pkt)
63 pad.load = "\x00" * pad_len
65 pkt = STLPktBuilder(pkt=base_pkt / pad, vm=vm)
67 return STLStream(packet=pkt, mode=STLTXCont())
69 def get_streams(self, direction=0, **kwargs):
70 return [self.create_stream()]
73 # dynamic load - used for trex console or simulator