+ :raises RuntimeError: If stop traffic script fails.
+ """
+ # No need to check subtype, we know it is TREX.
+ command_line = OptionString().add(u"python3")
+ dirname = f"{Constants.REMOTE_FW_DIR}/GPL/tools/trex"
+ command_line.add(f"'{dirname}/trex_stateless_stop.py'")
+ command_line.change_prefix(u"--")
+ for index, value in enumerate(self._xstats):
+ if value is not None:
+ value = value.replace(u"'", u"\"")
+ command_line.add_equals(f"xstat{index}", f"'{value}'")
+ stdout, _ = exec_cmd_no_error(
+ node, command_line, message=u"TRex stateless runtime error"
+ )
+ self._parse_traffic_results(stdout)
+
+ def trex_stl_start_remote_exec(
+ self, duration, rate, frame_size, traffic_profile, async_call=False,
+ latency=True, warmup_time=5.0, traffic_directions=2, tx_port=0,
+ rx_port=1):
+ """Execute script on remote node over ssh to start traffic.
+
+ In sync mode, measurement results are stored internally.
+ In async mode, initial data including xstats are stored internally.
+
+ :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 GPL/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 traffic_directions: Traffic is bi- (2) or uni- (1) directional.
+ Default: 2
+ :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 traffic_directions: int
+ :type tx_port: int
+ :type rx_port: int
+ :raises RuntimeError: In case of TG driver issue.
+ """
+ # No need to check subtype, we know it is TREX.
+ 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)
+ if not isinstance(duration, (float, int)):
+ duration = float(duration)
+ if not isinstance(warmup_time, (float, int)):
+ warmup_time = float(warmup_time)
+
+ command_line = OptionString().add(u"python3")
+ dirname = f"{Constants.REMOTE_FW_DIR}/GPL/tools/trex"
+ command_line.add(f"'{dirname}/trex_stateless_profile.py'")
+ command_line.change_prefix(u"--")
+ dirname = f"{Constants.REMOTE_FW_DIR}/GPL/traffic_profiles/trex"
+ quoted_path = f"'{dirname}/{traffic_profile}.py'"
+ command_line.add_with_value(u"profile", quoted_path)
+ command_line.add_with_value(u"duration", f"{duration!r}")
+ command_line.add_with_value(u"frame_size", frame_size)
+ command_line.add_with_value(u"rate", f"{rate!r}")
+ command_line.add_with_value(u"warmup_time", f"{warmup_time!r}")
+ command_line.add_with_value(u"port_0", p_0)
+ command_line.add_with_value(u"port_1", p_1)
+ command_line.add_with_value(u"traffic_directions", traffic_directions)
+ command_line.add_if(u"async_start", async_call)
+ command_line.add_if(u"latency", latency)
+ command_line.add_if(u"force", Constants.TREX_SEND_FORCE)
+
+ stdout, _ = exec_cmd_no_error(
+ self._node, command_line, timeout=float(duration) + 60,
+ message=u"TRex stateless runtime error"
+ )
+
+ self.traffic_directions = traffic_directions
+ if async_call:
+ # no result
+ self._start_time = time.time()
+ self._rate = float(rate[:-3]) if u"pps" in rate else float(rate)
+ self._received = None
+ self._sent = None
+ self._loss = None
+ self._latency = None
+ xstats = [None, None]
+ index = 0
+ for line in stdout.splitlines():
+ if f"Xstats snapshot {index}: " in line:
+ xstats[index] = line[19:]
+ index += 1
+ if index == 2:
+ break
+ self._xstats = tuple(xstats)
+ else:
+ self._parse_traffic_results(stdout)
+ self._start_time = None
+ self._rate = None
+
+ def stop_traffic_on_tg(self):
+ """Stop all traffic on TG.
+
+ :returns: Structure containing the result of the measurement.
+ :rtype: ReceiveRateMeasurement
+ :raises RuntimeError: If TG is not set.
+ """
+ subtype = check_subtype(self._node)
+ if subtype == NodeSubTypeTG.TREX:
+ self.trex_stl_stop_remote_exec(self._node)
+ return self.get_measurement_result()
+
+ def send_traffic_on_tg(
+ self, duration, rate, frame_size, traffic_profile, warmup_time=5,
+ async_call=False, latency=True, traffic_directions=2, tx_port=0,
+ rx_port=1):
+ """Send traffic from all configured interfaces on TG.
+
+ In async mode, xstats is stored internally,
+ to enable getting correct result when stopping the traffic.
+ In both modes, stdout is returned,
+ but _parse_traffic_results only works in sync output.
+
+ 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 GPL/traffic_profiles/trex for implemented modules.
+ :param warmup_time: Warmup phase in seconds.
+ :param async_call: Async mode.
+ :param latency: With latency measurement.
+ :param traffic_directions: Traffic is bi- (2) or uni- (1) directional.
+ Default: 2
+ :param tx_port: Traffic generator transmit port for first flow.
+ Default: 0
+ :param rx_port: Traffic generator receive port for first flow.
+ Default: 1