1 # Copyright (c) 2021 Cisco and/or its affiliates.
3 # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
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:
10 # http://www.apache.org/licenses/LICENSE-2.0
11 # https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
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
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.
24 """Stream profile for T-rex traffic generator.
27 - Two streams sent in directions 0 --> 1 and 1 --> 0 at the same time.
28 - Packet: ETH / DOT1Q / IP / VXLAN / ETH / IP
31 - Source IP address: 172.17.[0..1].2
32 - Destination IP address: 172.16.0.1
33 - Source UDP port: random([1024..65535])
34 - Destination UDP port: 4789
36 - Payload source MAC address: 00:aa:aa:00:00:[00..ff]
37 - Payload source IP address: 10.0.[0..255].2
38 - Payload destination MAC address: 00:bb:bb:00:00:[00..ff]
39 - Payload destination IP address: 10.0.[0..255].1
42 - Source IP address: 172.27.[0..1].2
43 - Destination IP address: 172.26.0.1
44 - Source UDP port: random([1024..65535])
45 - Destination UDP port: 4789
47 - Payload source MAC address: 00:bb:bb:00:00:[00..ff]
48 - Payload source IP address: 10.0.[0..255].1
49 - Payload destination MAC address: 00:aa:aa:00:00:[00..ff]
50 - Payload destination IP address: 10.0.[0..255].2
53 from trex.stl.api import *
54 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
56 # RFC 7348 - Virtual eXtensible Local Area Network (VXLAN):
57 # A Framework for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks
58 # http://tools.ietf.org/html/rfc7348
59 _VXLAN_FLAGS = list(u"R"*24 + u"RRRIRRRRR")
65 FlagsField(u"flags", 0x08000000, 32, _VXLAN_FLAGS),
66 ThreeBytesField(u"vni", 0),
67 XByteField(u"reserved", 0x00)
71 return self.sprintf(u"VXLAN (vni=%VXLAN.vni%)")
74 bind_layers(UDP, VXLAN, dport=4789)
75 bind_layers(VXLAN, Ether)
78 class TrafficStreams(TrafficStreamsBaseClass):
82 """Initialization and setting of streams' parameters."""
84 super(TrafficStreamsBaseClass, self).__init__()
88 def define_packets(self):
89 """Defines the packets to be sent from the traffic generator.
91 Packet definition: | ETH | DOT1Q | IP | VXLAN | ETH | IP
93 :returns: Packets to be sent from the traffic generator.
115 src=u"00:aa:aa:00:00:00",
116 dst=u"00:bb:bb:00:00:00"
143 src=u"00:bb:bb:00:00:00",
144 dst=u"00:aa:aa:00:00:00"
161 max_value=self.nf_chains - 1
190 pkt_offset=u"UDP.sport"
213 l3_offset="IP:{}".format(0),
214 l4_offset="UDP:{}".format(0),
215 l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP
228 max_value=self.nf_chains - 1
257 pkt_offset=u"UDP.sport"
280 l3_offset="IP:{}".format(0),
281 l4_offset="UDP:{}".format(0),
282 l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP
287 return base_pkt_a, base_pkt_b, vm1, vm2
290 """Register this traffic profile to T-rex.
292 Do not change this function.
294 :return: Traffic streams.
297 return TrafficStreams()