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 / IP / VXLAN / ETH / IP
29 - Source IP address: 172.17.0.2
30 - Destination IP address: 172.16.0.1
31 - Source UDP port: random([1024-65535])
32 - Destination UDP port: 4789
34 - Payload source MAC address: 00:aa:aa:00:00:[00..ff]
35 - Payload source IP address: 10.0.0.2
36 - Payload destination MAC address: 00:bb:bb:00:00:[00..ff]
37 - Payload destination IP address: 10.0.0.1
39 - Source IP address: 172.27.0.2
40 - Destination IP address: 172.26.0.1
41 - Source UDP port: random([1024-65535])
42 - Destination UDP port: 4789
44 - Payload source MAC address: 00:bb:bb:00:00:[00..ff]
45 - Payload source IP address: 10.0.0.1
46 - Payload destination MAC address: 00:aa:aa:00:00:[00..ff]
47 - Payload destination IP address: 10.0.0.2
50 from trex.stl.api import *
51 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
53 # RFC 7348 - Virtual eXtensible Local Area Network (VXLAN):
54 # A Framework for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks
55 # http://tools.ietf.org/html/rfc7348
56 _VXLAN_FLAGS = list(u"R"*24 + u"RRRIRRRRR")
62 FlagsField(u"flags", 0x08000000, 32, _VXLAN_FLAGS),
63 ThreeBytesField(u"vni", 0),
64 XByteField(u"reserved", 0x00)
68 return self.sprintf(u"VXLAN (vni=%VXLAN.vni%)")
71 bind_layers(UDP, VXLAN, dport=4789)
72 bind_layers(VXLAN, Ether)
75 class TrafficStreams(TrafficStreamsBaseClass):
79 """Initialization and setting of streams' parameters."""
81 super(TrafficStreamsBaseClass, self).__init__()
85 def define_packets(self):
86 """Defines the packets to be sent from the traffic generator.
88 Packet definition: | ETH | IP | VXLAN | ETH | IP
90 :returns: Packets to be sent from the traffic generator.
108 src=u"00:aa:aa:00:00:00",
109 dst=u"00:bb:bb:00:00:00"
133 src=u"00:bb:bb:00:00:00",
134 dst=u"00:aa:aa:00:00:00"
151 max_value=self.nf_chains - 1
180 pkt_offset=u"UDP.sport"
195 l3_offset="IP:{}".format(0),
196 l4_offset="UDP:{}".format(0),
197 l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP
210 max_value=self.nf_chains - 1
237 pkt_offset=u"UDP.sport"
252 l3_offset="IP:{}".format(0),
253 l4_offset="UDP:{}".format(0),
254 l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP
259 return base_pkt_a, base_pkt_b, vm1, vm2
262 """Register this traffic profile to T-rex.
264 Do not change this function.
266 :return: Traffic streams.
269 return TrafficStreams()