1 # Copyright (c) 2020 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Traffic profile for T-rex advanced stateful (astf) traffic generator.
16 - Two streams sent in directions 0 --> 1 (client -> server, requests) and
17 1 --> 0 (server -> client, responses) at the same time.
18 - Packet: ETH / IP / UDP
20 - Source IP address range: 192.168.0.0 - 192.168.63.255
21 - Destination IP address range: 20.0.0.0 - 20.0.63.255
23 - Source IP address range: destination IP address from packet received
25 - Destination IP address range: source IP address from packet received
28 This is a profile for PPS tests, it combines UDP connect and data transfer.
29 No delays, server response waits for full request.
32 from trex.astf.api import *
33 from profile_trex_astf_base_class import TrafficProfileBaseClass
36 class TrafficProfile(TrafficProfileBaseClass):
37 """Traffic profile."""
39 def __init__(self, **kwargs):
40 """Initialization and setting of profile parameters."""
42 super(TrafficProfileBaseClass, self).__init__()
44 # IPs used in packet headers.
45 self.p1_src_start_ip = u"192.168.0.0"
46 self.p1_src_end_ip = u"192.168.63.255"
47 self.p1_dst_start_ip = u"20.0.0.0"
48 self.p1_dst_end_ip = u"20.0.63.255"
50 self.headers_size = 42 # 14B l2 + 20B ipv4 + 8B UDP
54 self.n_data = 32 # TODO: set via input parameter
55 self.m_delay = 1200000 # delay 1200s (1,200,000 ms)
56 self.u_delay = 1000 * self.m_delay # delay 1200s (1,200,000,000 us)
59 def define_profile(self):
60 """Define profile to be used by advanced stateful traffic generator.
62 This method MUST return:
64 return ip_gen, templates
66 :returns: IP generator and profile templates for ASTFProfile().
69 if self.framesize == 64:
70 self.udp_data += self._gen_padding(self.headers_size, 72)
71 if self.framesize == 1518:
72 self.udp_data += self._gen_padding(self.headers_size, 1514)
75 prog_c = ASTFProgram(stream=False)
76 prog_c.set_keepalive_msg(self.m_delay)
77 prog_c.send_msg(self.udp_data)
78 # No delay, PPS tests combine connect and data send (no data receive).
79 prog_c.set_var(u"var1", self.n_data)
80 prog_c.set_label(u"a:")
81 prog_c.send_msg(self.udp_data)
82 prog_c.jmp_nz(u"var1", u"a:")
83 # We should read the server response,
84 # but no reason to overload client workers even more.
87 prog_s = ASTFProgram(stream=False)
88 prog_s.set_keepalive_msg(self.m_delay)
89 # If server closes too soon, new instances are started
90 # leading in too much replies. To prevent that, we need to recv all.
91 prog_s.recv_msg(1 + self.n_data)
92 # In packet loss scenarios, some instances never get here.
93 # This maybe increases server traffic duration,
94 # but no other way if we want to avoid
95 # TRex creating a second instance of the same server.
96 prog_s.send_msg(self.udp_data)
97 prog_s.set_var(u"var2", self.n_data)
98 prog_s.set_label(u"b:")
99 prog_s.send_msg(self.udp_data)
100 prog_s.jmp_nz(u"var2", u"b:")
101 # VPP never duplicates packets,
102 # so it is safe to close the server instance now.
105 ip_gen_c = ASTFIPGenDist(
106 ip_range=[self.p1_src_start_ip, self.p1_src_end_ip],
109 ip_gen_s = ASTFIPGenDist(
110 ip_range=[self.p1_dst_start_ip, self.p1_dst_end_ip],
114 glob=ASTFIPGenGlobal(ip_offset=u"0.0.0.1"),
115 dist_client=ip_gen_c,
120 s_assoc = ASTFAssociation(rules=ASTFAssociationRule(port=8080))
123 temp_c = ASTFTCPClientTemplate(
129 temp_s = ASTFTCPServerTemplate(program=prog_s, assoc=s_assoc)
130 template = ASTFTemplate(client_template=temp_c, server_template=temp_s)
132 return ip_gen, template, None
136 """Register this traffic profile to T-Rex.
138 Do not change this function.
140 :return: Traffic Profiles.
143 return TrafficProfile()