def update_subscriber(client, args): update = SubscriberUpdate() update.data.sid.CopyFrom(SIDUtils.to_pb(args.sid)) gsm = update.data.gsm lte = update.data.lte fields = update.mask.paths if len(args.gsm_auth_tuple) != 0: gsm.state = GSMSubscription.ACTIVE for auth_tuple in args.gsm_auth_tuple: gsm.auth_tuples.append(bytes.fromhex(auth_tuple)) fields.append('gsm.state') fields.append('gsm.auth_tuples') if args.lte_auth_key is not None: lte.state = LTESubscription.ACTIVE lte.auth_key = bytes.fromhex(args.lte_auth_key) fields.append('lte.state') fields.append('lte.auth_key') if args.lte_auth_next_seq is not None: update.data.state.lte_auth_next_seq = args.lte_auth_next_seq fields.append('state.lte_auth_next_seq') if args.lte_auth_opc is not None: lte.auth_opc = bytes.fromhex(args.lte_auth_opc) fields.append('lte.state') fields.append('lte.auth_opc') client.UpdateSubscriber(update)
def _get_apn_data(sid, apn_list): """ Get APN data in protobuf format. Args: apn_list : list of APN configuration Returns: update (protos.subscriberdb_pb2.SubscriberUpdate) """ # APN update = SubscriberUpdate() update.data.sid.CopyFrom(sid) non_3gpp = update.data.non_3gpp for apn in apn_list: apn_config = non_3gpp.apn_config.add() apn_config.service_selection = apn["apn_name"] apn_config.qos_profile.class_id = apn["qci"] apn_config.qos_profile.priority_level = apn["priority"] apn_config.qos_profile.preemption_capability = apn["pre_cap"] apn_config.qos_profile.preemption_vulnerability = apn["pre_vul"] apn_config.ambr.max_bandwidth_ul = apn["mbr_ul"] apn_config.ambr.max_bandwidth_dl = apn["mbr_dl"] apn_config.pdn = apn["pdn_type"] if "pdn_type" in apn else 0 if apn.get("static_ip", None): apn_config.assigned_static_ip = apn["static_ip"] return update
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 test_update_subscriber(self): """ Test if UpdateSubscriber rpc call works """ sid = SIDUtils.to_pb('IMSI1') data = SubscriberData(sid=sid) # Add subscriber self._stub.AddSubscriber(data) sub = self._stub.GetSubscriberData(sid) self.assertEqual(sub.lte.auth_key, b'') self.assertEqual(sub.state.lte_auth_next_seq, 0) # Update subscriber update = SubscriberUpdate() update.data.sid.CopyFrom(sid) update.data.lte.auth_key = b'\xab\xcd' update.data.state.lte_auth_next_seq = 1 update.mask.paths.append('lte.auth_key') # only auth_key self._stub.UpdateSubscriber(update) sub = self._stub.GetSubscriberData(sid) self.assertEqual(sub.state.lte_auth_next_seq, 0) # no change self.assertEqual(sub.lte.auth_key, b'\xab\xcd') update.data.state.lte_auth_next_seq = 1 update.mask.paths.append('state.lte_auth_next_seq') self._stub.UpdateSubscriber(update) sub = self._stub.GetSubscriberData(sid) self.assertEqual(sub.state.lte_auth_next_seq, 1) # Delete the subscriber self._stub.DeleteSubscriber(sid) with self.assertRaises(grpc.RpcError) as err: self._stub.UpdateSubscriber(update) self.assertEqual(err.exception.code(), grpc.StatusCode.NOT_FOUND)
def update_subscriber(client, args): update = SubscriberUpdate() update.data.sid.CopyFrom(SIDUtils.to_pb(args.sid)) gsm = update.data.gsm lte = update.data.lte non_3gpp = update.data.non_3gpp fields = update.mask.paths if len(args.gsm_auth_tuple) != 0: gsm.state = GSMSubscription.ACTIVE for auth_tuple in args.gsm_auth_tuple: gsm.auth_tuples.append(bytes.fromhex(auth_tuple)) fields.append('gsm.state') fields.append('gsm.auth_tuples') if args.lte_auth_key is not None: lte.state = LTESubscription.ACTIVE lte.auth_key = bytes.fromhex(args.lte_auth_key) fields.append('lte.state') fields.append('lte.auth_key') if args.lte_auth_next_seq is not None: update.data.state.lte_auth_next_seq = args.lte_auth_next_seq fields.append('state.lte_auth_next_seq') if args.lte_auth_opc is not None: lte.state = LTESubscription.ACTIVE lte.auth_opc = bytes.fromhex(args.lte_auth_opc) fields.append('lte.state') fields.append('lte.auth_opc') if args.apn_config is not None: apn_name = "apn_name" qci = "qci" priority = "priority" pre_cap = "preemption_capability" pre_vul = "preemption_vulnerability" ul = "mbr_uplink" dl = "mbr_downlink" pdn_type = "pdn_type" static_ip = "static_ip" vlan_id = "vlan" gw_ip = "gw_ip" gw_mac = "gw_mac" apn_keys = ( apn_name, qci, priority, pre_cap, pre_vul, ul, dl, pdn_type, static_ip, vlan_id, gw_ip, gw_mac, ) apn_data = args.apn_config for apn_d in apn_data: apn_val = apn_d.split(",") if len(apn_val) != 12: print( "Incorrect APN parameters." "Please check: subscriber_cli.py update -h", ) return apn_dict = dict(zip(apn_keys, apn_val)) apn_config = non_3gpp.apn_config.add() apn_config.service_selection = apn_dict[apn_name] apn_config.qos_profile.class_id = int(apn_dict[qci]) apn_config.qos_profile.priority_level = int(apn_dict[priority]) apn_config.qos_profile.preemption_capability = int( apn_dict[pre_cap], ) apn_config.qos_profile.preemption_vulnerability = int( apn_dict[pre_vul], ) apn_config.ambr.max_bandwidth_ul = int(apn_dict[ul]) apn_config.ambr.max_bandwidth_dl = int(apn_dict[dl]) apn_config.pdn = int(apn_dict[pdn_type]) apn_config.assigned_static_ip = apn_dict[static_ip] if apn_dict[vlan_id]: apn_config.resource.vlan_id = int(apn_dict[vlan_id]) if apn_dict[gw_ip]: apn_config.resource.gateway_ip = apn_dict[gw_ip] # allow mac address if gw-ip is specified if apn_dict[gw_mac]: apn_config.resource.gateway_mac = apn_dict[gw_mac] fields.append("non_3gpp") client.UpdateSubscriber(update)
def update_subscriber(client, args): update = SubscriberUpdate() update.data.sid.CopyFrom(SIDUtils.to_pb(args.sid)) gsm = update.data.gsm lte = update.data.lte non_3gpp = update.data.non_3gpp fields = update.mask.paths if len(args.gsm_auth_tuple) != 0: gsm.state = GSMSubscription.ACTIVE for auth_tuple in args.gsm_auth_tuple: gsm.auth_tuples.append(bytes.fromhex(auth_tuple)) fields.append('gsm.state') fields.append('gsm.auth_tuples') if args.lte_auth_key is not None: lte.state = LTESubscription.ACTIVE lte.auth_key = bytes.fromhex(args.lte_auth_key) fields.append('lte.state') fields.append('lte.auth_key') if args.lte_auth_next_seq is not None: update.data.state.lte_auth_next_seq = args.lte_auth_next_seq fields.append('state.lte_auth_next_seq') if args.lte_auth_opc is not None: lte.state = LTESubscription.ACTIVE lte.auth_opc = bytes.fromhex(args.lte_auth_opc) fields.append('lte.state') fields.append('lte.auth_opc') if args.apn_config is not None: apn_name = "apn_name" qci = "qci" priority = "priority" pre_cap = "preemption_capability" pre_vul = "preemption_vulnerability" ul = "mbr_uplink" dl = "mbr_downlink" apn_keys = (apn_name, qci, priority, pre_cap, pre_vul, ul, dl) apn_data = args.apn_config for apn_d in apn_data: apn_val = apn_d.split(",") if len(apn_val) != 7: print("Incorrect APN parameters." "Please check: subscriber_cli.py update -h") return apn_dict = dict(zip(apn_keys, apn_val)) apn_config = non_3gpp.apn_config.add() apn_config.service_selection = apn_dict[apn_name] apn_config.qos_profile.class_id = int(apn_dict[qci]) apn_config.qos_profile.priority_level = int(apn_dict[priority]) apn_config.qos_profile.preemption_capability = int( apn_dict[pre_cap]) apn_config.qos_profile.preemption_vulnerability = int( apn_dict[pre_vul]) apn_config.ambr.max_bandwidth_ul = int(apn_dict[ul]) apn_config.ambr.max_bandwidth_dl = int(apn_dict[dl]) fields.append('non_3gpp') client.UpdateSubscriber(update)