Ejemplo n.º 1
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)
Ejemplo n.º 2
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']
Ejemplo n.º 3
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._host_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)
Ejemplo n.º 4
0
        Args:
            error: error to log
        """
        # TODO do we want to actually send the error message back perhaps?
        self._set_headers(404, 'text/html')
        self.log_message('Error: %s', error)
        self.wfile.write(error.encode(encoding='utf_8'))

    do_GET = do_POST


class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
    pass


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--config',
                        help='location of yaml configuration file')
    args = parser.parse_args()
    config_filename = args.config
    conf = AuthConfig(config_filename)
    logger = get_logger('httpserver', conf.logger_location, logging.DEBUG, 0)
    HTTPHandler.logger = logger
    HTTPHandler.config = conf
    HTTPHandler.rule_gen = rule_generator.RuleGenerator(conf.rules)
    server = ThreadedHTTPServer(('', conf.listen_port), HTTPHandler)
    logger.info(('starting server %d', conf.listen_port))
    server.serve_forever()
Ejemplo n.º 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.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.
        prom_port = int(os.getenv('FAUCET_PROMETHEUS_PORT', '9244'))
        self.metrics = faucet_metrics.FaucetMetrics(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.metric_update_request_thread = hub.spawn(
            self.metric_update_request)

        self.dp_bgp_speakers = {}
        self._reset_bgp()

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