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:
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 / IP / VXLAN / ETH / IP
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
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
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
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
41 from trex.stl.api import *
42 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
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")
52 fields_desc = [FlagsField('flags', 0x08000000, 32, _VXLAN_FLAGS),
53 ThreeBytesField('vni', 0),
54 XByteField('reserved', 0x00)]
57 return self.sprintf("VXLAN (vni=%VXLAN.vni%)")
60 bind_layers(UDP, VXLAN, dport=4789)
61 bind_layers(VXLAN, Ether)
64 class TrafficStreams(TrafficStreamsBaseClass):
68 """Initialization and setting of streams' parameters."""
70 super(TrafficStreamsBaseClass, self).__init__()
74 def define_packets(self):
75 """Defines the packets to be sent from the traffic generator.
77 Packet definition: | ETH | IP | VXLAN | ETH | IP
79 :returns: Packets to be sent from the traffic generator.
86 IP(src='172.17.0.2', dst='172.16.0.1')/
87 UDP(sport=1024, dport=4789)/
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))
95 IP(src='172.27.0.2', dst='172.26.0.1')/
96 UDP(sport=1024, dport=4789)/
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))
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')
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')
137 return base_pkt_a, base_pkt_b, vm1, vm2
140 """Register this traffic profile to T-rex.
142 Do not change this function.
144 :return: Traffic streams.
147 return TrafficStreams()