def setup_udp_flows(dependency, flow, destination_nodes): """ Setup iperf3 to run udp flows Parameters ---------- dependency: int whether iperf3 is installed flow: Flow Flow parameters destination_nodes: Destination nodes so far already running iperf3 server Returns ------- dependency: int updated dependency in case iproute2 is not installed iperf3_runners: List[NetperfRunner] all the iperf3 udp flows generated workers: List[multiprocessing.Process] Processes to run iperf3 udp flows """ iperf3_runners = [] if not dependency: logger.warning("Iperf3 not found. Udp flows cannot be generated") else: # Get flow attributes [ src_ns, dst_ns, dst_addr, start_t, stop_t, n_flows, options, ] = flow._get_props() # pylint: disable=protected-access # Run iperf3 server if not already run before on given dst_node if dst_ns not in destination_nodes: Iperf3Runner.run_server(dst_ns) src_name = TopologyMap.get_namespace(src_ns)["name"] f_flow = "flow" if n_flows == 1 else "flows" logger.info( "Running %s udp %s from %s to %s...", n_flows, f_flow, src_name, dst_addr ) runner_obj = Iperf3Runner( src_ns, dst_addr, options["target_bw"], n_flows, start_t, stop_t - start_t, dst_ns, ) iperf3_runners.append(runner_obj) return iperf3_runners
def print_error(self, error_string_prefix): """ Method to print error from `self.err` """ self.err.seek(0) # rewind to start of file error = self.err.read().decode() ns_name = TopologyMap.get_namespace(self.ns_id)["name"] self.logger.error("%s at %s. %s", error_string_prefix, ns_name, error)
def run_server(ns_id): """ Run iperf server in `ns_id` Parameters ---------- ns_id : str namespace to run netserver on """ return_code = run_iperf_server(ns_id) if return_code != 0: ns_name = TopologyMap.get_namespace(ns_id)["name"] logger.error("Error running iperf3 server at %s.", ns_name)
def get_meta_item(self): """ Return the meta item for the given flow. This "meta" information is required by plotter. """ meta_item = { "meta": True, "start_time": str(self.start_time), "stop_time": str(self.start_time + self.run_time), } if self.dst_ns is not None: meta_item["destination_node"] = TopologyMap.get_namespace( self.dst_ns)["name"] return meta_item
def test_add_and_get_namespace(self): self.assertEqual( TopologyMap.get_namespace(self.ns_id1)["name"], self.ns_name1) self.assertEqual( TopologyMap.get_namespace(self.ns_id2)["name"], self.ns_name2)
def setup_tcp_flows(dependency, flow, ss_schedules, destination_nodes): """ Setup netperf to run tcp flows Parameters ---------- dependency: int whether netperf is installed flow: Flow Flow parameters ss_schedules: ss_schedules so far destination_nodes: Destination nodes so far already running netperf server Returns ------- dependency: int updated dependency in case netperf is not installed netperf_runners: List[NetperfRunner] all the netperf flows generated workers: List[multiprocessing.Process] Processes to run netperf flows ss_schedules: dict updated ss_schedules """ netperf_runners = [] if not dependency: logger.warning("Netperf not found. Tcp flows cannot be generated") else: # Get flow attributes [ src_ns, dst_ns, dst_addr, start_t, stop_t, n_flows, options, ] = flow._get_props() # pylint: disable=protected-access # Run netserver if not already run before on given dst_node if dst_ns not in destination_nodes: NetperfRunner.run_netserver(dst_ns) src_name = TopologyMap.get_namespace(src_ns)["name"] netperf_options = {} netperf_options["testname"] = "TCP_STREAM" netperf_options["cong_algo"] = options["cong_algo"] f_flow = "flow" if n_flows == 1 else "flows" logger.info( "Running %s netperf %s from %s to %s...", n_flows, f_flow, src_name, dst_addr, ) # Create new processes to be run simultaneously for _ in range(n_flows): runner_obj = NetperfRunner(src_ns, dst_addr, start_t, stop_t - start_t, **netperf_options) netperf_runners.append(runner_obj) # Find the start time and stop time to run ss command in `src_ns` to a `dst_addr` ss_schedules = _get_start_stop_time_for_ss(src_ns, dst_addr, start_t, stop_t, ss_schedules) return netperf_runners, ss_schedules