aboutsummaryrefslogtreecommitdiffstats
path: root/tools/pkt_gen/trex/trex_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pkt_gen/trex/trex_client.py')
-rw-r--r--tools/pkt_gen/trex/trex_client.py86
1 files changed, 79 insertions, 7 deletions
diff --git a/tools/pkt_gen/trex/trex_client.py b/tools/pkt_gen/trex/trex_client.py
index 3d6836d8..680497ec 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):
"""
@@ -130,7 +136,15 @@ class Trex(ITrafficGenerator):
else:
raise RuntimeError('T-Rex: Trex host not defined')
- ping = subprocess.Popen(cmd_ping, shell=True, stderr=subprocess.PIPE)
+ if settings.getValue('CLEAN_OUTPUT'):
+ ping = subprocess.Popen(cmd_ping,
+ shell=True,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.PIPE)
+ else:
+ ping = subprocess.Popen(cmd_ping,
+ shell=True,
+ stderr=subprocess.PIPE)
output, error = ping.communicate()
if ping.returncode:
@@ -146,9 +160,16 @@ class Trex(ITrafficGenerator):
self._trex_base_dir + "t-rex-64"
- find_trex = subprocess.Popen(cmd_find_trex,
- shell=True,
- stderr=subprocess.PIPE)
+ if settings.getValue('CLEAN_OUTPUT'):
+ find_trex = subprocess.Popen(cmd_find_trex,
+ shell=True,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.PIPE)
+ else:
+ find_trex = subprocess.Popen(cmd_find_trex,
+ shell=True,
+ stderr=subprocess.PIPE)
+
output, error = find_trex.communicate()
if find_trex.returncode:
@@ -159,8 +180,12 @@ class Trex(ITrafficGenerator):
% (self._trex_host_ip_addr, self._trex_base_dir))
try:
- self._stlclient = STLClient(username=self._trex_user, server=self._trex_host_ip_addr,
- verbose_level='info')
+ if settings.getValue('CLEAN_OUTPUT'):
+ self._stlclient = STLClient(username=self._trex_user, server=self._trex_host_ip_addr,
+ verbose_level='error')
+ else:
+ self._stlclient = STLClient(username=self._trex_user, server=self._trex_host_ip_addr,
+ verbose_level='info')
self._stlclient.connect()
except STLError:
raise RuntimeError('T-Rex: Cannot connect to T-Rex server. Please check if it is '
@@ -386,7 +411,8 @@ class Trex(ITrafficGenerator):
self._stlclient.set_port_attr(my_ports, promiscuous=True)
packet_1, packet_2 = self.create_packets(traffic, ports_info)
- self.show_packet_info(packet_1, packet_2)
+ if not settings.getValue('CLEAN_OUTPUT'):
+ self.show_packet_info(packet_1, packet_2)
stream_1, stream_2, stream_1_lat, stream_2_lat = Trex.create_streams(packet_1, packet_2, traffic)
self._stlclient.add_streams(stream_1, ports=[0])
self._stlclient.add_streams(stream_2, ports=[1])
@@ -564,6 +590,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 +663,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 +675,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 +716,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):