Perf: Bump T-Rex to 2.88
[csit.git] / GPL / traffic_profiles / trex / trex-stl-ethip4vxlan-ip4src1udpsrcrnd.py
1 # Copyright (c) 2021 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  - Two streams sent in directions 0 --> 1 and 1 --> 0 at the same time.
28  - Packet: ETH / IP / VXLAN / ETH / IP
29  - Direction 0 --> 1:
30    - Source IP address:                172.17.0.2
31    - Destination IP address:           172.16.0.1
32    - Source UDP port:                  random([1024-65535])
33    - Destination UDP port:             4789
34    - VXLAN VNI:                        0
35    - Payload source MAC address:       00:aa:aa:00:00:[00..ff]
36    - Payload source IP address:        10.0.0.2
37    - Payload destination MAC address:  00:bb:bb:00:00:[00..ff]
38    - Payload destination IP address:   10.0.0.1
39  - Direction 1 --> 0:
40    - Source IP address:                172.27.0.2
41    - Destination IP address:           172.26.0.1
42    - Source UDP port:                  random([1024-65535])
43    - Destination UDP port:             4789
44    - VXLAN VNI:                        0
45    - Payload source MAC address:       00:bb:bb:00:00:[00..ff]
46    - Payload source IP address:        10.0.0.1
47    - Payload destination MAC address:  00:aa:aa:00:00:[00..ff]
48    - Payload destination IP address:   10.0.0.2
49 """
50
51 from trex.stl.api import *
52 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
53
54 # RFC 7348 - Virtual eXtensible Local Area Network (VXLAN):
55 # A Framework for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks
56 # http://tools.ietf.org/html/rfc7348
57 _VXLAN_FLAGS = list(u"R"*24 + u"RRRIRRRRR")
58
59
60 class VXLAN(Packet):
61     name=u"VXLAN"
62     fields_desc = [
63         FlagsField(u"flags", 0x08000000, 32, _VXLAN_FLAGS),
64         ThreeBytesField(u"vni", 0),
65         XByteField(u"reserved", 0x00)
66     ]
67
68     def mysummary(self):
69         return self.sprintf(u"VXLAN (vni=%VXLAN.vni%)")
70
71
72 bind_layers(UDP, VXLAN, dport=4789)
73 bind_layers(VXLAN, Ether)
74
75
76 class TrafficStreams(TrafficStreamsBaseClass):
77     """Stream profile."""
78
79     def __init__(self):
80         """Initialization and setting of streams' parameters."""
81
82         super(TrafficStreamsBaseClass, self).__init__()
83
84         self.nf_chains = 1
85
86     def define_packets(self):
87         """Defines the packets to be sent from the traffic generator.
88
89         Packet definition: | ETH | IP | VXLAN | ETH | IP
90
91         :returns: Packets to be sent from the traffic generator.
92         :rtype: tuple
93         """
94
95         # Direction 0 --> 1
96         base_pkt_a = (
97             Ether()/
98             IP(
99                 src=u"172.17.0.2",
100                 dst=u"172.16.0.1"
101             )/
102             UDP(
103                 sport=1024,
104                 dport=4789)/
105             VXLAN(
106                 vni=0
107             )/
108             Ether(
109                 src=u"00:aa:aa:00:00:00",
110                 dst=u"00:bb:bb:00:00:00"
111             )/
112             IP(
113                 src=u"10.0.0.2",
114                 dst=u"10.0.0.1",
115                 proto=61
116             )
117         )
118
119         # Direction 1 --> 0
120         base_pkt_b = (
121             Ether()/
122             IP(
123                 src=u"172.27.0.2",
124                 dst=u"172.26.0.1"
125             )/
126             UDP(
127                 sport=1024,
128                 dport=4789
129             )/
130             VXLAN(
131                 vni=0
132             )/
133             Ether(
134                 src=u"00:bb:bb:00:00:00",
135                 dst=u"00:aa:aa:00:00:00"
136             )/
137             IP(
138                 src=u"10.0.0.1",
139                 dst=u"10.0.0.2",
140                 proto=61
141             )
142         )
143
144         # Direction 0 --> 1
145         vm1 = STLScVmRaw(
146             [
147                 STLVmFlowVar(
148                     name=u"nf_id",
149                     size=1,
150                     op=u"inc",
151                     min_value=0,
152                     max_value=self.nf_chains - 1
153                 ),
154                 STLVmFlowVar(
155                     name=u"in_mac",
156                     size=2,
157                     op=u"inc",
158                     min_value=0,
159                     max_value=255
160                 ),
161                 STLVmFlowVar(
162                     name=u"in_ip",
163                     size=1,
164                     op=u"inc",
165                     min_value=0,
166                     max_value=255
167                 ),
168                 STLVmFlowVar(
169                     name=u"src_port",
170                     size=2,
171                     op=u"random",
172                     min_value=1024,
173                     max_value=65535
174                 ),
175                 STLVmWrFlowVar(
176                     fv_name=u"nf_id",
177                     pkt_offset=28
178                 ),
179                 STLVmWrFlowVar(
180                     fv_name=u"src_port",
181                     pkt_offset=u"UDP.sport"
182                 ),
183                 STLVmWrFlowVar(
184                     fv_name=u"nf_id",
185                     pkt_offset=48
186                 ),
187                 STLVmWrFlowVar(
188                     fv_name=u"in_mac",
189                     pkt_offset=54
190                 ),
191                 STLVmWrFlowVar(
192                     fv_name=u"in_mac",
193                     pkt_offset=60
194                 ),
195                 STLVmFixChecksumHw(
196                     l3_offset="IP:{}".format(0),
197                     l4_offset="UDP:{}".format(0),
198                     l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP
199                 )
200             ]
201         )
202
203         # Direction 1 --> 0
204         vm2 = STLScVmRaw(
205             [
206                 STLVmFlowVar(
207                     name=u"nf_id",
208                     size=1,
209                     op=u"inc",
210                     min_value=0,
211                     max_value=self.nf_chains - 1
212                 ),
213                 STLVmFlowVar(
214                     name=u"in_mac",
215                     size=2, op=u"inc",
216                     min_value=0,
217                     max_value=255
218                 ),
219                 STLVmFlowVar(
220                     name=u"in_ip",
221                     size=1, op=u"inc",
222                     min_value=0,
223                     max_value=255
224                 ),
225                 STLVmFlowVar(
226                     name=u"src_port",
227                     size=2,
228                     op=u"random",
229                     min_value=1024,
230                     max_value=65535
231                 ),
232                 STLVmWrFlowVar(
233                     fv_name=u"nf_id",
234                     pkt_offset=28
235                 ),
236                 STLVmWrFlowVar(
237                     fv_name=u"src_port",
238                     pkt_offset=u"UDP.sport"
239                 ),
240                 STLVmWrFlowVar(
241                     fv_name=u"nf_id",
242                     pkt_offset=48
243                 ),
244                 STLVmWrFlowVar(
245                     fv_name=u"in_mac",
246                     pkt_offset=54
247                 ),
248                 STLVmWrFlowVar(
249                     fv_name=u"in_mac",
250                     pkt_offset=60
251                 ),
252                 STLVmFixChecksumHw(
253                     l3_offset="IP:{}".format(0),
254                     l4_offset="UDP:{}".format(0),
255                     l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP
256                 )
257             ]
258         )
259
260         return base_pkt_a, base_pkt_b, vm1, vm2
261
262 def register():
263     """Register this traffic profile to T-rex.
264
265     Do not change this function.
266
267     :return: Traffic streams.
268     :rtype: Object
269     """
270     return TrafficStreams()
271