bcd5328edd8fcf57214876c42c909a44ceaff0d7
[csit.git] / resources / traffic_profiles / trex / trex-sl-2n-ethip4udp-lb.py
1 # Copyright (c) 2019 Intel 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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """Stream profile for T-rex traffic generator.
15
16 Stream profile:
17  - Packet: ETH / IP / UDP
18  - Direction 0 --> 1:
19    - Source IP address range:      192.168.50.74 - 192.168.50.79
20    - Destination IP address range: 90.1.2.1
21  - Direction 1 --> 0:
22    - Source IP address range:      192.168.60.74 - 192.168.60.79
23    - Destination IP address range: 192.168.50.74 - 192.168.50.79
24 """
25
26 from trex.stl.api import *
27 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
28
29
30 class TrafficStreams(TrafficStreamsBaseClass):
31     """Stream profile."""
32
33     def __init__(self):
34         """Initialization and setting of streams' parameters."""
35
36         super(TrafficStreamsBaseClass, self).__init__()
37
38         # IPs used in packet headers.
39         self.p1_src_start_ip = '192.168.50.74'
40         self.p1_src_end_ip = '192.168.50.79'
41         self.p1_dst_start_ip = '90.1.2.1'
42
43         self.p2_src_start_ip = '192.168.60.74'
44         self.p2_src_end_ip = '192.168.60.79'
45         self.p2_dst_start_ip = '192.168.50.74'
46         self.p2_dst_end_ip = '192.168.50.79'
47
48         # UDP ports used in packet headers.
49         self.p1_src_udp_port = 63
50         self.p1_dst_udp_port = 20000
51
52         self.p2_src_udp_port = 3307
53         self.p2_dst_udp_port = 63
54
55     def define_packets(self):
56         """Defines the packets to be sent from the traffic generator.
57
58         Packet definition: | ETH | IP | UDP
59
60         :returns: Packets to be sent from the traffic generator.
61         :rtype: tuple
62         """
63
64         # Direction 0 --> 1
65         base_pkt_a = Ether() / IP(src=self.p1_src_start_ip,
66                                   dst=self.p1_dst_start_ip,
67                                   proto=17) / UDP(sport=self.p1_src_udp_port,
68                                                   dport=self.p1_dst_udp_port)
69         # Direction 1 --> 0
70         base_pkt_b = Ether() / IP(src=self.p2_src_start_ip,
71                                   dst=self.p2_dst_start_ip,
72                                   proto=17) / UDP(sport=self.p2_src_udp_port,
73                                                   dport=self.p2_dst_udp_port)
74
75         # Direction 0 --> 1
76         vm1 = STLScVmRaw([STLVmFlowVar(name="src",
77                                        min_value=self.p1_src_start_ip,
78                                        max_value=self.p1_src_end_ip,
79                                        size=4, op="inc"),
80                           STLVmWrFlowVar(fv_name="src", pkt_offset="IP.src"),
81                           STLVmFixIpv4(offset="IP")])
82         # Direction 1 --> 0
83         vm2 = STLScVmRaw([STLVmFlowVar(name="src",
84                                        min_value=self.p2_src_start_ip,
85                                        max_value=self.p2_src_end_ip,
86                                        size=4, op="inc"),
87                           STLVmWrFlowVar(fv_name="src", pkt_offset="IP.src"),
88                           STLVmFlowVar(name="dst",
89                                        min_value=self.p2_dst_start_ip,
90                                        max_value=self.p2_dst_end_ip,
91                                        size=4, op="inc"),
92                           STLVmWrFlowVar(fv_name="dst", pkt_offset="IP.dst"),
93                           STLVmFixIpv4(offset="IP")])
94
95         return base_pkt_a, base_pkt_b, vm1, vm2
96
97
98 def register():
99     """Register this traffic profile to T-rex.
100
101     Do not change this function.
102
103     :return: Traffic streams.
104     :rtype: Object
105     """
106     return TrafficStreams()