aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools/t-rex
diff options
context:
space:
mode:
Diffstat (limited to 'resources/tools/t-rex')
-rwxr-xr-xresources/tools/t-rex/t-rex-stateless.py118
1 files changed, 114 insertions, 4 deletions
diff --git a/resources/tools/t-rex/t-rex-stateless.py b/resources/tools/t-rex/t-rex-stateless.py
index 504ef50eef..ae8d187670 100755
--- a/resources/tools/t-rex/t-rex-stateless.py
+++ b/resources/tools/t-rex/t-rex-stateless.py
@@ -172,12 +172,13 @@ def create_streams_v46(base_pkt_a, base_pkt_b, vm1, vm2, frame_size):
return (stream1, stream2, lat_stream1, lat_stream2)
+
def create_streams(traffic_options, frame_size=64):
"""Create two IP packets to be used in stream.
:param traffic_options: Parameters for packets.
:param frame_size: Size of L2 frame.
- :type traffic_options: list
+ :type traffic_options: dict
:type frame_size: int
:return: Packet instances.
:rtype: Tuple of STLPktBuilder
@@ -197,13 +198,91 @@ def create_streams(traffic_options, frame_size=64):
p1_dst_end_ip = traffic_options['p1_dst_end_ip']
p2_dst_end_ip = traffic_options['p2_dst_end_ip']
- base_pkt_a = Ether()/IP(src=p1_src_start_ip, dst=p1_dst_start_ip, proto=61)
- base_pkt_b = Ether()/IP(src=p2_src_start_ip, dst=p2_dst_start_ip, proto=61)
+ try:
+ p1_src_start_udp_port = traffic_options['p1_src_start_udp_port']
+ p1_src_end_udp_port = traffic_options['p1_src_end_udp_port']
+ p1_dst_start_udp_port = traffic_options['p1_dst_start_udp_port']
+ p2_src_start_udp_port = traffic_options['p2_src_start_udp_port']
+ p2_dst_start_udp_port = traffic_options['p2_dst_start_udp_port']
+ p2_dst_end_udp_port = traffic_options['p2_dst_end_udp_port']
+ ports_defined = True
+ except KeyError:
+ ports_defined = False
+
+ if ports_defined:
+ base_pkt_a = (Ether() /
+ IP(src=p1_src_start_ip, dst=p1_dst_start_ip, proto=17) /
+ UDP(sport=int(p1_src_start_udp_port),
+ dport=int(p1_dst_start_udp_port)))
+ base_pkt_b = (Ether() /
+ IP(src=p2_src_start_ip, dst=p2_dst_start_ip, proto=17) /
+ UDP(sport=int(p2_src_start_udp_port),
+ dport=int(p2_dst_start_udp_port)))
+ else:
+ base_pkt_a = Ether() / IP(src=p1_src_start_ip, dst=p1_dst_start_ip,
+ proto=61)
+ base_pkt_b = Ether() / IP(src=p2_src_start_ip, dst=p2_dst_start_ip,
+ proto=61)
# The following code applies raw instructions to packet (IP src/dst
# increment). It splits the generated traffic by "ip_src"/"ip_dst" variable
# to cores and fix IPv4 header checksum.
- if p1_dst_end_ip and p2_dst_end_ip:
+ if ports_defined:
+ if p1_src_start_udp_port != p1_src_end_udp_port and \
+ p1_src_start_ip != p1_src_end_ip:
+ vm1 = STLScVmRaw([
+ STLVmTupleGen(ip_min=p1_src_start_ip,
+ ip_max=p1_src_end_ip,
+ port_min=int(p1_src_start_udp_port),
+ port_max=int(p1_src_end_udp_port),
+ name="tuple"),
+ STLVmWrFlowVar(fv_name="tuple.ip", pkt_offset="IP.src"),
+ STLVmFixIpv4(offset="IP"),
+ STLVmWrFlowVar(fv_name="tuple.port", pkt_offset="UDP.sport")
+ ])
+ vm2 = STLScVmRaw([
+ STLVmTupleGen(ip_min=p2_dst_start_ip,
+ ip_max=p2_dst_start_ip,
+ port_min=int(p2_dst_start_udp_port),
+ port_max=int(p2_dst_end_udp_port),
+ name="tuple"),
+ STLVmWrFlowVar(fv_name="tuple.ip", pkt_offset="IP.dst"),
+ STLVmFixIpv4(offset="IP"),
+ STLVmWrFlowVar(fv_name="tuple.port", pkt_offset="UDP.dport")
+ ])
+ elif p1_src_start_udp_port != p1_src_end_udp_port:
+ vm1 = STLScVmRaw([
+ STLVmFlowVar(name="sport",
+ min_value=int(p1_src_start_udp_port),
+ max_value=int(p1_src_end_udp_port),
+ size=2, op="inc"),
+ STLVmWrFlowVar(fv_name="sport", pkt_offset="UDP.sport")
+ ])
+ vm2 = STLScVmRaw([
+ STLVmFlowVar(name="dport",
+ min_value=int(p2_dst_start_udp_port),
+ max_value=int(p2_dst_end_udp_port),
+ size=2, op="inc"),
+ STLVmWrFlowVar(fv_name="dport", pkt_offset="UDP.dport")
+ ])
+ elif p1_src_start_udp_port == p1_src_end_udp_port:
+ vm1 = STLScVmRaw([STLVmFlowVar(name="src",
+ min_value=p1_src_start_ip,
+ max_value=p1_src_end_ip,
+ size=4, op="inc"),
+ STLVmWrFlowVar(fv_name="src",
+ pkt_offset="IP.src"),
+ STLVmFixIpv4(offset="IP"),
+ ], split_by_field="src")
+ vm2 = STLScVmRaw([STLVmFlowVar(name="src",
+ min_value=p2_src_start_ip,
+ max_value=p2_src_end_ip,
+ size=4, op="inc"),
+ STLVmWrFlowVar(fv_name="src",
+ pkt_offset="IP.src"),
+ STLVmFixIpv4(offset="IP"),
+ ], split_by_field="src")
+ elif p1_dst_end_ip and p2_dst_end_ip:
vm1 = STLScVmRaw([STLVmFlowVar(name="dst",
min_value=p1_dst_start_ip,
max_value=p1_dst_end_ip,
@@ -524,6 +603,7 @@ def parse_args():
# help="Port 1 source MAC address")
# parser.add_argument("--p1_dst_mac",
# help="Port 1 destination MAC address")
+
parser.add_argument("--p1_src_start_ip", required=True,
help="Port 1 source start IP address")
parser.add_argument("--p1_src_end_ip",
@@ -534,10 +614,26 @@ def parse_args():
parser.add_argument("--p1_dst_end_ip",
default=False,
help="Port 1 destination end IP address")
+
+ parser.add_argument("--p1_src_start_udp_port",
+ default=None,
+ help="Port 1 source start UDP port.")
+ parser.add_argument("--p1_src_end_udp_port",
+ default=None,
+ help="Port 1 source end UDP port.")
+
+ parser.add_argument("--p1_dst_start_udp_port",
+ default=None,
+ help="Port 1 destination start UDP port.")
+ parser.add_argument("--p1_dst_end_udp_port",
+ default=None,
+ help="Port 1 destination end UDP port.")
+
# parser.add_argument("--p2_src_mac",
# help="Port 2 source MAC address")
# parser.add_argument("--p2_dst_mac",
# help="Port 2 destination MAC address")
+
parser.add_argument("--p2_src_start_ip", required=True,
help="Port 2 source start IP address")
parser.add_argument("--p2_src_end_ip",
@@ -549,6 +645,20 @@ def parse_args():
default=False,
help="Port 2 destination end IP address")
+ parser.add_argument("--p2_src_start_udp_port",
+ default=None,
+ help="Port 2 source start UDP port.")
+ parser.add_argument("--p2_src_end_udp_port",
+ default=None,
+ help="Port 2 source end UDP port.")
+
+ parser.add_argument("--p2_dst_start_udp_port",
+ default=None,
+ help="Port 2 destination start UDP port.")
+ parser.add_argument("--p2_dst_end_udp_port",
+ default=None,
+ help="Port 2 destination end UDP port.")
+
return parser.parse_args()