29df3373d36798f4eb1390f903dda4b18699aaf2
[csit.git] / resources / traffic_profiles / trex / trex-sl-3n-ethip4-macsrc5kdst5k.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:13:87
21    - Destination MAC address range: fa:ce:00:00:00:00 - fa:ce:00:00:13:87
22    - Source IP address range:       10.0.0.0 - 10.0.19.135
23    - Destination IP address range:  20.0.0.0 - 20.0.19.135
24  - Direction 1 --> 0:
25    - Source MAC address range:      fa:ce:00:00:00:00 - fa:ce:00:00:13:87
26    - Destination MAC address range: ca:fe:00:00:00:00 - ca:fe:00:00:13:87
27    - Source IP address range:       20.0.0.0 - 20.0.19.135
28    - Destination IP address range:  10.0.0.0 - 10.0.19.135
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 = 5000
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.19.135"
55
56         self.p1_dst_start_ip = u"20.0.0.0"
57         self.p1_dst_end_ip = u"20.0.19.135"
58
59         self.p2_src_start_ip = u"20.0.0.0"
60         self.p2_src_end_ip = u"20.0.19.135"
61
62         self.p2_dst_start_ip = u"10.0.0.0"
63         self.p2_dst_end_ip = u"10.0.19.135"
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             ) /
92             IP(
93                 src=self.p2_src_start_ip,
94                 dst=self.p2_dst_start_ip,
95                 proto=61
96             )
97         )
98
99         # Direction 0 --> 1
100         vm1 = STLScVmRaw(
101             [
102                 STLVmFlowVar(
103                     name=u"mac_src",
104                     min_value=0,
105                     max_value=self.clients-1,
106                     size=4,
107                     op=u"inc"
108                 ),
109                 STLVmFlowVar(
110                     name=u"mac_dst",
111                     min_value=0,
112                     max_value=self.clients-1,
113                     size=4,
114                     op=u"inc"
115                 ),
116                 STLVmWrFlowVar(
117                     fv_name=u"mac_src",
118                     pkt_offset= 8
119                 ),
120                 STLVmWrFlowVar(
121                     fv_name=u"mac_dst",
122                     pkt_offset= 2
123                 ),
124                 STLVmFlowVar(
125                     name=u"ip_src",
126                     min_value=self.p1_src_start_ip,
127                     max_value=self.p1_src_end_ip,
128                     size=4,
129                     op=u"inc"
130                 ),
131                 STLVmWrFlowVar(
132                     fv_name=u"ip_src",
133                     pkt_offset=u"IP.src"
134                 ),
135                 STLVmFlowVar(
136                     name=u"ip_dst",
137                     min_value=self.p1_dst_start_ip,
138                     max_value=self.p1_dst_end_ip,
139                     size=4,
140                     op=u"inc"
141                 ),
142                 STLVmWrFlowVar(
143                     fv_name=u"ip_dst",
144                     pkt_offset=u"IP.dst"
145                 ),
146                 STLVmFixIpv4(
147                     offset=u"IP"
148                 )
149             ]
150         )
151         # Direction 1 --> 0
152         vm2 = STLScVmRaw(
153             [
154                 STLVmFlowVar(
155                     name=u"mac_src",
156                     min_value=0,
157                     max_value=self.clients-1,
158                     size=4,
159                     op=u"inc"
160                 ),
161                 STLVmFlowVar(
162                     name=u"mac_dst",
163                     min_value=0,
164                     max_value=self.clients-1,
165                     size=4,
166                     op=u"inc"
167                 ),
168                 STLVmWrFlowVar(
169                     fv_name=u"mac_src",
170                     pkt_offset= 8
171                 ),
172                 STLVmWrFlowVar(
173                     fv_name=u"mac_dst",
174                     pkt_offset= 2
175                 ),
176                 STLVmFlowVar(
177                     name=u"ip_src",
178                     min_value=self.p2_src_start_ip,
179                     max_value=self.p2_src_end_ip,
180                     size=4,
181                     op=u"inc"
182                 ),
183                 STLVmWrFlowVar(
184                     fv_name=u"ip_src",
185                     pkt_offset=u"IP.src"
186                 ),
187                 STLVmFlowVar(
188                     name=u"ip_dst",
189                     min_value=self.p2_dst_start_ip,
190                     max_value=self.p2_dst_end_ip,
191                     size=4,
192                     op=u"inc"
193                 ),
194                 STLVmWrFlowVar(
195                     fv_name=u"ip_dst",
196                     pkt_offset=u"IP.dst"
197                 ),
198                 STLVmFixIpv4(
199                     offset=u"IP"
200                 )
201             ]
202         )
203
204         return base_pkt_a, base_pkt_b, vm1, vm2
205
206
207 def register():
208     """Register this traffic profile to T-rex.
209
210     Do not change this function.
211
212     :return: Traffic streams.
213     :rtype: Object
214     """
215     return TrafficStreams()