aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/TrafficGenerator.py
diff options
context:
space:
mode:
authorPeter Mikus <pmikus@cisco.com>2016-05-13 09:57:03 +0200
committerPeter Mikus <pmikus@cisco.com>2016-05-26 15:13:04 +0200
commitf94e16167519c74707ec8b606da3f7b97c749c66 (patch)
tree91ac71037bce4bd1e0ce9a52e67802e2c0f808a7 /resources/libraries/python/TrafficGenerator.py
parent52913516a16429a0ec6573260cf946223c84f34d (diff)
Find PDR using binary search
- JIRA: CSIT-72 - modify libraries for PDR search evaluation - write robot framework keywords for PDR search - write Performance Test Cases using PDR Change-Id: Id06a2a7f78fe8626c221afe4178c5c30cc599762 Signed-off-by: Peter Mikus <pmikus@cisco.com>
Diffstat (limited to 'resources/libraries/python/TrafficGenerator.py')
-rw-r--r--resources/libraries/python/TrafficGenerator.py61
1 files changed, 55 insertions, 6 deletions
diff --git a/resources/libraries/python/TrafficGenerator.py b/resources/libraries/python/TrafficGenerator.py
index 3969891cf9..5dab8b98d5 100644
--- a/resources/libraries/python/TrafficGenerator.py
+++ b/resources/libraries/python/TrafficGenerator.py
@@ -46,11 +46,16 @@ class TGDropRateSearchImpl(DropRateSearch):
tg_instance.trex_stl_start_remote_exec(self.get_duration(),
unit_rate, frame_size,
traffic_type, False)
-
- # TODO: getters for tg_instance and loss_acceptance_type
- logger.trace("comparing: {} < {} ".format(tg_instance._loss,
- loss_acceptance))
- if float(tg_instance._loss) > float(loss_acceptance):
+ loss = tg_instance.get_loss()
+ sent = tg_instance.get_sent()
+ if self.loss_acceptance_type_is_percentage():
+ loss = (float(loss) / float(sent)) * 100
+
+ # TODO: getters for tg_instance
+ logger.trace("comparing: {} < {} {}".format(loss,
+ loss_acceptance,
+ loss_acceptance_type))
+ if float(loss) > float(loss_acceptance):
return False
else:
return True
@@ -73,6 +78,30 @@ class TrafficGenerator(object):
# T-REX interface order mapping
self._ifaces_reordered = 0
+ def get_loss(self):
+ """Return number of lost packets.
+
+ :return: Number of lost packets.
+ :rtype: str
+ """
+ return self._loss
+
+ def get_sent(self):
+ """Return number of sent packets.
+
+ :return: Number of sent packets.
+ :rtype: str
+ """
+ return self._sent
+
+ def get_received(self):
+ """Return number of received packets.
+
+ :return: Number of received packets.
+ :rtype: str
+ """
+ return self._received
+
#pylint: disable=too-many-arguments, too-many-locals
def initialize_traffic_generator(self, tg_node, tg_if1, tg_if2,
dut1_node, dut1_if1, dut1_if2,
@@ -361,7 +390,7 @@ class TrafficGenerator(object):
return self._result
def no_traffic_loss_occurred(self):
- """Fail is loss occurred in traffic run.
+ """Fail if loss occurred in traffic run.
:return: nothing
"""
@@ -369,3 +398,23 @@ class TrafficGenerator(object):
raise Exception('The traffic generation has not been issued')
if self._loss != '0':
raise Exception('Traffic loss occurred: {0}'.format(self._loss))
+
+ def partial_traffic_loss_accepted(self, loss_acceptance,
+ loss_acceptance_type):
+ """Fail if loss is higher then accepted in traffic run.
+
+ :return: nothing
+ """
+ if self._loss is None:
+ raise Exception('The traffic generation has not been issued')
+
+ if loss_acceptance_type == 'percentage':
+ loss = (float(self._loss) / float(self._sent)) * 100
+ elif loss_acceptance_type == 'frames':
+ loss = float(self._loss)
+ else:
+ raise Exception('Loss acceptance type not supported')
+
+ if loss > float(loss_acceptance):
+ raise Exception("Traffic loss {} above loss acceptance: {}".format(
+ loss, loss_acceptance))