Beispiel #1
0
 def stop_external(self, file_id):
     self.cfg = P4STA_utils.read_current_cfg()
     input = [
         "ssh", self.cfg["ext_host_user"] + "@" + self.cfg["ext_host_ssh"],
         "cd /home/" + self.cfg["ext_host_user"] +
         "/p4sta/externalHost/dpdkExtHost/; "
         "touch receiver_stop"
     ]
     res = subprocess.run(input).stdout
     print(res)
     input = [
         "ssh", "-o ConnectTimeout=5",
         self.cfg["ext_host_user"] + "@" + self.cfg["ext_host_ssh"],
         "cd /home/" + self.cfg["ext_host_user"] +
         "/p4sta/externalHost/dpdkExtHost/; "
         "./check_extH_status.sh; exit"
     ]
     c = 0
     while True:  # wait until exthost stopped
         time.sleep(1)
         c = c + 1
         res = subprocess.run(input, stdout=subprocess.PIPE).stdout
         result = res.decode()
         if result.find("1") > -1 or c > 59:
             # if 1 is found by check_extH_status.sh at external host,
             # receiver has finished saving csv files
             break
     subprocess.run([
         "scp", self.cfg["ext_host_user"] + "@" + self.cfg["ext_host_ssh"] +
         ":/home/" + self.cfg["ext_host_user"] +
         "/p4sta/externalHost/dpdkExtHost/raw_packet_counter_" + file_id +
         ".csv",
         P4STA_utils.get_results_path(file_id)
     ])
     subprocess.run([
         "scp", self.cfg["ext_host_user"] + "@" + self.cfg["ext_host_ssh"] +
         ":/home/" + self.cfg["ext_host_user"] +
         "/p4sta/externalHost/dpdkExtHost/packet_sizes_" + file_id + ".csv",
         P4STA_utils.get_results_path(file_id)
     ])
     subprocess.run([
         "scp", self.cfg["ext_host_user"] + "@" + self.cfg["ext_host_ssh"] +
         ":/home/" + self.cfg["ext_host_user"] +
         "/p4sta/externalHost/dpdkExtHost/timestamp1_list_" + file_id +
         ".csv",
         P4STA_utils.get_results_path(file_id)
     ])
     subprocess.run([
         "scp", self.cfg["ext_host_user"] + "@" + self.cfg["ext_host_ssh"] +
         ":/home/" + self.cfg["ext_host_user"] +
         "/p4sta/externalHost/dpdkExtHost/timestamp2_list_" + file_id +
         ".csv",
         P4STA_utils.get_results_path(file_id)
     ])
     time.sleep(1)
     P4STA_utils.execute_ssh(
         self.cfg["ext_host_user"], self.cfg["ext_host_ssh"],
         "cd /home/" + self.cfg["ext_host_user"] +
         "/p4sta/externalHost/dpdkExtHost/; rm *.csv")
     return True
Beispiel #2
0
    def ext_host_status_overview(self, results, index, cfg):
        super(ExtHostImpl, self).ext_host_status_overview(results, index, cfg)
        if results[index]["ext_host_ssh_ping"]:
            results[index][
                "ext_host_needed_sudos_to_add"] = P4STA_utils.\
                check_needed_sudos(
                {"sudo_rights": results[index]["ext_host_sudo_rights"]},
                ["/usr/bin/pkill", "/usr/bin/killall", "/sbin/rmmod",
                 "/sbin/modprobe", "/home/" + cfg["ext_host_user"] +
                 "/p4sta/externalHost/dpdkExtHost/build/receiver"],
                dynamic_mode_inp=results[index]["list_of_path_possibilities"])
            try:
                answer = P4STA_utils.execute_ssh(
                    cfg["ext_host_user"], cfg["ext_host_ssh"],
                    "[ -d '/home/" + cfg["ext_host_user"] +
                    "/p4sta/externalHost/dpdkExtHost/dpdk-19.11/build' ] "
                    "&& echo '1'")
                print(answer)
                if answer[0] == "1":
                    results[index]["custom_checks"] = [[
                        True, "DPDK", "is installed"
                    ]]
                else:
                    results[index]["custom_checks"] = [[
                        False, "DPDK", "no installation found"
                    ]]
            except Exception:
                results[index]["custom_checks"] = [[
                    False, "DPDK", "An error occured while checking "
                    "the DPDK installation path"
                ]]
            try:
                answer = P4STA_utils.execute_ssh(
                    cfg["ext_host_user"], cfg["ext_host_ssh"],
                    "cat /sys/kernel/mm/hugepages/hugepages-2048kB/"
                    "nr_hugepages")
                try:
                    num = int(answer[0])
                    if num < 500:
                        results[index]["custom_checks"].append([
                            False, "DPDK Hugepages",
                            "The number of configured hugepages(" + str(num) +
                            ") is too low or zero!"
                        ])
                    else:
                        results[index]["custom_checks"].append([
                            True, "DPDK Hugepages",
                            "The number of configured hugepages is " +
                            str(num) + "!"
                        ])
                except Exception:
                    results[index]["custom_checks"].append([
                        False, "DPDK Hugepages",
                        "An error occured while checking the hugepages: " +
                        answer
                    ])

            except Exception:
                results[index]["custom_checks"].append(
                    [False, "DPDK Hugepages", "ERROR"])
