Ejemplo n.º 1
0
 def testpmd_executable(self):
     if is_installed("dpdk-testpmd"):
         return "dpdk-testpmd"
     elif is_installed("testpmd"):
         return "testpmd"
     else:
         raise TestModuleError("testpmd not installed")
Ejemplo n.º 2
0
    def run(self):
        self._keep_server_running = True

        self.duration = self.get_opt("duration")
        if self.duration is None:
            self.duration = 60    # for client purposes
        else:
            self._keep_server_running = False    # for server purposes

        self.threshold = self.get_opt("threshold")

        role = self.get_mopt("role")
        cmd = self._compose_iperf_cmd(role)
        logging.debug("compiled command: %s" % cmd)
        if not is_installed("iperf"):
            res_data = {}
            res_data["msg"] = "Iperf is not installed on this machine!"
            logging.error(res_data["msg"])
            return self.set_fail(res_data)

        if role == "server":
            logging.debug("running as server ...")
            self.run_server(cmd)

            return self.set_pass()
        elif role == "client":
            logging.debug("running as client ...")
            (rv, message) = self.run_client(cmd)
            res_data = {"msg": message}
            if rv == False:
                return self.set_fail(res_data)

            return self.set_pass(res_data)
Ejemplo n.º 3
0
    def start_packet_capture(self, filt):
        if not is_installed("tcpdump"):
            raise Exception("Can't start packet capture, tcpdump not available")

        files = {}
        for if_id, dev in self._if_manager.get_mapped_devices().items():
            if dev.get_netns() != None:
                continue
            dev_name = dev.get_name()

            df_handle = NamedTemporaryFile(delete=False)
            dump_file = df_handle.name
            df_handle.close()

            files[if_id] = dump_file

            pcap = PacketCapture()
            pcap.set_interface(dev_name)
            pcap.set_output_file(dump_file)
            pcap.set_filter(filt)
            pcap.start()

            self._packet_captures[if_id] = pcap

        self._capture_files = files
        return files
Ejemplo n.º 4
0
    def run(self):
        if not is_installed("netserver"):
            res_data = {}
            res_data["msg"] = "Netserver is not installed on this machine!"
            logging.error(res_data["msg"])
            self._res_data = res_data
            return False

        cmd = "netserver -D{bind}{port} {opts}".format(
            bind=" -L " + str(self.params.bind),
            port=" -p " +
            str(self.params.port) if "port" in self.params else "",
            opts=self.params.opts if "opts" in self.params else "")

        logging.debug("compiled command: %s" % cmd)

        logging.debug("running as server...")

        proc = subprocess.Popen(cmd,
                                shell=True,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE,
                                close_fds=True)

        self.wait_on_interrupt()

        proc.kill()

        return True
Ejemplo n.º 5
0
    def start_packet_capture(self, filt):
        if not is_installed("tcpdump"):
            raise Exception("Can't start packet capture, tcpdump not available")

        files = {}
        for if_id, dev in self._if_manager.get_mapped_devices().iteritems():
            if dev.get_netns() != None:
                continue
            dev_name = dev.get_name()

            df_handle = NamedTemporaryFile(delete=False)
            dump_file = df_handle.name
            df_handle.close()

            files[if_id] = dump_file

            pcap = PacketCapture()
            pcap.set_interface(dev_name)
            pcap.set_output_file(dump_file)
            pcap.set_filter(filt)
            pcap.start()

            self._packet_captures[if_id] = pcap

        self._capture_files = files
        return files
Ejemplo n.º 6
0
    def run(self) -> bool:
        self._res_data = {}
        if not is_installed("perf"):
            self._res_data["msg"] = "perf is not installed on this machine!"
            logging.error(self._res_data["msg"])
            return False

        # can't use lnst.Common.ExecCmd.exec_cmd directly, because expected returncode is not zero
        cmd: str = self._compose_cmd()
        logging.debug(f"Executing: \"{cmd}\"")
        process = subprocess.Popen(cmd,
                                   shell=True,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   close_fds=True)

        self.wait_for_interrupt()

        stdout, stderr = process.communicate()

        if stdout:
            log_output(logging.debug, "Stdout", stdout.decode())
        if stderr:
            log_output(logging.debug, "Stderr", stderr.decode())

        self._res_data["filename"] = os.path.abspath(self.params.output_file)
        return process.returncode == -2
