From 12cb7cba45c1c6475075156c968787696af325e2 Mon Sep 17 00:00:00 2001 From: Kacper0199 Date: Wed, 16 Aug 2023 13:17:54 +0200 Subject: [PATCH] iperf3 inheritance iperf2 changes --- moler/cmd/unix/iperf3.py | 96 +--------------------------------------- 1 file changed, 2 insertions(+), 94 deletions(-) diff --git a/moler/cmd/unix/iperf3.py b/moler/cmd/unix/iperf3.py index 644eef689..c55c7eb61 100644 --- a/moler/cmd/unix/iperf3.py +++ b/moler/cmd/unix/iperf3.py @@ -18,14 +18,13 @@ import re -from moler.cmd.unix.genericunix import GenericUnixCommand +from moler.cmd.unix.iperf2 import Iperf2 from moler.util.converterhelper import ConverterHelper from moler.exceptions import CommandFailure from moler.exceptions import ParsingDone -from moler.publisher import Publisher -class Iperf3(GenericUnixCommand, Publisher): +class Iperf3(Iperf2): """ Run iperf3 command, return its statistics and report. @@ -118,36 +117,12 @@ def build_command_string(self): cmd = "iperf3 " + str(self.options) return cmd - @property - def protocol(self): - if any([self.options.startswith("-u"), " -u" in self.options, "--udp" in self.options]): - return "udp" - return "tcp" - - @property - def client(self): - return ("-c " in self.options) or ("--client " in self.options) - - @property - def server(self): - return any([self.options.startswith("-s"), - " -s" in self.options, - "--server" in self.options]) - @property def parallel_client(self): if self.client: return ("-P " in self.options) or ("--parallel " in self.options) return len(self._connection_dict.keys()) > 1 - @property - def singlerun_server(self): - singlerun_param_nonlast = ("-P 1 " in self.options) or ( - "--parallel 1 " in self.options) - singlerun_param_as_last = self.options.endswith( - "-P 1") or self.options.endswith("--parallel 1") - return singlerun_param_nonlast or singlerun_param_as_last - def on_new_line(self, line, is_full_line): if is_full_line: try: @@ -161,18 +136,6 @@ def on_new_line(self, line, is_full_line): pass return super(Iperf3, self).on_new_line(line, is_full_line) - def _process_line_from_command(self, current_chunk, line, is_full_line): - decoded_line = self._decode_line(line=line) - if self._is_replicated_cmd_echo(line): - return - self.on_new_line(line=decoded_line, is_full_line=is_full_line) - - def _is_replicated_cmd_echo(self, line): - prompt_and_command = r"{}\s*{}".format( - self._re_prompt.pattern, self.command_string) - found_echo = self._regex_helper.search(prompt_and_command, line) - return found_echo is not None - def subscribe(self, subscriber): """ Subscribe for notifications about iperf3 statistic as it comes. @@ -211,24 +174,6 @@ def is_end_of_cmd_output(self, line): else: return super(Iperf3, self).is_end_of_cmd_output(line) - def on_inactivity(self): - """ - Call when no data is received on connection within self.life_status.inactivity_timeout seconds. - - :return: None - """ - if self._stopping_server and (not self.done()): - self.break_cmd() - - def _schedule_delayed_break(self, delay): - self.life_status.inactivity_timeout = 1.0 # will activate on_inactivity() - - def _stop_server(self): - if not self._stopping_server: - if not self.singlerun_server: - self._schedule_delayed_break(delay=1.0) - self._stopping_server = True - _re_command_failure = re.compile( r"(?P.*failed.*|.*error.*|.*command not found.*|.*iperf:.*)") @@ -298,12 +243,6 @@ def _parse_headers(self, line): server,) raise ParsingDone - def _split_connection_name(self, connection_name): - client, server = connection_name - client_port, client_host = client.split("@") - server_port, server_host = server.split("@") - return client_host, client_port, server_host, server_port - # tcp server: # [ ID] Interval Transfer Bitrate # [ 5] 0.00-1.00 sec 2.56 GBytes 22.0 Gbits/sec @@ -378,19 +317,6 @@ def _parse_connection_info(self, line): raise ParsingDone - @staticmethod - def _detailed_parse_interval(iperf_record): - start, end = iperf_record["Interval"].split("-") - iperf_record["Interval"] = (float(start), float(end)) - return iperf_record - - @staticmethod - def _detailed_parse_datagrams(iperf_record): - if "Lost_vs_Total_Datagrams" in iperf_record: - lost, total = iperf_record["Lost_vs_Total_Datagrams"].split("/") - iperf_record["Lost_vs_Total_Datagrams"] = (int(lost), int(total)) - return iperf_record - @staticmethod def _convert_datagrams_parameter(iperf_record): if "Total_Datagrams" in iperf_record: @@ -404,24 +330,6 @@ def _convert_retr_parameter(iperf_record): iperf_record["Retr"] = int(iperf_record["Retr"]) return iperf_record - def _update_current_ret(self, connection_name, info_dict): - if connection_name in self.current_ret["CONNECTIONS"]: - self.current_ret["CONNECTIONS"][connection_name].append(info_dict) - else: - connection_dict = {connection_name: [info_dict]} - self.current_ret["CONNECTIONS"].update(connection_dict) - - def _all_multiport_records_of_interval(self, connection_name): - client, server = connection_name - client_port, client_host = client.split("@") - last_interval = self.current_ret["CONNECTIONS"][connection_name][-1]["Interval"] - for conn_name in self._same_host_connections[client_host]: - if conn_name not in self.current_ret["CONNECTIONS"]: - return False - if not self._get_last_record_of_interval(conn_name, last_interval): - return False - return True - def _get_last_record_of_interval(self, connection_name, interval): last_rec = self.current_ret["CONNECTIONS"][connection_name][-1] if last_rec["Interval"] == interval: