aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/DropRateSearch.py43
-rw-r--r--resources/libraries/python/TrafficGenerator.py61
2 files changed, 98 insertions, 6 deletions
diff --git a/resources/libraries/python/DropRateSearch.py b/resources/libraries/python/DropRateSearch.py
index 8f8e371add..1f8e5618fe 100644
--- a/resources/libraries/python/DropRateSearch.py
+++ b/resources/libraries/python/DropRateSearch.py
@@ -135,6 +135,49 @@ class DropRateSearch(object):
self._rate_max = float(max_rate)
self._rate_min = float(min_rate)
+ def set_loss_acceptance(self, loss_acceptance):
+ """Set loss acceptance treshold for PDR search.
+
+ :param loss_acceptance: Loss acceptance treshold for PDR search.
+ :type loss_acceptance: str
+ :return: nothing
+ """
+ if float(loss_acceptance) < 0:
+ raise ValueError("Loss acceptance must be higher or equal 0")
+ else:
+ self._loss_acceptance = float(loss_acceptance)
+
+ def get_loss_acceptance(self):
+ """Return configured loss acceptance treshold.
+
+ :return: Loss acceptance treshold.
+ :rtype: float
+ """
+ return self._loss_acceptance
+
+ def set_loss_acceptance_type_percentage(self):
+ """Set loss acceptance treshold type to percentage.
+
+ :return: nothing
+ """
+ self._loss_acceptance_type = LossAcceptanceType.PERCENTAGE
+
+ def set_loss_acceptance_type_frames(self):
+ """Set loss acceptance treshold type to frames.
+
+ :return: nothing
+ """
+ self._loss_acceptance_type = LossAcceptanceType.FRAMES
+
+ def loss_acceptance_type_is_percentage(self):
+ """Return true if loss acceptance treshold type is percentage,
+ false otherwise.
+
+ :return: True if loss acceptance treshold type is percentage.
+ :rtype: boolean
+ """
+ return self._loss_acceptance_type == LossAcceptanceType.PERCENTAGE
+
def set_search_linear_step(self, step_rate):
"""Set step size for linear search.
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))