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 - One stream sent in directions 0 --> 1.
18 - Packet: ETH / IP / UDP
20 - Source IP address range: 192.168.0.0 - 192.171.255.255
21 - Destination IP address range: 20.0.0.0 - 20.3.255.255
22 - Source UDP port range: 1024 - 1086
23 - Destination UDP port range: 8080
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 = u"192.168.0.0"
40 self.p1_src_end_ip = u"192.171.255.255"
41 self.p1_dst_start_ip = u"20.0.0.0"
42 self.p1_dst_end_ip = u"20.3.255.255"
44 # UDP ports used in packet headers.
45 self.p1_src_start_udp_port = 1024
46 self.p1_src_end_udp_port = 1086
47 self.p1_dst_start_udp_port = 8080
48 self.p1_dst_end_udp_port = 8080
50 def define_packets(self):
51 """Defines the packets to be sent from the traffic generator.
53 Packet definition: | ETH | IP | UDP |
55 :returns: Packets to be sent from the traffic generator.
63 src=self.p1_src_start_ip,
64 dst=self.p1_dst_start_ip,
68 sport=self.p1_src_start_udp_port,
69 dport=self.p1_dst_start_udp_port
80 min_value=self.p1_src_start_ip,
81 max_value=self.p1_src_end_ip,
86 min_value=self.p1_src_start_udp_port,
87 max_value=self.p1_src_end_udp_port,
91 min_value=self.p1_dst_start_ip,
92 max_value=self.p1_dst_end_ip,
96 min_value=self.p1_dst_start_udp_port,
97 max_value=self.p1_dst_end_udp_port,
100 vm1.write(fv_name="sIP", pkt_offset="IP.src")
101 vm1.write(fv_name="sport", pkt_offset="UDP.sport")
102 vm1.write(fv_name="dIP", pkt_offset="IP.dst")
103 vm1.write(fv_name="dport", pkt_offset="UDP.dport")
104 vm1.fix_chksum(offset='IP')
108 return base_pkt_a, base_pkt_b, vm1, vm2
111 """Register this traffic profile to T-rex.
113 Do not change this function.
115 :return: Traffic streams.
118 return TrafficStreams()