+ "sh -c 'sudo pkill t-rex && sleep 3'")
+ if int(ret) != 0:
+ logger.error('pkill t-rex failed: {0}'.format(stdout + stderr))
+ raise RuntimeError('pkill t-rex failed')
+
+ @staticmethod
+ def trex_stl_stop_remote_exec(node):
+ """Execute script on remote node over ssh to stop running traffic.
+
+ :param node: T-REX generator node.
+ :type node: dict
+ :returns: Nothing
+ :raises: RuntimeError if stop traffic script fails.
+ """
+ ssh = SSH()
+ ssh.connect(node)
+
+ (ret, _, _) = ssh.exec_command(
+ "sh -c '{}/resources/tools/trex/"
+ "trex_stateless_stop.py'".format(Constants.REMOTE_FW_DIR))
+
+ if int(ret) != 0:
+ raise RuntimeError('T-rex stateless runtime error')
+
+ def trex_stl_start_remote_exec(self, duration, rate, framesize,
+ traffic_type, async_call=False,
+ latency=True, warmup_time=5):
+ """Execute script on remote node over ssh to start traffic.
+
+ :param duration: Time expresed in seconds for how long to send traffic.
+ :param rate: Traffic rate expressed with units (pps, %)
+ :param framesize: L2 frame size to send (without padding and IPG).
+ :param traffic_type: Traffic profile.
+ :param async_call: If enabled then don't wait for all incomming trafic.
+ :param latency: With latency measurement.
+ :param warmup_time: Warmup time period.
+ :type duration: int
+ :type rate: str
+ :type framesize: str
+ :type traffic_type: str
+ :type async_call: bool
+ :type latency: bool
+ :type warmup_time: int
+ :returns: Nothing
+ :raises: RuntimeError in case of TG driver issue.
+ """
+ ssh = SSH()
+ ssh.connect(self._node)
+
+ _async = "--async" if async_call else ""
+ _latency = "--latency" if latency else ""
+ _p0, _p1 = (2, 1) if self._ifaces_reordered else (1, 2)
+
+ profile_path = ("{0}/resources/traffic_profiles/trex/"
+ "{1}.py".format(Constants.REMOTE_FW_DIR,
+ traffic_type))
+ (ret, stdout, _) = ssh.exec_command(
+ "sh -c "
+ "'{0}/resources/tools/trex/trex_stateless_profile.py "
+ "--profile {1} "
+ "--duration {2} "
+ "--frame_size {3} "
+ "--rate {4} "
+ "--warmup_time {5} "
+ "--port_0 {6} "
+ "--port_1 {7} "
+ "{8} " # --async
+ "{9}'". # --latency
+ format(Constants.REMOTE_FW_DIR, profile_path, duration, framesize,
+ rate, warmup_time, _p0 - 1, _p1 - 1, _async, _latency),
+ timeout=int(duration) + 60)
+
+ if int(ret) != 0:
+ raise RuntimeError('T-rex stateless runtime error')
+ elif async_call:
+ #no result
+ self._received = None
+ self._sent = None
+ self._loss = None
+ self._latency = None
+ else:
+ # last line from console output
+ line = stdout.splitlines()[-1]
+
+ self._result = line
+ logger.info('TrafficGen result: {0}'.format(self._result))
+
+ self._received = self._result.split(', ')[1].split('=')[1]
+ self._sent = self._result.split(', ')[2].split('=')[1]
+ self._loss = self._result.split(', ')[3].split('=')[1]
+
+ self._latency = []
+ self._latency.append(self._result.split(', ')[4].split('=')[1])
+ self._latency.append(self._result.split(', ')[5].split('=')[1])
+
+ def stop_traffic_on_tg(self):
+ """Stop all traffic on TG.
+
+ :returns: Nothing
+ :raises: RuntimeError if TG is not set.
+ """
+ if self._node is None:
+ raise RuntimeError("TG is not set")
+ if self._node['subtype'] == NodeSubTypeTG.TREX:
+ self.trex_stl_stop_remote_exec(self._node)
+
+ def send_traffic_on_tg(self, duration, rate, framesize,
+ traffic_type, warmup_time=5, async_call=False,
+ latency=True):
+ """Send traffic from all configured interfaces on TG.
+
+ :param duration: Duration of test traffic generation in seconds.
+ :param rate: Offered load per interface (e.g. 1%, 3gbps, 4mpps, ...).
+ :param framesize: Frame size (L2) in Bytes.
+ :param traffic_type: Traffic profile.
+ :param warmup_time: Warmup phase in seconds.
+ :param async_call: Async mode.
+ :param latency: With latency measurement.