mirror of
https://github.com/open5gs/open5gs.git
synced 2026-04-29 11:59:32 +00:00
rename utils to mongodb
This commit is contained in:
parent
964e7ecebd
commit
a6e3affbec
2 changed files with 0 additions and 0 deletions
55
support/mongodb/python/NextEPC.py
Normal file
55
support/mongodb/python/NextEPC.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import mongo
|
||||
import pymongo
|
||||
import random
|
||||
import bson
|
||||
|
||||
class NextEPC:
|
||||
def __init__(self, server, port):
|
||||
self.server = server
|
||||
self.port = port
|
||||
|
||||
|
||||
def GetSubscribers(self):
|
||||
myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/")
|
||||
mydb = myclient["nextepc"]
|
||||
mycol = mydb["subscribers"]
|
||||
subs_list = []
|
||||
for x in mycol.find():
|
||||
print(x)
|
||||
subs_list.append(x)
|
||||
pass
|
||||
|
||||
return subs_list
|
||||
|
||||
def GetSubscriber(self, imsi):
|
||||
myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/")
|
||||
mydb = myclient["nextepc"]
|
||||
mycol = mydb["subscribers"]
|
||||
myquery = { "imsi": str(imsi)}
|
||||
mydoc = mycol.find(myquery)
|
||||
for x in mydoc:
|
||||
print(x)
|
||||
return x
|
||||
|
||||
|
||||
def AddSubscriber(self, sub_data):
|
||||
|
||||
myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/")
|
||||
mydb = myclient["nextepc"]
|
||||
mycol = mydb["subscribers"]
|
||||
|
||||
x = mycol.insert_one(sub_data)
|
||||
print("Added subscriber with Inserted ID : " + str(x.inserted_id))
|
||||
return x.inserted_id
|
||||
|
||||
|
||||
def DeleteSubscriber(self, imsi):
|
||||
myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/")
|
||||
mydb = myclient["nextepc"]
|
||||
mycol = mydb["subscribers"]
|
||||
myquery = { "imsi": str(imsi)}
|
||||
x = mycol.delete_many(myquery)
|
||||
print(x.deleted_count, " subscribers deleted.")
|
||||
return x.deleted_count
|
||||
|
||||
|
||||
40
support/mongodb/python/README.md
Normal file
40
support/mongodb/python/README.md
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
## NextEPC Python Library
|
||||
|
||||
Basic Python library to interface with MongoDB subscriber DB in NextEPC HSS / PCRF. Requires Python 3+, mongo, pymongo and bson. (All available through PIP)
|
||||
|
||||
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:
|
||||
```
|
||||
import NextEPC
|
||||
NextEPC_1 = NextEPC("10.0.1.118", 27017)
|
||||
|
||||
pdn = [{'apn': 'internet', 'pcc_rule': [], 'ambr': {'downlink': 1234, 'uplink': 1234}, 'qos': {'qci': 9, 'arp': {'priority_level': 8, 'pre_emption_vulnerability': 1, 'pre_emption_capability': 1}}, 'type': 2}]
|
||||
sub_data = {'imsi': '891012222222300', \
|
||||
'pdn': pdn, \
|
||||
'ambr': {'downlink': 1024000, 'uplink': 1024001}, \
|
||||
'subscribed_rau_tau_timer': 12, \
|
||||
'network_access_mode': 2, \
|
||||
'subscriber_status': 0, \
|
||||
'access_restriction_data': 32, \
|
||||
'security': {'k': '465B5CE8 B199B49F AA5F0A2E E238A6BC', 'amf': '8000', 'op': None, 'opc': 'E8ED289D EBA952E4 283B54E8 8E6183CA'}, '__v': 0}
|
||||
|
||||
print(NextEPC_1.AddSubscriber(sub_data)) #Add Subscriber using dict of sub_data
|
||||
|
||||
print(NextEPC_1.GetSubscriber('891012222222300')) #Get added Subscriber's details
|
||||
|
||||
print(NextEPC_1.DeleteSubscriber('891012222222300')) #Delete Subscriber
|
||||
|
||||
Subscriber_List = NextEPC_1.GetSubscribers()
|
||||
for subscribers in Subscriber_List:
|
||||
print(subscribers['imsi'])
|
||||
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue