summaryrefslogtreecommitdiffstats
path: root/scripts/automation
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-12-18 20:11:31 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2016-12-19 11:23:48 +0200
commit5cfeb192a3ff47c5cacc21abe20db2f61a66dd2b (patch)
tree57a455e70d9ac9c453495f4929ac9fac5b9fb011 /scripts/automation
parentcc4bd93b660505a7c9d8e370a1220377907fa6d2 (diff)
changes from code review
Change-Id: I628608643d902bd6310b04b8036fc5f1fcc42309 Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
Diffstat (limited to 'scripts/automation')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py36
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py55
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py9
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py20
4 files changed, 48 insertions, 72 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
index 2aa0450d..a42247e7 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
@@ -2509,7 +2509,8 @@ class STLClient(object):
Ports on which to execute the command
ipg_usec : float
- Inter-packet gap in microseconds
+ Inter-packet gap in microseconds.
+ Exclusive with min_ipg_usec
speedup : float
A factor to adjust IPG. effectively IPG = IPG / speedup
@@ -2528,6 +2529,7 @@ class STLClient(object):
min_ipg_usec : float
Minimum inter-packet gap in microseconds to guard from too small ipg.
+ Exclusive with ipg_usec
:raises:
+ :exc:`STLError`
@@ -2596,7 +2598,8 @@ class STLClient(object):
Ports on which to execute the command
ipg_usec : float
- Inter-packet gap in microseconds
+ Inter-packet gap in microseconds.
+ Exclusive with min_ipg_usec
speedup : float
A factor to adjust IPG. effectively IPG = IPG / speedup
@@ -2624,6 +2627,7 @@ class STLClient(object):
min_ipg_usec : float
Minimum inter-packet gap in microseconds to guard from too small ipg.
+ Exclusive with ipg_usec
:raises:
+ :exc:`STLError`
@@ -2640,6 +2644,8 @@ class STLClient(object):
validate_type('vm', vm, (list, type(None)))
validate_type('is_dual', is_dual, bool)
validate_type('min_ipg_usec', min_ipg_usec, (float, int, type(None)))
+ if all([ipg_usec, min_ipg_usec]):
+ raise STLError('Please specify either ipg or minimal ipg, not both.')
# no support for > 1MB PCAP - use push remote
@@ -3696,24 +3702,24 @@ class STLClient(object):
if opts.remote:
self.push_remote(opts.file[0],
- ports = opts.ports,
- ipg_usec = opts.ipg_usec,
+ ports = opts.ports,
+ ipg_usec = opts.ipg_usec,
min_ipg_usec = opts.min_ipg_usec,
- speedup = opts.speedup,
- count = opts.count,
- duration = opts.duration,
- is_dual = opts.dual)
+ speedup = opts.speedup,
+ count = opts.count,
+ duration = opts.duration,
+ is_dual = opts.dual)
else:
self.push_pcap(opts.file[0],
- ports = opts.ports,
- ipg_usec = opts.ipg_usec,
+ ports = opts.ports,
+ ipg_usec = opts.ipg_usec,
min_ipg_usec = opts.min_ipg_usec,
- speedup = opts.speedup,
- count = opts.count,
- duration = opts.duration,
- force = opts.force,
- is_dual = opts.dual)
+ speedup = opts.speedup,
+ count = opts.count,
+ duration = opts.duration,
+ force = opts.force,
+ is_dual = opts.dual)
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
index 3bce671a..26613e56 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
@@ -1028,6 +1028,11 @@ class STLProfile(object):
# check filename
if not os.path.isfile(pcap_file):
raise STLError("file '{0}' does not exists".format(pcap_file))
+ if speedup <= 0:
+ raise STLError('Speedup should not be negative.')
+ if min_ipg_usec and min_ipg_usec < 0:
+ raise STLError('min_ipg_usec should not be negative.')
+
# make sure IPG is not less than 0.001 usec
if (ipg_usec is not None and (ipg_usec < 0.001 * speedup) and
@@ -1092,34 +1097,24 @@ class STLProfile(object):
def __pkts_to_streams (pkts, ipg_usec, min_ipg_usec, speedup, loop_count, vm, packet_hook, start_delay_usec = 0):
streams = []
- if speedup == 0:
- raise STLError('Speedup should not be 0')
- if min_ipg_usec and min_ipg_usec < 0:
- raise STLError('min_ipg_usec should not be negative.')
-
if packet_hook:
pkts = [(packet_hook(cap), meta) for (cap, meta) in pkts]
- if ipg_usec == None:
- constant_diff = None
- else:
- constant_diff = ipg_usec / float(speedup)
- if min_ipg_usec is not None:
- constant_diff = max(constant_diff, min_ipg_usec)
-
for i, (cap, meta) in enumerate(pkts, start = 1):
# IPG - if not provided, take from cap
- if constant_diff is None:
+ if ipg_usec is None:
packet_time = meta[0] * 1e6 + meta[1]
if i == 1:
- isg = min_ipg_usec if min_ipg_usec else 0
- else:
- isg = (packet_time - prev_time) / float(speedup)
- if min_ipg_usec:
- isg = max(isg, min_ipg_usec)
+ prev_time = packet_time
+ isg = (packet_time - prev_time) / float(speedup)
+ if min_ipg_usec and isg < min_ipg_usec:
+ isg = min_ipg_usec
prev_time = packet_time
- else:
- isg = constant_diff
+ else: # user specified ipg
+ if min_ipg_usec:
+ isg = min_ipg_usec
+ else:
+ isg = ipg_usec / float(speedup)
# handle last packet
if i == len(pkts):
@@ -1128,28 +1123,12 @@ class STLProfile(object):
else:
next = i + 1
action_count = 0
- self_start = False if i != 1 else True
-
- # add stream with delay that will not be part of loop: "delayed_start" -> 1 -> 2 -> 3 -> ... -> 1 -> 2
- if start_delay_usec and i == 1:
- if loop_count == 1: # no loop actually
- isg = start_delay_usec
- else:
- streams.append(STLStream(name = 'delayed_start',
- packet = STLPktBuilder(pkt_buffer = cap, vm = vm),
- mode = STLTXSingleBurst(total_pkts = 1, percentage = 100),
- self_start = True,
- isg = start_delay_usec,
- action_count = action_count,
- next = next))
- action_count = max(0, action_count - 1)
- self_start = False
streams.append(STLStream(name = i,
packet = STLPktBuilder(pkt_buffer = cap, vm = vm),
mode = STLTXSingleBurst(total_pkts = 1, percentage = 100),
- self_start = self_start,
- isg = isg,
+ self_start = True if (i == 1) else False,
+ isg = isg, # usec
action_count = action_count,
next = next))
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 5ae3cb27..a60a7ede 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
@@ -60,11 +60,10 @@ class RC():
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'))
+ for x in filter(len, listify(self.err())):
+ err_count += 1
+ if len(err_list) < show_count:
+ err_list.append(format_text(x, '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')
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py
index 6c5dd2c3..63b05bf4 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py
@@ -131,21 +131,13 @@ def yellow(text):
def underline(text):
return text_attribute(text, 'underline')
-
-start_end_newlines = re.compile('^(\n)*([^\n].*[^\n])?(\n)*$', re.DOTALL)
+# apply attribute on each non-empty line
def text_attribute(text, attribute):
- 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)
+ return '\n'.join(['{start}{txt}{end}'.format(
+ start = TEXT_CODES[attribute]['start'],
+ txt = line,
+ end = TEXT_CODES[attribute]['end'])
+ if line else '' for line in ('%s' % text).split('\n')])
FUNC_DICT = {'blue': blue,