caf56651fb6568f15d064c7f7b372b92eb7ec5cd
[csit.git] / resources / traffic_profiles / trex / trex-sl-ethip4vxlan-ip4src1udpsrcrnd.py
1 # Copyright (c) 2019 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 / VXLAN / ETH / IP
19  - Direction 0 --> 1:
20    - Source IP address:                172.17.0.2
21    - Destination IP address:           172.16.0.1
22    - Source UDP port:                  random([1024-65535])
23    - Destination UDP port:             4789
24    - VXLAN VNI:                        0
25    - Payload source MAC address:       00:aa:aa:00:00:[00..ff]
26    - Payload source IP address:        10.0.0.2
27    - Payload destination MAC address:  00:bb:bb:00:00:[00..ff]
28    - Payload destination IP address:   10.0.0.1
29  - Direction 1 --> 0:
30    - Source IP address:                172.27.0.2
31    - Destination IP address:           172.26.0.1
32    - Source UDP port:                  random([1024-65535])
33    - Destination UDP port:             4789
34    - VXLAN VNI:                        0
35    - Payload source MAC address:       00:bb:bb:00:00:[00..ff]
36    - Payload source IP address:        10.0.0.1
37    - Payload destination MAC address:  00:aa:aa:00:00:[00..ff]
38    - Payload destination IP address:   10.0.0.2
39 """
40
41 from trex.stl.api import *
42 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
43
44 # RFC 7348 - Virtual eXtensible Local Area Network (VXLAN):
45 # A Framework for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks
46 # http://tools.ietf.org/html/rfc7348
47 _VXLAN_FLAGS = list('R'*24 + "RRRIRRRRR")
48
49
50 class VXLAN(Packet):
51     name = 'VXLAN'
52     fields_desc = [FlagsField('flags', 0x08000000, 32, _VXLAN_FLAGS),
53                    ThreeBytesField('vni', 0),
54                    XByteField('reserved', 0x00)]
55
56     def mysummary(self):
57         return self.sprintf("VXLAN (vni=%VXLAN.vni%)")
58
59
60 bind_layers(UDP, VXLAN, dport=4789)
61 bind_layers(VXLAN, Ether)
62
63
64 class TrafficStreams(TrafficStreamsBaseClass):
65     """Stream profile."""
66
67     def __init__(self):
68         """Initialization and setting of streams' parameters."""
69
70         super(TrafficStreamsBaseClass, self).__init__()
71
72         self.nf_chains = 1
73
74     def define_packets(self):
75         """Defines the packets to be sent from the traffic generator.
76
77         Packet definition: | ETH | IP | VXLAN | 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             IP(src='172.17.0.2', dst='172.16.0.1')/
87             UDP(sport=1024, dport=4789)/
88             VXLAN(vni=0)/
89             Ether(src='00:aa:aa:00:00:00', dst='00:bb:bb:00:00:00')/
90             IP(src='10.0.0.2', dst='10.0.0.1', proto=61))
91
92         # Direction 1 --> 0
93         base_pkt_b = (
94             Ether()/
95             IP(src='172.27.0.2', dst='172.26.0.1')/
96             UDP(sport=1024, dport=4789)/
97             VXLAN(vni=0)/
98             Ether(src='00:bb:bb:00:00:00', dst='00:aa:aa:00:00:00')/
99             IP(src='10.0.0.1', dst='10.0.0.2', proto=61))
100
101         # Direction 0 --> 1
102         vm1 = STLScVmRaw([
103             STLVmFlowVar(name='nf_id', size=1, op='inc',
104                          min_value=0, max_value=self.nf_chains - 1),
105             STLVmFlowVar(name='in_mac', size=2, op='inc',
106                          min_value=0, max_value=255),
107             STLVmFlowVar(name='in_ip', size=1, op='inc',
108                          min_value=0, max_value=255),
109             STLVmFlowVar(name='src_port', size=2, op='random',
110                          min_value=1024, max_value=65535),
111             STLVmWrFlowVar(fv_name='nf_id', pkt_offset=28),
112             STLVmWrFlowVar(fv_name='src_port', pkt_offset='UDP.sport'),
113             STLVmWrFlowVar(fv_name='nf_id', pkt_offset=48),
114             STLVmWrFlowVar(fv_name='in_mac', pkt_offset=54),
115             STLVmWrFlowVar(fv_name='in_mac', pkt_offset=60),
116             STLVmFixIpv4(offset = 'IP')
117         ])
118
119         # Direction 1 --> 0
120         vm2 = STLScVmRaw([
121             STLVmFlowVar(name='nf_id', size=1, op='inc',
122                          min_value=0, max_value=self.nf_chains - 1),
123             STLVmFlowVar(name='in_mac', size=2, op='inc',
124                          min_value=0, max_value=255),
125             STLVmFlowVar(name='in_ip', size=1, op='inc',
126                          min_value=0, max_value=255),
127             STLVmFlowVar(name='src_port', size=2, op='random',
128                          min_value=1024, max_value=65535),
129             STLVmWrFlowVar(fv_name='nf_id', pkt_offset=28),
130             STLVmWrFlowVar(fv_name='src_port', pkt_offset='UDP.sport'),
131             STLVmWrFlowVar(fv_name='nf_id', pkt_offset=48),
132             STLVmWrFlowVar(fv_name='in_mac', pkt_offset=54),
133             STLVmWrFlowVar(fv_name='in_mac', pkt_offset=60),
134             STLVmFixIpv4(offset = 'IP')
135         ])
136
137         return base_pkt_a, base_pkt_b, vm1, vm2
138
139 def register():
140     """Register this traffic profile to T-rex.
141
142     Do not change this function.
143
144     :return: Traffic streams.
145     :rtype: Object
146     """
147     return TrafficStreams()
148