1 # Copyright (c) 2019 Intel 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 - Packet: ETH / IP / UDP
19 - Source IP address range: 192.168.50.74 - 192.168.50.79
20 - Destination IP address range: 90.1.2.1
22 - Source IP address range: 192.168.60.74 - 192.168.60.79
23 - Destination IP address range: 192.168.50.74 - 192.168.50.79
26 from trex.stl.api import *
27 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
30 class TrafficStreams(TrafficStreamsBaseClass):
34 """Initialization and setting of streams' parameters."""
36 super(TrafficStreamsBaseClass, self).__init__()
38 # IPs used in packet headers.
39 self.p1_src_start_ip = '192.168.50.74'
40 self.p1_src_end_ip = '192.168.50.79'
41 self.p1_dst_start_ip = '90.1.2.1'
43 self.p2_src_start_ip = '192.168.60.74'
44 self.p2_src_end_ip = '192.168.60.79'
45 self.p2_dst_start_ip = '192.168.50.74'
46 self.p2_dst_end_ip = '192.168.50.79'
48 # UDP ports used in packet headers.
49 self.p1_src_udp_port = 63
50 self.p1_dst_udp_port = 20000
52 self.p2_src_udp_port = 3307
53 self.p2_dst_udp_port = 63
55 def define_packets(self):
56 """Defines the packets to be sent from the traffic generator.
58 Packet definition: | ETH | IP | UDP
60 :returns: Packets to be sent from the traffic generator.
65 base_pkt_a = Ether() / IP(src=self.p1_src_start_ip,
66 dst=self.p1_dst_start_ip,
67 proto=17) / UDP(sport=self.p1_src_udp_port,
68 dport=self.p1_dst_udp_port)
70 base_pkt_b = Ether() / IP(src=self.p2_src_start_ip,
71 dst=self.p2_dst_start_ip,
72 proto=17) / UDP(sport=self.p2_src_udp_port,
73 dport=self.p2_dst_udp_port)
76 vm1 = STLScVmRaw([STLVmFlowVar(name="src",
77 min_value=self.p1_src_start_ip,
78 max_value=self.p1_src_end_ip,
80 STLVmWrFlowVar(fv_name="src", pkt_offset="IP.src"),
81 STLVmFixIpv4(offset="IP")])
83 vm2 = STLScVmRaw([STLVmFlowVar(name="src",
84 min_value=self.p2_src_start_ip,
85 max_value=self.p2_src_end_ip,
87 STLVmWrFlowVar(fv_name="src", pkt_offset="IP.src"),
88 STLVmFlowVar(name="dst",
89 min_value=self.p2_dst_start_ip,
90 max_value=self.p2_dst_end_ip,
92 STLVmWrFlowVar(fv_name="dst", pkt_offset="IP.dst"),
93 STLVmFixIpv4(offset="IP")])
95 return base_pkt_a, base_pkt_b, vm1, vm2
99 """Register this traffic profile to T-rex.
101 Do not change this function.
103 :return: Traffic streams.
106 return TrafficStreams()