Ejemplo n.º 7
0
Archivo: Iperf.py Proyecto: Axonis/lnst
    def run(self):
        self._res_data = {}
        if not is_installed("iperf3"):
            self._res_data["msg"] = "Iperf is not installed on this machine!"
            logging.error(self._res_data["msg"])
            return False

        cmd = self._compose_cmd()

        logging.debug("compiled command: %s" % cmd)
        logging.debug("running as {} ...".format(self._role))

        server = subprocess.Popen(cmd,
                                  shell=True,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE,
                                  close_fds=True)

        try:
            stdout, stderr = server.communicate()
            stdout = stdout.decode()
            stderr = stderr.decode()
        except KeyboardInterrupt:
            pass

        try:
            self._res_data["data"] = json.loads(stdout)
        except JSONDecodeError:
            self._res_data["msg"] = "Error while parsing the iperf json output"
            self._res_data["data"] = stdout
            self._res_data["stderr"] = stderr
            logging.error(self._res_data["msg"])
            return False

        try:
            self._check_json_sanity()
        except:
            self._res_data["msg"] = "Iperf provided incomplete json data"
            self._res_data["data"] = stdout
            self._res_data["stderr"] = stderr
            logging.error(self._res_data["msg"])
            return False

        self._res_data["stderr"] = stderr

        if stderr != "":
            self._res_data["msg"] = "errors reported by iperf"
            logging.error(self._res_data["msg"])
            logging.error(self._res_data["stderr"])

        if server.returncode > 0:
            self._res_data["msg"] = "{} returncode = {}".format(
                self._role, server.returncode)
            logging.error(self._res_data["msg"])
            return False

        return True
Ejemplo n.º 8
0
    def run(self):
        cmd = self._compose_cmd()
        logging.debug("compiled command: %s" % cmd)
        if self._role == "client":
            if not is_installed("netperf"):
                res_data = {}
                res_data["msg"] = "Netperf is not installed on this machine!"
                logging.error(res_data["msg"])
                return self.set_fail(res_data)

            (rv, res_data) = self._run_client(cmd)
            if rv == False:
                return self.set_fail(res_data)
            return self.set_pass(res_data)
        elif self._role == "server":
            if not is_installed("netserver"):
                res_data = {}
                res_data["msg"] = "Netserver is not installed on this machine!"
                logging.error(res_data["msg"])
                return self.set_fail(res_data)
            self._run_server(cmd)
Ejemplo n.º 9
0
    def run(self):
        cmd = self._compose_cmd()
        logging.debug("compiled command: %s" % cmd)
        if self._role == "client":
            if not is_installed("netperf"):
                res_data = {}
                res_data["msg"] = "Netperf is not installed on this machine!"
                logging.error(res_data["msg"])
                return self.set_fail(res_data)

            (rv, res_data) = self._run_client(cmd)
            if rv == False:
                return self.set_fail(res_data)
            return self.set_pass(res_data)
        elif self._role == "server":
            if not is_installed("netserver"):
                res_data = {}
                res_data["msg"] = "Netserver is not installed on this machine!"
                logging.error(res_data["msg"])
                return self.set_fail(res_data)
            self._run_server(cmd)
Ejemplo n.º 10
0
    def run(self):
        cmd = self._compose_cmd()
        logging.debug("compiled command: %s" % cmd)
        if not is_installed("netperf"):
            res_data = {}
            res_data["msg"] = "Netperf is not installed on this machine!"
            logging.error(res_data["msg"])
            self._res_data = res_data
            return False

        (rv, res_data) = self._run_client(cmd)
        self._res_data = res_data
        if rv is False:
            return False
        return True
Ejemplo n.º 11
0
    def run(self):
        self._res_data = {}
        if not is_installed("tcpdump"):
            self._res_data["msg"] = "tcpdump is not installed on this machine!"
            logging.error(self._res_data["msg"])
            return False

        self._prepare_grep_exprs()
        cmd = self._compose_cmd()
        logging.debug("compiled command: {}".format(cmd))

        packet_assert_process = subprocess.Popen(
            cmd,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            close_fds=True,
        )

        try:
            self.wait_for_interrupt()
        except:
            raise LnstError("Could not handle interrupt properly.")

        stdout, stderr = packet_assert_process.communicate()
        stdout = stdout.decode()
        stderr = stderr.decode()

        self._res_data["stderr"] = stderr
        # tcpdump always reports information to stderr, there may be actual
        # errors but also just generic debug information
        logging.debug(self._res_data["stderr"])

        for line in stdout.split("\n"):
            self._check_line(line)

        logging.debug("Capturing finised. Received %d packets." % self._p_recv)
        self._res_data["p_recv"] = self._p_recv

        if packet_assert_process.returncode != 0:
            return False
        else:
            return True