Beispiel #3
0
 def stop_all_servers(servers):
     for server in servers:
         # no need to define namespace because
         # sudo pkill kills all processes running on host
         print("Trying to stop all iPerf3 instances at server " +
               server["ssh_ip"])
         P4STA_utils.execute_ssh(server["ssh_user"], server["ssh_ip"],
                                 "sudo pkill iperf3")
Beispiel #4
0
 def start_client(ssh_user, ssh_ip, dst_ip, port, ns_option,
                  duration, json_id, flag):
     exec = str(ns_option) + " iperf3 -c " + str(
         dst_ip) + " -T s" + str(json_id) + " -p " + str(
             port) + " " + flag + " -J --logfile s" + str(
                 json_id) + ".json -t " + str(duration)
     print(exec)
     P4STA_utils.execute_ssh(ssh_user, ssh_ip, exec)
Beispiel #5
0
 def check_namespaces(user, ip):
     namespaces = P4STA_utils.execute_ssh(user, ip, "ip netns list")
     answer = []
     for ns in namespaces:
         if ns != "":
             ns_name = ns.split(" ")[0]
             answer.append([str(ns)] + P4STA_utils.execute_ssh(
                 user, ip, "sudo ip netns exec " + str(ns_name) +
                 " ifconfig"))
     return answer
    def start_stamper_software(self, cfg):
        try:
            input = "ip route get " + cfg["stamper_ssh"]
            output = subprocess.run(input, stdout=subprocess.PIPE,
                                    shell=True).stdout.decode("utf-8").replace(
                                        "\n", "").split(" ")
            route_iface = output[output.index("dev") + 1]
            # Assumes that all bmv2 management SSH IPs are in /24 subnet
            # should be 10.99.66.0/24
            ip_splitted = cfg["ext_host_ssh"].split(".")
            subprocess.run("sudo ip route add " + ".".join(ip_splitted[:3]) +
                           ".0/24 via " + cfg["stamper_ssh"] + " dev " +
                           route_iface,
                           stdout=subprocess.PIPE,
                           shell=True)
        except Exception:
            print(traceback.format_exc())
            print("ERROR: Adding ip route to bmv2 server failed. "
                  "Mininet hosts could not be reachable.")

        lines_check = P4STA_utils.execute_ssh(
            cfg["stamper_user"], cfg["stamper_ssh"],
            "cat " + cfg["bmv2_dir"] + "/LICENSE")
        if len(lines_check) > 100:
            subprocess.run([
                self.realPath + "/scripts/start_mininet.sh", "/home/" +
                cfg["stamper_user"] + "/p4sta/stamper/bmv2/scripts/netgen.py",
                cfg["stamper_user"], cfg["stamper_ssh"], project_path
            ])
        else:
            print("BMV2 DIR NOT FOUND AT BMV2 TARGET: " + str(cfg["bmv2_dir"]))
            return "BMV2 DIR NOT FOUND AT BMV2 TARGET: " + str(cfg["bmv2_dir"])
Beispiel #7
0
 def check_port_open(server_ssh_user, server_ip, port, ns_option):
     answer_list = P4STA_utils.execute_ssh(
         server_ssh_user, server_ip,
         str(ns_option) + " if lsof -Pi :" + str(port) +
         " -sTCP:LISTEN -t >/dev/null; then echo running; fi " +
         ns_option_end)
     return "running" in answer_list
Beispiel #8
0
 def loadgen_status_overview(self, host, results, index):
     super(LoadGeneratorImpl,
           self).loadgen_status_overview(host, results, index)
     answer = P4STA_utils.execute_ssh(host["ssh_user"], host["ssh_ip"],
                                      "iperf3 -v")
     version = ""
     try:
         for line in answer:
             if line.find("iperf") > -1:
                 version = line
     except Exception:
         pass
     if version != "":
         version = re.sub('[^0-9,.]', '', version)
         ver_split = version.split(".")
         if len(ver_split) == 3 and ver_split[0] == "3":
             if float(".".join(ver_split[1:3])) >= 1.3:
                 results[index]["custom_checks"] = [[
                     True, "iPerf3", version
                 ]]
             else:
                 results[index]["custom_checks"] = [[
                     False, "iPerf3",
                     version + " [version older than 3.1.3 will not work]"
                 ]]
         elif len(ver_split) == 2 and ver_split[0] == "3":
             if float(ver_split[1] > 7):
                 results[index]["custom_checks"] = [[
                     True, "iPerf3", version
                 ]]
             else:
                 results[index]["custom_checks"] = [[
                     False, "iPerf3",
                     version + " [version older than 3.1.3 will not work]"
                 ]]
     else:
         answer = P4STA_utils.execute_ssh(host["ssh_user"], host["ssh_ip"],
                                          "which iperf3")
         if answer[0] != "":
             results[index]["custom_checks"] = [[
                 False, "iPerf3",
                 "version not detected but installed at " + answer[0]
             ]]
         else:
             results[index]["custom_checks"] = [[
                 False, "iPerf3", "installation not found"
             ]]
