-#!/usr/bin/python
+#!/usr/bin/python3
# Copyright (c) 2019 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
latency.
"""
-import sys
import argparse
import json
+import sys
sys.path.insert(0, "/opt/trex-core-2.54/scripts/automation/"
"trex_control_plane/interactive/")
:return: Formatted and rounded output "min/avg/max"
:rtype: string
"""
-
try:
t_min = int(round(float(lat_min)))
except ValueError:
:type async_start: bool
:type unidirection: bool
"""
-
client = None
total_rcvd = 0
total_sent = 0
client.remove_all_streams(ports=[port_0, port_1])
if "macsrc" in profile_file:
- client.set_port_attr(ports=[port_0, port_1], promiscuous=True,
- resolve=False)
+ client.set_port_attr(ports=[port_0, port_1], promiscuous=True)
if isinstance(framesize, int):
client.add_streams(streams[0], ports=[port_0])
if not unidirection:
stats = client.get_stats()
print("##### Warmup statistics #####")
- print(json.dumps(stats, indent=4, separators=(',', ': '),
- sort_keys=True))
+ print(json.dumps(stats, indent=4, separators=(',', ': ')))
lost_a = stats[port_0]["opackets"] - stats[port_1]["ipackets"]
if not unidirection:
# 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 not unidirection:
+ 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)
stats = client.get_stats()
print("##### Statistics #####")
- print(json.dumps(stats, indent=4, separators=(',', ': '),
- sort_keys=True))
+ print(json.dumps(stats, indent=4, separators=(',', ': ')))
lost_a = stats[port_0]["opackets"] - stats[port_1]["ipackets"]
if not unidirection:
p_0=port_0, p_1=port_1, v=lost_a))
if not unidirection:
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 err:
- sys.stderr.write("{0}\n".format(err))
+ except STLError as ex_error:
+ print(ex_error, file=sys.stderr)
sys.exit(1)
finally:
else:
if client:
client.disconnect()
- if isinstance(rate, unicode):
- rate = rate.encode("utf-8")
- if isinstance(duration, unicode):
- duration = duration.encode("utf-8")
print("rate={0!r}, totalReceived={1}, totalSent={2}, "
"frameLoss={3}, latencyStream0(usec)={4}, "
"latencyStream1(usec)={5}, targetDuration={d!r}".
It verifies the given command line arguments and runs "simple_burst"
function.
"""
-
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--profile",
required=True,
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.")
port_0=args.port_0,
port_1=args.port_1,
latency=args.latency,
- async_start=args.async,
+ async_start=args.async_start,
unidirection=args.unidirection)