1) limit number of streams per port to 20k 15/5315/1
authorYaroslav Brustinov <[email protected]>
Mon, 12 Dec 2016 15:38:43 +0000 (17:38 +0200)
committerYaroslav Brustinov <[email protected]>
Mon, 19 Dec 2016 09:23:48 +0000 (11:23 +0200)
2) fix showing error in TUI
3) represensation of STLError: show only errors if error, limit by 10 entries

Change-Id: Ib8de9222e7fc09dd67275283857d0d7e9cb5988c
Signed-off-by: Yaroslav Brustinov <[email protected]>
scripts/automation/trex_control_plane/stl/console/trex_tui.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py
src/stateless/cp/trex_stateless_port.cpp

index bf6ed16..37ef800 100644 (file)
@@ -1153,7 +1153,7 @@ class AsyncKeysEngineConsole:
                 # errors
                 else:
                     err_msgs = ascii_split(str(func_rc))
-                    self.last_status = format_text(err_msgs[0], 'red')
+                    self.last_status = format_text(clear_formatting(err_msgs[0]), 'red')
                     if len(err_msgs) > 1:
                         self.last_status += " [{0} more errors messages]".format(len(err_msgs) - 1)
                     color = 'red'
index 964acce..2aa0450 100755 (executable)
@@ -15,6 +15,7 @@ from .utils import parsing_opts, text_tables, common
 from .utils.common import *
 from .utils.text_opts import *
 from functools import wraps
+from texttable import ansi_len
 
 from collections import namedtuple
 from yaml import YAMLError
@@ -2025,7 +2026,6 @@ class STLClient(object):
 
     @__api_check(True)
     def get_xstats(self, port_id):
-        print(port_id)
         """
             Get extended stats of port: all the counters as dict.
 
@@ -3407,9 +3407,8 @@ class STLClient(object):
                 self.add_streams(profile.get_streams(), ports = port)
 
         except STLError as e:
-            error = 'Unknown error.'
-            for line in e.brief().split('\n'):
-                if line:
+            for line in e.brief().splitlines():
+                if ansi_len(line.strip()):
                     error = line
             msg = format_text("\nError loading profile '{0}'".format(opts.file[0]), 'bold')
             self.logger.log(msg + '\n')
index 81015dd..5ae3cb2 100644 (file)
@@ -50,11 +50,26 @@ class RC():
         return (e if len(e) != 1 else e[0])
 
     def __str__ (self):
-        s = ""
-        for x in self.rc_list:
-            if x.data:
-                s += format_text("\n{0}".format(x.data), 'bold')
-        return s
+        if self.good():
+            s = ""
+            for x in self.rc_list:
+                if x.data:
+                    s += format_text("\n{0}".format(x.data), 'bold')
+            return s
+        else:
+            show_count = 10
+            err_list = []
+            err_count = 0
+            for x in self.rc_list:
+                if x.data and not x.rc:
+                    err_count += 1
+                    if len(err_list) < show_count:
+                        err_list.append(format_text(x.data, 'bold'))
+            s = '\n' if len(err_list) > 1 else ''
+            if err_count > show_count:
+                s += format_text('Occurred %s errors, showing first %s:\n' % (err_count, show_count), 'bold')
+            s += '\n'.join(err_list)
+            return s
 
     def __iter__(self):
         return self.rc_list.__iter__()
index bfb9695..6c5dd2c 100644 (file)
@@ -27,6 +27,9 @@ class TextCodesStripper:
     def strip (s):
         return re.sub(TextCodesStripper.pattern, '', s)
 
+def clear_formatting(s):
+    return TextCodesStripper.strip(s)
+
 def format_num (size, suffix = "", compact = True, opts = None):
     if opts is None:
         opts = ()
@@ -129,10 +132,20 @@ def underline(text):
     return text_attribute(text, 'underline')
 
 
+start_end_newlines = re.compile('^(\n)*([^\n].*[^\n])?(\n)*$', re.DOTALL)
 def text_attribute(text, attribute):
-    return "{start}{txt}{stop}".format(start=TEXT_CODES[attribute]['start'],
-                                       txt=text,
-                                       stop=TEXT_CODES[attribute]['end'])
+    match = start_end_newlines.match(text)
+    try:
+        startpad, msg, endpad = match.groups('')
+    except:
+        startpad = endpad = ''
+        msg = text
+    return "{startpad}{startattr}{txt}{endattr}{endpad}".format(
+                startpad = startpad,
+                startattr = TEXT_CODES[attribute]['start'],
+                txt = msg,
+                endattr = TEXT_CODES[attribute]['end'],
+                endpad = endpad)
 
 
 FUNC_DICT = {'blue': blue,
index 97f60dd..170098a 100644 (file)
@@ -909,6 +909,9 @@ TrexStatelessPort::add_stream(TrexStream *stream) {
 
     verify_state(PORT_STATE_IDLE | PORT_STATE_STREAMS, "add_stream");
 
+    if (m_stream_table.size() >= 20000) {
+        throw TrexException("Reached limit of 20k streams at the port.");
+    }
     get_stateless_obj()->m_rx_flow_stat.add_stream(stream);
 
     m_stream_table.add_stream(stream);