diff --git a/simu/mec_database.py b/simu/mec_database.py index 7a6cf232e2e97ed6c01d714f706bb8191e9314b3..9fb2cda0a7bc1f1e4aec53c1470717bd37aa08b9 100644 --- a/simu/mec_database.py +++ b/simu/mec_database.py @@ -153,6 +153,15 @@ class mec_database: return resp # End of method __to_transport_info__ + def __to_rni_subscriptions__(self, p_subscription, p_subscription_type): + """ Build a RNI subscription Json message. """ + print(">>> __to_rni_subscriptions__") + resp = "{\"CellChangeSubscription\": {\"subscriptionType\": \"" + p_subscription_type + "\",\"callbackReference\": \"http://meAppClient.example.com/rni/v2/notifications/cell_change/77777\", \"_links\": {\"self\": \"http://example.com/exampleAPI/rni/v2/subscriptions\"}, \"filterCriteria\": {\"appInsId\": \"01\", \"associateId\": [{\"type\": \"UE_IPV4_ADDRESS\", \"value\": 1}], \"plmn\": {\"mcc\": \"01\", \"mnc\": \"001\"}, \"cellId\": [\"0x800000A\"], \"hoStatus\": \"COMPLETED\"}, \"expiryDeadline\": {\"seconds\": 1577836800, \"nanoSeconds\": 0}}}" +# resp = "{\"CellChangeSubscription\": {\"callbackReference\": " + p_subscription['callbackReference'] + ", \"_links\": {\"self\": " + p_subscription['_links'] + "}, \"filterCriteria\": {\"appInsId\": " + p_subscription['filterCriteria']['appInsId'] + ", \"associateId\": [{\"type\": " + p_subscription['filterCriteria']['associateId']['type'] + ", \"value\": " + p_subscription['filterCriteria']['associateId']['value'] + "}], \"plmn\": {\"mcc\": " + p_subscription['filterCriteria']['plmn']['mcc'] + ", \"mnc\": " + p_subscription['filterCriteria']['plmn']['mnc'] + "}, \"cellId\": [" + p_subscription['filterCriteria']['cellId'] + "], 'hoStatus': " + p_subscription['filterCriteria']['hoStatus'] + "}, \"expiryDeadline\": {\"seconds\": " + p_subscription['expiryDeadline']['seconds'] + ", \"nanoSeconds\": \"" + p_subscription['expiryDeadline']['nanoSeconds'] + "}}" + print("__to_rni_subscriptions__: ", resp) + return resp + # end of __to_rni_subscriptions__ + def getSubscriberList(self, p_uri): """ Build a SubscriberList Json message. """ print(">>> getSubscriberList") @@ -307,6 +316,14 @@ class mec_database: return resp # End of method getUEidentityTagInfo + def getBwAllocationAppInst(self, p_app_inst, p_ue_identity_tag): + print(">>> getBwAllocationAppInst: ", p_app_inst, ", ", p_ue_identity_tag) + resp = None + resp = "{\"bwInfo\": {\"timeStamp\": {\"seconds\": 0,\"nanoSeconds\": 0},\"appInsId\": \"string\",\"requestType\": \"APPLICATION_SPECIFIC_BW_ALLOCATION\",\"sessionFilter\": [{\"sourceIp\": \"string\",\"sourcePort\": [\"string\"],\"dstAddress\": \"string\",\"dstPort\": [\"string\"],\"protocol\": \"string\"}],\"fixedBWPriority\": \"not defined in the present document\",\"fixedAllocation\": \"string\",\"allocationDirection\": \"00 = Downlink (towards the UE)\"}}" + print("getBwAllocationAppInst: ", resp) + return resp + # End of method getBwAllocationAppInst + def registerUEidentity(self, p_app_inst, p_json_msg): print(">>> registerUEidentity", p_json_msg) if p_json_msg["state"] != "REGISTERED" and p_json_msg["state"] != "UNREGISTERED": @@ -363,12 +380,32 @@ class mec_database: return resp # End of unregisterSubscription - def getBwAllocationAppInst(self, p_app_inst, p_ue_identity_tag): - print(">>> getBwAllocationAppInst: ", p_app_inst, ", ", p_ue_identity_tag) + def registerRniSubscription(self, p_json_msg): + print(">>> registerRniSubscription: ", p_json_msg) resp = None - resp = "{\"bwInfo\": {\"timeStamp\": {\"seconds\": 0,\"nanoSeconds\": 0},\"appInsId\": \"string\",\"requestType\": \"APPLICATION_SPECIFIC_BW_ALLOCATION\",\"sessionFilter\": [{\"sourceIp\": \"string\",\"sourcePort\": [\"string\"],\"dstAddress\": \"string\",\"dstPort\": [\"string\"],\"protocol\": \"string\"}],\"fixedBWPriority\": \"not defined in the present document\",\"fixedAllocation\": \"string\",\"allocationDirection\": \"00 = Downlink (towards the UE)\"}}" - print("getBwAllocationAppInst: ", resp) + if p_json_msg['subscriptionType'] == 'CELL_CHANGE': + resp = self.__to_rni_subscriptions__(p_json_msg, 'CELL_CHANGE') return resp - # End of method getBwAllocationAppInst + # End of registerRniSubscription + + def getRabInfo(self, p_cell_id): + print(">>> getRabInfo: ", p_cell_id) + resp = None + if p_cell_id == '0xFFFFFFFF': + resp = "{\"problemDetails\": {\t\"type\": \"Bad Request\",\t\"title\": \"RnisAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" + else: + resp = "{ \"RabInfo\": { \"timeStamp\": { \"seconds\": 1577836800, \"nanoSeconds\": 0 }, \"appInsId\": \"01\", \"requestId\": \"01\", \"cellUserInfo\": { \"ecgi\": { \"plmn\": { \"mcc\": \"001\", \"mnc\": \"01\" }, \"cellId\": \"" + p_cell_id + "\" }, \"ueInfo\": { \"associateId\": null, \"type\": \"1\", \"value\": \"192.0.2.0\", \"erabInfo\": { \"erabId\": 10 }, \"erabQosParameters\": { \"qci\": 7, \"qosInformation\": { \"erabMbrDl\": 10, \"erabMbrUl\": 10, \"erabGbrDl\": 10, \"erabGbrUl\": 10 } } } } } }" + return resp + # End of getRabInfo + + def getPlmnInfo(self, p_app_inst): + print(">>> getPlmnInfo: ", p_app_inst) + resp = None + if p_app_inst == '99': + resp = "{\"problemDetails\": {\t\"type\": \"Bad Request\",\t\"title\": \"RnisAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" + else: + resp = "{ \"PlmnInfo\": { \"timeStamp\": { \"seconds\": 1577836800, \"nanoSeconds\": 0 }, \"appInsId\": \"" + p_app_inst + "\", \"ecgi\": { \"plmn\": { \"mcc\": \"001\", \"mnc\": \"01\" }, \"cellId\": \"0x800000A\" } } }" + return resp + # End of getPlmnInfo # End of class mec_database diff --git a/simu/mec_http_server.py b/simu/mec_http_server.py index 6cc35ef0b148b29421760c810b9bb39f0787f950..438871884bec4fbcc04a5c145725aa837ca36160 100644 --- a/simu/mec_http_server.py +++ b/simu/mec_http_server.py @@ -100,9 +100,8 @@ class myHandler(http.server.BaseHTTPRequestHandler): elif resp.find('Forbidden') != -1: self.send_response(403, 'Forbidden') resp = "" - elif resp.find('Bad Request') != -1: + elif resp.find('Bad Request') != -1 or resp.find('Wrong parameters') != -1: self.send_response(400, 'Bad Request') - resp = "" elif resp.find('Precondition Failed') != -1: self.send_response(412, 'Precondition Failed') resp = "{\"problemDetails\": {\t\"type\": \"Precondition Failed\",\t\"title\": \"N/A\",\t\"status\": 412,\t\"detail\": \"Wrong preconditions\",\t\"instance\": \"N/A\"}}" @@ -110,6 +109,8 @@ class myHandler(http.server.BaseHTTPRequestHandler): elif resp.find('userTrackingSubscription') != -1: self.send_response(201, 'Created') resp = "" + elif resp.find('CellChangeSubscription') != -1: + self.send_response(201, 'Created') else: self.send_response(200, 'OK') self.send_header('Host', self.headers.get('Host')) # send_header() shall be after send_response() @@ -172,9 +173,6 @@ class myHandler(http.server.BaseHTTPRequestHandler): self.send_response(412, 'Precondition Failed') resp = "{\"problemDetails\": {\t\"type\": \"Precondition Failed\",\t\"title\": \"N/A\",\t\"status\": 412,\t\"detail\": \"Wrong preconditions\",\t\"instance\": \"N/A\"}}" content_type = 'application/problem+json' - elif resp.find('userTrackingSubscription') != -1: - self.send_response(201, 'Created') - resp = "" else: self.send_response(200, 'OK') self.send_header('Host', self.headers.get('Host')) # send_header() shall be after send_response() @@ -377,8 +375,7 @@ class myHandler(http.server.BaseHTTPRequestHandler): content_type = 'application/problem+json' if (resp == None): resp = "{\"problemDetails\": {\t\"type\": \"Bad Request\",\t\"title\": \"UEidentityAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" - content_type = 'application/problem+json' - elif resp.find('problemDetails') != -1: + if resp.find('problemDetails') != -1: content_type = 'application/problem+json' print ("<<< __process__ue__identity__api__: ", resp, ", ", content_type) @@ -393,24 +390,63 @@ class myHandler(http.server.BaseHTTPRequestHandler): if p_split[4].startswith('subscriptions'): if p_split.__len__() == 5: s = p_split[4].split('?') - if s.__len__() == 1: - resp = self.__db__.getSubscriptionLinkList(self.path) + if s.__len__() == 1: # Chek message body + # Register/Unregister operation + body = None + # Extract the body if any + content_len = int(self.headers.get('Content-Length')) + if (content_len != 0): + body = self.rfile.read(content_len) + json_msg = self.__decode__json__body__(body) + if (json_msg == None): + resp = "{\"problemDetails\": {\t\"type\": \"Body processing not supported\",\t\"title\": \"UEidentityAPI\",\t\"status\": 400,\t\"detail\": \"Unknown request\",\t\"instance\": \"string\"}}" + else: + resp = self.__db__.registerRniSubscription(json_msg) elif s[0] != 'subscriptions': resp = "{\"problemDetails\": {\t\"type\": \"Bad Request\",\t\"title\": \"RnisAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" - content_type = 'application/problem+json' else: s = s[1].split('=') print('__process__rnis__api__: ', s) if s[0] != 'subscription_type': resp = "{\"problemDetails\": {\t\"type\": \"Bad Request\",\t\"title\": \"RnisAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" - content_type = 'application/problem+json' + elif s[1] == 'wrongSubscriptionType': + resp = "{\"problemDetails\": {\t\"type\": \"Bad Request\",\t\"title\": \"RnisAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" else: resp = self.__db__.getSubscriptionLinkList(self.path) elif p_split.__len__() == 6: if p_split[5] == '': resp = self.__db__.getSubscriptionLinkList(self.path) + elif s[0] != 'subscriptions': + resp = "{\"problemDetails\": {\t\"type\": \"Bad Request\",\t\"title\": \"RnisAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" + else: + s = s[1].split('=') + print('__process__rnis__api__: ', s) + if s[0] != 'subscription_type': + resp = "{\"problemDetails\": {\t\"type\": \"Bad Request\",\t\"title\": \"RnisAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" + elif s[1] == 'wrongSubscriptionType': + resp = "{\"problemDetails\": {\t\"type\": \"Bad Request\",\t\"title\": \"RnisAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" + else: + resp = self.__db__.getSubscriptionLinkList(self.path) + elif p_split[4].startswith('queries'): + if p_split.__len__() == 5: + s = p_split[4].split('?') + if s.__len__() == 1: # Chek message body + pass + else: + if s[0] != 'queries': + resp = "{\"problemDetails\": {\t\"type\": \"Bad Request\",\t\"title\": \"RnisAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" + else: + s = s[1].split('=') + print('__process__rnis__api__ (queries): ', s) + if s[0] == 'cell_id': + resp = self.__db__.getRabInfo(s[1]) + elif s[0] == 'plmn_info': + resp = self.__db__.getPlmnInfo(s[1]) + else: + resp = "{\"problemDetails\": {\t\"type\": \"Bad Request\",\t\"title\": \"RnisAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" if (resp == None): resp = "{\"problemDetails\": {\t\"type\": \"Not supported\",\t\"title\": \"RnisAPI\",\t\"status\": 400,\t\"detail\": \"Wrong parameters\",\t\"instance\": \"string\"}}" + if resp.find('problemDetails') != -1: content_type = 'application/problem+json' print ("<<< __process__rnis__api__: ", resp, ", ", content_type) @@ -481,6 +517,8 @@ class myHandler(http.server.BaseHTTPRequestHandler): return json_msg.get("ueIdentityTags")[0] elif ("userTrackingSubscription" in json_msg.keys()) == True: return json_msg.get("userTrackingSubscription") + elif ("CellChangeSubscription" in json_msg.keys()) == True: + return json_msg.get("CellChangeSubscription") return None # End of __decode__json__body__