aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSridhar K. N. Rao <sridhar.rao@spirent.com>2021-08-04 14:19:11 +0530
committerSridhar K. N. Rao <sridhar.rao@spirent.com>2021-08-25 19:18:45 +0530
commit40b2686a395cb5f9097139ba9503ab9193abc980 (patch)
tree87926feebd417f115f9615027ed5fc5c3595ad9a
parent220aed1de03317d1ad6f3ebbec9f6b93e44522c7 (diff)
Trex Per-Trial Bi-Directional Stats
This patch adds code to get stats for each trial for each port. Added changes suggested by AL 1. Include dropped packets 2. Include Latency values Added missing comma (thanks to Parth). Removed WIP Signed-off-by: Sridhar K. N. Rao <sridhar.rao@spirent.com> Change-Id: If760fbae2362c3f622c5517f5e53e159e31fccea
-rw-r--r--tools/pkt_gen/trex/trex_client.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/pkt_gen/trex/trex_client.py b/tools/pkt_gen/trex/trex_client.py
index 3d6836d8..ff9d5c79 100644
--- a/tools/pkt_gen/trex/trex_client.py
+++ b/tools/pkt_gen/trex/trex_client.py
@@ -85,6 +85,11 @@ _SCAPY_FRAME = {
'{IP_PROTO}(sport={IP_PROTO_dport}, dport={IP_PROTO_sport})',
}
+def cast_integer(value):
+ """
+ force 0 value if NaN value from TRex to avoid error in JSON result parsing
+ """
+ return int(value) if not isnan(value) else 0
class Trex(ITrafficGenerator):
"""Trex Traffic generator wrapper."""
@@ -103,6 +108,7 @@ class Trex(ITrafficGenerator):
self._stlclient = None
self._verification_params = None
self._show_packet_data = False
+ self.trial_results = []
def show_packet_info(self, packet_a, packet_b):
"""
@@ -564,6 +570,48 @@ class Trex(ITrafficGenerator):
result[ResultsConstants.CAPTURE_TX] = stats['capture_tx']
if 'capture_rx' in stats:
result[ResultsConstants.CAPTURE_RX] = stats['capture_rx']
+ # Write all per-trial results to a file
+ filec = os.path.join(settings.getValue('RESULTS_PATH'), 'trex_pertrial_results.csv')
+
+ ports = [0, 1]
+ with open(filec, 'a') as fcp:
+ fcp.write("frame_size,port,rx_pkts,tx_pkts,rx_bytes,tx_bytes,"+
+ "rx_pps,tx_pps,rx_bps,tx_bps,"+
+ "drp_pkts_d1,drp_pkts_d2,min1,avg1,max1,"+
+ "min2,avg2,max2\n")
+ for key in self.trial_results:
+ for port in ports:
+ stats = self.trial_results[key][port]
+ far_end_stats = self.trial_results[key][1 - port]
+ tx_pkts = stats['opackets']
+ rx_pkts = stats['ipackets']
+ tx_bytes = stats['obytes']
+ rx_bytes = stats['ibytes']
+ rx_pps = stats['rx_pps']
+ tx_pps = stats['tx_pps']
+ rx_bps = stats['rx_bps']
+ tx_bps = stats['tx_bps']
+ dr_pkts_d1 = (cast_integer(far_end_stats['0packets'])
+ - cast_integer(stats['ipackets']))
+ dr_pkts_d2 = (cast_integer(stats['0packets'])
+ - cast_integer(far_end_stats['ipackets']))
+ try:
+ min1 = float(stats["latency"][0]["latency"]["total_min"])
+ min2 = float(stats["latency"][1]["latency"]["total_min"])
+ max1 = float(stats["latency"][0]["latency"]["total_max"])
+ max2 = float(stats["latency"][1]["latency"]["total_max"])
+ avg1 = float(stats["latency"][0]["latency"]["average"])
+ avg2 = float(stats["latency"][1]["latency"]["average"])
+ except TypeError:
+ min1,min2,max1,max2,avg1,avg2 = -1.0
+
+ fcp.write("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17}\n".format(
+ key,port,rx_pkts,tx_pkts,rx_bytes,
+ tx_bytes,rx_pps,tx_pps,rx_bps,tx_bps,
+ dr_pkts_d1, dr_pkts_d2, min1, avg1, max1,
+ min2, avg2, max2))
+
+
return result
def learning_packets(self, traffic):
@@ -595,6 +643,7 @@ class Trex(ITrafficGenerator):
"""
threshold = settings.getValue('TRAFFICGEN_TREX_RFC2544_TPUT_THRESHOLD')
max_repeat = settings.getValue('TRAFFICGEN_TREX_RFC2544_MAX_REPEAT')
+ frame_size = traffic['l2']['framesize']
loss_verification = settings.getValue('TRAFFICGEN_TREX_RFC2544_BINARY_SEARCH_LOSS_VERIFICATION')
if loss_verification:
self._logger.info("Running Binary Search with Loss Verification")
@@ -606,8 +655,10 @@ class Trex(ITrafficGenerator):
right = boundaries['right']
center = boundaries['center']
self._logger.info('Starting RFC2544 trials')
+ results = []
while (right - left) > threshold:
stats = self.generate_traffic(new_params, duration)
+ results.append(copy.deepcopy(stats))
test_lossrate = ((stats["total"]["opackets"] - stats[
"total"]["ipackets"]) * 100) / stats["total"]["opackets"]
if stats["total"]["ipackets"] == 0:
@@ -645,6 +696,7 @@ class Trex(ITrafficGenerator):
new_params = copy.deepcopy(traffic)
new_params['frame_rate'] = center
iteration += 1
+ self.trial_results[frame_size] = results
return stats_ok
def send_cont_traffic(self, traffic=None, duration=30):