X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FTrafficGenerator.py;h=4da1c8766f8738c1b341cda4b0a806a9803fc505;hp=698b67ead24c5b46a15a2ba8e69349fa6f656c7a;hb=4c6fe5602edcbd9857a846e5b13a21d5c671a2c8;hpb=45393e98c3162faaa2fdc86ef471798a8e4bb5f2 diff --git a/resources/libraries/python/TrafficGenerator.py b/resources/libraries/python/TrafficGenerator.py index 698b67ead2..4da1c8766f 100644 --- a/resources/libraries/python/TrafficGenerator.py +++ b/resources/libraries/python/TrafficGenerator.py @@ -33,7 +33,7 @@ class TGDropRateSearchImpl(DropRateSearch): super(TGDropRateSearchImpl, self).__init__() def measure_loss(self, rate, frame_size, loss_acceptance, - loss_acceptance_type, traffic_type): + loss_acceptance_type, traffic_type, skip_warmup=False): """Runs the traffic and evaluate the measured results. :param rate: Offered traffic load. @@ -41,15 +41,17 @@ class TGDropRateSearchImpl(DropRateSearch): :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], ...). + :param skip_warmup: Start TRex without warmup traffic if true. :type rate: int :type frame_size: str :type loss_acceptance: float :type loss_acceptance_type: LossAcceptanceType :type traffic_type: str + :type skip_warmup: bool :returns: Drop threshold exceeded? (True/False) :rtype: bool - :raises: NotImplementedError if TG is not supported. - :raises: RuntimeError if TG is not specified. + :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-*() @@ -60,9 +62,15 @@ class TGDropRateSearchImpl(DropRateSearch): 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) + if skip_warmup: + tg_instance.trex_stl_start_remote_exec(self.get_duration(), + unit_rate, frame_size, + traffic_type, + warmup_time=0) + else: + 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(): @@ -174,7 +182,7 @@ class TrafficGenerator(object): :type tg_if1_dst_mac: str :type tg_if2_dst_mac: str :returns: nothing - :raises: RuntimeError in case of issue during initialization. + :raises RuntimeError: In case of issue during initialization. """ if tg_node['type'] != NodeType.TG: raise RuntimeError('Node type is not a TG') @@ -307,6 +315,24 @@ class TrafficGenerator(object): # critical error occurred raise RuntimeError('t-rex-64 startup failed') + @staticmethod + def is_trex_running(node): + """Check if TRex is running using pidof. + + :param node: Traffic generator node. + :type node: dict + :returns: True if TRex is running otherwise False. + :rtype: bool + :raises RuntimeError: If node type is not a TG. + """ + if node['type'] != NodeType.TG: + raise RuntimeError('Node type is not a TG') + + ssh = SSH() + ssh.connect(node) + ret, _, _ = ssh.exec_command_sudo("pidof t-rex") + return bool(int(ret) == 0) + @staticmethod def teardown_traffic_generator(node): """TG teardown. @@ -314,8 +340,8 @@ class TrafficGenerator(object): :param node: Traffic generator node. :type node: dict :returns: nothing - :raises: RuntimeError if TRex teardown failed. - :raises: RuntimeError if node type is not a TG. + :raises RuntimeError: If node type is not a TG, + or if TRex teardown fails. """ if node['type'] != NodeType.TG: raise RuntimeError('Node type is not a TG') @@ -334,7 +360,7 @@ class TrafficGenerator(object): :param node: TRex generator node. :type node: dict :returns: Nothing - :raises: RuntimeError if stop traffic script fails. + :raises RuntimeError: If stop traffic script fails. """ ssh = SSH() ssh.connect(node) @@ -366,7 +392,7 @@ class TrafficGenerator(object): :type latency: bool :type warmup_time: int :returns: Nothing - :raises: RuntimeError in case of TG driver issue. + :raises RuntimeError: In case of TG driver issue. """ ssh = SSH() ssh.connect(self._node) @@ -421,7 +447,7 @@ class TrafficGenerator(object): """Stop all traffic on TG. :returns: Nothing - :raises: RuntimeError if TG is not set. + :raises RuntimeError: If TG is not set. """ if self._node is None: raise RuntimeError("TG is not set") @@ -449,9 +475,9 @@ class TrafficGenerator(object): :type latency: bool :returns: TG output. :rtype: str - :raises: RuntimeError if TG is not set. - :raises: RuntimeError if node is not TG or subtype is not specified. - :raises: NotImplementedError if TG is not supported. + :raises RuntimeError: If TG is not set, or if node is not TG, + or if subtype is not specified. + :raises NotImplementedError: If TG is not supported. """ node = self._node @@ -476,7 +502,7 @@ class TrafficGenerator(object): """Fail if loss occurred in traffic run. :returns: nothing - :raises: Exception if loss occured. + :raises Exception: If loss occured. """ if self._loss is None: raise Exception('The traffic generation has not been issued') @@ -492,7 +518,7 @@ class TrafficGenerator(object): :type loss_acceptance: float :type loss_acceptance_type: LossAcceptanceType :returns: nothing - :raises: Exception if loss is above acceptance criteria. + :raises Exception: If loss is above acceptance criteria. """ if self._loss is None: raise Exception('The traffic generation has not been issued')