def _build_add_subs_data(num_subs: int, input_file: str):
    add_subs_reqs = []
    for i in range(1, num_subs):
        sid = SubscriberID(id=str(i).zfill(15))
        config = Non3GPPUserProfile(
            apn_config=[APNConfiguration(service_selection=TEST_APN)], )
        data = SubscriberData(sid=sid, non_3gpp=config)
        add_sub_req_dict = json_format.MessageToDict(data)
        add_subs_reqs.append(add_sub_req_dict)

    with open(input_file, 'w') as file:
        json.dump(add_subs_reqs, file, separators=(',', ':'))
def _load_subs(num_subs: int) -> List[SubscriberID]:
    client = SubscriberDBStub(
        ServiceRegistry.get_rpc_channel('subscriberdb', ServiceRegistry.LOCAL))
    sids = []

    for i in range(1, num_subs):
        sid = SubscriberID(id=str(i).zfill(15))
        config = Non3GPPUserProfile(
            apn_config=[APNConfiguration(service_selection="magma.ipv4")])
        data = SubscriberData(sid=sid, non_3gpp=config)
        client.AddSubscriber(data)
        sids.append(sid)
    return sids
Beispiel #3
0
    def add_sub(cls, sid: str, apn: str, ip: str, vlan: str = None,
                gw_ip=None, gw_mac=None):
        sub_db_sid = SIDUtils.to_pb(sid)
        lte = LTESubscription()
        lte.state = LTESubscription.ACTIVE
        state = SubscriberState()
        state.lte_auth_next_seq = 1
        non_3gpp = Non3GPPUserProfile()
        subs_data = SubscriberData(sid=sub_db_sid, lte=lte, state=state,
                                   non_3gpp=non_3gpp)

        cls.subs[str(sub_db_sid)] = subs_data
        cls.add_sub_ip(sid, apn, ip, vlan, gw_ip, gw_mac)
def _build_update_subs_data(num_subs: int, input_file: str):
    active_sids = _load_subs(num_subs)
    update_subs_reqs = []
    for sid in active_sids:
        config = Non3GPPUserProfile(
            apn_config=[APNConfiguration(service_selection=TEST_APN_UPDATE)], )
        data = SubscriberData(sid=sid, non_3gpp=config)
        update = SubscriberUpdate(data=data)
        update_sub_req_dict = json_format.MessageToDict(update)
        update_subs_reqs.append(update_sub_req_dict)

    with open(input_file, 'w') as file:
        json.dump(update_subs_reqs, file, separators=(',', ':'))
def _load_subs(num_subs: int) -> List[SubscriberID]:
    client = SubscriberDBStub(
        ServiceRegistry.get_rpc_channel(
            SUBSCRIBERDB_SERVICE_NAME,
            ServiceRegistry.LOCAL,
        ), )
    sids = []

    for i in range(1, num_subs):
        sid = SubscriberID(id=str(i).zfill(15))
        config = Non3GPPUserProfile(
            apn_config=[APNConfiguration(service_selection=TEST_APN)], )
        data = SubscriberData(sid=sid, non_3gpp=config)
        client.AddSubscriber(data)
        sids.append(sid)
    return sids