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.
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 = '192.168.0.1'
45 self.p1_dst_end_ip = '192.168.0.1'
47 self.http_req = (b'GET /0KB.bin HTTP/1.1\r\n'
49 'User-Agent: trex/astf\r\n'
51 'Connection: keep-alive\r\n\r\n'
52 .format(host=self.p1_dst_start_ip))
53 self.http_res = (b'HTTP/1.1 200 OK\r\n'
54 'Server: nginx/1.13.7\r\n'
55 'Date: Mon, 01 Jan 2018 00:00:00 GMT\r\n'
56 'Content-Type: application/octet-stream\r\n'
57 'Content-Length: {length}\r\n'
58 'Last-Modified: Mon, 01 Jan 2018 00:00:00 GMT\r\n'
59 'Connection: keep-alive\r\n'
60 'ETag: "5a027c14-0"\r\n'
61 'Accept-Ranges: bytes\r\n\r\n'
62 .format(length=self.content_len))
64 def create_profile(self):
66 prog_c = ASTFProgram()
68 for i in range(self.transaction_per_conn):
69 prog_c.send(self.http_req * self.requests)
70 prog_c.recv((len(self.http_res) + self.content_len) * self.requests)
75 ip_gen_c = ASTFIPGenDist(ip_range=[self.p1_src_start_ip,
78 ip_gen_s = ASTFIPGenDist(ip_range=[self.p1_dst_start_ip,
81 ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="0.0.0.1"),
86 tcp_params = ASTFTCPInfo(window=32768)
88 c_glob_info = ASTFGlobalInfo()
91 client_template = ASTFTCPClientTemplate(program=prog_c,
94 server_template = ASTFTCPServerTemplate(program=ASTFProgram(),
96 template = ASTFTemplate(client_template=client_template,
97 server_template=server_template)
100 return ASTFProfile(default_ip_gen=ip_gen, templates=template,
101 default_c_glob_info=c_glob_info)
103 def get_profile(self):
104 return self.create_profile()