Beispiel #9
0
    def loadgen_status_overview(self, host, results, index):
        def check_iface(user, ip, iface, namespace=""):
            ipv4, mac, prefix, up_state, iface_found = \
                P4STA_utils.fetch_interface(user, ip, iface, namespace)
            if ipv4 == "" or ipv4 == []:
                ipv4 = "n/a"
            if mac == "" or mac == []:
                mac = "device not found"
            return ipv4, mac, prefix, up_state

        def check_namespaces(user, ip):
            namespaces = P4STA_utils.execute_ssh(user, ip, "ip netns list")
            answer = []
            for ns in namespaces:
                if ns != "":
                    ns_name = ns.split(" ")[0]
                    answer.append([str(ns)] + P4STA_utils.execute_ssh(
                        user, ip, "sudo ip netns exec " + str(ns_name) +
                        " ifconfig"))
            return answer

        res = {}
        res["ssh_ping"] = (os.system("timeout 1 ping " + host["ssh_ip"] +
                                     " -c 1") == 0)
        if res["ssh_ping"]:
            if "namespace_id" in host:
                res["fetched_ipv4"], res["fetched_mac"], \
                    res["fetched_prefix"], res["up_state"] = check_iface(
                    host['ssh_user'], host['ssh_ip'], host['loadgen_iface'],
                    host["namespace_id"])
            else:
                res["fetched_ipv4"], res["fetched_mac"], \
                    res["fetched_prefix"], res["up_state"] = check_iface(
                    host['ssh_user'], host['ssh_ip'],
                    host['loadgen_iface'], "")

            res["sudo_rights"], list_of_path_possibilities = \
                P4STA_utils.check_sudo(
                    host['ssh_user'], host['ssh_ip'], dynamic_mode=True)
            print("Loadgen sudo path possibilities:")
            print(list_of_path_possibilities)
            res["needed_sudos_to_add"] = P4STA_utils.check_needed_sudos(
                {"sudo_rights": res["sudo_rights"]},
                self.loadgen_cfg["status_check"]["needed_sudos_to_add"],
                dynamic_mode_inp=list_of_path_possibilities)
            res["ip_routes"] = P4STA_utils.execute_ssh(host['ssh_user'],
                                                       host['ssh_ip'],
                                                       "ip route")
            res["namespaces"] = check_namespaces(host['ssh_user'],
                                                 host['ssh_ip'])

        else:
            res["sudo_rights"] = ["not reachable"]
            res["needed_sudos_to_add"] = []
            res["fetched_ipv4"], res["fetched_mac"] = ("", "")
            res["fetched_prefix"], res["up_state"] = ("", "down")
            res["ip_routes"] = []
            res["namespaces"] = []
        results[index] = res
Beispiel #10
0
    def check_if_p4_compiled(self, cfg):
        all_files = P4STA_utils.execute_ssh(
            cfg["stamper_user"], cfg["stamper_ssh"],
            "ls /home/" + cfg["stamper_user"] + "/p4sta/stamper/bmv2/data")
        found_jsons = []

        for item in all_files:
            if item.endswith("json") and item.find(cfg["program"]) > -1:
                found_jsons.append(item)
        if len(found_jsons) > 0:
            return True, "Found compiled " + " ".join(
                found_jsons
            ) + " in /home/" + cfg["stamper_user"] + "/p4sta/stamper/bmv2/data"
        else:
            return False, "No compiled " + cfg[
                "program"] + ".json found in /home/" + cfg[
                    "stamper_user"] + "/p4sta/stamper/bmv2/data"
Beispiel #11
0
 def stamper_status_overview(self, results, index, cfg):
     super(TargetImpl, self).stamper_status_overview(results, index, cfg)
     try:
         answer = P4STA_utils.execute_ssh(
             cfg["stamper_user"], cfg["stamper_ssh"],
             "cat /proc/sys/net/ipv4/ip_forward")
         if answer[0] == "0":
             results[index]["custom_checks"] = [[
                 False, "IPv4 forwarding", "0 (disabled)"
             ]]
         elif answer[0] == "1":
             results[index]["custom_checks"] = [[
                 True, "IPv4 forwarding", "1 (enabled)"
             ]]
         else:
             results[index]["custom_checks"] = [[
                 False, "IPv4 forwarding", "error"
             ]]
     except Exception:
         print(traceback.format_exc())
