X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Ftools%2Ftrex%2Ftrex_stateless_profile.py;h=b888bcdea9f07332bcf31e64f75c04d596581ee1;hb=43e969af97832930a122aca538ef271e714838b5;hp=2837778f7a98c7941c7b2a2a7ada29fe702223a6;hpb=4fa06bcfa9ef951b9062ddfc85ce58dcb742bcf7;p=csit.git diff --git a/resources/tools/trex/trex_stateless_profile.py b/resources/tools/trex/trex_stateless_profile.py index 2837778f7a..b888bcdea9 100755 --- a/resources/tools/trex/trex_stateless_profile.py +++ b/resources/tools/trex/trex_stateless_profile.py @@ -18,26 +18,28 @@ the profile and sends the traffic. At the end, it measures the packet loss and latency. """ -import sys import argparse import json +import sys sys.path.insert(0, "/opt/trex-core-2.61/scripts/automation/" "trex_control_plane/interactive/") from trex.stl.api import * -def fmt_latency(lat_min, lat_avg, lat_max): +def fmt_latency(lat_min, lat_avg, lat_max, hdrh): """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 + :param hdrh: Base64 encoded compressed HDRHistogram object. + :type lat_min: str + :type lat_avg: str + :type lat_max: str + :type hdrh: str + :return: Formatted and rounded output (hdrh unchanged) "min/avg/max/hdrh". + :rtype: str """ try: t_min = int(round(float(lat_min))) @@ -52,7 +54,7 @@ def fmt_latency(lat_min, lat_avg, lat_max): except ValueError: t_max = int(-1) - return "/".join(str(tmp) for tmp in (t_min, t_avg, t_max)) + return "/".join(str(tmp) for tmp in (t_min, t_avg, t_max, hdrh)) def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, @@ -100,8 +102,8 @@ def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, total_sent = 0 lost_a = 0 lost_b = 0 - lat_a = "-1/-1/-1" - lat_b = "-1/-1/-1" + lat_a = "-1/-1/-1/" + lat_b = "-1/-1/-1/" # Read the profile: try: @@ -186,7 +188,14 @@ def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, # Choose rate and start traffic: client.start(ports=ports, mult=rate, duration=duration) - if not async_start: + if async_start: + # For async stop, we need to export the current snapshot. + xsnap0 = client.ports[0].get_xstats().reference_stats + print("Xstats snapshot 0: {s!r}".format(s=xsnap0)) + if traffic_directions > 1: + xsnap1 = client.ports[1].get_xstats().reference_stats + print("Xstats snapshot 1: {s!r}".format(s=xsnap1)) + else: # Block until done: client.wait_on_traffic(ports=ports, timeout=duration+30) @@ -207,15 +216,15 @@ def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, # Stats index is not a port number, but "pgid". # TODO: Find out what "pgid" means. if latency: + lat_obj = stats["latency"][0]["latency"] lat_a = fmt_latency( - str(stats["latency"][0]["latency"]["total_min"]), - str(stats["latency"][0]["latency"]["average"]), - str(stats["latency"][0]["latency"]["total_max"])) + str(lat_obj["total_min"]), str(lat_obj["average"]), + str(lat_obj["total_max"]), str(lat_obj["hdrh"])) if traffic_directions > 1: + lat_obj = stats["latency"][1]["latency"] 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(lat_obj["total_min"]), str(lat_obj["average"]), + str(lat_obj["total_max"]), str(lat_obj["hdrh"])) if traffic_directions > 1: total_sent = stats[0]["opackets"] + stats[1]["opackets"] @@ -228,7 +237,7 @@ def simple_burst(profile_file, duration, framesize, rate, warmup_time, port_0, p_0=port_0, p_1=port_1, v=lost_a)) if traffic_directions > 1: print("packets lost from {p_1} --> {p_0}: {v} pkts".format( - p_0=port_0, p_1=port_1, v=lost_b)) + p_0=port_0, p_1=port_1, v=lost_b)) except STLError as ex_error: print(ex_error, file=sys.stderr) @@ -281,7 +290,7 @@ def main(): required=True, type=int, help="Port 1 on the traffic generator.") - parser.add_argument("--async", + parser.add_argument("--async_start", action="store_true", default=False, help="Non-blocking call of the script.") @@ -309,7 +318,7 @@ def main(): port_0=args.port_0, port_1=args.port_1, latency=args.latency, - async_start=args.async, + async_start=args.async_start, traffic_directions=args.traffic_directions)