summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-04-14 17:23:04 +0300
committerYaroslav Brustinov <ybrustin@cisco.com>2016-04-14 17:23:04 +0300
commit501fb3b44f14e9c0d40a63bd8b47200b01e50be9 (patch)
treea45a01a5d0e724282f83df5b419916afd6784ca6 /scripts/automation/trex_control_plane
parente0720b15ec9dc695a8c1799e87cbe41a670cb616 (diff)
regression: python3 support
Diffstat (limited to 'scripts/automation/trex_control_plane')
-rwxr-xr-xscripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py15
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py15
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py26
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py11
4 files changed, 43 insertions, 24 deletions
diff --git a/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py
index 9ca13e17..4fd1e4c7 100755
--- a/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py
+++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py
@@ -592,7 +592,10 @@ class CTRexClient(object):
"""
try:
- return binascii.a2b_base64(self.server.get_trex_daemon_log())
+ res = binascii.a2b_base64(self.server.get_trex_daemon_log())
+ if type(res) is bytes:
+ return res.decode()
+ return res
except AppError as err:
self._handle_AppError_exception(err.args[0])
except ProtocolError:
@@ -613,7 +616,10 @@ class CTRexClient(object):
"""
try:
- return binascii.a2b_base64(self.server.get_trex_log())
+ res = binascii.a2b_base64(self.server.get_trex_log())
+ if type(res) is bytes:
+ return res.decode()
+ return res
except AppError as err:
self._handle_AppError_exception(err.args[0])
except ProtocolError:
@@ -636,7 +642,10 @@ class CTRexClient(object):
try:
version_dict = OrderedDict()
- result_lines = binascii.a2b_base64(self.server.get_trex_version()).split('\n')
+ res = binascii.a2b_base64(self.server.get_trex_version())
+ if type(res) is bytes:
+ res = res.decode()
+ result_lines = res.split('\n')
for line in result_lines:
if not line:
continue
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
index 9518852f..45f3dd45 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
@@ -172,23 +172,12 @@ import sys
import os
import socket
import copy
-from collections import defaultdict, OrderedDict
+from collections import defaultdict
from .api import *
from .trex_stl_types import *
from .utils.common import get_number
-class LRU_cache(OrderedDict):
- def __init__(self, maxlen = 20, *args, **kwargs):
- OrderedDict.__init__(self, *args, **kwargs)
- self.maxlen = maxlen
-
- def __setitem__(self, *args, **kwargs):
- OrderedDict.__setitem__(self, *args, **kwargs)
- if len(self) > self.maxlen:
- self.popitem(last = False)
-
-
class HLT_ERR(dict):
def __init__(self, log = 'Unknown error', **kwargs):
dict.__init__(self, {'status': 0})
@@ -1078,7 +1067,7 @@ def generate_packet(**user_kwargs):
if ip_tos < 0 or ip_tos > 255:
raise STLError('TOS %s is not in range 0-255' % ip_tos)
l3_layer = IP(tos = ip_tos,
- len = kwargs['l3_length'],
+ #len = kwargs['l3_length'], don't let user create corrupt packets
id = kwargs['ip_id'],
frag = kwargs['ip_fragment_offset'],
ttl = kwargs['ip_ttl'],
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
index f0ac5c33..e182f5ea 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
@@ -200,7 +200,7 @@ class CTRexInfoGenerator(object):
@staticmethod
def _get_rational_block_char(value, range_start, interval):
# in Konsole, utf-8 is sometimes printed with artifacts, return ascii for now
- return 'X' if value >= range_start + float(interval) / 2 else ' '
+ #return 'X' if value >= range_start + float(interval) / 2 else ' '
value -= range_start
ratio = float(value) / interval
if ratio <= 0.0625:
@@ -225,8 +225,8 @@ class CTRexInfoGenerator(object):
relevant_port = self.__get_relevant_ports(port_id_list)[0]
hist_len = len(relevant_port.port_stats.history)
hist_maxlen = relevant_port.port_stats.history.maxlen
- util_tx_hist = [0] * (hist_maxlen - hist_len) + [round(relevant_port.port_stats.history[i]['m_percentage']) for i in range(hist_len)]
- util_rx_hist = [0] * (hist_maxlen - hist_len) + [round(relevant_port.port_stats.history[i]['m_rx_percentage']) for i in range(hist_len)]
+ util_tx_hist = [0] * (hist_maxlen - hist_len) + [round(relevant_port.port_stats.history[i]['tx_percentage']) for i in range(hist_len)]
+ util_rx_hist = [0] * (hist_maxlen - hist_len) + [round(relevant_port.port_stats.history[i]['rx_percentage']) for i in range(hist_len)]
stats_table = text_tables.TRexTextTable()
@@ -239,7 +239,7 @@ class CTRexInfoGenerator(object):
stats_table.add_row([y, ''.join([self._get_rational_block_char(util_tx, y, 5) for util_tx in util_tx_hist]),
''.join([self._get_rational_block_char(util_rx, y, 5) for util_rx in util_rx_hist])])
- return {"port_statistics": ExportableStats({}, stats_table)}
+ return {"port_graph": ExportableStats({}, stats_table)}
def _generate_port_stats(self, port_id_list):
relevant_ports = self.__get_relevant_ports(port_id_list)
@@ -414,7 +414,7 @@ class CTRexStats(object):
self.reference_stats = {}
self.latest_stats = {}
self.last_update_ts = time.time()
- self.history = deque(maxlen = 30)
+ self.history = deque(maxlen = 47)
self.lock = threading.Lock()
self.has_baseline = False
@@ -723,12 +723,24 @@ class CPortStats(CTRexStats):
pps = snapshot.get("m_total_tx_pps")
rx_bps = snapshot.get("m_total_rx_bps")
rx_pps = snapshot.get("m_total_rx_pps")
+ ts_diff = 0.5 # TODO: change this to real ts diff from server
bps_L1 = calc_bps_L1(bps, pps)
- rx_bps_L1 = calc_bps_L1(rx_bps, rx_pps)
+ bps_rx_L1 = calc_bps_L1(rx_bps, rx_pps)
snapshot['m_total_tx_bps_L1'] = bps_L1
snapshot['m_percentage'] = (bps_L1 / self._port_obj.get_speed_bps()) * 100
- snapshot['m_rx_percentage'] = (rx_bps_L1 / self._port_obj.get_speed_bps()) * 100
+
+ # TX line util not smoothed
+ diff_tx_pkts = snapshot.get('opackets', 0) - self.latest_stats.get('opackets', 0)
+ diff_tx_bytes = snapshot.get('obytes', 0) - self.latest_stats.get('obytes', 0)
+ tx_bps_L1 = calc_bps_L1(8.0 * diff_tx_bytes / ts_diff, float(diff_tx_pkts) / ts_diff)
+ snapshot['tx_percentage'] = 100.0 * tx_bps_L1 / self._port_obj.get_speed_bps()
+
+ # RX line util not smoothed
+ diff_rx_pkts = snapshot.get('ipackets', 0) - self.latest_stats.get('ipackets', 0)
+ diff_rx_bytes = snapshot.get('ibytes', 0) - self.latest_stats.get('ibytes', 0)
+ rx_bps_L1 = calc_bps_L1(8.0 * diff_rx_bytes / ts_diff, float(diff_rx_pkts) / ts_diff)
+ snapshot['rx_percentage'] = 100.0 * rx_bps_L1 / self._port_obj.get_speed_bps()
# simple...
self.latest_stats = snapshot
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py
index f6718fda..d84af22f 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py
@@ -1,5 +1,5 @@
-from collections import namedtuple
+from collections import namedtuple, OrderedDict
from .utils.text_opts import *
from .trex_stl_exceptions import *
import types
@@ -157,3 +157,12 @@ class StatNotAvailable(object):
def __cmp__(self, *args, **kwargs):
raise Exception("Stat '%s' not available at this setup" % self.stat_name)
+class LRU_cache(OrderedDict):
+ def __init__(self, maxlen = 20, *args, **kwargs):
+ OrderedDict.__init__(self, *args, **kwargs)
+ self.maxlen = maxlen
+
+ def __setitem__(self, *args, **kwargs):
+ OrderedDict.__setitem__(self, *args, **kwargs)
+ if len(self) > self.maxlen:
+ self.popitem(last = False)