コード例 #1
0
    def __init__(self, *args, **kwargs):
        super(Faucet, self).__init__(*args, **kwargs)

        # There doesnt seem to be a sensible method of getting command line
        # options into ryu apps. Instead I am using the environment variable
        # FAUCET_CONFIG to allow this to be set, if it is not set it will
        # default to valve.yaml
        sysprefix = get_sys_prefix()
        self.config_file = os.getenv('FAUCET_CONFIG',
                                     sysprefix + '/etc/ryu/faucet/faucet.yaml')
        self.logfile = os.getenv('FAUCET_LOG',
                                 sysprefix + '/var/log/ryu/faucet/faucet.log')
        self.exc_logfile = os.getenv(
            'FAUCET_EXCEPTION_LOG',
            sysprefix + '/var/log/ryu/faucet/faucet_exception.log')

        # Set the signal handler for reloading config file
        signal.signal(signal.SIGHUP, self.signal_handler)

        # Create dpset object for querying Ryu's DPSet application
        self.dpset = kwargs['dpset']

        # Setup logging
        self.logger = get_logger(self.logname, self.logfile, logging.DEBUG, 0)
        # Set up separate logging for exceptions
        self.exc_logger = get_logger(self.exc_logname, self.exc_logfile,
                                     logging.DEBUG, 1)

        # TODO: metrics instance can be passed to Valves also,
        # for DP specific instrumentation.
        self.metrics = FaucetMetrics()
        prom_port = int(os.getenv('FAUCET_PROMETHEUS_PORT', '9244'))
        start_http_server(prom_port)

        # Set up a valve object for each datapath
        self.valves = {}
        self.config_hashes, valve_dps = dp_parser(self.config_file,
                                                  self.logname)
        for valve_dp in valve_dps:
            # pylint: disable=no-member
            valve_cl = valve_factory(valve_dp)
            if valve_cl is None:
                self.logger.error('Hardware type not supported for DP: %s',
                                  valve_dp.name)
            else:
                valve = valve_cl(valve_dp, self.logname)
                self.valves[valve_dp.dp_id] = valve
                valve.update_config_metrics(self.metrics)

        self.gateway_resolve_request_thread = hub.spawn(
            self.gateway_resolve_request)
        self.host_expire_request_thread = hub.spawn(self.host_expire_request)

        self.dp_bgp_speakers = {}
        self._reset_bgp()

        # Register to API
        api = kwargs['faucet_api']
        api._register(self)
        self.send_event_to_observers(EventFaucetAPIRegistered())
コード例 #2
0
    def __init__(self, *args, **kwargs):
        super(Faucet, self).__init__(*args, **kwargs)

        # There doesnt seem to be a sensible method of getting command line
        # options into ryu apps. Instead I am using the environment variable
        # FAUCET_CONFIG to allow this to be set, if it is not set it will
        # default to valve.yaml
        self.config_file = get_setting('FAUCET_CONFIG')
        self.loglevel = get_setting('FAUCET_LOG_LEVEL')
        self.logfile = get_setting('FAUCET_LOG')
        self.exc_logfile = get_setting('FAUCET_EXCEPTION_LOG')
        self.stat_reload = get_setting('FAUCET_CONFIG_STAT_RELOAD')

        self.dpset = kwargs['dpset']
        self.api = kwargs['faucet_experimental_api']

        # Setup logging
        self.logger = get_logger(self.logname, self.logfile, self.loglevel, 0)
        # Set up separate logging for exceptions
        self.exc_logger = get_logger(self.exc_logname, self.exc_logfile,
                                     logging.DEBUG, 1)

        self.valves = {}
        self.config_hashes = None
        self.config_file_stats = None
        self.metrics = faucet_metrics.FaucetMetrics()
        self.notifier = faucet_experimental_event.FaucetExperimentalEventNotifier(
            get_setting('FAUCET_EVENT_SOCK'), self.metrics, self.logger)
        self._bgp = faucet_bgp.FaucetBgp(self.logger, self._send_flow_msgs)
