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 / DOT1Q / IP / VXLAN / ETH / IP
21 - Source IP address: 172.17.0.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.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('R'*24 + "RRRIRRRRR")
54 fields_desc = [FlagsField('flags', 0x08000000, 32, _VXLAN_FLAGS),
55 ThreeBytesField('vni', 0),
56 XByteField('reserved', 0x00)]
59 return self.sprintf("VXLAN (vni=%VXLAN.vni%)")
62 bind_layers(UDP, VXLAN, dport=4789)
63 bind_layers(VXLAN, Ether)
66 class TrafficStreams(TrafficStreamsBaseClass):
70 """Initialization and setting of streams' parameters."""
72 super(TrafficStreamsBaseClass, self).__init__()
76 def define_packets(self):
77 """Defines the packets to be sent from the traffic generator.
79 Packet definition: | ETH | DOT1Q | IP | VXLAN | ETH | IP
81 :returns: Packets to be sent from the traffic generator.
89 IP(src='172.17.0.2', dst='172.16.0.1')/
90 UDP(sport=1024, dport=4789)/
92 Ether(src='00:aa:aa:00:00:00', dst='00:bb:bb:00:00:00')/
93 IP(src='10.0.0.2', dst='10.0.0.1', proto=61))
99 IP(src='172.27.0.2', dst='172.26.0.1')/
100 UDP(sport=1024, dport=4789)/
102 Ether(src='00:bb:bb:00:00:00', dst='00:aa:aa:00:00:00')/
103 IP(src='10.0.0.1', dst='10.0.0.2', proto=61))
107 STLVmFlowVar(name='nf_id', size=1, op='inc',
108 min_value=0, max_value=self.nf_chains - 1),
109 STLVmFlowVar(name='in_mac', size=2, op='inc',
110 min_value=0, max_value=255),
111 STLVmFlowVar(name='in_ip', size=1, op='inc',
112 min_value=0, max_value=255),
113 STLVmFlowVar(name='src_port', size=2, op='random',
114 min_value=1024, max_value=65535),
115 STLVmWrFlowVar(fv_name='nf_id', pkt_offset=32),
116 STLVmWrFlowVar(fv_name='src_port', pkt_offset='UDP.sport'),
117 STLVmWrFlowVar(fv_name='nf_id', pkt_offset=52),
118 STLVmWrFlowVar(fv_name='in_mac', pkt_offset=58),
119 STLVmWrFlowVar(fv_name='in_mac', pkt_offset=64),
120 STLVmWrFlowVar(fv_name='in_ip', pkt_offset=82),
121 STLVmWrFlowVar(fv_name='in_ip', pkt_offset=86),
122 STLVmFixIpv4(offset = 'IP')
127 STLVmFlowVar(name='nf_id', size=1, op='inc',
128 min_value=0, max_value=self.nf_chains - 1),
129 STLVmFlowVar(name='in_mac', size=2, op='inc',
130 min_value=0, max_value=255),
131 STLVmFlowVar(name='in_ip', size=1, op='inc',
132 min_value=0, max_value=255),
133 STLVmFlowVar(name='src_port', size=2, op='random',
134 min_value=1024, max_value=65535),
135 STLVmWrFlowVar(fv_name='nf_id', pkt_offset=32),
136 STLVmWrFlowVar(fv_name='src_port', pkt_offset='UDP.sport'),
137 STLVmWrFlowVar(fv_name='nf_id', pkt_offset=52),
138 STLVmWrFlowVar(fv_name='in_mac', pkt_offset=58),
139 STLVmWrFlowVar(fv_name='in_mac', pkt_offset=64),
140 STLVmWrFlowVar(fv_name='in_ip', pkt_offset=82),
141 STLVmWrFlowVar(fv_name='in_ip', pkt_offset=86),
142 STLVmFixIpv4(offset = 'IP')
145 return base_pkt_a, base_pkt_b, vm1, vm2
148 """Register this traffic profile to T-rex.
150 Do not change this function.
152 :return: Traffic streams.
155 return TrafficStreams()