tests: replace pycodestyle with black
[vpp.git] / src / plugins / nat / extras / nat_test_fast_path.py
1 from trex_stl_lib.api import *
2
3
4 class STLS1:
5     def create_stream(self):
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", limit_flows=10000),
34                     name="stuple",
35                     limit_flows=100,
36                 ),
37                 STLVmTupleGen(
38                     ip_min="2.0.0.1",
39                     ip_max="2.255.255.254",
40                     port_min=1025,
41                     port_max=65535,
42                     # name="dtuple", limit_flows=100000000),
43                     name="dtuple",
44                     limit_flows=100,
45                 ),
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"),
49                 # fix checksum
50                 STLVmFixIpv4(offset="IP"),
51                 # write udp.port
52                 STLVmWrFlowVar(fv_name="stuple.port", pkt_offset="UDP.sport"),
53                 STLVmWrFlowVar(fv_name="dtuple.port", pkt_offset="UDP.dport"),
54             ]
55         )
56
57         base_pkt = (
58             Ether() / IP(src="16.0.0.1", dst="2.0.0.1") / UDP(dport=12, sport=1025)
59         )
60         pad = Padding()
61         if len(base_pkt) < 64:
62             pad_len = 64 - len(base_pkt)
63             pad.load = "\x00" * pad_len
64
65         pkt = STLPktBuilder(pkt=base_pkt / pad, vm=vm)
66
67         return STLStream(packet=pkt, mode=STLTXCont())
68
69     def get_streams(self, direction=0, **kwargs):
70         return [self.create_stream()]
71
72
73 # dynamic load - used for trex console or simulator
74 def register():
75     return STLS1()