1 # Copyright (c) 2018 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 """ASTF profile for TRex traffic generator.
17 - Client side traffic in directions 0 --> 1.
18 - Server side traffic disabled.
19 - Packet: ETH / IP / TCP / HTTP1.1
21 - Source IP address range: 172.16.130.2 - 172.16.130.2
22 - Destination IP address range: 192.168.0.1
25 from trex_astf_lib.api import *
30 """Initialization and setting of streams' parameters."""
32 # Response content length.
33 self.content_len = 115
34 # Number of requests per HTTP transaction.
36 # Number of transactions per HTTP connection.
37 self.transaction_per_conn = 1
38 # Use TCP RST instead of FIN+ACK.
39 self.tcp_reset = False
41 # IP used in packet headers.
42 self.p1_src_start_ip = '172.16.130.2'
43 self.p1_src_end_ip = '172.16.130.2'
44 self.p1_dst_start_ip = '172.16.130.1'
45 self.p1_dst_end_ip = '172.16.130.1'
47 self.http_req = (b'GET / HTTP/1.1\r\n'
49 'User-Agent: trex/astf\r\n'
51 .format(host=self.p1_dst_start_ip))
52 self.http_res = (b'HTTP/1.1 200 OK\r\n'
53 'Content-Type: text/html\r\n'
54 'Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n'
55 'Connection: close\r\n'
56 'Pragma: no-cache\r\n'
57 'Content-Length: {length}\r\n\r\n'
58 .format(length=self.content_len))
60 def create_profile(self):
62 prog_c = ASTFProgram()
64 for i in range(self.transaction_per_conn):
65 prog_c.send(self.http_req * self.requests)
66 prog_c.recv((len(self.http_res) + self.content_len) * self.requests)
71 ip_gen_c = ASTFIPGenDist(ip_range=[self.p1_src_start_ip,
74 ip_gen_s = ASTFIPGenDist(ip_range=[self.p1_dst_start_ip,
77 ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="0.0.0.1"),
82 tcp_params = ASTFTCPInfo(window=32768)
84 c_glob_info = ASTFGlobalInfo()
87 client_template = ASTFTCPClientTemplate(program=prog_c,
90 server_template = ASTFTCPServerTemplate(program=ASTFProgram(),
92 template = ASTFTemplate(client_template=client_template,
93 server_template=server_template)
96 return ASTFProfile(default_ip_gen=ip_gen, templates=template,
97 default_c_glob_info=c_glob_info)
99 def get_profile(self):
100 return self.create_profile()