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 self.enable_grpc and check_listening_on_port(self.grpc_port): return True elif self.thrift_port and check_listening_on_port( self.thrift_port): return True sleep(0.5)
def __init__(self, name, sw_path = None, json_path = None, grpc_port = None, thrift_port = None, pcap_dump = False, log_console = False, verbose = False, device_id = None, enable_debugger = False, log_file = None, cpu_port = None, **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".format(json_path)) 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 thrift_port is not None: self.thrift_port = thrift_port else: self.thrift_port = P4RuntimeSwitch.next_thrift_port P4RuntimeSwitch.next_thrift_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 log_file is not None: self.log_file = log_file else: self.log_file = "/tmp/p4s.{}.log".format(self.name) 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.cpu_port = cpu_port
def check_ap_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(int(self.grpc_port)): return True sleep(0.5)
def __init__(self, name, sw_path=None, json_path=None, thrift_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) 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.verbose = verbose logfile = "/log/p4s.{}.log".format(self.name) self.output = open(logfile, '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.grpc_port)) exit(1) self.pcap_dump = pcap_dump self.enable_debugger = enable_debugger self.log_console = log_console self.device_id = P4Switch.device_id P4Switch.device_id += 1 self.nanomsg = "ipc:///log/bm-{}-log.ipc".format(self.device_id) if "operating_mode" in kwargs: self.operating_mode = kwargs["operating_mode"] else: self.operating_mode = "NORMAL" if "switch_rel_cpu_speed" in kwargs: self.switch_rel_cpu_speed = kwargs["switch_rel_cpu_speed"] else: self.switch_rel_cpu_speed = 1.0 if "n_round_insns" in kwargs: self.n_round_insns = kwargs["n_round_insns"] else: self.n_round_insns = 1000000 self.tracer_path = "/usr/bin/tracer" self.switch_pid = None
def check_switch_started(self, pid): """While the process is running (pid exists), we check if the Thrift server has been started. If the Thrift server is ready, we assume that the switch was started successfully. This is only reliable if the Thrift server is started at the end of the init process""" while True: if not os.path.exists(os.path.join("/proc", str(pid))): return False if check_listening_on_port(self.thrift_port): return True sleep(0.5)
def __init__(self, name, sw_path=None, json_path=None, thrift_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) 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) # disable IPv6 self.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1") self.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1") self.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1") self.sw_path = sw_path self.json_path = json_path self.verbose = verbose logfile = "/tmp/p4s.{}.log".format(self.name) self.output = open(logfile, '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.grpc_port)) exit(1) 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)
def __init__(self, name, sw_path=None, json_path=None, grpc_port=None, thrift_port=None, pcap_dump=False, log_console=False, verbose=False, device_id=None, enable_debugger=False, log_dir=None, log_file=None, log_level=None, log_flush=True, cpu_port=None, **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) #do not upload any json: self.json_path = None self.log_level = log_level self.log_flush = log_flush 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 thrift_port is not None: self.thrift_port = thrift_port else: self.thrift_port = P4RuntimeSwitch.next_thrift_port P4RuntimeSwitch.next_thrift_port += 1 if cpu_port is not None: self.cpu_port = cpu_port else: self.cpu_port = P4RuntimeSwitch.next_cpu_port 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.enable_debugger = enable_debugger self.log_console = log_console if log_dir is not None: self.log_file = str(log_dir) + '/' + str(self.name) # if log_file is not None: # self.log_file = log_file # else: # self.log_file = "/tmp/p4s.{}.log".format(self.name) 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.pcap_dump = pcap_dump self.nanomsg = "ipc:///tmp/bm-{}-log.ipc".format(self.device_id)
def __init__(self, name, sw_path=None, enable_grpc=True, grpc_port=None, thrift_port=None, pcap_dump=False, log_console=False, start_controller=True, program=None, verbose=False, device_id=None, enable_debugger=False, cli_path=None, log_file=None, **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) self.cli_path = cli_path self.program = program self.enable_grpc = enable_grpc json_path = None p4info_path = None if self.program: json_path = self.program.json() if self.program.p4info(): p4info_path = self.program.p4info() 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 p4info_path is not None: if not os.path.isfile(p4info_path): error("Invalid P4Info file.\n") exit(1) self.p4info_path = p4info_path else: self.p4info_path = None self.grpc_port = grpc_port if self.enable_grpc and grpc_port is None: self.grpc_port = P4RuntimeSwitch.next_grpc_port P4RuntimeSwitch.next_grpc_port += 1 if thrift_port is not None: self.thrift_port = thrift_port else: self.thrift_port = P4RuntimeSwitch.next_thrift_port P4RuntimeSwitch.next_thrift_port += 1 if enable_grpc and 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/p4app-logs/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 self.start_controller = start_controller if not self.program.supportsP4Runtime(): self.start_controller = False self.sw_conn = None if log_file is not None: self.log_file = log_file else: self.log_file = logfile 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)
def __init__(self, name, sw_path = None, json_path = None, grpc_port = None, thrift_port = None, pcap_dump = False, log_console = False, verbose = False, device_id = None, enable_debugger = False, log_file = None, **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 thrift_port is not None: self.thrift_port = thrift_port else: # Note(rachit): Assumes that the switch names are of the form 's\d+' # and that each name is distinct. The number is used to create the # thrift port. switch_regex = re.compile(r"^s(\d+)$") s_num = int(switch_regex.search(name).group(1)) self.thrift_port = 9090 + s_num print "Binding", name, "to thrift port", self.thrift_port 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 log_file is not None: self.log_file = log_file else: self.log_file = "/tmp/p4s.{}.log".format(self.name) 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)