2019-10-27 08:41:14 +00:00
## Open5GS Python Library
2019-07-15 08:28:45 +00:00
2021-04-25 06:25:51 +00:00
Basic Python library to interface with MongoDB subscriber DB in Open5GS HSS / PCRF. Requires Python 3+, pymongo and bson. (All available through PIP)
2019-07-15 08:28:45 +00:00
If you are planning to run this on a different machine other than localhost (the machine hosting the MongoDB service) you will need to enable remote access to MongoDB by binding it's IP to 0.0.0.0:
This is done by editing ```/etc/mongodb.conf``` and changing the bind IP to:
``` bind_ip = 0.0.0.0 ```
Restart MongoDB for changes to take effect.
``` $ /etc/init.d/mongodb restart ```
Basic Example:
```
2019-10-27 08:41:14 +00:00
import Open5GS
Open5GS_1 = Open5GS("10.0.1.118", 27017)
2019-07-15 08:28:45 +00:00
2021-03-30 07:56:23 +00:00
slice_data = [
{
"sst": 1,
"default_indicator": True,
"session": [
{
"name": "internet",
2022-04-27 12:36:34 +00:00
"type": 3, "pcc_rule": [], "ambr": {"uplink": {"value": 1, "unit": 3}, "downlink": {"value": 1, "unit": 3}},
2021-03-30 07:56:23 +00:00
"qos": {
"index": 9,
"arp": {"priority_level": 8, "pre_emption_capability": 1, "pre_emption_vulnerability": 1}
}
}
]
}
]
sub_data = {
"imsi": "001010000000004",
"subscribed_rau_tau_timer": 12,
2022-01-16 03:35:55 +00:00
"network_access_mode": 0,
2021-03-30 07:56:23 +00:00
"subscriber_status": 0,
"access_restriction_data": 32,
"slice" : slice_data,
2022-04-27 12:36:34 +00:00
"ambr": {"uplink": {"value": 1, "unit": 3}, "downlink": {"value": 1, "unit": 3}},
2021-03-30 07:56:23 +00:00
"security": {
"k": "465B5CE8 B199B49F AA5F0A2E E238A6BC",
"amf": "8000",
'op': None,
"opc": "E8ED289D EBA952E4 283B54E8 8E6183CA"
},
"schema_version": 1,
"__v": 0
}
2019-07-15 08:28:45 +00:00
2019-10-27 08:41:14 +00:00
print(Open5GS_1.AddSubscriber(sub_data)) #Add Subscriber using dict of sub_data
2019-07-15 08:28:45 +00:00
2019-10-27 08:41:14 +00:00
print(Open5GS_1.GetSubscriber('891012222222300')) #Get added Subscriber's details
2019-07-15 08:28:45 +00:00
2020-03-15 06:28:50 +00:00
print(Open5GS_1.UpdateSubscriber('891012222222300', sub_data)) #Update subscriber
2019-10-27 08:41:14 +00:00
print(Open5GS_1.DeleteSubscriber('891012222222300')) #Delete Subscriber
2019-07-15 08:28:45 +00:00
2019-10-27 08:41:14 +00:00
Subscriber_List = Open5GS_1.GetSubscribers()
2019-07-15 08:28:45 +00:00
for subscribers in Subscriber_List:
print(subscribers['imsi'])
```