nat: add more trex test scripts
[vpp.git] / src / plugins / nat / extras / nat_test_fast_path.py
1 from trex_stl_lib.api import *
2
3
4 class STLS1(object):
5
6     def create_stream(self):
7         # base_pkt = Ether()/IP(dst="2.2.0.1")/UDP(dport=12)
8
9         # pad = Padding()
10         # if len(base_pkt) < 64:
11         #     pad_len = 64 - len(base_pkt)
12         #     pad.load = '\x00' * pad_len
13
14         # vm = STLVM()
15
16         # 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
18         # vm.write(fv_name="tuple.ip", pkt_offset="IP.src")
19         # vm.fix_chksum()
20
21         # vm.write(fv_name="tuple.port", pkt_offset="UDP.sport")
22
23         # pkt = STLPktBuilder(pkt=base_pkt/pad, vm=vm)
24
25         # return STLStream(packet=pkt, mode=STLTXCont())
26
27         vm = STLScVmRaw([STLVmTupleGen(ip_min="10.0.0.1", ip_max="10.255.255.254",
28                                        port_min=1025, port_max=65535,
29                                        # name="stuple", limit_flows=10000),
30                                        name="stuple", limit_flows=100),
31                          STLVmTupleGen(ip_min="2.0.0.1", ip_max="2.255.255.254",
32                                        port_min=1025, port_max=65535,
33                                        # name="dtuple", limit_flows=100000000),
34                                        name="dtuple", limit_flows=100),
35
36                          # write ip to packet IP.src
37                          STLVmWrFlowVar(fv_name="stuple.ip",
38                                         pkt_offset="IP.src"),
39                          STLVmWrFlowVar(fv_name="dtuple.ip",
40                                         pkt_offset="IP.dst"),
41                          # fix checksum
42                          STLVmFixIpv4(offset="IP"),
43                          # write udp.port
44                          STLVmWrFlowVar(fv_name="stuple.port",
45                                         pkt_offset="UDP.sport"),
46                          STLVmWrFlowVar(fv_name="dtuple.port",
47                                         pkt_offset="UDP.dport"),
48                          ]
49                         )
50
51         base_pkt = Ether()/IP(src="16.0.0.1", dst="2.0.0.1")/UDP(dport=12, sport=1025)
52         pad = Padding()
53         if len(base_pkt) < 64:
54             pad_len = 64 - len(base_pkt)
55             pad.load = '\x00' * pad_len
56
57         pkt = STLPktBuilder(pkt=base_pkt/pad, vm=vm)
58
59         return STLStream(packet=pkt, mode=STLTXCont())
60
61     def get_streams(self, direction=0, **kwargs):
62         return [self.create_stream()]
63
64
65 # dynamic load - used for trex console or simulator
66 def register():
67     return STLS1()