コード例 #3
0
    def __init__(self, *args, **kwargs):
        super(Gauge, self).__init__(*args, **kwargs)
        sysprefix = get_sys_prefix()
        self.config_file = os.getenv('GAUGE_CONFIG',
                                     sysprefix + '/etc/ryu/faucet/gauge.yaml')
        self.exc_logfile = os.getenv(
            'GAUGE_EXCEPTION_LOG',
            sysprefix + '/var/log/ryu/faucet/gauge_exception.log')
        self.logfile = os.getenv('GAUGE_LOG',
                                 sysprefix + '/var/log/ryu/faucet/gauge.log')

        # Setup logging
        self.logger = get_logger(self.logname, self.logfile, logging.DEBUG, 0)
        # Set up separate logging for exceptions
        self.exc_logger = get_logger(self.exc_logname, self.exc_logfile,
                                     logging.DEBUG, 1)

        # Set the signal handler for reloading config file
        signal.signal(signal.SIGHUP, self.signal_handler)

        # dict of watchers/handlers:
        # indexed by dp_id and then by name
        self.watchers = {}
        confs = watcher_parser(self.config_file, self.logname)
        for conf in confs:
            watcher = watcher_factory(conf)(conf, self.logname)
            self.watchers.setdefault(watcher.dp.dp_id, {})
            self.watchers[watcher.dp.dp_id][watcher.conf.type] = watcher
        # Create dpset object for querying Ryu's DPSet application
        self.dpset = kwargs['dpset']
コード例 #4
0
    def __init__(self, *args, **kwargs):
        super(Gauge, self).__init__(*args, **kwargs)
        sysprefix = get_sys_prefix()
        self.config_file = os.getenv('GAUGE_CONFIG',
                                     sysprefix + '/etc/ryu/faucet/gauge.yaml')
        self.loglevel = os.getenv('GAUGE_LOG_LEVEL', logging.INFO)
        self.exc_logfile = os.getenv(
            'GAUGE_EXCEPTION_LOG',
            sysprefix + '/var/log/ryu/faucet/gauge_exception.log')
        self.logfile = os.getenv('GAUGE_LOG',
                                 sysprefix + '/var/log/ryu/faucet/gauge.log')

        # Setup logging
        self.logger = get_logger(self.logname, self.logfile, self.loglevel, 0)
        # Set up separate logging for exceptions
        self.exc_logger = get_logger(self.exc_logname, self.exc_logfile,
                                     logging.DEBUG, 1)

        self.prom_client = GaugePrometheusClient()

        # Create dpset object for querying Ryu's DPSet application
        self.dpset = kwargs['dpset']

        # dict of watchers/handlers, indexed by dp_id and then by name
        self.watchers = {}
        self._load_config()

        # Set the signal handler for reloading config file
        signal.signal(signal.SIGHUP, self.signal_handler)
        signal.signal(signal.SIGINT, self.signal_handler)
コード例 #5
0
    def __init__(self, *args, **kwargs):
        super(Faucet, self).__init__(*args, **kwargs)

        # There doesnt seem to be a sensible method of getting command line
        # options into ryu apps. Instead I am using the environment variable
        # FAUCET_CONFIG to allow this to be set, if it is not set it will
        # default to valve.yaml
        sysprefix = get_sys_prefix()
        self.config_file = os.getenv('FAUCET_CONFIG',
                                     sysprefix + '/etc/ryu/faucet/faucet.yaml')
        self.loglevel = os.getenv('FAUCET_LOG_LEVEL', logging.INFO)
        self.logfile = os.getenv('FAUCET_LOG',
                                 sysprefix + '/var/log/ryu/faucet/faucet.log')
        self.exc_logfile = os.getenv(
            'FAUCET_EXCEPTION_LOG',
            sysprefix + '/var/log/ryu/faucet/faucet_exception.log')

        # Create dpset object for querying Ryu's DPSet application
        self.dpset = kwargs['dpset']

        # Setup logging
        self.logger = get_logger(self.logname, self.logfile, self.loglevel, 0)
        # Set up separate logging for exceptions
        self.exc_logger = get_logger(self.exc_logname, self.exc_logfile,
                                     logging.DEBUG, 1)

        self.valves = {}

        # Start Prometheus
        prom_port = int(os.getenv('FAUCET_PROMETHEUS_PORT', '9302'))
        prom_addr = os.getenv('FAUCET_PROMETHEUS_ADDR', '')
        self.metrics = faucet_metrics.FaucetMetrics()
        self.metrics.start(prom_port, prom_addr)

        # Start BGP
        self._bgp = faucet_bgp.FaucetBgp(self.logger, self._send_flow_msgs)

        # Configure all Valves
        self._load_configs(self.config_file)

        # Start all threads
        self._threads = [
            hub.spawn(thread) for thread in (self._gateway_resolve_request,
                                             self._state_expire_request,
                                             self._metric_update_request,
                                             self._advertise_request)
        ]

        # Register to API
        api = kwargs['faucet_api']
        api._register(self)
        self.send_event_to_observers(EventFaucetAPIRegistered())

        # Set the signal handler for reloading config file
        signal.signal(signal.SIGHUP, self._signal_handler)
        signal.signal(signal.SIGINT, self._signal_handler)
コード例 #6
0
 def __init__(self, *args, **kwargs):
     super(RyuAppBase, self).__init__(*args, **kwargs)
     self.dpset = kwargs['dpset']
     self.config_file = self.get_setting('CONFIG', True)
     self.stat_reload = self.get_setting('CONFIG_STAT_RELOAD')
     loglevel = self.get_setting('LOG_LEVEL')
     logfile = self.get_setting('LOG')
     exc_logfile = self.get_setting('EXCEPTION_LOG')
     self.logger = get_logger(self.logname, logfile, loglevel, 0)
     self.exc_logger = get_logger(self.exc_logname, exc_logfile,
                                  logging.DEBUG, 1)
コード例 #7
0
ファイル: valve_ryuapp.py プロジェクト: gizmoguy/faucet
 def __init__(self, *args, **kwargs):
     super(RyuAppBase, self).__init__(*args, **kwargs)
     self.dpset = kwargs['dpset']
     self._reg = kwargs.get('reg', None)
     self.config_file = self.get_setting('CONFIG', True)
     self.stat_reload = self.get_setting('CONFIG_STAT_RELOAD')
     loglevel = self.get_setting('LOG_LEVEL')
     logfile = self.get_setting('LOG')
     exc_logfile = self.get_setting('EXCEPTION_LOG')
     self.logger = get_logger(
         self.logname, logfile, loglevel, 0)
     self.exc_logger = get_logger(
         self.exc_logname, exc_logfile, logging.DEBUG, 1)
コード例 #8
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.dpset = kwargs['dpset']
     self._reg = kwargs.get('reg', None)
     self.config_file = self.get_setting('CONFIG', True)
     self.stat_reload = self.get_setting('CONFIG_STAT_RELOAD')
     loglevel = self.get_setting('LOG_LEVEL')
     logfile = self.get_setting('LOG')
     exc_logfile = self.get_setting('EXCEPTION_LOG')
     self.logger = get_logger(self.logname, logfile, loglevel, 0)
     self.exc_logger = get_logger(self.exc_logname, exc_logfile,
                                  logging.DEBUG, 1)
     self.threads = []
     self.thread_managers = []
     self.prom_client = None
コード例 #9
0
ファイル: test_valve.py プロジェクト: qasimraz/faucet
 def setup_valve(self, config):
     """Set up test DP with config."""
     self.tmpdir = tempfile.mkdtemp()
     self.config_file = os.path.join(self.tmpdir, 'valve_unit.yaml')
     self.faucet_event_sock = os.path.join(self.tmpdir, 'event.sock')
     self.table = FakeOFTable(self.NUM_TABLES)
     logfile = os.path.join(self.tmpdir, 'faucet.log')
     self.logger = valve_util.get_logger(self.LOGNAME, logfile,
                                         logging.DEBUG, 0)
     self.registry = CollectorRegistry()
     # TODO: verify Prometheus variables
     self.metrics = faucet_metrics.FaucetMetrics(reg=self.registry)  # pylint: disable=unexpected-keyword-arg
     # TODO: verify events
     self.notifier = faucet_experimental_event.FaucetExperimentalEventNotifier(
         self.faucet_event_sock, self.metrics, self.logger)
     self.bgp = faucet_bgp.FaucetBgp(self.logger, self.metrics,
                                     self.send_flows_to_dp_by_id)
     self.valves_manager = valves_manager.ValvesManager(
         self.LOGNAME, self.logger, self.metrics, self.notifier, self.bgp,
         self.send_flows_to_dp_by_id)
     self.notifier.start()
     self.update_config(config)
     self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     self.sock.connect(self.faucet_event_sock)
     self.connect_dp()
コード例 #10
0
 def ofchannel_log(self, ofmsgs):
     """Log OpenFlow messages in text format to debugging log."""
     if (self.dp is not None and self.dp.ofchannel_log is not None):
         if self.ofchannel_logger is None:
             self.ofchannel_logger = valve_util.get_logger(
                 self.dp.ofchannel_log, self.dp.ofchannel_log,
                 logging.DEBUG, 0)
         for i, ofmsg in enumerate(ofmsgs, start=1):
             log_prefix = '%u/%u %s' % (i, len(ofmsgs),
                                        valve_util.dpid_log(self.dp.dp_id))
             self.ofchannel_logger.debug('%s %s', log_prefix, ofmsg)
コード例 #11
0
    def __init__(self, *args, **kwargs):
        super(Gauge, self).__init__(*args, **kwargs)
        self.config_file = get_setting('GAUGE_CONFIG')
        self.loglevel = get_setting('GAUGE_LOG_LEVEL')
        self.exc_logfile = get_setting('GAUGE_EXCEPTION_LOG')
        self.logfile = get_setting('GAUGE_LOG')
        self.stat_reload = get_bool_setting('GAUGE_CONFIG_STAT_RELOAD')

        # Setup logging
        self.logger = get_logger(self.logname, self.logfile, self.loglevel, 0)
        # Set up separate logging for exceptions
        self.exc_logger = get_logger(self.exc_logname, self.exc_logfile,
                                     logging.DEBUG, 1)

        self.dpset = kwargs['dpset']

        self.prom_client = GaugePrometheusClient()

        # dict of watchers/handlers, indexed by dp_id and then by name
        self.watchers = {}
        self.config_file_stats = None
コード例 #12
0
ファイル: test_valve.py プロジェクト: nfz1/faucet
 def setup_valve(self, config):
     """Set up test DP with config."""
     self.tmpdir = tempfile.mkdtemp()
     self.config_file = os.path.join(self.tmpdir, 'valve_unit.yaml')
     self.faucet_event_sock = os.path.join(self.tmpdir, 'event.sock')
     self.logfile = os.path.join(self.tmpdir, 'faucet.log')
     self.table = FakeOFTable(self.NUM_TABLES)
     self.logger = valve_util.get_logger('faucet', self.logfile,
                                         logging.DEBUG, 0)
     self.registry = CollectorRegistry()
     # TODO: verify Prometheus variables
     self.metrics = faucet_metrics.FaucetMetrics(reg=self.registry)  # pylint: disable=unexpected-keyword-arg
     # TODO: verify events
     self.notifier = faucet_experimental_event.FaucetExperimentalEventNotifier(
         self.faucet_event_sock, self.metrics, self.logger)
     self.notifier.start()
     dp = self.update_config(config, self.DP)
     self.valve = valve_factory(dp)(dp, 'test_valve', self.notifier)
     self.valve.update_config_metrics(self.metrics)
     self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     self.sock.connect(self.faucet_event_sock)