Beispiel #12
0
    def stamper_status(self, cfg):
        pid = self.get_pid(cfg)
        print(pid)
        if pid > 0:
            dev_status = "Yes! PID: " + str(pid)
            running = True
            try:
                lines_pm = P4STA_utils.execute_ssh(
                    cfg["stamper_user"], cfg["stamper_ssh"], "cat /home/" +
                    cfg["stamper_user"] + "/p4sta/stamper/bmv2/data/mn.log")
            except Exception:
                lines_pm = ["Error while reading mininet output"]
        else:
            dev_status = "not running"
            running = False
            lines_pm = [
                "No portmanager available",
                "Are you sure you selected a target before?"
            ]

        return lines_pm, running, dev_status
Beispiel #13
0
    def start_external(self, file_id, multi=1, tsmax=(2**32 - 1)):
        self.cfg = P4STA_utils.read_current_cfg()

        cmd = "cd /home/" + self.cfg[
            "ext_host_user"] + "/p4sta/externalHost/dpdkExtHost/; touch " \
                               "receiver_stop; sleep 0.5; rm receiver_stop; " \
                               "sudo build/receiver 0"
        if self.cfg["selected_target"] == "bmv2":  # if mininet
            # load vfio module
            cmd = "sudo rmmod vfio-pci; sudo rmmod vfio_iommu_type1; " \
                  "sudo rmmod vfio; sudo modprobe vfio-pci; " + cmd
            cmd += " --vdev=eth_af_packet42,iface=" + self.cfg[
                "ext_host_if"] + ",blocksz=4096,framesz=2048,framecnt=512," \
                                 "qpairs=1,qdisc_bypass=0"
        cmd += " -- --name " + file_id + " > foo.out 2> foo.err < /dev/null &"
        print(cmd)
        res = P4STA_utils.execute_ssh(self.cfg["ext_host_user"],
                                      self.cfg["ext_host_ssh"], cmd)
        print("started DPDK-based external host")
        print(res)
        errors = ()
        return errors
Beispiel #14
0
 def execute_ssh(self, cfg, arg):
     # input = ["ssh", cfg["stamper_user"] + "@" + cfg["stamper_ssh"], arg]
     # res = subprocess.Popen(input, stdout=subprocess.PIPE).stdout
     # return res.read().decode().split("\n")
     return P4STA_utils.execute_ssh(cfg["stamper_user"], cfg["stamper_ssh"],
                                    arg)
