summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/automation/trex_control_plane/client/trex_stateless_client.py19
-rwxr-xr-xscripts/automation/trex_control_plane/console/parsing_opts.py89
2 files changed, 62 insertions, 46 deletions
diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
index b3476268..c1dea9eb 100755
--- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
@@ -292,14 +292,6 @@ class Port(object):
def get_all_streams (self):
return self.streams
-
- def process_mul (self, mul):
- # if percentage - translate
- if mul['type'] == 'percentage':
- mul['type'] = 'max_bps'
- mul['max'] = self.get_speed_bps() * (mul['max'] / 100)
-
-
# start traffic
def start (self, mul, duration):
if self.state == self.STATE_DOWN:
@@ -311,8 +303,6 @@ class Port(object):
if self.state == self.STATE_TX:
return self.err("Unable to start traffic - port is already transmitting")
- self.process_mul(mul)
-
params = {"handler": self.handler,
"port_id": self.port_id,
"mul": mul,
@@ -385,8 +375,6 @@ class Port(object):
if (self.state != self.STATE_TX) :
return self.err("port is not transmitting")
- self.process_mul(mul)
-
params = {"handler": self.handler,
"port_id": self.port_id,
"mul": mul}
@@ -1018,13 +1006,14 @@ class CTRexStatelessClient(object):
parsing_opts.FORCE,
parsing_opts.STREAM_FROM_PATH_OR_FILE,
parsing_opts.DURATION,
- parsing_opts.MULTIPLIER)
+ parsing_opts.MULTIPLIER_STRICT)
opts = parser.parse_args(line.split())
if opts is None:
return RC_ERR("bad command line paramters")
+
if opts.db:
stream_list = self.stream_db.get_stream_pack(opts.db)
rc = RC(stream_list != None)
@@ -1044,7 +1033,7 @@ class CTRexStatelessClient(object):
# total has no meaning with percentage - its linear
if opts.total and (opts.mult['type'] != 'percentage'):
# if total was set - divide it between the ports
- opts.mult['max'] = opts.mult['max'] / len(opts.ports)
+ opts.mult['value'] = opts.mult['value'] / len(opts.ports)
return self.cmd_start(opts.ports, stream_list, opts.mult, opts.force, opts.duration)
@@ -1078,7 +1067,7 @@ class CTRexStatelessClient(object):
# total has no meaning with percentage - its linear
if opts.total and (opts.mult['type'] != 'percentage'):
# if total was set - divide it between the ports
- opts.mult['max'] = opts.mult['max'] / len(opts.ports)
+ opts.mult['value'] = opts.mult['value'] / len(opts.ports)
return self.cmd_update(opts.ports, opts.mult)
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",