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 - Two streams sent in directions 0 --> 1 and 1 --> 0 at the same time.
18 - Packet: ETH / IP / UDP
20 - Source IP address range: 192.168.0.0 - 192.168.63.255
21 - Destination IP address range: 20.0.0.0
22 - Source UDP port range: 1024 - 1086
23 - Destination UDP port range: 1024
25 - Source IP address range: 20.0.0.0
26 - Destination IP address range: 68.142.68.0 - 68.142.68.15
27 - Source UDP port range: 1024
28 - Destination UDP port range: 1024 - 65535
31 from trex.stl.api import *
32 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
35 class TrafficStreams(TrafficStreamsBaseClass):
39 """Initialization and setting of streams' parameters."""
41 super(TrafficStreamsBaseClass, self).__init__()
43 # IPs used in packet headers.
44 self.p1_src_start_ip = u"192.168.0.0"
45 self.p1_src_end_ip = u"192.168.63.255"
46 self.p1_dst_start_ip = u"20.0.0.0"
47 self.p1_dst_end_ip = u"20.0.0.0"
49 self.p2_src_start_ip = u"20.0.0.0"
50 self.p2_src_end_ip = u"20.0.0.0"
51 self.p2_dst_start_ip = u"68.142.68.0"
52 self.p2_dst_end_ip = u"68.142.68.15"
54 # UDP ports used in packet headers.
55 self.p1_src_start_udp_port = 1024
56 self.p1_src_end_udp_port = 1086
57 self.p1_dst_start_udp_port = 1024
58 self.p1_dst_end_udp_port = 1024
60 self.p2_src_start_udp_port = 1024
61 self.p2_src_end_udp_port = 1024
62 self.p2_dst_start_udp_port = 1024
63 self.p2_dst_end_udp_port = 65535
65 def define_packets(self):
66 """Defines the packets to be sent from the traffic generator.
68 Packet definition: | ETH | IP | UDP |
70 :returns: Packets to be sent from the traffic generator.
78 src=self.p1_src_start_ip,
79 dst=self.p1_dst_start_ip,
83 sport=self.p1_src_start_udp_port,
84 dport=self.p1_dst_start_udp_port
91 src=self.p2_src_start_ip,
92 dst=self.p2_dst_start_ip,
96 sport=self.p2_src_start_udp_port,
97 dport=self.p2_dst_start_udp_port
104 min_value=self.p1_src_start_ip,
105 max_value=self.p1_src_end_ip,
109 vm1.var(name="sport",
110 min_value=self.p1_src_start_udp_port,
111 max_value=self.p1_src_end_udp_port,
115 min_value=self.p1_dst_start_ip,
116 max_value=self.p1_dst_end_ip,
119 vm1.var(name="dport",
120 min_value=self.p1_dst_start_udp_port,
121 max_value=self.p1_dst_end_udp_port,
124 vm1.write(fv_name="sIP", pkt_offset="IP.src")
125 vm1.write(fv_name="sport", pkt_offset="UDP.sport")
126 vm1.write(fv_name="dIP", pkt_offset="IP.dst")
127 vm1.write(fv_name="dport", pkt_offset="UDP.dport")
128 vm1.fix_chksum(offset='IP')
132 min_value=self.p2_src_start_ip,
133 max_value=self.p2_src_end_ip,
137 vm2.var(name="sport",
138 min_value=self.p2_src_start_udp_port,
139 max_value=self.p2_src_end_udp_port,
143 min_value=self.p2_dst_start_ip,
144 max_value=self.p2_dst_end_ip,
148 vm2.var(name="dport",
149 min_value=self.p2_dst_start_udp_port,
150 max_value=self.p2_dst_end_udp_port,
153 vm2.write(fv_name="sIP", pkt_offset="IP.src")
154 vm2.write(fv_name="sport", pkt_offset="UDP.sport")
155 vm2.write(fv_name="dIP", pkt_offset="IP.dst")
156 vm2.write(fv_name="dport", pkt_offset="UDP.dport")
157 vm2.fix_chksum(offset='IP')
159 return base_pkt_a, base_pkt_b, vm1, vm2
162 """Register this traffic profile to T-rex.
164 Do not change this function.
166 :return: Traffic streams.
169 return TrafficStreams()