import struct
import sys
-sys.path.insert(0, "/opt/trex-core-2.03/scripts/automation/"+\
+sys.path.insert(0, "/opt/trex-core-2.22/scripts/automation/"+\
"trex_control_plane/stl/")
from trex_stl_lib.api import *
print "IPv6: start_ip is greater then end_ip"
sys.exit(2)
- max_p1 = abs(int(lo1) - int(lo2)) + 1
+ max_p1 = abs(int(lo1) - int(lo2))
base_p1 = lo1
except AddressValueError as ex_error:
print ex_error
max(0, fsize_no_fcs-len(base_pkt_b))))
lat_stream1 = STLStream(packet=pkt_lat_a,
flow_stats=STLFlowLatencyStats(pg_id=0),
- mode=STLTXCont(pps=1000))
+ mode=STLTXCont(pps=9000))
# second traffic stream with a phase of 10ns (inter stream gap)
lat_stream2 = STLStream(packet=pkt_lat_b,
isg=10.0,
flow_stats=STLFlowLatencyStats(pg_id=1),
- mode=STLTXCont(pps=1000))
+ mode=STLTXCont(pps=9000))
stream1 = STLStream(packet=pkt_a,
- mode=STLTXCont(pps=1000))
+ mode=STLTXCont(pps=9000))
# second traffic stream with a phase of 10ns (inter stream gap)
stream2 = STLStream(packet=pkt_b,
isg=10.0,
- mode=STLTXCont(pps=1000))
+ mode=STLTXCont(pps=9000))
elif type(frame_size) is str:
lat_stream1 = []
lat_stream2 = []
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
p2_src_end_ip = traffic_options['p2_src_end_ip']
p2_dst_start_ip = traffic_options['p2_dst_start_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)
-
- # The following code applies raw instructions to packet (IP src increment).
- # It splits the generated traffic by "ip_src" variable to cores and fix
- # IPv4 header checksum.
- 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")
- # The following code applies raw instructions to packet (IP src increment).
- # It splits the generated traffic by "ip_src" variable to cores and fix
- # IPv4 header checksum.
- 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")
+ p1_dst_end_ip = traffic_options['p1_dst_end_ip']
+ p2_dst_end_ip = traffic_options['p2_dst_end_ip']
+
+ 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 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,
+ size=4, op="inc"),
+ STLVmWrFlowVar(fv_name="dst", pkt_offset="IP.dst"),
+ STLVmFixIpv4(offset="IP"),
+ ], split_by_field="dst")
+ vm2 = STLScVmRaw([STLVmFlowVar(name="dst",
+ min_value=p2_dst_start_ip,
+ max_value=p2_dst_end_ip,
+ size=4, op="inc"),
+ STLVmWrFlowVar(fv_name="dst", pkt_offset="IP.dst"),
+ STLVmFixIpv4(offset="IP"),
+ ], split_by_field="dst")
+ else:
+ 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")
return create_streams_v46(base_pkt_a, base_pkt_b, vm1, vm2, frame_size)
p2_src_end_ip = traffic_options['p2_src_end_ip']
p2_dst_start_ip = traffic_options['p2_dst_start_ip']
- base_p1, max_p1 = get_start_end_ipv6(p1_src_start_ip, p1_src_end_ip)
- base_p2, max_p2 = get_start_end_ipv6(p2_src_start_ip, p2_src_end_ip)
+ p1_dst_end_ip = traffic_options['p1_dst_end_ip']
+ p2_dst_end_ip = traffic_options['p2_dst_end_ip']
base_pkt_a = Ether()/IPv6(src=p1_src_start_ip, dst=p1_dst_start_ip)
base_pkt_b = Ether()/IPv6(src=p2_src_start_ip, dst=p2_dst_start_ip)
- # The following code applies raw instructions to packet (IP src increment).
- # It splits the generated traffic by "ip_src" variable to cores
- vm1 = STLScVmRaw([STLVmFlowVar(name="ipv6_src",
- min_value=base_p1,
- max_value=max_p1+base_p1,
- size=8, op="inc"),
- STLVmWrFlowVar(fv_name="ipv6_src", pkt_offset="IPv6.src",
- offset_fixup=8)
- ]
- , split_by_field="ipv6_src")
-
- # The following code applies raw instructions to packet (IP src increment).
- # It splits the generated traffic by "ip_src" variable to cores
- vm2 = STLScVmRaw([STLVmFlowVar(name="ipv6_src",
- min_value=base_p2,
- max_value=max_p2+base_p2,
- size=8, op="inc"),
- STLVmWrFlowVar(fv_name="ipv6_src", pkt_offset="IPv6.src",
- offset_fixup=8)
- ]
- , split_by_field="ipv6_src")
+ # 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.
+ if p1_dst_end_ip and p2_dst_end_ip:
+ base_p1, max_p1 = get_start_end_ipv6(p1_dst_start_ip, p1_dst_end_ip)
+ base_p2, max_p2 = get_start_end_ipv6(p2_dst_start_ip, p2_dst_end_ip)
+
+ vm1 = STLScVmRaw([STLVmFlowVar(name="ipv6_dst",
+ min_value=base_p1,
+ max_value=max_p1+base_p1,
+ size=8, op="inc"),
+ STLVmWrFlowVar(fv_name="ipv6_dst",
+ pkt_offset="IPv6.dst",
+ offset_fixup=8)
+ ]
+ , split_by_field="ipv6_dst")
+ vm2 = STLScVmRaw([STLVmFlowVar(name="ipv6_dst",
+ min_value=base_p2,
+ max_value=max_p2+base_p2,
+ size=8, op="inc"),
+ STLVmWrFlowVar(fv_name="ipv6_dst",
+ pkt_offset="IPv6.dst",
+ offset_fixup=8)
+ ]
+ , split_by_field="ipv6_dst")
+ else:
+ base_p1, max_p1 = get_start_end_ipv6(p1_src_start_ip, p1_src_end_ip)
+ base_p2, max_p2 = get_start_end_ipv6(p2_src_start_ip, p2_src_end_ip)
+
+ vm1 = STLScVmRaw([STLVmFlowVar(name="ipv6_src",
+ min_value=base_p1,
+ max_value=max_p1+base_p1,
+ size=8, op="inc"),
+ STLVmWrFlowVar(fv_name="ipv6_src",
+ pkt_offset="IPv6.src",
+ offset_fixup=8)
+ ]
+ , split_by_field="ipv6_src")
+ vm2 = STLScVmRaw([STLVmFlowVar(name="ipv6_src",
+ min_value=base_p2,
+ max_value=max_p2+base_p2,
+ size=8, op="inc"),
+ STLVmWrFlowVar(fv_name="ipv6_src",
+ pkt_offset="IPv6.src",
+ offset_fixup=8)
+ ]
+ , split_by_field="ipv6_src")
return create_streams_v46(base_pkt_a, base_pkt_b, vm1, vm2, frame_size)
+def fmt_latency(lat_min, lat_avg, lat_max):
+ """ Return formatted, rounded latency
+
+ :param lat_min: Min latency
+ :param lat_avg: Average latency
+ :param lat_max: Max latency
+ :type lat_min: string
+ :type lat_avg: string
+ :type lat_max: string
+ :return: Formatted and rounded output "min/avg/max"
+ :rtype: string
+ """
+
+ try:
+ t_min = int(round(float(lat_min)))
+ except ValueError:
+ t_min = int(-1)
+ try:
+ t_avg = int(round(float(lat_avg)))
+ except ValueError:
+ t_avg = int(-1)
+ try:
+ t_max = int(round(float(lat_max)))
+ except ValueError:
+ t_max = int(-1)
+
+ return "/".join(str(tmp) for tmp in (t_min, t_avg, t_max))
+
def simple_burst(stream_a, stream_b, stream_lat_a, stream_lat_b, duration, rate,
warmup_time, async_start, latency):
"""Run the traffic with specific parameters.
total_sent = 0
lost_a = 0
lost_b = 0
- lat_a = 'NA'
- lat_b = 'NA'
+ lat_a = "-1/-1/-1"
+ lat_b = "-1/-1/-1"
try:
# turn this off if too many logs
client.add_streams(stream_b, ports=[1])
if latency:
- client.add_streams(stream_lat_a, ports=[0])
- client.add_streams(stream_lat_b, ports=[1])
+ try:
+ client.add_streams(stream_lat_a, ports=[0])
+ client.add_streams(stream_lat_b, ports=[1])
+ except:
+ #Disable latency if NIC does not support requested stream type
+ print "##### FAILED to add latency streams #####"
+ latency = False
#warmup phase
if warmup_time > 0:
if client.get_warnings():
for warning in client.get_warnings():
- print_error(warning)
+ print(warning)
# read the stats after the test
stats = client.get_stats()
if client.get_warnings():
for warning in client.get_warnings():
- print_error(warning)
+ print(warning)
# read the stats after the test
stats = client.get_stats()
lost_b = stats[1]["opackets"] - stats[0]["ipackets"]
if latency:
- lat_a = "/".join((\
+ lat_a = fmt_latency(\
str(stats["latency"][0]["latency"]["total_min"]),\
str(stats["latency"][0]["latency"]["average"]),\
- str(stats["latency"][0]["latency"]["total_max"])))
- lat_b = "/".join((\
+ str(stats["latency"][0]["latency"]["total_max"]))
+ lat_b = fmt_latency(\
str(stats["latency"][1]["latency"]["total_min"]),\
str(stats["latency"][1]["latency"]["average"]),\
- str(stats["latency"][1]["latency"]["total_max"])))
+ str(stats["latency"][1]["latency"]["total_max"]))
total_sent = stats[0]["opackets"] + stats[1]["opackets"]
total_rcvd = stats[0]["ipackets"] + stats[1]["ipackets"]
# 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", required=True,
+ parser.add_argument("--p1_src_end_ip",
+ default=False,
help="Port 1 source end IP address")
parser.add_argument("--p1_dst_start_ip", required=True,
help="Port 1 destination start IP address")
-# parser.add_argument("--p1_dst_end_ip",
-# help="Port 1 destination end IP address")
+ 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", required=True,
+ parser.add_argument("--p2_src_end_ip",
+ default=False,
help="Port 2 source end IP address")
parser.add_argument("--p2_dst_start_ip", required=True,
help="Port 2 destination start IP address")
-# parser.add_argument("--p2_dst_end_ip",
-# help="Port 2 destination end IP address")
+ parser.add_argument("--p2_dst_end_ip",
+ 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()
_traffic_options[attr] = getattr(args, attr)
if _use_ipv6:
- # WARNING: Trex limitation to IPv4 only. IPv6 is not yet supported.
- print_error('IPv6 latency is not supported yet. Running without lat.')
- _latency = False
-
stream_a, stream_b, stream_lat_a, stream_lat_b = create_streams_v6(
_traffic_options, frame_size=_frame_size)
else: