Beispiel #1
0
    def load(self):
        """
        Instantiates and schedules the Ryu app eventlets in the service
        eventloop.
        """

        # Some setups might not use REDIS
        if (self._magma_service.config['redis_enabled']):
            # Wait for redis as multiple controllers rely on it
            while not redisAvailable(self.rule_id_mapper.redis_cli):
                logging.warning("Pipelined waiting for redis...")
                time.sleep(1)
        else:
            self.rule_id_mapper._rule_nums_by_rule = {}
            self.rule_id_mapper._rules_by_rule_num = {}
            self.session_rule_version_mapper._version_by_imsi_and_rule = {}
            self.interface_to_prefix_mapper._prefix_by_interface = {}
            self.tunnel_id_mapper._tunnel_map = {}

        manager = AppManager.get_instance()
        manager.load_apps([app.module for app in self._apps])
        contexts = manager.create_contexts()
        contexts['rule_id_mapper'] = self.rule_id_mapper
        contexts[
            'session_rule_version_mapper'] = self.session_rule_version_mapper
        contexts['interface_to_prefix_mapper'] = self.interface_to_prefix_mapper
        contexts['tunnel_id_mapper'] = self.tunnel_id_mapper
        contexts['app_futures'] = {app.name: Future() for app in self._apps}
        contexts['internal_ip_allocator'] = \
            InternalIPAllocator(self._magma_service.config)
        contexts['config'] = self._magma_service.config
        contexts['mconfig'] = self._magma_service.mconfig
        contexts['loop'] = self._magma_service.loop
        contexts['service_manager'] = self

        sessiond_chan = ServiceRegistry.get_rpc_channel(
            'sessiond', ServiceRegistry.LOCAL)
        mobilityd_chan = ServiceRegistry.get_rpc_channel(
            'mobilityd', ServiceRegistry.LOCAL)
        contexts['rpc_stubs'] = {
            'mobilityd': MobilityServiceStub(mobilityd_chan),
            'sessiond': LocalSessionManagerStub(sessiond_chan),
        }

        # Instantiate and schedule apps
        for app in manager.instantiate_apps(**contexts):
            # Wrap the eventlet in asyncio so it will stop when the loop is
            # stopped
            future = aioeventlet.wrap_greenthread(app,
                                                  self._magma_service.loop)

            # Schedule the eventlet for evaluation in service loop
            asyncio.ensure_future(future)

        # In development mode, run server so that
        if environment.is_dev_mode():
            server_thread = of_rest_server.start(manager)
            future = aioeventlet.wrap_greenthread(server_thread,
                                                  self._magma_service.loop)
            asyncio.ensure_future(future)
Beispiel #2
0
    def start_ryu_apps(self, launch_successful_future):
        """
        Starts up ryu applications, all the configuration is parsed from the
        test_setup config provided in the unit test.

        If apps throw an exception on launch, error is passed in the
        launch_successful_future and will prevent infinitely waiting.
        """
        self.reset_static_vars()
        hub.spawn(self._process_queue)

        app_lists = [a.value.name for a in self._test_setup.apps]
        app_futures = {
            controller.value.app_future: future
            for (controller, future) in self._test_setup.references.items()
        }

        manager = AppManager.get_instance()
        manager.load_apps(app_lists)
        contexts = manager.create_contexts()
        contexts['sids_by_ip'] = {}     # shared by both metering apps
        contexts['rule_id_mapper'] = \
            self._test_setup.service_manager.rule_id_mapper
        contexts['internal_ip_allocator'] = \
            InternalIPAllocator(self._test_setup.config)
        contexts['session_rule_version_mapper'] = \
            self._test_setup.service_manager.session_rule_version_mapper
        contexts['interface_to_prefix_mapper'] = \
            self._test_setup.service_manager.interface_to_prefix_mapper
        contexts['restart_info_store'] = \
            self._test_setup.service_manager.restart_info_store
        contexts['app_futures'] = app_futures
        contexts['config'] = self._test_setup.config
        contexts['mconfig'] = self._test_setup.mconfig
        contexts['loop'] = self._test_setup.loop
        contexts['rpc_stubs'] = self._test_setup.rpc_stubs
        contexts['service_manager'] = self._test_setup.service_manager
        contexts['ebpf_manager'] = None
        contexts['qos_manager'] = QosManager(self._test_setup.loop, self._test_setup.config)

        logging.basicConfig(
            level=logging.INFO,
            format='[%(asctime)s %(levelname)s %(name)s] %(message)s',
        )

        services = []
        try:
            services.extend(manager.instantiate_apps(**contexts))
        except Exception as e:
            launch_successful_future.set_result(
                "Ryu apps launch exception: {}".format(e),
            )
            raise

        launch_successful_future.set_result("Setup successful")

        self.run(manager)
Beispiel #3
0
    def load(self):
        """
        Instantiates and schedules the Ryu app eventlets in the service
        eventloop.
        """
        manager = AppManager.get_instance()
        manager.load_apps([app.module for app in self._apps])
        contexts = manager.create_contexts()
        contexts['rule_id_mapper'] = RuleIDToNumMapper()
        contexts[
            'session_rule_version_mapper'] = self.session_rule_version_mapper
        contexts['app_futures'] = {app.name: Future() for app in self._apps}
        contexts['internal_ip_allocator'] = \
            InternalIPAllocator(self._magma_service.config)
        contexts['config'] = self._magma_service.config
        contexts['mconfig'] = self._magma_service.mconfig
        contexts['loop'] = self._magma_service.loop
        contexts['service_manager'] = self

        sessiond_chan = ServiceRegistry.get_rpc_channel(
            'sessiond', ServiceRegistry.LOCAL)
        mobilityd_chan = ServiceRegistry.get_rpc_channel(
            'mobilityd', ServiceRegistry.LOCAL)
        contexts['rpc_stubs'] = {
            'mobilityd': MobilityServiceStub(mobilityd_chan),
            'sessiond': LocalSessionManagerStub(sessiond_chan),
        }

        # Instantiate and schedule apps
        for app in manager.instantiate_apps(**contexts):
            # Wrap the eventlet in asyncio so it will stop when the loop is
            # stopped
            future = aioeventlet.wrap_greenthread(app,
                                                  self._magma_service.loop)

            # Schedule the eventlet for evaluation in service loop
            asyncio.ensure_future(future)

        # In development mode, run server so that
        if environment.is_dev_mode():
            server_thread = of_rest_server.start(manager)
            future = aioeventlet.wrap_greenthread(server_thread,
                                                  self._magma_service.loop)
            asyncio.ensure_future(future)