Esempio n. 1
0
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 :)"])
Esempio n. 2
0
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")
Esempio n. 3
0
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 :)"])
Esempio n. 4
0
def terminate_ns(nsId, requester):
    """
    Starts a process to terminate the NS instance identified by "nsId".
    Parameters
    ----------
    nsId: string
        Identifier of the NS instance to terminate.
    requester: string
        IP address of the entity making the request
    Returns
    -------
    operationId: string
        Identifier of the operation in charge of terminating the service.
    """
    log_queue.put(
        ["INFO", "*****Time measure: SOEc SOEc terminating a nested"])
    if not ns_db.exists_nsId(nsId):
        return 404
    registered_requester = ns_db.get_ns_requester(nsId)
    if (registered_requester != requester):
        return 404
    # check the ns status
    status = ns_db.get_ns_status(nsId)
    log_queue.put(
        ["INFO", "Network service %s is in %s state." % (nsId, status)])

    if status in ["TERMINATING", "TERMINATED", "NOT_INSTANTIATED"]:
        return 400
    # if status is INSTANTIATING, kill the instantiation process
    if status == "INSTANTIATING":
        # set related operation as CANCELLED
        operationId = operation_db.get_operationId(nsId, "INSTANTIATION")
        operation_db.set_operation_status(operationId, "CANCELLED")
        # cancel instantiation process
        process = processes[operationId]
        process.terminate()
        process.join()

    operationId = create_operation_identifier(nsId, "TERMINATION")
    ps = Process(target=terminate_ns_process, args=(nsId, None))
    ps.start()

    # save process
    processes[operationId] = ps
    # log_queue.put(["INFO", "*****Time measure: finished termination at SOEc"])
    return operationId
Esempio n. 5
0
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 :)"])
Esempio n. 6
0
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 :)"])
Esempio n. 7
0
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")
Esempio n. 8
0
def scale_ns_process(nsId, body, nestedInfo=None):
    """
    Performs the scaling of the service identified by "nsId" according to the info at body 
    Parameters
    ----------
    nsId: string
        Identifier of the Network Service Instance.
    body: request body including scaling operation
    Returns
    -------
    """
    log_queue.put([
        "INFO",
        "*****Time measure for nsId: %s: SOEc SOEc scaling a nested/regular NS"
        % nsId
    ])
    log_queue.put(
        ["INFO",
         "scale_ns_process with nsId %s, body %s" % (nsId, body)])
    # get the nsdId that corresponds to nsId
    if nestedInfo:
        nsdId = next(iter(nestedInfo))
        current_df = nestedInfo[nsdId][0]
        current_il = nestedInfo[nsdId][1]
    else:
        nsdId = ns_db.get_nsdId(nsId)
        # get current instantiation level
        current_df = ns_db.get_ns_df(nsId)
        current_il = ns_db.get_ns_il(nsId)
    # first get the ns and vnfs descriptors
    nsd_json = nsd_db.get_nsd_json(nsdId, None)
    # for each vnf in the NSD, get its json descriptor
    vnfdIds = nsd_json["nsd"]["vnfdId"]
    vnfds_json = {}
    for vnfdId in vnfdIds:
        vnfds_json[vnfdId] = vnfd_db.get_vnfd_json(vnfdId, None)
    #request RO
    sap_info_pre_scaling = ns_db.get_ns_sap_info(nsId)
    log_queue.put([
        "INFO",
        "*****Time measure for nsId: %s: SOEc SOEc-ROE prepared info for scaling"
        % (nsId)
    ])
    rooe.scale_ns(nsId, nsd_json, vnfds_json, body, current_df, current_il,
                  nestedInfo)
    log_queue.put([
        "INFO",
        "*****Time measure for nsId: %s: SOEc SOEc-ROE updated DBs scaling a NS"
        % (nsId)
    ])
    # checks the result of scaling, maybe it has not be done due to lack of resources
    operationId = operation_db.get_operationId(nsId, "INSTANTIATION")
    if ((operation_db.get_operation_status(operationId) == "SUCCESSFULLY_DONE")
            and ns_db.get_ns_status(nsId) == "INSTANTIATED"):
        # maybe we have to update the monitoring jobs: we assume that new performance monitoring jobs
        # will be similar to one already present
        sap_info = ns_db.get_ns_sap_info(nsId)
        log_queue.put(["INFO", "new sapInfo after scaling: %s" % (sap_info)])
        monitoring.update_ns_monitoring(nsId, nsd_json, vnfds_json, sap_info)
        log_queue.put([
            "INFO",
            "*****Time measure for nsId: %s: SOEc SOEc updated monitoring info"
            % nsId
        ])
        log_queue.put([
            "DEBUG",
            "monitoring exporters updated after scaling for nsId %s" % (nsId)
        ])
        # update alerts: it is not needed
    # however, in the case of aiml_scaling it is needed, to restart the spark job
    else:
        if ns_db.get_ns_status(nsId) == "INSTANTIATED":
            log_queue.put(
                ["DEBUG", "Scaling operation failed due to lack of resources"])
        elif ns_db.get_ns_status(nsId) == "FAILED":
            log_queue.put(
                ["DEBUG", "Scaling operation failed at the MANO platform"])
    aiml_scaling_info = ns_db.get_aiml_info(nsId, "scaling")
    if (aiml_scaling_info and (ns_db.get_ns_status(nsId) == "INSTANTIATED")):
        log_queue.put(
            ["DEBUG", "The AIML platform is triggering the scaling operation"])
        alert_configure.update_ns_aiml_scale_work(nsId, aiml_scaling_info)
        log_queue.put([
            "INFO",
            "*****Time measure for nsId: %s: SOEc SOEc updated AIML alert job"
            % nsId
        ])
    log_queue.put(["INFO", "scale_ns_process finished for nsId %s" % (nsId)])
    log_queue.put([
        "INFO",
        "*****Time measure for nsId: %s: SOEc SOEc finished scaling a nested/regular NS"
        % (nsId)
    ])
    notification_db.create_notification_record({
        "nsId":
        nsId,
        "type":
        "fa-gears",
        "text":
        nsId + " SCALED",
        "time":
        datetime.now().strftime("%d/%m/%Y %H:%M:%S.%f")
    })