Commit a83e280d authored by Yann Garcia's avatar Yann Garcia

Add support of userTracking

parent 1cdc329a
subscription_id,corr_id,address,callback,ue_event_criteria,resourceURL
......@@ -5,7 +5,7 @@ from datetime import datetime, time
class mec_database:
""" Private properties """
__path__ = "/Users/yanng/OneDrive/Documents/Python/Mec/data/" # To be updated according to the local settings
__path__ = "/Users/yanng/Documents/workspace_titan/STF569_Mec/simu/data/" # To be updated according to the local settings
__subscribers__ = None
__registered_list__ = None
__zones__ = None
......@@ -14,6 +14,7 @@ class mec_database:
__location_info__ = None
__cells__ = None
__associated__ = None
__subscribions__ = None
def __init__(self):
""" Default ctor: Open Pandas database. """
......@@ -24,6 +25,7 @@ class mec_database:
self.__location_info__ = pd.DataFrame(pd.read_csv(self.__path__ + 'location_info.csv', index_col = 'accessPointId'))
self.__cells__ = pd.DataFrame(pd.read_csv(self.__path__ + 'cells.csv', encoding = 'utf-8', index_col = 'cellId'))
self.__associated__ = pd.DataFrame(pd.read_csv(self.__path__ + 'associated.csv', encoding = 'utf-8', index_col = 'cellId'))
self.__subscriptions__ = pd.DataFrame(pd.read_csv(self.__path__ + 'subscriptions.csv', encoding = 'utf-8', index_col = 'subscription_id'))
#self.dump()
# End of __init__
......@@ -36,10 +38,16 @@ class mec_database:
print("LocationInfo: ", self.__location_info__.head())
print("Cells: ", self.__cells__.head())
print("Associated: ", self.__associated__.head())
print("subscriptions: ", self.__subscribions__.head())
# End of dump
def __to_accessPoint__(self, p_access_point, p_location):
""" Build an AccessPointLocation Json message. """
"""
Build an AccessPointLocation Json message.
Keyword arguments:
-- p_access_point: Access point identifier
-- p_location : Access point geographical location
"""
print(">>> __to_accessPoint__: ", p_access_point)
print("__to_accessPoint__: location= ", p_location['latitude'][0])
i = 0.0
......@@ -56,7 +64,11 @@ class mec_database:
# End of __to_accessPoint__
def __to_zone__(self, p_zone):
""" Build a Zones Json message. """
"""
Build a Zones Json message.
Keyword arguments:
-- p_zone: Zone description
"""
print(">>> __to_zone__: ", p_zone)
resp = "{\t\"zoneId\": \"" + p_zone[0] + "\",\t\"numberOfAccessPoints\": \"" + str(p_zone[1]) + "\",\t\"numberOfUnserviceableAccessPoints\": \"" + str(p_zone[2]) + "\",\t\"numberOfUsers\": \"" + str(p_zone[3]) + "\",\t\"resourceURL\": \"" + p_zone[4] + "\"}"
print("__to_zone__: ", resp)
......@@ -79,6 +91,21 @@ class mec_database:
return resp
# End of __to_ueIdentityTagInfo__
def __to_subscriptions__(self, p_subscription):
""" Build the userTrackingSubscription response """
print(">>> __to_subscriptions__: ", p_subscription)
resp = "\t{\"userTrackingSubscription\": {\t\"clientCorrelator\": \"" + p_subscription[1] + "\",\t\"callbackReference\": {\"notifyURL\": \"" + p_subscription[3] + "\"},\t\"address\": \"" + p_subscription[2] + "\",\t\"userEventCriteria\" : ["
resp += "\"" + p_subscription[4][0] + "\""
i = 1
while i < len(p_subscription[4]):
resp += ",\"" + p_subscription[4][i] + "\""
i += 1
# End of 'while' statement
resp += "],\t\"resourceURL\":\"" + p_subscription[5] + "\"\t}}"
print("__to_subscriptions__: ", resp)
return resp
# End of __to_subscriptions__
def getSubscriberList(self, p_uri):
""" Build a SubscriberList Json message. """
print(">>> getSubscriberList")
......@@ -199,6 +226,43 @@ class mec_database:
return resp
# End of method registerUEidentity
def registerSubscription(self, p_json_msg, p_uri):
print(">>> registerSubscription: ", p_json_msg, "/", p_uri)
resp = None
subscription_id = "subscription" + p_json_msg["clientCorrelator"]
try:
# Check the record does not exist
self.__subscriptions__.loc[self.__subscriptions__['subscription_id'] == subscription_id]
print("registerSubscription: There is a subscription for ", subscription_id)
except KeyError:
#print("registerSubscription: Add new row in subscription")
resource_url = "http://example.com" + p_uri + "/" + subscription_id
row = pd.Series({ 'subscription_id': subscription_id, 'corr_id': p_json_msg["clientCorrelator"], 'address': p_json_msg["address"], 'callback': p_json_msg["callbackReference"]["notifyURL"], 'ue_event_criteria': p_json_msg["userEventCriteria"], 'resourceURL': resource_url })
#print("registerSubscription: row: ", row)
self.__subscriptions__ = self.__subscriptions__.append(row, ignore_index=True).reindex()
#print("registerSubscription: ", self.__subscriptions__.head())
r = tuple(self.__subscriptions__.loc[self.__subscriptions__['subscription_id'] == subscription_id].to_records())
#print("registerSubscription: New added row: ", r[0])
resp = self.__to_subscriptions__(r[0])
return resp
# End of registerSubscription
def unregisterSubscription(self, p_subscription_id):
print(">>> unregisterSubscription: ", p_subscription_id)
resp = None
try:
# Check the record exists
r = self.__subscriptions__.loc[self.__subscriptions__['subscription_id'] == p_subscription_id]
t = tuple(r.to_records())
print("unregisterSubscription: Find row: ", t)
resp = self.__to_subscriptions__(t[0])
# Remove it
self.__subscriptions__.drop(r.index)
except KeyError:
print("unregisterSubscription: No subscription for ", p_subscription_id)
return resp
# End of unregisterSubscription
def getBwAllocationAppInst(self, p_app_inst, p_ue_identity_tag):
print(">>> getBwAllocationAppInst: ", p_app_inst, ", ", p_ue_identity_tag)
resp = None
......
This diff is collapsed.
......@@ -30,7 +30,7 @@ if __name__ == '__main__':
# Wait forever for incoming http requests in background
#server.serve_forever()
threading.Thread(target=server.serve_forever).start()
# Use keybord entries to trigger notifications
# Use keybord entries to trigBger notifications
while exit == False:
ch = getch()
if ch == b'\x03':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment