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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
14 """Stream profile for T-rex traffic generator.
17 - Two streams sent in directions 0 --> 1 and 1 --> 0 at the same time.
18 - Packet: ETH / DOT1Q / IP / VXLAN / ETH / IP
21 - Source IP address: 172.17.[0..3].2
22 - Destination IP address: 172.16.0.1
23 - Source UDP port: random([1024..65535])
24 - Destination UDP port: 4789
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
32 - Source IP address: 172.27.[0..3].2
33 - Destination IP address: 172.26.0.1
34 - Source UDP port: random([1024..65535])
35 - Destination UDP port: 4789
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
43 from trex.stl.api import *
44 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
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")
55 FlagsField(u"flags", 0x08000000, 32, _VXLAN_FLAGS),
56 ThreeBytesField(u"vni", 0),
57 XByteField(u"reserved", 0x00)
61 return self.sprintf(u"VXLAN (vni=%VXLAN.vni%)")
64 bind_layers(UDP, VXLAN, dport=4789)
65 bind_layers(VXLAN, Ether)
68 class TrafficStreams(TrafficStreamsBaseClass):
72 """Initialization and setting of streams' parameters."""
74 super(TrafficStreamsBaseClass, self).__init__()
78 def define_packets(self):
79 """Defines the packets to be sent from the traffic generator.
81 Packet definition: | ETH | DOT1Q | IP | VXLAN | ETH | IP
83 :returns: Packets to be sent from the traffic generator.
105 src=u"00:aa:aa:00:00:00",
106 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"
203 l3_offset="IP:{}".format(0),
204 l4_offset="UDP:{}".format(0),
205 l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP
218 max_value=self.nf_chains - 1
247 pkt_offset=u"UDP.sport"
270 l3_offset="IP:{}".format(0),
271 l4_offset="UDP:{}".format(0),
272 l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP
277 return base_pkt_a, base_pkt_b, vm1, vm2
280 """Register this traffic profile to T-rex.
282 Do not change this function.
284 :return: Traffic streams.
287 return TrafficStreams()