+from resources.libraries.python.DropRateSearch import DropRateSearch
+
+__all__ = ['TrafficGenerator', 'TGDropRateSearchImpl']
+
+
+class TGDropRateSearchImpl(DropRateSearch):
+ """Drop Rate Search implementation."""
+
+ def __init__(self):
+ super(TGDropRateSearchImpl, self).__init__()
+
+ def measure_loss(self, rate, frame_size, loss_acceptance,
+ loss_acceptance_type, traffic_type):
+ """Runs the traffic and evaluate the measured results.
+
+ :param rate: Offered traffic load.
+ :param frame_size: Size of frame.
+ :param loss_acceptance: Permitted drop ratio or frames count.
+ :param loss_acceptance_type: Type of permitted loss.
+ :param traffic_type: Traffic profile ([2,3]-node-L[2,3], ...).
+ :type rate: int
+ :type frame_size: str
+ :type loss_acceptance: float
+ :type loss_acceptance_type: LossAcceptanceType
+ :type traffic_type: str
+ :returns: Drop threshold exceeded? (True/False)
+ :rtype: bool
+ :raises: NotImplementedError if TG is not supported.
+ :raises: RuntimeError if TG is not specified.
+ """
+ # we need instance of TrafficGenerator instantiated by Robot Framework
+ # to be able to use trex_stl-*()
+ tg_instance = BuiltIn().get_library_instance(
+ 'resources.libraries.python.TrafficGenerator')
+
+ if tg_instance.node['subtype'] is None:
+ raise RuntimeError('TG subtype not defined')
+ elif tg_instance.node['subtype'] == NodeSubTypeTG.TREX:
+ unit_rate = str(rate) + self.get_rate_type_str()
+ tg_instance.trex_stl_start_remote_exec(self.get_duration(),
+ unit_rate, frame_size,
+ traffic_type)
+ loss = tg_instance.get_loss()
+ sent = tg_instance.get_sent()
+ if self.loss_acceptance_type_is_percentage():
+ loss = (float(loss) / float(sent)) * 100
+
+ logger.trace("comparing: {} < {} {}".format(loss,
+ loss_acceptance,
+ loss_acceptance_type))
+ if float(loss) > float(loss_acceptance):
+ return False
+ else:
+ return True
+ else:
+ raise NotImplementedError("TG subtype not supported")
+
+ def get_latency(self):
+ """Returns min/avg/max latency.
+
+ :returns: Latency stats.
+ :rtype: list
+ """
+ tg_instance = BuiltIn().get_library_instance(
+ 'resources.libraries.python.TrafficGenerator')
+ return tg_instance.get_latency_int()