Perf: Bump T-Rex to 2.88
[csit.git] / GPL / traffic_profiles / trex / trex-astf-ethip4udp-65536h-pps.py
1 # Copyright (c) 2021 Cisco and/or its affiliates.
2 #
3 # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
4 #
5 # Licensed under the Apache License 2.0 or
6 # GNU General Public License v2.0 or later;  you may not use this file
7 # except in compliance with one of these Licenses. You
8 # may obtain a copy of the Licenses at:
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #     https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 #
13 # Note: If this file is linked with Scapy, which is GPLv2+, your use of it
14 # must be under GPLv2+.  If at any point in the future it is no longer linked
15 # with Scapy (or other GPLv2+ licensed software), you are free to choose
16 # Apache 2.
17 #
18 # Unless required by applicable law or agreed to in writing, software
19 # distributed under the License is distributed on an "AS IS" BASIS,
20 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 # See the License for the specific language governing permissions and
22 # limitations under the License.
23
24 """Traffic profile for T-rex advanced stateful (astf) traffic generator.
25 Traffic profile:
26  - Two streams sent in directions 0 --> 1 (client -> server, requests) and
27    1 --> 0 (server -> client, responses) at the same time.
28  - Packet: ETH / IP / UDP
29  - Direction 0 --> 1:
30    - Source IP address range:      192.168.0.0 - 192.168.255.255
31    - Destination IP address range: 20.0.0.0 - 20.0.255.255
32  - Direction 1 --> 0:
33    - Source IP address range:      destination IP address from packet received
34      on port 1
35    - Destination IP address range: source IP address from packet received
36      on port 1
37
38 This is a profile for PPS tests, it combines UDP connect and data transfer.
39 No delays, server response waits for full request.
40 """
41
42 from trex.astf.api import *
43 from profile_trex_astf_base_class import TrafficProfileBaseClass
44
45
46 class TrafficProfile(TrafficProfileBaseClass):
47     """Traffic profile."""
48
49     def __init__(self, **kwargs):
50         """Initialization and setting of profile parameters."""
51
52         super(TrafficProfileBaseClass, self).__init__()
53
54         # IPs used in packet headers.
55         self.p1_src_start_ip = u"192.168.0.0"
56         self.p1_src_end_ip = u"192.168.255.255"
57         self.p1_dst_start_ip = u"20.0.0.0"
58         self.p1_dst_end_ip = u"20.0.255.255"
59
60         self.headers_size = 42  # 14B l2 + 20B ipv4 + 8B UDP
61
62         self.udp_data = u""
63
64         self.n_data = 32  # TODO: set via input parameter
65         self.m_delay = 2000000  # delay 2000s (2,000,000 ms)
66         self.u_delay = 1000 * self.m_delay  # delay 2000s (2,000,000,000 us)
67         self.limit = 4128768
68
69     def define_profile(self):
70         """Define profile to be used by advanced stateful traffic generator.
71
72         This method MUST return:
73
74             return ip_gen, templates
75
76         :returns: IP generator and profile templates for ASTFProfile().
77         :rtype: tuple
78         """
79         if self.framesize == 64:
80             self.udp_data += self._gen_padding(self.headers_size, 72)
81         if self.framesize == 1518:
82             self.udp_data += self._gen_padding(self.headers_size, 1514)
83
84         # Client program.
85         prog_c = ASTFProgram(stream=False)
86         prog_c.set_keepalive_msg(self.m_delay)
87         prog_c.send_msg(self.udp_data)
88         # No delay, PPS tests combine connect and data send (no data receive).
89         prog_c.set_var(u"var1", self.n_data)
90         prog_c.set_label(u"a:")
91         prog_c.send_msg(self.udp_data)
92         prog_c.jmp_nz(u"var1", u"a:")
93         # We should read the server response,
94         # but no reason to overload client workers even more.
95
96         # Server program.
97         prog_s = ASTFProgram(stream=False)
98         prog_s.set_keepalive_msg(self.m_delay)
99         # If server closes too soon, new instances are started
100         # leading in too much replies. To prevent that, we need to recv all.
101         prog_s.recv_msg(1 + self.n_data)
102         # In packet loss scenarios, some instances never get here.
103         # This maybe increases server traffic duration,
104         # but no other way if we want to avoid
105         # TRex creating a second instance of the same server.
106         prog_s.send_msg(self.udp_data)
107         prog_s.set_var(u"var2", self.n_data)
108         prog_s.set_label(u"b:")
109         prog_s.send_msg(self.udp_data)
110         prog_s.jmp_nz(u"var2", u"b:")
111         # VPP never duplicates packets,
112         # so it is safe to close the server instance now.
113
114         # ip generators
115         ip_gen_c = ASTFIPGenDist(
116             ip_range=[self.p1_src_start_ip, self.p1_src_end_ip],
117             distribution=u"seq"
118         )
119         ip_gen_s = ASTFIPGenDist(
120             ip_range=[self.p1_dst_start_ip, self.p1_dst_end_ip],
121             distribution=u"seq"
122         )
123         ip_gen = ASTFIPGen(
124             glob=ASTFIPGenGlobal(ip_offset=u"0.0.0.1"),
125             dist_client=ip_gen_c,
126             dist_server=ip_gen_s
127         )
128
129         # server association
130         s_assoc = ASTFAssociation(rules=ASTFAssociationRule(port=8080))
131
132         # template
133         temp_c = ASTFTCPClientTemplate(
134             program=prog_c,
135             ip_gen=ip_gen,
136             limit=self.limit,
137             port=8080
138         )
139         temp_s = ASTFTCPServerTemplate(program=prog_s, assoc=s_assoc)
140         template = ASTFTemplate(client_template=temp_c, server_template=temp_s)
141
142         return ip_gen, template, None
143
144
145 def register():
146     """Register this traffic profile to T-Rex.
147
148     Do not change this function.
149
150     :return: Traffic Profiles.
151     :rtype: Object
152     """
153     return TrafficProfile()