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

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.