diff options
Diffstat (limited to 'scripts/automation/trex_control_plane/console/parsing_opts.py')
-rwxr-xr-x | scripts/automation/trex_control_plane/console/parsing_opts.py | 89 |
1 files changed, 58 insertions, 31 deletions
diff --git a/scripts/automation/trex_control_plane/console/parsing_opts.py b/scripts/automation/trex_control_plane/console/parsing_opts.py index 0bcdce84..d7bf583a 100755 --- a/scripts/automation/trex_control_plane/console/parsing_opts.py +++ b/scripts/automation/trex_control_plane/console/parsing_opts.py @@ -10,16 +10,17 @@ ArgumentGroup = namedtuple('ArgumentGroup', ['type', 'args', 'options']) # list of available parsing options MULTIPLIER = 1 -PORT_LIST = 2 -ALL_PORTS = 3 -PORT_LIST_WITH_ALL = 4 -FILE_PATH = 5 -FILE_FROM_DB = 6 -SERVER_IP = 7 -STREAM_FROM_PATH_OR_FILE = 8 -DURATION = 9 -FORCE = 10 -TOTAL = 11 +MULTIPLIER_STRICT = 2 +PORT_LIST = 3 +ALL_PORTS = 4 +PORT_LIST_WITH_ALL = 5 +FILE_PATH = 6 +FILE_FROM_DB = 7 +SERVER_IP = 8 +STREAM_FROM_PATH_OR_FILE = 9 +DURATION = 10 +FORCE = 11 +TOTAL = 12 # list of ArgumentGroup types MUTEX = 1 @@ -54,10 +55,15 @@ match_multiplier_help = """Multiplier should be passed in the following format: will provide a percentage of the line rate. examples : '-m 10', '-m 10kbps', '-m 10mpps', '-m 23%%' """ -def match_multiplier(val): - '''match some val against multiplier shortcut inputs ''' +def match_multiplier_common(val, strict_abs = True): - match = re.match("^(\d+(\.\d+)?)(bps|kbps|mbps|gbps|pps|kpps|mpps|%?)$", val) + # on strict absolute we do not allow +/- + if strict_abs: + match = re.match("^(\d+(\.\d+)?)(bps|kbps|mbps|gbps|pps|kpps|mpps|%?)$", val) + op = None + else: + match = re.match("^(\d+(\.\d+)?)(bps|kbps|mbps|gbps|pps|kpps|mpps|%?)([\+\-])?$", val) + op = match.group(4) result = {} @@ -65,44 +71,53 @@ def match_multiplier(val): value = float(match.group(1)) unit = match.group(3) + + # raw type (factor) if not unit: result['type'] = 'raw' - result['max'] = value + result['value'] = value elif unit == 'bps': - result['type'] = 'max_bps' - result['max'] = value + result['type'] = 'bps' + result['value'] = value elif unit == 'kbps': - result['type'] = 'max_bps' - result['max'] = value * 1000 + result['type'] = 'bps' + result['value'] = value * 1000 elif unit == 'mbps': - result['type'] = 'max_bps' - result['max'] = value * 1000 * 1000 + result['type'] = 'bps' + result['value'] = value * 1000 * 1000 elif unit == 'gbps': - result['type'] = 'max_bps' - result['max'] = value * 1000 * 1000 * 1000 + result['type'] = 'bps' + result['value'] = value * 1000 * 1000 * 1000 elif unit == 'pps': - result['type'] = 'max_pps' - result['max'] = value + result['type'] = 'pps' + result['value'] = value elif unit == "kpps": - result['type'] = 'max_pps' - result['max'] = value * 1000 + result['type'] = 'pps' + result['value'] = value * 1000 elif unit == "mpps": - result['type'] = 'max_pps' - result['max'] = value * 1000 * 1000 + result['type'] = 'pps' + result['value'] = value * 1000 * 1000 elif unit == "%": - # will be translated by the port object result['type'] = 'percentage' - result['max'] = value + result['value'] = value + + + if op == "+": + result['op'] = "add" + elif op == "-": + result['op'] = "sub" + else: + result['op'] = "abs" return result @@ -110,6 +125,13 @@ def match_multiplier(val): raise argparse.ArgumentTypeError(match_multiplier_help) +def match_multiplier(val): + '''match some val against multiplier shortcut inputs ''' + return match_multiplier_common(val, strict_abs = False) + +def match_multiplier_strict(val): + '''match some val against multiplier shortcut inputs ''' + return match_multiplier_common(val, strict_abs = True) def is_valid_file(filename): if not os.path.isfile(filename): @@ -121,9 +143,14 @@ def is_valid_file(filename): OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'], {'help': match_multiplier_help, 'dest': "mult", - 'default': {'type':'raw', 'max':1}, + 'default': {'type':'raw', 'value':1, 'op': 'abs'}, 'type': match_multiplier}), + MULTIPLIER_STRICT: ArgumentPack(['-m', '--multiplier'], + {'help': match_multiplier_help, + 'dest': "mult", + 'default': {'type':'raw', 'value':1, 'op': 'abs'}, + 'type': match_multiplier_strict}), TOTAL: ArgumentPack(['-t', '--total'], {'help': "traffic will be divided between all ports specified", |