Beispiel #15
0
    def run_loadgens(self, file_id, duration, l4_selected, packet_size_mtu,
                     results_path, loadgen_rate_limit, loadgen_flows,
                     loadgen_server_groups):
        self.cfg = P4STA_utils.read_current_cfg()
        loadgen_flows = int(loadgen_flows)

        def check_ns(host):
            if "namespace_id" in host:
                return "sudo ip netns exec " + str(host["namespace_id"])
            else:
                return ""

        def thread_join(thrs):
            for thread in thrs:
                thread.start()
            for thread in thrs:
                thread.join()

        def check_iperf_server(server_ssh_user, server_ip, start_port,
                               ns_option):
            # ssh into server and check locally if port is open
            def check_port_open(server_ssh_user, server_ip, port, ns_option):
                answer_list = P4STA_utils.execute_ssh(
                    server_ssh_user, server_ip,
                    str(ns_option) + " if lsof -Pi :" + str(port) +
                    " -sTCP:LISTEN -t >/dev/null; then echo running; fi " +
                    ns_option_end)
                return "running" in answer_list

            def check_thrd(server_ssh_user, server_ip, port, ns_option):
                print_str = "check iPerf3 Server Port " + str(
                    port) + " at " + server["ssh_ip"] + \
                            " with Namespace " + ns_option + " => "
                time.sleep(0.5)
                if not check_port_open(server_ssh_user, server_ip, port,
                                       ns_option):
                    time.sleep(1.5)
                    if not check_port_open(server_ssh_user, server_ip, port,
                                           ns_option):
                        print_str += "[fail]"
                        raise Exception("iPerf3 Server Port " + str(port) +
                                        " at " + server["ssh_ip"] +
                                        " not open.")
                    else:
                        print_str += "[ok]"
                        print(print_str)
                else:
                    print_str += "[ok]"
                    print(print_str)

            ns_option_end = ""
            if ns_option != "":
                ns_option = ns_option + " bash -c '"
                ns_option_end = "'"

            thrds = []
            for add in range(loadgen_flows):
                x = threading.Thread(target=check_thrd,
                                     args=(server_ssh_user, server_ip,
                                           start_port + add, ns_option))
                thrds.append(x)
            thread_join(thrds)

        # iperf -s threads at one (!) host
        def start_servers(ssh_user, ssh_ip, start_port, flows, ns_option,
                          server_dict):
            def start_server(ssh_user, ssh_ip, start_port, ns_option):
                P4STA_utils.execute_ssh(
                    ssh_user, ssh_ip,
                    str(ns_option) + " iperf3 -s -p " + str(start_port))

            port = int(start_port)
            for fl in range(flows):
                print("iperf3 server flow " + str(fl) + " start at " +
                      str(ssh_ip) + " port " + str(port) + " with NS option " +
                      str(ns_option))
                server_dict["open_iperf_ports"].append(port)
                thread = threading.Thread(target=start_server,
                                          args=(ssh_user, ssh_ip, port,
                                                ns_option))
                thread.start()
                port = port + 1

        def stop_all_servers(servers):
            for server in servers:
                # no need to define namespace because
                # sudo pkill kills all processes running on host
                print("Trying to stop all iPerf3 instances at server " +
                      server["ssh_ip"])
                P4STA_utils.execute_ssh(server["ssh_user"], server["ssh_ip"],
                                        "sudo pkill iperf3")

        # iperf -c threads at one (!) host
        def start_clients(ssh_user, ssh_ip, dst_ip, start_port, flows,
                          ns_option, duration, flag, start_json_id):
            def start_client(ssh_user, ssh_ip, dst_ip, port, ns_option,
                             duration, json_id, flag):
                exec = str(ns_option) + " iperf3 -c " + str(
                    dst_ip) + " -T s" + str(json_id) + " -p " + str(
                        port) + " " + flag + " -J --logfile s" + str(
                            json_id) + ".json -t " + str(duration)
                print(exec)
                P4STA_utils.execute_ssh(ssh_user, ssh_ip, exec)

            threads = []
            port = int(start_port)
            json_id = int(start_json_id)
            for fl in range(flows):
                print("iperf3 client " + str(fl) + " start at " + str(ssh_ip) +
                      " connect to " + str(dst_ip) + " port " + str(port) +
                      " with NS option " + str(ns_option))
                thread = threading.Thread(target=start_client,
                                          args=(ssh_user, ssh_ip, dst_ip, port,
                                                ns_option, duration, json_id,
                                                flag))
                threads.append(thread)
                port = port + 1
                json_id = json_id + 1
            thread_join(threads)

        # [1,2,3,4,5,6,7...] with y = 3 => 1,2,3,1,2,3,1,2,3
        def custom_modulo(x, y):
            if x % y == 0:
                return y
            else:
                return x % y

        # first kill all running iperf instances
        for loadgen_grp in self.cfg["loadgen_groups"]:
            if loadgen_grp["use_group"] == "checked":
                stop_all_servers(loadgen_grp["loadgens"])

        iperf_server_groups = []
        iperf_client_groups = []
        for loadgen_grp in self.cfg["loadgen_groups"]:
            if loadgen_grp["use_group"] == "checked":
                if loadgen_grp["group"] in loadgen_server_groups:
                    iperf_server_groups.append(loadgen_grp)
                else:
                    iperf_client_groups.append(loadgen_grp)

        num_clients = sum([len(x["loadgens"]) for x in iperf_client_groups])
        print("num_clients")
        print(num_clients)

        if loadgen_rate_limit > 0 and num_clients > 0:
            limit_per_host_in_bit_s = int(
                (loadgen_rate_limit * 1000000) / (loadgen_flows * num_clients))
            limit_str = "-b " + str(limit_per_host_in_bit_s)
        elif loadgen_rate_limit > 0 and num_clients == 0:
            limit_str = "-b " + str(
                int((loadgen_rate_limit * 1000000) / loadgen_flows))
        else:
            limit_str = ""

        if l4_selected == "tcp":
            # normally MSS = MTU - 40 here - 16 because 16 byte tstamps added
            mss = int(packet_size_mtu) - 56
            flag = "-M " + str(mss)
            flag = flag + " " + limit_str
        else:
            # timestamps in payload! no need for extra 16 byte space
            mss = int(packet_size_mtu) - 40
            if limit_str == "":
                flag = "-u -b 100G --length " + str(
                    mss)  # 100G option allows to use maximum speed
            else:
                flag = "-u " + limit_str + "--length " + str(mss)
        print("iperf flags: " + flag)

        # case where only one group and one DUT port is used
        if len(iperf_client_groups) == 0 and len(iperf_server_groups) == 1:
            iperf_client_groups = copy.deepcopy(iperf_server_groups)
            # move first entry to end
            first_loadgen = iperf_client_groups[0]["loadgens"][0]
            del (iperf_client_groups[0]["loadgens"][0])
            iperf_client_groups[0]["loadgens"].append(first_loadgen)
            counter = 1
            for client in iperf_client_groups[0]["loadgens"]:
                client["id"] = counter
                counter += 1
            num_clients = 1
            print("num_clients updated because only one loadgen group is used")
            print(num_clients)

        # case where all groups are servers
        elif len(iperf_client_groups) == 0 and len(iperf_server_groups) == len(
                self.cfg["loadgen_groups"]):
            iperf_client_groups = copy.deepcopy(iperf_server_groups)
            first_group = iperf_client_groups[0]
            del (iperf_client_groups[0])
            iperf_client_groups.append(first_group)
            counter = 1
            for client_grp in iperf_client_groups:
                client_grp["group"] = counter
                counter = counter + 1

        for server_group in iperf_server_groups:
            for server in server_group["loadgens"]:
                server["open_iperf_ports"] = []

        start_port = 5101
        for server_group in iperf_server_groups:
            for server in server_group["loadgens"]:
                for i in range(num_clients):
                    start_servers(server["ssh_user"],
                                  server["ssh_ip"],
                                  str(start_port),
                                  loadgen_flows,
                                  check_ns(server),
                                  server_dict=server)
                    start_port = start_port + loadgen_flows

        start_port = 5101
        check_threads = list()
        for server_group in iperf_server_groups:
            for server in server_group["loadgens"]:
                for i in range(num_clients):

                    x = threading.Thread(target=check_iperf_server,
                                         args=(server["ssh_user"],
                                               server["ssh_ip"], start_port,
                                               check_ns(server)))
                    check_threads.append(x)

                    start_port = start_port + loadgen_flows
        thread_join(check_threads)

        print("iperf server groups")
        print(iperf_server_groups)
        print("iperf client groups")
        print(iperf_client_groups)

        threads = list()
        json_id = 1
        for client_group in iperf_client_groups:
            for client in client_group["loadgens"]:
                client["num_started_flows"] = 0
                for server_group in iperf_server_groups:
                    for server in server_group["loadgens"]:
                        start_client = False
                        do_break = False
                        # if more clients in client grp than server grp connect
                        # remaining clients to first servers again
                        if len(client_group["loadgens"]) >= len(
                                server_group["loadgens"]):
                            c_mod = custom_modulo(
                                client["id"], len(server_group["loadgens"]))
                            if server["id"] == c_mod \
                                    and client["loadgen_ip"] != \
                                    server["loadgen_ip"]:
                                start_client = True
                                do_break = True
                        else:
                            c_mod = custom_modulo(
                                server["id"], len(client_group["loadgens"]))

                            if client["id"] == c_mod \
                                    and client["loadgen_ip"] != \
                                    server["loadgen_ip"]:
                                start_client = True
                                do_break = False

                        if start_client:
                            if len(server["open_iperf_ports"]) > 0:
                                start_port = server["open_iperf_ports"][0]
                                for i in range(loadgen_flows):
                                    if start_port + i \
                                            in server["open_iperf_ports"]:
                                        server["open_iperf_ports"].remove(
                                            start_port + i)
                                print("select port range starting at " +
                                      str(start_port) + " to connect from " +
                                      client["loadgen_ip"] + " to " +
                                      server["loadgen_ip"])
                                x = threading.Thread(
                                    target=start_clients,
                                    args=(client["ssh_user"], client["ssh_ip"],
                                          server["loadgen_ip"], start_port,
                                          loadgen_flows, check_ns(client),
                                          duration, flag, json_id))
                                threads.append(x)
                                json_id = json_id + loadgen_flows
                                client["num_started_flows"] = \
                                    client["num_started_flows"] + loadgen_flows
                                if do_break:
                                    break
                            else:
                                print(
                                    "No available port found in server dict: "
                                    + str(server) + " from server group id " +
                                    str(server_group["group"]))

        thread_join(threads)

        # get jsons from clients
        json_id = 1
        for client_grp in iperf_client_groups:
            for client in client_grp["loadgens"]:
                for f in range(client["num_started_flows"]):
                    exc = "scp " + client["ssh_user"] + "@" + client[
                        "ssh_ip"] + ":s" + str(
                        json_id + f) + ".json " + results_path + "/iperf3_s" \
                          + str(json_id + f) + "_" + str(file_id) + ".json"
                    print(exc)
                    subprocess.run(exc, shell=True)
                json_id = json_id + client["num_started_flows"]

        # delete in second loop because
        # e.g. in case of docker one rm -f deletes all jsons for all clients
        for client_grp in iperf_client_groups:
            for client in client_grp["loadgens"]:
                P4STA_utils.execute_ssh(client["ssh_user"], client["ssh_ip"],
                                        "rm -f s*.json")

        for server_group in iperf_server_groups:
            stop_all_servers(server_group["loadgens"])
