Beispiel #1
0
 def prepareNFFG(self, nffg):
     manager = NFFG_Manager(nffg)  
     
     # Retrieve the VNF templates, if a node is a new graph, expand it
     logging.debug('Add templates to nffg')
     manager.addTemplates()
     logging.debug('Post expansion: '+nffg.getJSON())
     
     # Optimize NF-FG, currently the switch VNF when possible will be collapsed
     manager.mergeUselessVNFs()   
     
     # Change the remote node ID in remote_endpoint_id and in prepare_connection_to_remote_endpoint_id to the internal value
     self.convertRemoteNodeID(nffg)
    def searchMatchesBetweenDomains(self, domains_info, domain_id_1, domain_id_2, number_of_links):
        matches_found = 0
        characterization = []
        middle_nffg = None
        domain_1 = domains_info[domain_id_1]
        # Directly linked domains
        # Vlan
        for interface in domain_1.interfaces:
            for neighbor in interface.neighbors:
                if neighbor.domain_name != "internet" and neighbor.interface is not None:
                    # Search for direct connections
                    try:
                        remote_domain = Domain().getDomainFromName(neighbor.domain_name)
                    except DomainNotFound:
                        # Remote_domain not found, continue
                        continue
                    remote_node = neighbor.node
                    remote_interface_name = neighbor.interface
                    if remote_domain.id == domain_id_2 and remote_domain.id in domains_info:
                        remote_interface = domains_info[remote_domain.id].getInterface(
                            remote_node, remote_interface_name
                        )
                        if (
                            remote_interface is not None
                            and self.isNeighbor(remote_interface, Domain().getDomain(domain_id_1).name, interface)
                            is True
                        ):
                            if interface.vlan is True and remote_interface.vlan is True:
                                while matches_found < number_of_links:
                                    vlan_id = self.findFreeVlanId(interface.vlans_free, remote_interface.vlans_free)
                                    if vlan_id is not None:
                                        print("vlan match found")
                                        matches_found = matches_found + 1
                                        characterization.append(
                                            Vlan(
                                                interface.node,
                                                interface.name,
                                                domain_1.type,
                                                remote_node,
                                                remote_interface_name,
                                                remote_domain.type,
                                                vlan_id,
                                            )
                                        )
                                    else:
                                        logging.debug("vlan id free not found")
                                        break
                                if matches_found == number_of_links:
                                    break
            if matches_found == number_of_links:
                break
        # Direct links
        if matches_found < number_of_links:
            for interface in domain_1.interfaces:
                for neighbor in interface.neighbors:
                    if neighbor.domain_name != "internet" and neighbor.interface is not None:
                        # Search for direct connections
                        try:
                            remote_domain = Domain().getDomainFromName(neighbor.domain_name)
                        except DomainNotFound:
                            # Remote_domain not found, continue
                            continue
                        remote_node = neighbor.node
                        remote_interface_name = neighbor.interface
                        if remote_domain.id == domain_id_2 and remote_domain.id in domains_info:
                            remote_interface = domains_info[remote_domain.id].getInterface(
                                remote_node, remote_interface_name
                            )
                            if (
                                remote_interface is not None
                                and self.isNeighbor(remote_interface, Domain().getDomain(domain_id_1).name, interface)
                                is True
                            ):
                                print("direct link match found")
                                matches_found = matches_found + 1
                                characterization.append(
                                    DirectLink(
                                        interface.node,
                                        interface.name,
                                        domain_1.type,
                                        remote_node,
                                        remote_interface_name,
                                        remote_domain.type,
                                    )
                                )
                                if matches_found == number_of_links:
                                    break
                if matches_found == number_of_links:
                    break
        # Domains not directly linked
        if matches_found < number_of_links:
            for interface in domain_1.interfaces:
                result = self.searchConnectionThroughADomain(domains_info, interface, domain_id_1, domain_id_2)
                if result is not None:
                    middle_domain = result[0]
                    middle_interface_1 = result[1]
                    middle_interface_2 = result[2]
                    remote_interface = result[3]
                    # TODO: Direct links support?
                    if (
                        interface.vlan is True
                        and middle_interface_1.vlan is True
                        and middle_interface_2.vlan is True
                        and remote_interface.vlan is True
                    ):
                        middle_nffg = NF_FG()
                        middle_nffg.name = "Passthrough"
                        middle_nffg.domain = middle_domain.name
                        nffg_manager = NFFG_Manager(middle_nffg)
                        while matches_found < number_of_links:
                            vlan_id_1 = self.findFreeVlanId(interface.vlans_free, middle_interface_1.vlans_free)
                            vlan_id_2 = self.findFreeVlanId(middle_interface_2.vlans_free, remote_interface.vlans_free)
                            if vlan_id_1 is not None and vlan_id_2 is not None:
                                print("vlan match through an external domain found")
                                nffg_manager.addEndpointsCoupleAndFlowrules(matches_found)
                                matches_found = matches_found + 1
                                characterization.append(
                                    Vlan(
                                        interface.node,
                                        interface.name,
                                        domain_1.type,
                                        middle_interface_1.node,
                                        middle_interface_1.name,
                                        middle_domain.type,
                                        vlan_id_1,
                                        partial=1,
                                    )
                                )
                                characterization.append(
                                    Vlan(
                                        middle_interface_2.node,
                                        middle_interface_2.name,
                                        middle_domain.type,
                                        remote_interface.node,
                                        remote_interface.name,
                                        Domain().getDomain(domain_id_2).type,
                                        vlan_id_2,
                                        partial=2,
                                    )
                                )
                            else:
                                logging.debug("vlan id free not found")
                                break
                        if matches_found == number_of_links:
                            break
        # Domains connected through an IP domain
        # GRE
        if matches_found < number_of_links:
            # Search for internet connections
            for interface in domain_1.interfaces:
                if self.isConnectedToIPDomain(interface) is True and interface.gre is True:
                    # if self.checkActiveTunnels(interface, node_id_2) is True:
                    domain_2 = domains_info[domain_id_2]
                    for remote_interface in domain_2.interfaces:
                        if self.isConnectedToIPDomain(remote_interface) is True and remote_interface.gre is True:
                            # Gre_tunnel endpoints found
                            # If local and/or remote interfaces are Openstack compute nodes we need to set the local/remote GRE IP addresses accordingly
                            if interface.node is not None:
                                local_ip = interface.node
                            else:
                                local_ip = Domain().getDomainIP(domain_id_1)
                            if remote_interface.node is not None:
                                remote_ip = remote_interface.node
                            else:
                                remote_ip = Domain().getDomainIP(domain_id_2)
                            while matches_found < number_of_links:
                                print("gre match found")
                                matches_found = matches_found + 1
                                characterization.append(Gre(local_ip, remote_ip))
                            break
                if matches_found == number_of_links:
                    break

        if matches_found == number_of_links:
            print("Characterization found")
            return characterization, middle_nffg
        else:
            return None