Ejemplo n.º 12
0
    def run(self):
        self._res_data = {}
        if not is_installed("tcpdump"):
            self._res_data["msg"] = "tcpdump is not installed on this machine!"
            logging.error(self._res_data["msg"])
            return False

        self._prepare_grep_exprs()
        cmd = self._compose_cmd()
        logging.debug("compiled command: {}".format(cmd))

        packet_assert_process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE, close_fds=True)

        try:
            self.wait_for_interrupt()
        except:
            raise LnstError("Could not handle interrupt properly.")

        with packet_assert_process.stdout, packet_assert_process.stderr:
            stderr=packet_assert_process.stderr.read().decode()
            stdout=packet_assert_process.stdout.read().decode()

        self._res_data["stderr"] = stderr

        if self._is_real_err(stderr):
            self._res_data["msg"] = "errors reported by tcpdump"
            logging.error(self._res_data["msg"])
            logging.error(self._res_data["stderr"])
            return False

        for line in stdout.split("\n"):
            self._check_line(line)

        logging.debug("Capturing finised. Received %d packets." % self._p_recv)
        self._res_data["p_recv"] = self._p_recv

        return True
Ejemplo n.º 13
0
 def _add_rm_port(self, action, slave_id):
     if is_installed("brctl"):
         self._add_rm_port_brctl(action, slave_id)
     else:
         self._add_rm_port_iproute(action, slave_id)
Ejemplo n.º 14
0
Archivo: Ping.py Proyecto: pgagne/lnst
    def run(self):
        self._res_data = {}
        if not is_installed("ping"):
            self._res_data["msg"] = "Ping is not installed on this machine!"
            logging.error(self._res_data["msg"])
            return False

        cmd = self._compose_cmd()

        logging.debug("compiled command: {}".format(cmd))

        ping_process = subprocess.Popen(cmd,
                                        shell=True,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE,
                                        close_fds=True)

        try:
            stdout, stderr = ping_process.communicate()
            stdout = stdout.decode()
            stderr = stderr.decode()
        except KeyboardInterrupt:
            pass

        if ping_process.returncode > 1:
            self._res_data["msg"] = "returncode = {}".format(
                ping_process.returncode)
            logging.error(self._res_data["msg"])
            if stderr != "":
                self._res_data["stderr"] = stderr
                logging.error("errors reported by ping")
                logging.error(self._res_data["stderr"])
            return False

        stat_pttr1 = r'(\d+) packets transmitted, (\d+) received'
        stat_pttr2 = r'rtt min/avg/max/mdev = (\d+\.\d+)/(\d+\.\d+)/(\d+\.\d+)/(\d+\.\d+) ms'

        match = re.search(stat_pttr1, stdout)
        if not match:
            self._res_data = {"msg": "expected pattern not found"}
            logging.error(self._res_data["msg"])
            return False
        else:
            trans_pkts, recv_pkts = match.groups()
            rate = int(round((float(recv_pkts) / float(trans_pkts)) * 100))
            logging.debug("Transmitted '{}', received '{}', "
                          "rate '{}%'".format(trans_pkts, recv_pkts, rate))

            self._res_data = {
                "trans_pkts": trans_pkts,
                "recv_pkts": recv_pkts,
                "rate": rate
            }

        match = re.search(stat_pttr2, stdout)
        if not match:
            if self._res_data['rate'] > 0:
                self._res_data = {"msg": "expected pattern not found"}
                logging.error(self._res_data["msg"])
                return False
        else:
            tmin, tavg, tmax, tmdev = [float(x) for x in match.groups()]
            logging.debug("rtt min \"%.3f\", avg \"%.3f\", max \"%.3f\", "
                          "mdev \"%.3f\"" % (tmin, tavg, tmax, tmdev))

            self._res_data["rtt_min"] = tmin
            self._res_data["rtt_max"] = tmax
            self._res_data["rtt_avg"] = tavg
            self._res_data["rtt_mdev"] = tmdev

        return True