Esempio n. 1
0
def pcef_create_session(args):
    chan = ServiceRegistry.get_rpc_channel(args.pcef, ServiceRegistry.LOCAL)
    client = LocalSessionManagerStub(chan)
    request = LocalCreateSessionRequest(
        sid=SIDUtils.to_pb(args.imsi),
        ue_ipv4=args.user_ip)
    client.CreateSession(request)
Esempio n. 2
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)
Esempio n. 3
0
def main():
    service = MagmaService('policydb', mconfigs_pb2.PolicyDB())

    apn_rules_dict = ApnRuleAssignmentsDict()
    assignments_dict = RuleAssignmentsDict()
    basenames_dict = BaseNameDict()
    rating_groups_dict = RatingGroupsDict()
    sessiond_chan = ServiceRegistry.get_rpc_channel('sessiond',
                                                    ServiceRegistry.LOCAL)
    session_mgr_stub = LocalSessionManagerStub(sessiond_chan)
    sessiond_stub = SessionProxyResponderStub(sessiond_chan)
    reauth_handler = ReAuthHandler(assignments_dict, sessiond_stub)

    # Add all servicers to the server
    session_servicer = SessionRpcServicer(service.mconfig,
                                          rating_groups_dict,
                                          basenames_dict,
                                          apn_rules_dict)
    session_servicer.add_to_server(service.rpc_server)

    orc8r_chan = ServiceRegistry.get_rpc_channel('policydb',
                                                 ServiceRegistry.CLOUD)
    policy_stub = PolicyAssignmentControllerStub(orc8r_chan)
    policy_servicer = PolicyRpcServicer(reauth_handler, basenames_dict,
                                        policy_stub)
    policy_servicer.add_to_server(service.rpc_server)

    # Start a background thread to stream updates from the cloud
    if service.config['enable_streaming']:
        stream = StreamerClient(
            {
                'policydb': PolicyDBStreamerCallback(),
                'apn_rule_mappings': ApnRuleMappingsStreamerCallback(
                    session_mgr_stub,
                    basenames_dict,
                    apn_rules_dict,
                ),
                'rule_mappings': RuleMappingsStreamerCallback(
                    reauth_handler,
                    basenames_dict,
                    assignments_dict,
                    apn_rules_dict,
                ),
                'rating_groups': RatingGroupsStreamerCallback(
                    rating_groups_dict),

            },
            service.loop,
        )
        stream.start()
    else:
        logging.info('enable_streaming set to False. Streamer disabled!')

    # Run the service loop
    service.run()

    # Cleanup the service
    service.close()
Esempio n. 4
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['config'] = self._magma_service.config
        contexts['mconfig'] = self._magma_service.mconfig
        contexts['loop'] = self._magma_service.loop
        contexts['service_manager'] = self

        records_chan = ServiceRegistry.get_rpc_channel('meteringd_records',
                                                       ServiceRegistry.CLOUD)
        sessiond_chan = ServiceRegistry.get_rpc_channel(
            'sessiond', ServiceRegistry.LOCAL)
        mobilityd_chan = ServiceRegistry.get_rpc_channel(
            'mobilityd', ServiceRegistry.LOCAL)
        contexts['rpc_stubs'] = {
            'metering_cloud': MeteringdRecordsControllerStub(records_chan),
            '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)
Esempio n. 5
0
def pcef_end_session(args):
    chan = ServiceRegistry.get_rpc_channel(args.pcef, ServiceRegistry.LOCAL)
    client = LocalSessionManagerStub(chan)
    client.EndSession(SIDUtils.to_pb(args.imsi))