Example #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 :)"])
Example #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")
Example #3
0
def ns_view(ns_id):
    # get the nsdId that corresponds to nsId
    nsd_id = ns_db.get_nsdId(ns_id)
    domain = nsd_db.get_nsd_domain(nsd_id)
    nsd_json = nsd_db.get_nsd_json(nsd_id)
    flavour_id = ns_db.get_ns_flavour_id(ns_id)
    ns_instantiation_level_id = ns_db.get_ns_instantiation_level_id(ns_id)
    # print("Flavor /instantiation level of ns_id to be visualize: {} {}".format(flavour_id, ns_instantiation_level_id))
    ns_network = {}
    level = "{}_{}_{}".format(nsd_id, flavour_id, ns_instantiation_level_id)
    # print("Total Level: {}".format(level))
    if domain == 'local':
        html_page = 'ns_view.html'
        placement_info = nsir_db.get_placement_info(ns_id)
        list_osm_json, default_index = gui_utils.ifa014_conversion(nsd_json)
        for element in list_osm_json:
            if element['nsd:nsd-catalog']['nsd'][0]['id'] == level:
                ns_network = gui_utils.json_network_nsd(
                    element, placement_info)
    elif domain == 'Composite':
        html_page = 'ns_composite_view.html'
        list_osm_json, default_index = gui_utils.composite_desc_conversion(
            nsd_json)
        for element in list_osm_json:
            if element['nsd:nsd-catalog']['nsd-composite'][0]['id'] == level:
                ns_network = gui_utils.json_network_composite_ns(
                    element, ns_id)
    else:
        message = {'Error': 'Error: Something Wrong with domain of Descriptor'}
        log_queue.put(["ERROR", message['Error']])
        flash(message['Error'], 'danger')
        return redirect(request.referrer)
    return render_template(html_page,
                           html_title=ns_db.get_ns_name(ns_id),
                           d3_network=json_graph.node_link_data(ns_network))
Example #4
0
def json_network_composite_ns(descriptor, ns_id=None):
    """
    Return the node-link format of the YAML NS Composite Instance
    :param descriptor: yaml object representing the NS composite descriptor
    :param ns_id: ns_id (useful to visualize the NSD instance
    :return: nx json graph format
    """
    # retrieve the list of nested ns id for placement info
    list_of_nested_ns_id = []
    ns_table_entry = ns_db.get_ns_record(ns_id)
    if 'nestedNsId' in ns_table_entry:
        # ASSUMPTION: ONLY ONE NSID IN THIS COLUMN
        list_of_nested_ns_id.append({
            "nsd_id":
            ns_db.get_nsdId(ns_table_entry['nestedNsId']),
            "ns_id":
            ns_table_entry['nestedNsId'],
            # ASSUMPTION: instantiate a composite service from a "local" nested service
            "federated_domain":
            "local"
        })
    if 'nested_service_info' in ns_table_entry:
        for nested_id in ns_table_entry['nested_service_info']:
            list_of_nested_ns_id.append({
                "nsd_id":
                nested_id['nested_id'],
                "ns_id":
                nested_id['nested_instance_id'],
                "federated_domain":
                nested_id['domain']
            })
    else:
        # TODO intrinsic issue with composite, review the dbs
        pass
    nsd_response = descriptor['nsd:nsd-catalog']['nsd-composite'][0]
    # create a nx.Graph
    g = nx.Graph()
    # dealing with the 'constituent-nsd'
    nsd_array = nsd_response['constituent-nsd']
    # for each constituent-nsd of composite remapping of vl names (if necessary) and create the graph
    for nsd_nested_item in nsd_array:
        ns_ir_net_map = nsir_db.get_network_mapping(ns_id)
        ns_ir_rename_map = nsir_db.get_renaming_network_mapping(ns_id)
        # print(ns_ir_net_map, ns_ir_rename_map)
        # network remapping part
        mapping = {}
        if bool(ns_ir_net_map):
            # case of composite NOT from scratch
            if bool(ns_ir_rename_map):
                for vl in ns_ir_net_map['nestedVirtualLinkConnectivity'][
                        nsd_nested_item['nested-nsd-id']]:
                    for key_vl, value_vl in vl.items():
                        for key_rename, value_rename in ns_ir_rename_map.items(
                        ):
                            if value_vl == value_rename:
                                mapping[key_vl] = key_rename
            # case of composite from scratch
            else:
                for vl in ns_ir_net_map['nestedVirtualLinkConnectivity'][
                        nsd_nested_item['nested-nsd-id']]:
                    for key_vl, value_vl in vl.items():
                        mapping[key_vl] = value_vl
        else:
            # TODO evaluate this possibility, maybe an intrinsic issue of dbs
            print("TODO")
            pass
        # print('Network mapping {}:'.format(mapping))
        nsd_json = nsd_db.get_nsd_json(nsd_nested_item['nested-nsd-id'])
        domain_federation = next(
            item['federated_domain'] for item in list_of_nested_ns_id
            if item.get("nsd_id") == nsd_nested_item['nested-nsd-id'])
        if isinstance(domain_federation, dict):
            domain_federation = next(iter(domain_federation))
        # print("Federated domain: {}".format(domain_federation))
        # find df and instantiation level of composite nsd
        level = "{}_{}_{}".format(nsd_nested_item['nested-nsd-id'],
                                  nsd_nested_item['nested-ns-df-id'],
                                  nsd_nested_item['nested-ns-inst-level-id'])
        # TODO verify that level should be the same in below case
        # level = nsd_nested_item['nsd-id-ref']
        ns_network = {}
        # retrieve the json of composite nsd (with correct df and instantiation level)
        list_osm_json, default_index = ifa014_conversion(nsd_json)
        for element in list_osm_json:
            if element['nsd:nsd-catalog']['nsd'][0]['id'] == level:
                ns_network = element
        # creating graph of nested NS
        nsd_response = ns_network['nsd:nsd-catalog']['nsd'][0]
        # renaming involved network
        for vld_item in nsd_response['vld']:
            vld_name = vld_item['name']
            if vld_item['name'] in mapping:
                vld_item['short-name'] = mapping[vld_name]
                vld_item['id'] = mapping[vld_name]
                vld_item['name'] = mapping[vld_name]
        # dealing with the 'constituent-vnfd'
        vnfd_array = nsd_response['constituent-vnfd']
        for nsd_item in vnfd_array:
            # TODO verify the correct behaviour among the two following lines code
            current_node_id = g.number_of_nodes()
            # current_node_id = selected_node(g, nsd_item['vnfd-id-ref'])
            # add a node in the nx.Graph for every vnfd
            g.add_node(current_node_id,
                       features="VNFD: {}".format(nsd_item['vnfd-id-ref']),
                       ref_node_id=nsd_item['member-vnf-index'],
                       name=nsd_item['vnfd-id-ref'],
                       type="VNFD",
                       shape="circle",
                       nested=[nsd_nested_item['nested-nsd-id']],
                       federation=[str(domain_federation)],
                       group=1)
        # dealing with the 'vld'
        vld_array = nsd_response['vld']
        for vld_item in vld_array:
            vld_connections_array = vld_item['vnfd-connection-point-ref']
            # current_node_id = g.number_of_nodes()
            current_node_id = selected_node(g, vld_item['name'])
            # add a node in the nx.Graph for every vld
            g.add_node(
                current_node_id,
                features="VLD: {}".format(vld_item['name']),
                name=vld_item['name'],
                type="VLD",
                shape="rect",
                # nested=[nsd_nested_item['nested-nsd-id']],
                # federation=str(domain_federation),
                group=2)
            # nested parameters is a list of shared components
            if 'nested' in g.nodes[current_node_id]:
                g.nodes[current_node_id]['nested'].append(
                    nsd_nested_item['nested-nsd-id'])
            else:
                g.nodes[current_node_id]['nested'] = [
                    nsd_nested_item['nested-nsd-id']
                ]
            # federation parameters is a list of shared components
            if 'federation' in g.nodes[current_node_id]:
                g.nodes[current_node_id]['federation'].append(
                    str(domain_federation))
            else:
                g.nodes[current_node_id]['federation'] = [
                    str(domain_federation)
                ]
            list_ids = list()
            # dealing with the corresponding links between different elements
            for vld_connection_item in vld_connections_array:
                list_ids.append((vld_connection_item['member-vnf-index-ref'],
                                 vld_connection_item['vnfd-id-ref']))
            for element in list_ids:
                for nodes in g:
                    if g.nodes[nodes]['group'] == 1:
                        if element[0] == g.nodes[nodes][
                                'ref_node_id'] and element[1] == g.nodes[
                                    nodes]['name']:
                            # add a link
                            g.add_edge(nodes,
                                       selected_node(g, vld_item['name']))
        # adding placement info
        id_for_placement = ''
        for nested_ns_id in list_of_nested_ns_id:
            if nested_ns_id['nsd_id'] == nsd_nested_item['nested-nsd-id']:
                id_for_placement = nested_ns_id['ns_id']
        if nsir_db.exists_nsir(id_for_placement):
            placement_info = nsir_db.get_placement_info(id_for_placement)
            # update the name of vl in common for composite for placement algorithm
            for used_vls in placement_info['usedVLs']:
                for i, mapped_vl in enumerate(used_vls['mappedVLs']):
                    if mapped_vl in mapping:
                        used_vls['mappedVLs'][i] = mapping[mapped_vl]

            if placement_info:
                g = add_placement(g, placement_info)
    # d = json_graph.node_link_data(g)  # node-link format to serialize
    # print(d)
    # return d
    return g