1 # Copyright (c) 2021 Cisco and/or its affiliates.
3 # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5 # Licensed under the Apache License 2.0 or
6 # GNU General Public License v2.0 or later; you may not use this file
7 # except in compliance with one of these Licenses. You
8 # may obtain a copy of the Licenses at:
10 # http://www.apache.org/licenses/LICENSE-2.0
11 # https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13 # Note: If this file is linked with Scapy, which is GPLv2+, your use of it
14 # must be under GPLv2+. If at any point in the future it is no longer linked
15 # with Scapy (or other GPLv2+ licensed software), you are free to choose
18 # Unless required by applicable law or agreed to in writing, software
19 # distributed under the License is distributed on an "AS IS" BASIS,
20 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 # See the License for the specific language governing permissions and
22 # limitations under the License.
24 """Stream profile for T-rex traffic generator.
27 - Two streams sent in directions 0 --> 1 and 1 --> 0 at the same time.
30 - Source IP address range: 10.128.1.0 - 10.128.1.255
31 - Destination IP address range: 10.0.1.0 - 10.0.1.255
33 - Packet: ETH / IP / UDP / GENEVE / ETH / IP
34 - Outer Source IP address range: 1.1.1.1
35 - Outer Destination IP address range: 1.1.1.2
36 - Inner Source IP address range: 10.0.1.0 - 10.0.1.255
37 - Inner Destination IP address range: 10.128.1.0 - 10.128.1.255
38 - Source UDP port range: 1024 - 1279
39 - Destination UDP port range: 6081
42 from ctypes import c_int
43 from ipaddress import IPv4Address
45 from scapy.contrib.geneve import GENEVE
46 from trex.stl.api import *
48 from profile_trex_stateless_base_class import TrafficStreamsBaseClass
51 class TrafficStreams(TrafficStreamsBaseClass):
55 """Initialization and setting of streams' parameters."""
57 super(TrafficStreamsBaseClass, self).__init__()
59 # Nr. of GENEVE tunnels
61 # VNIs used in GENEVE headers of Direction 1 --> 0.
62 self.p2_geneve_start_vni = 1
64 # IPs used in packet headers of Direction 0 --> 1.
65 self.p1_src_start_ip = u"10.128.1.0"
66 self.p1_dst_start_ip = u"10.0.1.0"
68 # IPs used in packet headers of Direction 1 --> 0.
69 self.p2_outer_src_ip = u"1.1.1.1"
70 self.p2_outer_dst_ip = u"1.1.1.2"
72 self.p2_inner_src_start_ip = u"10.0.1.0"
73 self.p2_inner_dst_start_ip = u"10.128.1.0"
75 # MACs used in inner ethernet header of Direction 1 --> 0.
76 self.p2_inner_dst_mac = u"d0:0b:ee:d0:00:00"
78 # UDP ports used in packet headers of Direction 1 --> 0.
79 self.p2_udp_sport_start = 1024
80 self.p2_udp_dport = 6081
82 def define_packets(self):
83 """Defines the packets to be sent from the traffic generator.
85 Packet definition: | ETH | IP | UDP |
87 :returns: Packets to be sent from the traffic generator.
90 p1_src_start_ip_int = int(IPv4Address(self.p1_src_start_ip))
91 p1_dst_start_ip_int = int(IPv4Address(self.p1_dst_start_ip))
92 p2_inner_src_start_ip_int = int(IPv4Address(self.p2_inner_src_start_ip))
93 p2_inner_dst_start_ip_int = int(IPv4Address(self.p2_inner_dst_start_ip))
99 src=self.p1_src_start_ip,
100 dst=self.p1_dst_start_ip,
108 src=self.p2_outer_src_ip,
109 dst=self.p2_outer_dst_ip,
113 sport=self.p2_udp_sport_start,
114 dport=self.p2_udp_dport
116 GENEVE(vni=self.p2_geneve_start_vni) /
117 Ether(dst=self.p2_inner_dst_mac) /
119 src=self.p2_inner_src_start_ip,
120 dst=self.p2_inner_dst_start_ip,
124 base_pkt_b /= Raw(load=self._gen_payload(110 - len(base_pkt_b)))
130 min_value=p1_src_start_ip_int,
131 max_value=p1_src_start_ip_int + self.n_tunnels * 256 - 1,
141 min_value=p1_dst_start_ip_int,
142 max_value=p1_dst_start_ip_int + self.n_tunnels * 256 - 1,
161 max_value=self.n_tunnels * 256 - 1,
169 add_value=p2_inner_src_start_ip_int,
170 pkt_offset=u"IP:1.src"
176 add_value=p2_inner_dst_start_ip_int,
177 pkt_offset=u"IP:1.dst"
183 add_value=self.p2_udp_sport_start,
184 pkt_offset=u"UDP.sport"
190 add_value=(self.p2_geneve_start_vni << 8),
191 pkt_offset=u"GENEVE.vni"
201 self.p2_inner_dst_mac.replace(u":", u"")[6:12], 16
204 pkt_offset=u"Ether:1.dst"
215 l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP
220 return base_pkt_a, base_pkt_b, vm1, vm2
224 """Register this traffic profile to T-rex.
226 Do not change this function.
228 :return: Traffic streams.
231 return TrafficStreams()