Switch licenses in GPL directory
[csit.git] / GPL / traffic_profiles / trex / trex-stl-2n-ethip4-macsrc50kdst50k.py
1 # Copyright (c) 2020 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 Apache 2.
16 #
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22
23 """Stream profile for T-rex traffic generator.
24
25 Stream profile:
26  - Two streams sent in directions 0 --> 1 and 1 --> 0 at the same time.
27  - Packet: ETH / IP /
28  - Direction 0 --> 1:
29    - Source MAC address range:      ca:fe:00:00:00:00 - ca:fe:00:00:c3:4f
30    - Destination MAC address range: fa:ce:00:00:00:00 - fa:ce:00:00:c3:4f
31    - Source IP address range:       10.0.0.0 - 10.0.195.79
32    - Destination IP address range:  20.0.0.0 - 20.0.195.79
33  - Direction 1 --> 0:
34    - Source MAC address range:      fa:ce:00:00:00:00 - fa:ce:00:00:c3:4f
35    - Destination MAC address range: ca:fe:00:00:00:00 - ca:fe:00:00:c3:4f
36    - Source IP address range:       20.0.0.0 - 20.0.195.79
37    - Destination IP address range:  10.0.0.0 - 10.0.195.79
38 """
39
40 from trex.stl.api import *
41 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
42
43
44 class TrafficStreams(TrafficStreamsBaseClass):
45     """Stream profile."""
46
47     def __init__(self):
48         """Initialization and setting of streams' parameters."""
49
50         super(TrafficStreamsBaseClass, self).__init__()
51
52         self.clients = 50000
53
54         # MACs used in packet headers.
55         self.p1_src_start_mac = u"ca:fe:00:00:00:00" # mask: 00:00:FF:FF:FF:FF
56         self.p1_dst_start_mac = u"fa:ce:00:00:00:00" # mask: 00:00:FF:FF:FF:FF
57
58         self.p2_src_start_mac = u"fa:ce:00:00:00:00" # mask: 00:00:FF:FF:FF:FF
59         self.p2_dst_start_mac = u"ca:fe:00:00:00:00" # mask: 00:00:FF:FF:FF:FF
60
61         # IPs used in packet headers.
62         self.p1_src_start_ip = u"10.0.0.0"
63         self.p1_src_end_ip = u"10.0.195.79"
64
65         self.p1_dst_start_ip = u"20.0.0.0"
66         self.p1_dst_end_ip = u"20.0.195.79"
67
68         self.p2_src_start_ip = u"20.0.0.0"
69         self.p2_src_end_ip = u"20.0.195.79"
70
71         self.p2_dst_start_ip = u"10.0.0.0"
72         self.p2_dst_end_ip = u"10.0.195.79"
73
74     def define_packets(self):
75         """Defines the packets to be sent from the traffic generator.
76
77         Packet definition: | ETH | IP |
78
79         :returns: Packets to be sent from the traffic generator.
80         :rtype: tuple
81         """
82
83         # Direction 0 --> 1
84         base_pkt_a = (
85             Ether(
86                 src=self.p1_src_start_mac,
87                 dst=self.p1_dst_start_mac
88             ) /
89             IP(
90                 src=self.p1_src_start_ip,
91                 dst=self.p1_dst_start_ip,
92                 proto=61
93             )
94         )
95         # Direction 1 --> 0
96         base_pkt_b = (
97             Ether(
98                 src=self.p2_src_start_mac,
99                 dst=self.p2_dst_start_mac) /
100             IP(
101                 src=self.p2_src_start_ip,
102                 dst=self.p2_dst_start_ip,
103                 proto=61
104             )
105         )
106
107         # Direction 0 --> 1
108         vm1 = STLScVmRaw(
109             [
110                 STLVmFlowVar(
111                     name=u"mac_src",
112                     min_value=0,
113                     max_value=self.clients-1,
114                     size=4,
115                     op=u"inc"
116                 ),
117                 STLVmFlowVar(
118                     name=u"mac_dst",
119                     min_value=0,
120                     max_value=self.clients-1,
121                     size=4,
122                     op=u"inc"
123                 ),
124                 STLVmWrFlowVar(
125                     fv_name=u"mac_src",
126                     pkt_offset= 8
127                 ),
128                 STLVmWrFlowVar(
129                     fv_name=u"mac_dst",
130                     pkt_offset= 2
131                 ),
132                 STLVmFlowVar(
133                     name=u"ip_src",
134                     min_value=self.p1_src_start_ip,
135                     max_value=self.p1_src_end_ip,
136                     size=4,
137                     op=u"inc"
138                 ),
139                 STLVmWrFlowVar(
140                     fv_name=u"ip_src",
141                     pkt_offset=u"IP.src"
142                 ),
143                 STLVmFlowVar(
144                     name=u"ip_dst",
145                     min_value=self.p1_dst_start_ip,
146                     max_value=self.p1_dst_end_ip,
147                     size=4,
148                     op=u"inc"
149                 ),
150                 STLVmWrFlowVar(
151                     fv_name=u"ip_dst",
152                     pkt_offset=u"IP.dst"
153                 ),
154                 STLVmFixIpv4(
155                     offset=u"IP"
156                 )
157             ]
158         )
159         # Direction 1 --> 0
160         vm2 = STLScVmRaw(
161             [
162                 STLVmFlowVar(
163                     name=u"mac_src",
164                     min_value=0,
165                     max_value=self.clients-1,
166                     size=4,
167                     op=u"inc"
168                 ),
169                 STLVmFlowVar(
170                     name=u"mac_dst",
171                     min_value=0,
172                     max_value=self.clients-1,
173                     size=4,
174                     op=u"inc"
175                 ),
176                 STLVmWrFlowVar(
177                     fv_name=u"mac_src",
178                     pkt_offset= 8
179                 ),
180                 STLVmWrFlowVar(
181                     fv_name=u"mac_dst",
182                     pkt_offset= 2
183                 ),
184                 STLVmFlowVar(
185                     name=u"ip_src",
186                     min_value=self.p2_src_start_ip,
187                     max_value=self.p2_src_end_ip,
188                     size=4,
189                     op=u"inc"
190                 ),
191                 STLVmWrFlowVar(
192                     fv_name=u"ip_src",
193                     pkt_offset=u"IP.src"
194                 ),
195                 STLVmFlowVar(
196                     name=u"ip_dst",
197                     min_value=self.p2_dst_start_ip,
198                     max_value=self.p2_dst_end_ip,
199                     size=4,
200                     op=u"inc"
201                 ),
202                 STLVmWrFlowVar(
203                     fv_name=u"ip_dst",
204                     pkt_offset=u"IP.dst"
205                 ),
206                 STLVmFixIpv4(
207                     offset=u"IP"
208                 )
209             ]
210         )
211
212         return base_pkt_a, base_pkt_b, vm1, vm2
213
214
215 def register():
216     """Register this traffic profile to T-rex.
217
218     Do not change this function.
219
220     :return: Traffic streams.
221     :rtype: Object
222     """
223     return TrafficStreams()