1 # Copyright (c) 2020 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 Apache 2.
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
23 """Stream profile for T-rex traffic generator.
26 - Two streams sent in directions 0 --> 1 and 1 --> 0 at the same time.
27 - Packet: ETH / DOT1Q / IP / VXLAN / ETH / IP
30 - Source IP address: 172.17.[0..5].2
31 - Destination IP address: 172.16.0.1
32 - Source UDP port: random([1024..65535])
33 - Destination UDP port: 4789
35 - Payload source MAC address: 00:aa:aa:00:00:[00..ff]
36 - Payload source IP address: 10.0.[0..255].2
37 - Payload destination MAC address: 00:bb:bb:00:00:[00..ff]
38 - Payload destination IP address: 10.0.[0..255].1
41 - Source IP address: 172.27.[0..5].2
42 - Destination IP address: 172.26.0.1
43 - Source UDP port: random([1024..65535])
44 - Destination UDP port: 4789
46 - Payload source MAC address: 00:bb:bb:00:00:[00..ff]
47 - Payload source IP address: 10.0.[0..255].1
48 - Payload destination MAC address: 00:aa:aa:00:00:[00..ff]
49 - Payload destination IP address: 10.0.[0..255].2
52 from trex.stl.api import *
53 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
55 # RFC 7348 - Virtual eXtensible Local Area Network (VXLAN):
56 # A Framework for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks
57 # http://tools.ietf.org/html/rfc7348
58 _VXLAN_FLAGS = list(u"R"*24 + u"RRRIRRRRR")
64 FlagsField(u"flags", 0x08000000, 32, _VXLAN_FLAGS),
65 ThreeBytesField(u"vni", 0),
66 XByteField(u"reserved", 0x00)
70 return self.sprintf(u"VXLAN (vni=%VXLAN.vni%)")
73 bind_layers(UDP, VXLAN, dport=4789)
74 bind_layers(VXLAN, Ether)
77 class TrafficStreams(TrafficStreamsBaseClass):
81 """Initialization and setting of streams' parameters."""
83 super(TrafficStreamsBaseClass, self).__init__()
87 def define_packets(self):
88 """Defines the packets to be sent from the traffic generator.
90 Packet definition: | ETH | DOT1Q | IP | VXLAN | ETH | IP
92 :returns: Packets to be sent from the traffic generator.
114 src=u"00:aa:aa:00:00:00",
115 dst=u"00:bb:bb:00:00:00"
142 src=u"00:bb:bb:00:00:00",
143 dst=u"00:aa:aa:00:00:00"
160 max_value=self.nf_chains - 1
189 pkt_offset=u"UDP.sport"
212 l3_offset="IP:{}".format(0),
213 l4_offset="UDP:{}".format(0),
214 l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP
227 max_value=self.nf_chains - 1
256 pkt_offset=u"UDP.sport"
279 l3_offset="IP:{}".format(0),
280 l4_offset="UDP:{}".format(0),
281 l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP
286 return base_pkt_a, base_pkt_b, vm1, vm2
289 """Register this traffic profile to T-rex.
291 Do not change this function.
293 :return: Traffic streams.
296 return TrafficStreams()