示例#1
0
 def check_switch_started(self, pid):
     for _ in range(SWITCH_START_TIMEOUT * 2):
         if not os.path.exists(os.path.join("/proc", str(pid))):
             return False
         if check_listening_on_port(self.grpc_port):
             return True
         sleep(0.5)
示例#2
0
    def __init__(self,
                 name,
                 sw_path=None,
                 json_path=None,
                 log_file=None,
                 thrift_port=None,
                 pcap_dump=False,
                 pcap_dir="",
                 log_console=False,
                 verbose=False,
                 device_id=None,
                 enable_debugger=False,
                 sw_ip="10.0.1.254",
                 **kwargs):

        Switch.__init__(self, name, **kwargs)
        assert sw_path
        assert json_path

        # make sure that the provided sw_path is valid
        pathCheck(sw_path)
        # make sure that the provided JSON file exists
        if not os.path.isfile(json_path):
            error("Invalid JSON file.\n")
            exit(1)
        self.sw_path = sw_path
        self.json_path = json_path
        self.pcap_dir = pcap_dir
        self.verbose = verbose
        self.pcap_dump = pcap_dump
        self.enable_debugger = enable_debugger
        self.log_console = log_console
        self.log_file = log_file
        if self.log_file is None:
            self.log_file = "/tmp/p4s.{}.log".format(self.name)
        if self.log_console:
            self.output = open(self.log_file, 'w')
        self.thrift_port = thrift_port
        if check_listening_on_port(self.thrift_port):
            error(
                '%s cannot bind port %d because it is bound by another process\n'
                % (self.name, self.thrift_port))
            exit(1)
        if device_id is not None:
            self.device_id = device_id
            P4Switch.device_id = max(P4Switch.device_id, device_id)
        else:
            self.device_id = P4Switch.device_id
            P4Switch.device_id += 1
        self.nanomsg = "ipc:///tmp/bm-{}-log.ipc".format(self.device_id)

        self.simple_switch_pid = None
        self.sw_ip = sw_ip
示例#3
0
    def __init__(self,
                 name,
                 sw_path=None,
                 json_path=None,
                 grpc_port=None,
                 pcap_dump=False,
                 log_console=False,
                 verbose=False,
                 device_id=None,
                 enable_debugger=False,
                 **kwargs):
        Switch.__init__(self, name, **kwargs)
        assert (sw_path)
        self.sw_path = sw_path
        # make sure that the provided sw_path is valid
        pathCheck(sw_path)

        if json_path is not None:
            # make sure that the provided JSON file exists
            if not os.path.isfile(json_path):
                error("Invalid JSON file.\n")
                exit(1)
            self.json_path = json_path
        else:
            self.json_path = None

        if grpc_port is not None:
            self.grpc_port = grpc_port
        else:
            self.grpc_port = P4RuntimeSwitch.next_grpc_port
            P4RuntimeSwitch.next_grpc_port += 1

        if check_listening_on_port(self.grpc_port):
            error(
                '%s cannot bind port %d because it is bound by another process\n'
                % (self.name, self.grpc_port))
            exit(1)

        self.verbose = verbose
        logfile = "/tmp/p4s.{}.log".format(self.name)
        self.output = open(logfile, 'w')
        self.pcap_dump = pcap_dump
        self.enable_debugger = enable_debugger
        self.log_console = log_console
        if device_id is not None:
            self.device_id = device_id
            P4Switch.device_id = max(P4Switch.device_id, device_id)
        else:
            self.device_id = P4Switch.device_id
            P4Switch.device_id += 1
        self.nanomsg = "ipc:///tmp/bm-{}-log.ipc".format(self.device_id)