aboutsummaryrefslogtreecommitdiffstats
path: root/resources/traffic_profiles/trex/trex-sf-2n-ethip4tcphttp-1u1s-vpp-cps.py
blob: 0533978830b5242cdb5a2b591ccb5a64f4dfe588 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright (c) 2018 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""ASTF profile for TRex traffic generator.

ASTF profile:
 - Client side traffic in directions 0 --> 1.
 - Server side traffic disabled.
 - Packet: ETH / IP / TCP / HTTP1.1
 - Direction 0 --> 1:
   - Source IP address range:      172.16.130.2 - 172.16.130.2
   - Destination IP address range: 192.168.0.1
"""

from trex_astf_lib.api import *


class Prof1():
    def __init__(self):
        """Initialization and setting of streams' parameters."""

        # Response content length.
        self.content_len = 115
        # Number of requests per HTTP transaction.
        self.requests = 1
        # Number of transactions per HTTP connection.
        self.transaction_per_conn = 1
        # Use TCP RST instead of FIN+ACK.
        self.tcp_reset = False

        # IP used in packet headers.
        self.p1_src_start_ip = '172.16.130.2'
        self.p1_src_end_ip = '172.16.130.2'
        self.p1_dst_start_ip = '172.16.130.1'
        self.p1_dst_end_ip = '172.16.130.1'

        self.http_req = (b'GET / HTTP/1.1\r\n'
                          'Host: {host}\r\n'
                          'User-Agent: trex/astf\r\n'
                          'Accept: */*\r\n\r\n'
                          .format(host=self.p1_dst_start_ip))
        self.http_res = (b'HTTP/1.1 200 OK\r\n'
                          'Content-Type: text/html\r\n'
                          'Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n'
                          'Connection: close\r\n'
                          'Pragma: no-cache\r\n'
                          'Content-Length: {length}\r\n\r\n'
                          .format(length=self.content_len))

    def create_profile(self):
        # client operations
        prog_c = ASTFProgram()
        prog_c.connect()
        for i in range(self.transaction_per_conn):
            prog_c.send(self.http_req * self.requests)
            prog_c.recv((len(self.http_res) + self.content_len) * self.requests)
        if self.tcp_reset:
            prog_c.reset()

        # ip generator
        ip_gen_c = ASTFIPGenDist(ip_range=[self.p1_src_start_ip,
                                           self.p1_src_end_ip],
                                 distribution="seq")
        ip_gen_s = ASTFIPGenDist(ip_range=[self.p1_dst_start_ip,
                                           self.p1_dst_end_ip],
                                 distribution="seq")
        ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="0.0.0.1"),
                           dist_client=ip_gen_c,
                           dist_server=ip_gen_s)

        # TCP parameters
        tcp_params = ASTFTCPInfo(window=32768)
        # client tunables
        c_glob_info = ASTFGlobalInfo()

        # template
        client_template = ASTFTCPClientTemplate(program=prog_c,
                                                tcp_info=tcp_params,
                                                ip_gen=ip_gen)
        server_template = ASTFTCPServerTemplate(program=ASTFProgram(),
                                                tcp_info=tcp_params)
        template = ASTFTemplate(client_template=client_template,
                                server_template=server_template)

        # profile
        return ASTFProfile(default_ip_gen=ip_gen, templates=template,
                           default_c_glob_info=c_glob_info)

    def get_profile(self):
        return self.create_profile()


def register():
    return Prof1()