01b6e3c55e6639244ce379115a61c9814bdcce5d
[csit.git] / GPL / traffic_profiles / trex / trex-stl-ethip4-ip4dst10000p3.py
1 # Copyright (c) 2023 Cisco and/or its affiliates.
2 #
3 # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
4 #
5 # Licensed under the Apache License 2.0 or
6 # GNU General Public License v2.0 or later;  you may not use this file
7 # except in compliance with one of these Licenses. You
8 # may obtain a copy of the Licenses at:
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #     https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 #
13 # Note: If this file is linked with Scapy, which is GPLv2+, your use of it
14 # must be under GPLv2+.  If at any point in the future it is no longer linked
15 # with Scapy (or other GPLv2+ licensed software), you are free to choose
16 # Apache 2.
17 #
18 # Unless required by applicable law or agreed to in writing, software
19 # distributed under the License is distributed on an "AS IS" BASIS,
20 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 # See the License for the specific language governing permissions and
22 # limitations under the License.
23
24 """Stream profile for T-rex traffic generator.
25
26 Stream profile:
27  - Three parallel bi-directional streams sent as W --> E and E --> W
28    at the same time.
29  - Packet: ETH / IP /
30 """
31
32 from trex.stl.api import *
33 from profile_trex_stateless_scale_class import TrafficStreamsScaleClass
34
35
36 class TrafficStreams(TrafficStreamsScaleClass):
37     """Stream profile."""
38
39     def __init__(self):
40         """Initialization and setting of streams' parameters."""
41
42         super(TrafficStreamsScaleClass, self).__init__()
43
44         self.pkt_data = [
45             # Direction W --> E:
46             {
47                 "src_start_ip": "10.0.0.1",
48                 "dst_start_ip": "20.0.0.0",
49                 "dst_end_ip": "20.0.39.15"
50             },
51             # Direction W --> E:
52             {
53                 "src_start_ip": "30.0.0.1",
54                 "dst_start_ip": "40.0.0.0",
55                 "dst_end_ip": "40.0.39.15"
56             },
57             # Direction W --> E:
58             {
59                 "src_start_ip": "50.0.0.1",
60                 "dst_start_ip": "60.0.0.0",
61                 "dst_end_ip": "60.0.39.15"
62             },
63             # Direction E --> W:
64             {
65                 "src_start_ip": "20.0.0.1",
66                 "dst_start_ip": "10.0.0.0",
67                 "dst_end_ip": "10.0.39.15"
68             },
69             # Direction E --> W:
70             {
71                 "src_start_ip": "40.0.0.1",
72                 "dst_start_ip": "30.0.0.0",
73                 "dst_end_ip": "30.0.39.15"
74             },
75             # Direction E --> W:
76             {
77                 "src_start_ip": "60.0.0.1",
78                 "dst_start_ip": "50.0.0.0",
79                 "dst_end_ip": "50.0.39.15"
80             }
81
82         ]
83         self.pkt_base = []
84         self.pkt_vm = []
85
86     def define_packets(self):
87         """Defines the packets to be sent from the traffic generator.
88
89         Packet definition: | ETH | IP |
90
91         :returns: Base packets to be sent and transformation function.
92         :rtype: tuple
93         """
94         for i in range(len(self.pkt_data)):
95             self.pkt_base.append(
96                 Ether() /
97                 IP(
98                     src=self.pkt_data[i]["src_start_ip"],
99                     dst=self.pkt_data[i]["dst_start_ip"],
100                     proto=61
101                 )
102             )
103             self.pkt_vm.append(
104                 STLScVmRaw(
105                     [
106                         STLVmFlowVar(
107                             name="dst",
108                             min_value=self.pkt_data[i]["dst_start_ip"],
109                             max_value=self.pkt_data[i]["dst_end_ip"],
110                             size=4,
111                             op="inc"
112                         ),
113                         STLVmWrFlowVar(
114                             fv_name="dst",
115                             pkt_offset="IP.dst"
116                         ),
117                         STLVmFixIpv4(
118                             offset="IP"
119                         )
120                     ]
121                 )
122             )
123
124         return self.pkt_base, self.pkt_vm
125
126
127 def register():
128     """Register this traffic profile to T-Rex.
129
130     Do not change this function.
131
132     :return: Traffic streams.
133     :rtype: Object
134     """
135     return TrafficStreams()