tests: replace pycodestyle with black
[vpp.git] / src / plugins / nat / extras / nat_test_slow_path_with_latency.py
1 from trex_stl_lib.api import *
2
3
4 class STLS1:
5     def create_stream(self, port_id):
6         # base_pkt = Ether()/IP(dst="2.2.0.1")/UDP(dport=12)
7
8         # pad = Padding()
9         # if len(base_pkt) < 64:
10         #     pad_len = 64 - len(base_pkt)
11         #     pad.load = '\x00' * pad_len
12
13         # vm = STLVM()
14
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)
16
17         # vm.write(fv_name="tuple.ip", pkt_offset="IP.src")
18         # vm.fix_chksum()
19
20         # vm.write(fv_name="tuple.port", pkt_offset="UDP.sport")
21
22         # pkt = STLPktBuilder(pkt=base_pkt/pad, vm=vm)
23
24         # return STLStream(packet=pkt, mode=STLTXCont())
25
26         vm = STLScVmRaw(
27             [
28                 STLVmTupleGen(
29                     ip_min="10.0.0.1",
30                     ip_max="10.255.255.254",
31                     port_min=1025,
32                     port_max=65535,
33                     name="stuple",
34                     limit_flows=10000,
35                 ),
36                 STLVmTupleGen(
37                     ip_min="2.0.0.1",
38                     ip_max="2.255.255.254",
39                     port_min=1025,
40                     port_max=65535,
41                     name="dtuple",
42                     limit_flows=100000000,
43                 ),
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"),
47                 # fix checksum
48                 STLVmFixIpv4(offset="IP"),
49                 # write udp.port
50                 STLVmWrFlowVar(fv_name="stuple.port", pkt_offset="UDP.sport"),
51                 STLVmWrFlowVar(fv_name="dtuple.port", pkt_offset="UDP.dport"),
52             ]
53         )
54
55         base_pkt = (
56             Ether() / IP(src="16.0.0.1", dst="2.0.0.1") / UDP(dport=12, sport=1025)
57         )
58         pad = Padding()
59         if len(base_pkt) < 64:
60             pad_len = 64 - len(base_pkt)
61             pad.load = "\x00" * pad_len
62
63         pad = max(0, 64 - len(base_pkt)) * "x"
64         pad_latency = max(0, (64 - 4) - len(base_pkt)) * "x"
65
66         pkt = STLPktBuilder(pkt=base_pkt / pad, vm=vm)
67
68         return [
69             STLStream(packet=pkt, mode=STLTXCont()),
70             # latency stream
71             STLStream(
72                 packet=STLPktBuilder(pkt=base_pkt / pad_latency),
73                 mode=STLTXCont(pps=1000),
74                 flow_stats=STLFlowLatencyStats(pg_id=12 + port_id),
75             ),
76         ]
77
78     def get_streams(self, direction=0, **kwargs):
79         # return [self.create_stream()]
80         return self.create_stream(kwargs["port_id"])
81
82
83 # dynamic load - used for trex console or simulator
84 def register():
85     return STLS1()