nat: add more trex test scripts
[vpp.git] / src / plugins / nat / extras / nat_test_slow_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                          STLVmTupleGen(ip_min="2.0.0.1", ip_max="2.255.255.254",
31                                        port_min=1025, port_max=65535,
32                                        name="dtuple", limit_flows=100000000),
33
34                          # write ip to packet IP.src
35                          STLVmWrFlowVar(fv_name="stuple.ip",
36                                         pkt_offset="IP.src"),
37                          STLVmWrFlowVar(fv_name="dtuple.ip",
38                                         pkt_offset="IP.dst"),
39                          # fix checksum
40                          STLVmFixIpv4(offset="IP"),
41                          # write udp.port
42                          STLVmWrFlowVar(fv_name="stuple.port",
43                                         pkt_offset="UDP.sport"),
44                          STLVmWrFlowVar(fv_name="dtuple.port",
45                                         pkt_offset="UDP.dport"),
46                          ]
47                         )
48
49         base_pkt = Ether()/IP(src="16.0.0.1", dst="2.0.0.1")/UDP(dport=12, sport=1025)
50         pad = Padding()
51         if len(base_pkt) < 64:
52             pad_len = 64 - len(base_pkt)
53             pad.load = '\x00' * pad_len
54
55         pkt = STLPktBuilder(pkt=base_pkt/pad, vm=vm)
56
57         return STLStream(packet=pkt, mode=STLTXCont())
58
59     def get_streams(self, direction=0, **kwargs):
60         return [self.create_stream()]
61
62
63 # dynamic load - used for trex console or simulator
64 def register():
65     return STLS1()