1 # Copyright (c) 2018 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
23 - Payload source MAC address: 00:de:ad:00:00:00
24 - Payload source IP address: 10.0.0.2
25 - Payload destination MAC address: 00:de:ad:00:00:01
26 - Payload destination IP address: 10.0.0.1
28 - Source IP address: 172.27.0.2
29 - Destination IP address: 172.26.0.1
31 - Payload source MAC address: 00:de:ad:00:00:01
32 - Payload source IP address: 10.0.0.1
33 - Payload destination MAC address: 00:de:ad:00:00:00
34 - Payload destination IP address: 10.0.0.2
38 from trex_stl_lib.api import *
39 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
41 # RFC 7348 - Virtual eXtensible Local Area Network (VXLAN):
42 # A Framework for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks
43 # http://tools.ietf.org/html/rfc7348
44 _VXLAN_FLAGS = list('R'*24 + "RRRIRRRRR")
49 fields_desc = [FlagsField("flags", 0x08000000, 32, _VXLAN_FLAGS),
50 ThreeBytesField("vni", 0),
51 XByteField("reserved", 0x00)]
54 return self.sprintf("VXLAN (vni=%VXLAN.vni%)")
57 bind_layers(UDP, VXLAN, dport=4789)
58 bind_layers(VXLAN, Ether)
61 class TrafficStreams(TrafficStreamsBaseClass):
65 """Initialization and setting of streams' parameters."""
67 super(TrafficStreamsBaseClass, self).__init__()
69 def define_packets(self):
70 """Defines the packets to be sent from the traffic generator.
72 Packet definition: | ETH | IP |
74 :returns: Packets to be sent from the traffic generator.
81 IP(src="172.17.0.2",dst="172.16.0.1")/
82 UDP(sport=1337,dport=4789)/
84 Ether(src="00:de:ad:00:00:00",dst="00:de:ad:00:00:01")/
85 IP(src="10.0.0.2",dst="10.0.0.1"))
90 IP(src="172.27.0.2",dst="172.26.0.1")/
91 UDP(sport=1337,dport=4789)/
93 Ether(src="00:de:ad:00:00:01",dst="00:de:ad:00:00:00")/
94 IP(src="10.0.0.1",dst="10.0.0.2"))
99 STLVmFlowVar(name="src", min_value="172.17.0.2" ,
100 max_value="172.17.0.254", size=4, op="inc"),
101 STLVmFlowVar(name="src_mac", min_value=2 , max_value=3100,
103 STLVmWrFlowVar(fv_name="src", pkt_offset="IP.src"),
104 STLVmWrFlowVar(fv_name="src_mac", pkt_offset=60),
105 STLVmFixIpv4(offset = "IP")
110 STLVmFlowVar(name="src", min_value="172.27.0.2" ,
111 max_value="172.27.0.254", size=4, op="inc"),
112 STLVmFlowVar(name="src_mac", min_value=2 , max_value=3100,
114 STLVmWrFlowVar(fv_name="src", pkt_offset="IP.src"),
115 STLVmWrFlowVar(fv_name="src_mac", pkt_offset=60),
116 STLVmFixIpv4(offset = "IP")
119 # for now there's a single VXLAN tunnel per direction, the above
120 # variations are for reference only
123 return base_pkt_a, base_pkt_b, vm1, vm2
126 """Register this traffic profile to T-rex.
128 Do not change this function.
130 :return: Traffic streams.
133 return TrafficStreams()