def scale_ns(nsId, nsd_json, vnfds_json, request, current_df, current_il): # all intelligence delegated to wrapper coreMano = createWrapper() scaled_vnfs_info = {} placement_info = nsir_db.get_placement_info(nsId) [scaled_vnfs_info, scale_ops] = coreMano.scale_ns(nsId, nsd_json, vnfds_json, request, current_df, current_il, placement_info) if (scaled_vnfs_info is not None) and ("sapInfo" in scaled_vnfs_info): log_queue.put(["DEBUG", "ROOE: SCALING updating nsi:%s sapInfo %s" % (nsId, scaled_vnfs_info["sapInfo"])]) ns_db.save_sap_info(nsId, scaled_vnfs_info["sapInfo"]) # update list of VLs to be deployed [vls_info, vls_to_remove] = update_vls_info_mtp(nsId, scale_ops) # ask network execution engine to update the virtual links eenet.update_vls(nsId, vls_info, vls_to_remove) # set operation status as SUCCESSFULLY_DONE operationId = operation_db.get_operationId(nsId, "INSTANTIATION") if scaled_vnfs_info is not None: log_queue.put(["DEBUG", "NS Scaling finished correctly"]) operation_db.set_operation_status(operationId, "SUCCESSFULLY_DONE") # update the IL in the database after finishing correctly the operations target_il = extract_target_il(request) ns_db.set_ns_il(nsId, target_il) # set ns status as INSTANTIATED ns_db.set_ns_status(nsId, "INSTANTIATED") else: log_queue.put(["ERROR", "NS Scaling FAILED"]) operation_db.set_operation_status(operationId, "FAILED") # set ns status as FAILED ns_db.set_ns_status(nsId, "FAILED") log_queue.put(["INFO", "SCALING FINISHED :)"])
def scale_ns(nsId, body): """ Starts a process to scale the Network Service associated with the instance identified by "nsId". Parameters ---------- nsId: string Identifier of the Network Service Instance. body: request body Returns ------- string Id of the operation associated to the Network Service instantiation. """ log_queue.put( ["INFO", "scale_ns for nsId %s with body: %s" % (nsId, body)]) # client = MongoClient() # fgtso_db = client.fgtso # ns_coll = fgtso_db.ns if not ns_db.exists_nsId(nsId): return 404 status = ns_db.get_ns_status(nsId) if status != "INSTANTIATED": return 400 ns_db.set_ns_status(nsId, "INSTANTIATING") operationId = create_operation_identifier(nsId, "INSTANTIATION") ps = Process(target=scale_ns_process, args=(nsId, body)) ps.start() # save process processes[operationId] = ps return operationId
def terminate_ns(nsId): """ Function description Parameters ---------- param1: type param1 description Returns ------- name: type return description """ # check if placement info has been saved in nsri database and update the resources database if nsir_db.exists_nsir(nsId): placement_info = nsir_db.get_placement_info(nsId) resources_db.add_resources_information(placement_info) # tell the eenet to release the links # line below commented until mtp is ready # eenet.uninstall_vls(nsId) # tell the mano to terminate coreMano = createWrapper() coreMano.terminate_ns(nsId) # update service status in db ns_db.set_ns_status(nsId, "TERMINATED") # set operation status as SUCCESSFULLY_DONE operationId = operation_db.get_operationId(nsId, "TERMINATION") operation_db.set_operation_status(operationId, "SUCCESSFULLY_DONE")
def terminate_ns(nsId): """ Function description Parameters ---------- param1: type param1 description Returns ------- name: type return description """ log_queue.put([ "INFO", "*****Time measure: ROE Starting ROE processing to terminate" ]) if (nsId.find('_') == -1): status = ns_db.get_ns_status(nsId) ns_db.set_ns_status(nsId, "TERMINATING") else: status = "INSTANTIATED" # tell the eenet to release the links # line below commented until mtp is ready if (status != "FAILED"): # if it has failed, the MANO platform should have cleaned the deployment and # no any logical link has been established # tell the mano to terminate coreMano = createWrapper() coreMano.terminate_ns(nsId) log_queue.put(["INFO", "*****Time measure: ROE ROE, terminated VNFs"]) # ask network execution engine to deploy the virtual links eenet.uninstall_vls(nsId) log_queue.put( ["INFO", "*****Time measure: ROE ROE, terminated VLs at MTP"]) # remove the information from the nsir nsir_db.delete_nsir_record(nsId) # set operation status as SUCCESSFULLY_DONE if (nsId.find('_') == -1): # update service status in db ns_db.set_ns_status(nsId, "TERMINATED") #the service is single, I can update the operationId and the status log_queue.put(["INFO", "Removing a single NS"]) operationId = operation_db.get_operationId(nsId, "TERMINATION") operation_db.set_operation_status(operationId, "SUCCESSFULLY_DONE") log_queue.put(["INFO", "TERMINATION FINISHED :)"])
def terminate_ns(nsId): """ Function description Parameters ---------- param1: type param1 description Returns ------- name: type return description """ ns_db.set_ns_status(nsId, "TERMINATING") # tell the eenet to release the links # line below commented until mtp is ready # tell the mano to terminate coreMano = createWrapper() coreMano.terminate_ns(nsId) # ask network execution engine to deploy the virtual links eenet.uninstall_vls(nsId) # remove the information from the nsir nsir_db.delete_nsir_record(nsId) # update service status in db ns_db.set_ns_status(nsId, "TERMINATED") # set operation status as SUCCESSFULLY_DONE if (nsId.find('_') == -1): #the service is single, I can update the operationId and the status log_queue.put(["INFO", "Removing a single NS"]) operationId = operation_db.get_operationId(nsId, "TERMINATION") operation_db.set_operation_status(operationId, "SUCCESSFULLY_DONE") log_queue.put(["INFO", "TERMINATION FINISHED :)"])
def instantiate_ns(nsId, nsd_json, vnfds_json, request, nestedInfo=None): """ Function description Parameters ---------- param1: type param1 description Returns ------- name: type return description """ # extract the relevant information for the PA algorithm from the nsd_vnfd log_queue.put(["INFO", "*****Time measure: ROE starting ROE processing"]) extracted_info = extract_nsd_info_for_pa(nsd_json, vnfds_json, request) log_queue.put(["INFO", "*****Time measure: ROE extracted NSD info at ROE"]) log_queue.put(["INFO", dumps(extracted_info, indent=4)]) # first get mtp resources and lock db resources = sbi.get_mtp_resources() log_queue.put(["INFO", "MTP resources are:"]) log_queue.put(["INFO", dumps(resources, indent=4)]) log_queue.put(["INFO", "*****Time measure: ROE retrieved MTP resources"]) # ask pa to calculate the placement - read pa config from properties file config = RawConfigParser() config.read("../../sm/rooe/rooe.properties") pa_ip = config.get("PA", "pa.ip") pa_port = config.get("PA", "pa.port") pa_path = config.get("PA", "pa.path") pa_enable = config.get("PA", "pa.enable") placement_info = {} if pa_enable == "yes": pa_uri = "http://" + pa_ip + ":" + pa_port + pa_path # ask pa to calculate the placement - prepare the body paId = str(uuid4()) pa_resources = parse_resources_for_pa(resources, vnfds_json.keys()) body_pa = {"ReqId": paId, "nfvi": pa_resources, "nsd": extracted_info["nsd"], "callback": "http://localhost:8080/5gt/so/v1/__callbacks/pa/" + paId} log_queue.put(["INFO", "Body for PA is:"]) log_queue.put(["INFO", dumps(body_pa, indent=4)]) # ask pa to calculate the placement - do request header = {'Content-Type': 'application/json', 'Accept': 'application/json'} log_queue.put(["INFO", "*****Time measure: ROE PA request generated"]) try: conn = HTTPConnection(pa_ip, pa_port) conn.request("POST", pa_uri, dumps(body_pa), header) # ask pa to calculate the placement - read response and close connection rsp = conn.getresponse() placement_info = rsp.read().decode('utf-8') placement_info = loads(placement_info) conn.close() except ConnectionRefusedError: # the PA server is not running or the connection configuration is wrong log_queue.put(["ERROR", "the PA server is not running or the connection configuration is wrong"]) log_queue.put(["INFO", "output of the PA is: "]) log_queue.put(["INFO", placement_info]) placement_info = amending_pa_output(extracted_info["nsd"], placement_info) log_queue.put(["INFO", "*****Time measure: ROE PA calculation done"]) log_queue.put(["INFO", "PA tuned output is:"]) log_queue.put(["INFO", placement_info]) else: # to be removed when PA code tested: static placement for testing purposes pa_responses = config.items("RESPONSE") for pa_response in pa_responses: if (nsd_json["nsd"]["nsdIdentifier"].lower().find(pa_response[0]) !=-1): placement_info = json.loads(pa_response[1]) log_queue.put(["INFO", "PA TUNED (manually) output is:"]) log_queue.put(["DEBUG", placement_info]) log_queue.put(["DEBUG", "Service NameId is: %s" % nsd_json["nsd"]["nsdIdentifier"]]) if nestedInfo: key = next(iter(nestedInfo)) log_queue.put(["DEBUG", "the key of nestedInfo in ROOE is: %s"%key]) if len(nestedInfo[key]) > 1: # nested from a consumer domain nsId_tmp = nsId else: # nested local nsId_tmp = nsId + '_' + next(iter(nestedInfo)) else: nsId_tmp = nsId nsir_db.save_placement_info(nsId_tmp, placement_info) # ask cloudify/OSM to deploy vnfs coreMano = createWrapper() deployed_vnfs_info = {} deployed_vnfs_info = coreMano.instantiate_ns(nsId, nsd_json, vnfds_json, request, placement_info, resources, nestedInfo) log_queue.put(["INFO", "The deployed_vnfs_info"]) log_queue.put(["INFO", dumps(deployed_vnfs_info, indent=4)]) if (deployed_vnfs_info is not None) and ("sapInfo" in deployed_vnfs_info): log_queue.put(["INFO", "ROOE: updating nsi:%s sapInfo: %s" % (nsId, deployed_vnfs_info["sapInfo"])]) ns_db.save_sap_info(nsId, deployed_vnfs_info["sapInfo"]) log_queue.put(["INFO", "*****Time measure: ROE created VNF's"]) if deployed_vnfs_info is not None: # list of VLs to be deployed vls_info = extract_vls_info_mtp(resources, extracted_info, placement_info, nsId_tmp, nestedInfo) log_queue.put(["INFO", "*****Time measure: ROE extracted VL's at MTP"]) # ask network execution engine to deploy the virtual links eenet.deploy_vls(vls_info, nsId_tmp) log_queue.put(["INFO", "*****Time measure: ROE created LL's at MTP"]) # set operation status as SUCCESSFULLY_DONE if (nsId_tmp.find('_') == -1): # the service is single, I can update the operationId, and the status operationId = operation_db.get_operationId(nsId, "INSTANTIATION") if deployed_vnfs_info is not None: log_queue.put(["INFO", "NS Instantiation finished correctly"]) operation_db.set_operation_status(operationId, "SUCCESSFULLY_DONE") # set ns status as INSTANTIATED ns_db.set_ns_status(nsId, "INSTANTIATED") else: log_queue.put(["ERROR", "NS Instantiation FAILED"]) operation_db.set_operation_status(operationId, "FAILED") # set ns status as FAILED ns_db.set_ns_status(nsId, "FAILED") log_queue.put(["INFO", "INSTANTIATION FINISHED :)"])
def instantiate_ns(nsId, nsd_json, vnfds_json, request): """ Function description Parameters ---------- param1: type param1 description Returns ------- name: type return description """ # extract the relevant information for the PA algorithm from the nsd_vnfd # extracted_info = extract_nsd_info_for_pa(nsd_json, vnfds_json, request) extracted_info = extract_nsd_info_for_pa(nsd_json, vnfds_json, request) log_queue.put(["DEBUG", "NSD extracted info for PA is:"]) log_queue.put(["DEBUG", json.dumps(extracted_info, indent=4)]) # first get mtp resources and lock db resources = get_mtp_resources() # ask pa to calculate the placement - read pa config from properties file config = RawConfigParser() config.read("../../sm/rooe/rooe.properties") pa_ip = config.get("PA", "pa.ip") pa_port = config.get("PA", "pa.port") pa_path = config.get("PA", "pa.path") pa_uri = "http://" + pa_ip + ":" + pa_port + pa_path # ask pa to calculate the placement - prepare the body paId = str(uuid4()) body = { "ReqId": paId, "nfvi": resources, "nsd": extracted_info, "callback": "http://localhost:8080/5gt/so/v1/__callbacks/pa/" + paId } # ask pa to calculate the placement - do request header = {'Content-Type': 'application/json', 'Accept': 'application/json'} placement_info = {} # code below is commented until PA is ready # try: # conn = HTTPConnection(pa_ip, pa_port) # conn.request("POST", pa_uri, body, header) # # # ask pa to calculate the placement - read response and close connection # rsp = self.conn.getresponse() # placement_info = rsp.read() # conn.close() # except ConnectionRefusedError: # # the PA server is not running or the connection configuration is wrong # log_queue.put(["ERROR", "the PA server is not running or the connection configuration is wrong"]) placement_info = { "usedNFVIPops": [{ "NFVIPoPID": "openstack-site29_Zona1_w", "mappedVNFs": ["webserver", "spr21"] }, { "NFVIPoPID": "openstack-site31_w", "mappedVNFs": ["spr1"] }], "usedLLs": [{ "LLID": "151515", "mappedVLs": ["VideoData"] }], "usedVLs": [{ "NFVIPoP": "openstack-site29_Zona1_w", "mappedVLs": ["VideoDistribution"] }, { "NFVIPoP": "openstack-site31_w", "mappedVLs": ["mgt"] }], "totalLatency": 1.3 } # save placement info in database nsir_db.save_placement_info(nsId, placement_info) # ask cloudify/OSM to deploy vnfs coreMano = createWrapper() deployed_vnfs_info = {} deployed_vnfs_info = coreMano.instantiate_ns(nsId, nsd_json, body, placement_info) if deployed_vnfs_info is not None and "sapInfo" in deployed_vnfs_info: log_queue.put(["DEBUG", "rooe: updating nsi:%s sapInfo" % nsId]) ns_db.save_sap_info(nsId, deployed_vnfs_info["sapInfo"]) # list of VLs to be deployed vls_info = extract_vls_info_mtp(resources, extracted_info, placement_info) # ask network execution engine to deploy the virtual links # line below commented until mtp is ready # eenet.deploy_vls(vls_info, nsId) # set operation status as SUCCESSFULLY_DONE operationId = operation_db.get_operationId(nsId, "INSTANTIATION") if deployed_vnfs_info is not None: log_queue.put(["DEBUG", "NS Instantiation finished correctly"]) operation_db.set_operation_status(operationId, "SUCCESSFULLY_DONE") # set ns status as INSTANTIATED ns_db.set_ns_status(nsId, "INSTANTIATED") else: log_queue.put(["ERROR", "NS Instantiation FAILED"]) operation_db.set_operation_status(operationId, "FAILED") # set ns status as FAILED ns_db.set_ns_status(nsId, "FAILED")