summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-07-25 15:21:30 +0300
committerimarom <imarom@cisco.com>2016-07-25 15:22:32 +0300
commite3b43560ff867c35ee726da9a98aed8acdc53b70 (patch)
tree5faac3264630830368ed1e58c4302abb1148c4f3 /scripts
parent34a4ff7b92ee7cc09e38f599d83d9fdf1fa3a8bc (diff)
TRex console - add support for L1 BPS
https://trex-tgn.cisco.com/youtrack/issue/trex-230
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py92
1 files changed, 44 insertions, 48 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
index 8be154af..af7e90c1 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
@@ -96,78 +96,74 @@ match_multiplier_help = """Multiplier should be passed in the following format:
# value should be divided
def decode_multiplier(val, allow_update = False, divide_count = 1):
+ factor_table = {None: 1, 'k': 1e3, 'm': 1e6, 'g': 1e9}
+ pattern = "^(\d+(\.\d+)?)(((k|m|g)?(bpsl1|pps|bps))|%)?"
+
# do we allow updates ? +/-
if not allow_update:
- match = re.match("^(\d+(\.\d+)?)(bps|kbps|mbps|gbps|pps|kpps|mpps|%?)$", val)
+ pattern += "$"
+ match = re.match(pattern, val)
op = None
else:
- match = re.match("^(\d+(\.\d+)?)(bps|kbps|mbps|gbps|pps|kpps|mpps|%?)([\+\-])?$", val)
+ pattern += "([\+\-])?$"
+ match = re.match(pattern, val)
if match:
- op = match.group(4)
+ op = match.group(7)
else:
op = None
result = {}
- if match:
-
- value = float(match.group(1))
- unit = match.group(3)
-
+ if not match:
+ return None
-
- # raw type (factor)
- if not unit:
- result['type'] = 'raw'
- result['value'] = value
+ # value in group 1
+ value = float(match.group(1))
- elif unit == 'bps':
- result['type'] = 'bps'
- result['value'] = value
+ # decode unit as whole
+ unit = match.group(3)
- elif unit == 'kbps':
- result['type'] = 'bps'
- result['value'] = value * 1000
+ # k,m,g
+ factor = match.group(5)
- elif unit == 'mbps':
- result['type'] = 'bps'
- result['value'] = value * 1000 * 1000
+ # type of multiplier
+ m_type = match.group(6)
- elif unit == 'gbps':
- result['type'] = 'bps'
- result['value'] = value * 1000 * 1000 * 1000
+ # raw type (factor)
+ if not unit:
+ result['type'] = 'raw'
+ result['value'] = value
- elif unit == 'pps':
- result['type'] = 'pps'
- result['value'] = value
+ # percentage
+ elif unit == '%':
+ result['type'] = 'percentage'
+ result['value'] = value
- elif unit == "kpps":
- result['type'] = 'pps'
- result['value'] = value * 1000
+ elif m_type == 'bps':
+ result['type'] = 'bps'
+ result['value'] = value * factor_table[factor]
- elif unit == "mpps":
- result['type'] = 'pps'
- result['value'] = value * 1000 * 1000
+ elif m_type == 'pps':
+ result['type'] = 'pps'
+ result['value'] = value * factor_table[factor]
- elif unit == "%":
- result['type'] = 'percentage'
- result['value'] = value
+ elif m_type == 'bpsl1':
+ result['type'] = 'bpsl1'
+ result['value'] = value * factor_table[factor]
- if op == "+":
- result['op'] = "add"
- elif op == "-":
- result['op'] = "sub"
- else:
- result['op'] = "abs"
+ if op == "+":
+ result['op'] = "add"
+ elif op == "-":
+ result['op'] = "sub"
+ else:
+ result['op'] = "abs"
- if result['op'] != 'percentage':
- result['value'] = result['value'] / divide_count
+ if result['op'] != 'percentage':
+ result['value'] = result['value'] / divide_count
- return result
+ return result
- else:
- return None
def match_multiplier(val):