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