async def _get_client(service): (ip, port) = ServiceRegistry.get_service_address(service) return await aioh2.open_connection(ip, port)
def main(): """Start mobilityd""" service = MagmaService('mobilityd', mconfigs_pb2.MobilityD()) # Optionally pipe errors to Sentry sentry_init(service_name=service.name) # Load service configs and mconfig config = service.config mconfig = service.mconfig multi_apn = config.get('multi_apn', mconfig.multi_apn_ip_alloc) static_ip_enabled = config.get('static_ip', mconfig.static_ip_enabled) allocator_type = mconfig.ip_allocator_type dhcp_iface = config.get('dhcp_iface', 'dhcp0') dhcp_retry_limit = config.get('retry_limit', RETRY_LIMIT) # TODO: consider adding gateway mconfig to decide whether to # persist to Redis client = get_default_client() store = MobilityStore( client, config.get('persist_to_redis', False), config.get('redis_port', DEFAULT_REDIS_PORT), ) chan = ServiceRegistry.get_rpc_channel( 'subscriberdb', ServiceRegistry.LOCAL, ) ipv4_allocator = _get_ipv4_allocator( store, allocator_type, static_ip_enabled, multi_apn, dhcp_iface, dhcp_retry_limit, SubscriberDBStub(chan), ) # Init IPv6 allocator, for now only IP_POOL mode is supported for IPv6 ipv6_allocator = IPv6AllocatorPool( store=store, session_prefix_alloc_mode=_get_value_or_default( mconfig.ipv6_prefix_allocation_type, DEFAULT_IPV6_PREFIX_ALLOC_MODE, ), ) # Load IPAddressManager ip_address_man = IPAddressManager(ipv4_allocator, ipv6_allocator, store) # Add all servicers to the server mobility_service_servicer = MobilityServiceRpcServicer( ip_address_man, config.get('print_grpc_payload', False), ) mobility_service_servicer.add_to_server(service.rpc_server) # Load IPv4 and IPv6 blocks from the configurable mconfig file # No dynamic reloading support for now, assume restart after updates ipv4_block = _get_ip_block(mconfig.ip_block, "IPv4") if ipv4_block is not None: logging.info('Adding IPv4 block') try: mobility_service_servicer.add_ip_block(ipv4_block) except OverlappedIPBlocksError: logging.warning("Overlapped IPv4 block: %s", ipv4_block) ipv6_block = _get_ip_block(mconfig.ipv6_block, "IPv6") if ipv6_block is not None: logging.info('Adding IPv6 block') try: mobility_service_servicer.add_ip_block(ipv6_block) except OverlappedIPBlocksError: logging.warning("Overlapped IPv6 block: %s", ipv6_block) # Run the service loop service.run() # Cleanup the service service.close()
def send_policy_rar(client, args): sessiond_chan = ServiceRegistry.get_rpc_channel("sessiond", ServiceRegistry.LOCAL) sessiond_client = SessionProxyResponderStub(sessiond_chan) flow_list_str = args.flow_rules.split(";") flow_match_list = [] for i, flow_str in enumerate(flow_list_str): print("%d: %s" % (i, flow_str)) flow_fields = flow_str.split(",") if flow_fields[0] == "UL": flow_direction = FlowMatch.UPLINK elif flow_fields[0] == "DL": flow_direction = FlowMatch.DOWNLINK else: print("%s is not valid" % flow_fields[0]) raise ValueError( "UL or DL are the only valid" " values for first parameter of flow match", ) ip_protocol = int(flow_fields[1]) if flow_fields[1] == FlowMatch.IPPROTO_TCP: udp_src_port = 0 udp_dst_port = 0 if flow_fields[3]: tcp_src_port = int(flow_fields[3]) else: tcp_src_port = 0 if flow_fields[5]: tcp_dst_port = int(flow_fields[5]) else: tcp_dst_port = 0 elif flow_fields[1] == FlowMatch.IPPROTO_UDP: tcp_src_port = 0 tcp_dst_port = 0 if flow_fields[3]: udp_src_port = int(flow_fields[3]) else: udp_src_port = 0 if flow_fields[5]: udp_dst_port = int(flow_fields[5]) else: udp_dst_port = 0 else: udp_src_port = 0 udp_dst_port = 0 tcp_src_port = 0 tcp_dst_port = 0 flow_match_list.append( FlowDescription( match=FlowMatch( direction=flow_direction, ip_proto=ip_protocol, ipv4_src=flow_fields[2], ipv4_dst=flow_fields[4], tcp_src=tcp_src_port, tcp_dst=tcp_dst_port, udp_src=udp_src_port, udp_dst=udp_dst_port, ), action=FlowDescription.PERMIT, ), ) qos_parameter_list = args.qos.split(",") if len(qos_parameter_list) == 7: # utilize user passed arguments policy_qos = FlowQos( qci=int(args.qci), max_req_bw_ul=int(qos_parameter_list[0]), max_req_bw_dl=int(qos_parameter_list[1]), gbr_ul=int(qos_parameter_list[2]), gbr_dl=int(qos_parameter_list[3]), arp=QosArp( priority_level=int(qos_parameter_list[4]), pre_capability=int(qos_parameter_list[5]), pre_vulnerability=int(qos_parameter_list[6]), ), ) else: # parameter missing, use default values policy_qos = FlowQos( qci=int(args.qci), max_req_bw_ul=100000, max_req_bw_dl=100000, arp=QosArp(priority_level=1, pre_capability=1, pre_vulnerability=0), ) policy_rule = PolicyRule( id=args.policy_id, priority=int(args.priority), flow_list=flow_match_list, tracking_type=PolicyRule.NO_TRACKING, rating_group=1, monitoring_key=None, qos=policy_qos, ) qos = QoSInformation(qci=int(args.qci)) reauth_result = sessiond_client.PolicyReAuth( PolicyReAuthRequest( session_id=args.session_id, imsi=args.imsi, rules_to_remove=[], rules_to_install=[], dynamic_rules_to_install=[DynamicRuleInstall(policy_rule=policy_rule)], event_triggers=[], revalidation_time=None, usage_monitoring_credits=[], qos_info=qos, ), ) print(reauth_result)
def main(): """Start mobilityd""" service = MagmaService('mobilityd', mconfigs_pb2.MobilityD()) # Load service configs and mconfig config = service.config mconfig = service.mconfig # Optionally pipe errors to Sentry sentry_init(service_name=service.name, sentry_mconfig=service.shared_mconfig.sentry_config) multi_apn = config.get('multi_apn', mconfig.multi_apn_ip_alloc) static_ip_enabled = config.get('static_ip', mconfig.static_ip_enabled) allocator_type = mconfig.ip_allocator_type dhcp_iface = config.get('dhcp_iface', 'dhcp0') dhcp_retry_limit = config.get('retry_limit', RETRY_LIMIT) ipv6_prefixlen = config.get('ipv6_prefixlen', None) # TODO: consider adding gateway mconfig to decide whether to # persist to Redis client = get_default_client() store = MobilityStore(client, ) chan = ServiceRegistry.get_rpc_channel( 'subscriberdb', ServiceRegistry.LOCAL, ) ipv4_allocator = _get_ipv4_allocator( store, allocator_type, static_ip_enabled, multi_apn, dhcp_iface, dhcp_retry_limit, SubscriberDBStub(chan), ) # Init IPv6 allocator, for now only IP_POOL mode is supported for IPv6 ipv6_allocator = _get_ipv6_allocator( store, allocator_type, static_ip_enabled, mconfig, ipv6_prefixlen, SubscriberDBStub(chan), ) # Load IPAddressManager ip_address_man = IPAddressManager(ipv4_allocator, ipv6_allocator, store) # Load IPv4 and IPv6 blocks from the configurable mconfig file # No dynamic reloading support for now, assume restart after updates ipv4_block = _get_ip_block(mconfig.ip_block, "IPv4") if ipv4_block is not None: logging.info('Adding IPv4 block') try: allocated_ip_blocks = ip_address_man.list_added_ip_blocks() if ipv4_block not in allocated_ip_blocks: # Cleanup previously allocated IP blocks ip_address_man.remove_ip_blocks(*allocated_ip_blocks, force=True) ip_address_man.add_ip_block(ipv4_block) except OverlappedIPBlocksError: logging.warning("Overlapped IPv4 block: %s", ipv4_block) ipv6_block = _get_ip_block(mconfig.ipv6_block, "IPv6") if ipv6_block is not None: logging.info('Adding IPv6 block') try: allocated_ipv6_block = ip_address_man.get_assigned_ipv6_block() if ipv6_block != allocated_ipv6_block: ip_address_man.add_ip_block(ipv6_block) # configure IPv6 default GW store.dhcp_gw_info.read_default_gw_v6() except OverlappedIPBlocksError: logging.warning("Overlapped IPv6 block: %s", ipv6_block) # Add all servicers to the server mobility_service_servicer = MobilityServiceRpcServicer( ip_address_man, config.get('print_grpc_payload', False), ) mobility_service_servicer.add_to_server(service.rpc_server) service.run() # Cleanup the service service.close()