+ (ret, _, _) = ssh.exec_command(
+ "sh -c 'sudo pkill t-rex && sleep 3'")
+ if int(ret) != 0:
+ 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: TRex 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('TRex stateless runtime error')
+
+ def trex_stl_start_remote_exec(
+ self, duration, rate, frame_size, traffic_profile, async_call=False,
+ latency=True, warmup_time=5.0, unidirection=False, tx_port=0,
+ rx_port=1):
+ """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 frame_size: L2 frame size to send (without padding and IPG).
+ :param traffic_profile: Module name as a traffic profile identifier.
+ See resources/traffic_profiles/trex for implemented modules.
+ :param async_call: If enabled then don't wait for all incomming trafic.
+ :param latency: With latency measurement.
+ :param warmup_time: Warmup time period.
+ :param unidirection: Traffic is unidirectional. Default: False
+ :param tx_port: Traffic generator transmit port for first flow.
+ Default: 0
+ :param rx_port: Traffic generator receive port for first flow.
+ Default: 1
+ :type duration: float
+ :type rate: str
+ :type frame_size: str
+ :type traffic_profile: str
+ :type async_call: bool
+ :type latency: bool
+ :type warmup_time: float
+ :type unidirection: bool
+ :type tx_port: int
+ :type rx_port: int
+ :raises RuntimeError: In case of TG driver issue.
+ """
+ ssh = SSH()
+ ssh.connect(self._node)
+ reorder = self._ifaces_reordered # Just to make the next line fit.
+ p_0, p_1 = (rx_port, tx_port) if reorder else (tx_port, rx_port)
+ # Values from Robot can introduce type unicode,
+ # we need to encode them, so that repr() does not lead with 'u'.
+ if isinstance(rate, unicode):
+ rate = rate.encode("utf-8")
+ if isinstance(duration, unicode):
+ duration = duration.encode("utf-8")
+ if isinstance(warmup_time, unicode):
+ warmup_time = warmup_time.encode("utf-8")
+ command = (
+ "sh -c '{tool}/resources/tools/trex/trex_stateless_profile.py"
+ " --profile {prof}/resources/traffic_profiles/trex/{traffic}.py"
+ " --duration {duration!r} --frame_size {frame_size} --rate {rate!r}"
+ " --warmup_time {warmup!r} --port_0 {p_0} --port_1 {p_1}").format(
+ tool=Constants.REMOTE_FW_DIR, prof=Constants.REMOTE_FW_DIR,
+ traffic=traffic_profile, duration=duration,
+ frame_size=frame_size, rate=rate, warmup=warmup_time, p_0=p_0,
+ p_1=p_1)
+ if async_call:
+ command += " --async"
+ if latency:
+ command += " --latency"
+ if unidirection:
+ command += " --unidirection"
+ command += "'"
+
+ (ret, stdout, _) = ssh.exec_command(
+ command, timeout=float(duration) + 60)
+
+ if int(ret) != 0:
+ raise RuntimeError('TRex 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, frame_size, traffic_profile, warmup_time=5,
+ async_call=False, latency=True, unidirection=False, tx_port=0,
+ rx_port=1):
+ """Send traffic from all configured interfaces on TG.
+
+ Note that bidirectional traffic also contains flows
+ transmitted from rx_port and received in tx_port.
+ But some tests use asymmetric traffic, so those arguments are relevant.
+
+ Also note that traffic generator uses DPDK driver which might
+ reorder port numbers based on wiring and PCI numbering.
+ This method handles that, so argument values are invariant,
+ but you can see swapped valued in debug logs.
+
+ TODO: Is it better to have less descriptive argument names
+ just to make them less probable to be viewed as misleading or confusing?
+ See https://gerrit.fd.io/r/#/c/17625/11/resources/libraries/python\
+ /TrafficGenerator.py@406
+
+ :param duration: Duration of test traffic generation in seconds.
+ :param rate: Offered load per interface (e.g. 1%, 3gbps, 4mpps, ...).
+ :param frame_size: Frame size (L2) in Bytes.
+ :param traffic_profile: Module name as a traffic profile identifier.
+ See resources/traffic_profiles/trex for implemented modules.
+ :param warmup_time: Warmup phase in seconds.
+ :param async_call: Async mode.
+ :param latency: With latency measurement.
+ :param unidirection: Traffic is unidirectional. Default: False
+ :param tx_port: Traffic generator transmit port for first flow.
+ Default: 0
+ :param rx_port: Traffic generator receive port for first flow.
+ Default: 1