Beispiel #16
0
 def start_server(ssh_user, ssh_ip, start_port, ns_option):
     P4STA_utils.execute_ssh(
         ssh_user, ssh_ip,
         str(ns_option) + " iperf3 -s -p " + str(start_port))
    def get_server_install_script(self,
                                  user_name,
                                  ip,
                                  target_specific_dict={}):
        print("INSTALLING TOFINO STAMPER TARGET:")
        print(target_specific_dict)
        sde_path = ""
        if "sde" in target_specific_dict and len(
                target_specific_dict["sde"]) > 1:
            sde_path = target_specific_dict["sde"]
        else:
            lines = P4STA_utils.execute_ssh(user_name, ip, "cat $HOME/.bashrc")
            for line in lines:
                if line.find("export SDE_INSTALL") > -1:
                    lrep = line.replace("\n", "")
                    start = lrep.find("=") + 1
                    sde_path = lrep[start:]
                    print("/**************************/")
                    print("Found $SDE_INSTALL at target " + ip + " = " +
                          sde_path)
                    print("/**************************/")
            if sde_path == "":
                print("\033[1;33m/**********************************"
                      "****************************/")
                print("WARNING: SDE Path not found on Tofino, using "
                      "/opt/bf-sde-9.3.0")
                print("/*********************************************"
                      "*****************/\033[0m")
                sde_path = "/opt/bf-sde-9.3.0"

        # create install_tofino.sh
        add_sudo_rights_str = "#!/bin/bash\nadd_sudo_rights() {\ncurrent_" \
                              "user=$USER\n  if (sudo -l | grep -q " \
                              "'(ALL : ALL) SETENV: NOPASSWD: '$1); then\n  " \
                              "  echo 'visudo entry already exists';" \
                              "\n  else\n    sleep 0.1\n    echo " \
                              "$current_user' ALL=(ALL:ALL) NOPASSWD:" \
                              "SETENV:'$1 | " \
                              "sudo EDITOR='tee -a' visudo; \n  fi\n}\n"

        with open(dir_path + "/scripts/install_tofino.sh", "w") as f:
            f.write(add_sudo_rights_str)
            for sudo in self.target_cfg["status_check"]["needed_sudos_to_add"]:
                if sudo.find("run_switchd.sh") > -1:
                    f.write("add_sudo_rights " + sde_path +
                            "/run_switchd.sh\n")
                else:
                    f.write("add_sudo_rights $(which " + sudo + ")\n")
        os.chmod(dir_path + "/scripts/install_tofino.sh", 0o775)

        lst = []
        lst.append('echo "====================================="')
        lst.append('echo "Installing Barefoot Tofino stamper target on ' + ip +
                   '"')
        lst.append('echo "====================================="')

        lst.append('echo "START: Copying Tofino files on remote server:"')
        lst.append('cd ' + dir_path + "/scripts")

        lst.append('if ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no ' +
                   user_name + '@' + ip + ' "echo \'ssh to ' + ip +
                   ' ***worked***\';"; [ $? -eq 255 ]; then')

        lst.append('  echo "====================================="')
        lst.append('  echo "\033[0;31m ERROR: Failed to connect to Stamper '
                   'server with IP: ' + ip + ' \033[0m"')
        lst.append('  echo "====================================="')

        lst.append('else')
        lst.append(
            '  chmod +x stop_switchd.sh start_switchd.sh switchd_status.sh')
        lst.append('  ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no ' +
                   user_name + '@' + ip + ' \"echo "SSH to stamper device **'
                   '*__worked__***\"; mkdir -p /home/' + user_name +
                   '/p4sta/stamper/tofino1/"')

        lst.append("   echo ")

        lst.append('  scp install_tofino.sh ' + user_name + '@' + ip +
                   ':/home/' + user_name + '/p4sta/stamper/tofino1/')
        lst.append('  ssh  -o ConnectTimeout=2 -o StrictHostKeyChecking=no ' +
                   user_name + '@' + ip + ' "cd /home/' + user_name +
                   '/p4sta/stamper/tofino1/; chmod +x install_tofino.sh;"')
        lst.append(
            '  ssh  -t -o ConnectTimeout=2 -o StrictHostKeyChecking=no ' +
            user_name + '@' + ip + ' "cd /home/' + user_name +
            '/p4sta/stamper/tofino1; ./install_tofino.sh ' + ';"')

        lst.append('  echo "Downloading bfruntime.proto from Tofino Target"')
        # important to use dir_path because THIS file is stored
        # there but target could be other tofino
        lst.append('  cd ' + dir_path + '/bfrt_grpc')
        lst.append('  scp ' + user_name + '@' + ip + ':' + sde_path +
                   '/install/share/bf_rt_shared/proto/bfruntime.proto proto/ ')
        lst.append('  echo "Building python3 stub at management server from '
                   'bfruntime.proto for Tofino Target"')
        lst.append('  source ../../../pastaenv/bin/activate; python3 -m '
                   'grpc_tools.protoc -I ./proto --python_out=. '
                   '--grpc_python_out=. ./proto/bfruntime.proto; deactivate')

        lst.append('  echo "FINISHED setting up Barefoot Tofino target"')
        lst.append('  echo "====================================="')
        lst.append('  echo "\033[0;31m IMPORTANT NOTE: P4 source code must be '
                   'compiled manually on Tofino after compiling Intel/Barefoot'
                   ' SDE\033[0m"')
        lst.append('  echo "====================================="')
        lst.append('  echo ""')
        lst.append('  echo "====================================="')
        lst.append('  echo "\033[0;31m IMPORTANT NOTE: Please stop the install'
                   '.sh script in the CLI and restart P4STA with ./run.sh in o'
                   'rder to load the freshly compiled grpc files correctly. '
                   '\033[0m"')
        lst.append('  echo "====================================="')
        lst.append('fi')

        return lst
Beispiel #18
0
    def start_external(self, file_id, multi=1, tsmax=(2**32 - 1)):
        self.cfg = P4STA_utils.read_current_cfg()

        ext_py_dir = self.host_cfg["real_path"]
        errors = ()

        # check pip3 modules
        answer = P4STA_utils.execute_ssh(
            self.cfg["ext_host_user"], self.cfg["ext_host_ssh"],
            "python3 -c 'import pkgutil; print(1 if pkgutil.find_loader"
            "(\"setproctitle\") else 0)'")
        if answer[0] == "0":
            errors = errors + (
                "Python Module 'setproctitle' not found at external host -> "
                "'pip3 install setproctitle'", )
            return errors

        answer = P4STA_utils.execute_ssh(
            self.cfg["ext_host_user"], self.cfg["ext_host_ssh"],
            "mkdir -p /home/" + self.cfg["ext_host_user"] +
            "/p4sta/externalHost/python; "
            "sudo killall external_host_python_receiver")

        input = [
            "scp", ext_py_dir + "/pythonRawSocketExtHost.py",
            self.cfg["ext_host_user"] + "@" + self.cfg["ext_host_ssh"] +
            ":/home/" + self.cfg["ext_host_user"] +
            "/p4sta/externalHost/python"
        ]
        res = subprocess.run(input, stdout=subprocess.PIPE, timeout=3).stdout

        input = [
            "scp", ext_py_dir + "/check_extH_status.sh",
            self.cfg["ext_host_user"] + "@" + self.cfg["ext_host_ssh"] +
            ":/home/" + self.cfg["ext_host_user"] +
            "/p4sta/externalHost/python"
        ]
        res = subprocess.run(input, stdout=subprocess.PIPE, timeout=3).stdout

        args = "chmod +x /home/" + self.cfg["ext_host_user"] + \
               "/p4sta/externalHost/python/pythonRawSocketExtHost.py; " \
               "chmod +x /home/" + self.cfg["ext_host_user"] + \
               "/p4sta/externalHost/python/check_extH_status.sh;" \
               " rm -f /home/" + self.cfg["ext_host_user"] + \
               "/p4sta/externalHost/python/pythonRawSocketExtHost.log"
        print(args)
        res = P4STA_utils.execute_ssh(self.cfg["ext_host_user"],
                                      self.cfg["ext_host_ssh"], args)

        print("now start python extHost")
        call = "sudo ./pythonRawSocketExtHost.py --name " + file_id + \
               " --interface " + self.cfg["ext_host_if"] + " --multi " + str(
                   multi) + " --tsmax " + str(tsmax)
        args = "cd /home/" + self.cfg["ext_host_user"] + \
               "/p4sta/externalHost/python/; nohup " + call + \
               " > foo.out 2> foo.err < /dev/null &"
        print(args)
        res = P4STA_utils.execute_ssh(self.cfg["ext_host_user"],
                                      self.cfg["ext_host_ssh"], args)

        time.sleep(2)  # wait for the ext-host to succeed/fail
        # check if interface is not found or other crash
        input = [
            "ssh", self.cfg["ext_host_user"] + "@" + self.cfg["ext_host_ssh"],
            "cd /home/" + self.cfg["ext_host_user"] +
            "/p4sta/externalHost/python; cat pythonRawSocketExtHost.log; "
            "exit"
        ]
        res = subprocess.run(input, stdout=subprocess.PIPE, timeout=3).stdout
        result = res.decode("utf-8")

        if result.find("Errno 19") > -1:
            errors = errors + ("Interface " + str(self.cfg["ext_host_if"]) +
                               " not found at external host: " + result, )
        elif result.find("Exception") > -1:
            errors = errors + ("An exception occurred: " + result, )
        elif result.find("Started") == -1:
            errors = errors + ("Ext host not started properly", )

        return errors