def initialize(self): """ .. seealso:: :func:`AbstractAPI.initialize() <escape.util.api.AbstractAPI.initialize>` """ log.debug("Initializing Resource Orchestration Sublayer...") self.orchestrator = ResourceOrchestrator(self) if self._nffg_file: try: service_request = self._read_data_from_file(self._nffg_file) service_request = NFFG.parse(service_request) dov = self.orchestrator.virtualizerManager.dov self.__proceed_instantiation( nffg=service_request, resource_view=dov.get_resource_info()) except (ValueError, IOError, TypeError) as e: log.error("Can't load service request from file because of: " + str(e)) quit_with_error(msg=str(e), logger=log) else: log.info("Graph representation is loaded successfully!") # Initiate ROS REST-API if needed if self._agent or self._rosapi: self._initiate_ros_api() log.info("Resource Orchestration Sublayer has been initialized!") if self._agent: log.warning( "In AGENT mode Service Layer is not going to be initialized!")
def rest_api_mappings(self, mappings): """ Calculate the mappings of NFs given in the mappings structure. :param mappings: requested mappings :type mappings: Mappings :return: new mappings with extended info :rtype: Mappings """ slor_topo = self.__get_slor_resource_view().get_resource_info() log.debug("Collecting mapping info...") response = self.orchestrator.collect_mappings(mappings=mappings, slor_topo=slor_topo) log.debug("Resolving domain URLs...") adaptation = self.get_dependent_component("adaptation") if adaptation is None: log.error("Adaptation Layer is missing!") else: for mapping in response: domain = mapping.target.domain.get_value() url = adaptation.controller_adapter.get_domain_url( domain=domain) if url: log.debug("Found URL: %s for domain: %s" % (url, domain)) else: log.error("URL is missing from domain: %s!" % domain) url = "N/A" mapping.target.domain.set_value("%s@%s" % (domain, url)) return response
def rest_api_mapping_info(self, service_id): """ Return with collected information of mapping of a given service. :param service_id: service request ID :type service_id: str :return: mapping info :rtype: dict """ # Create base response structure ret = {"service_id": service_id} log.debug("Collecting mapping info...") mapping = self.orchestrator.collect_mapping_info(service_id=service_id) if isinstance(mapping, basestring): return ret log.debug("Resolving domain URLs...") adaptation = self.get_dependent_component("adaptation") if adaptation is None: log.error("Adaptation Layer is missing!") else: adaptation.controller_adapter.collect_domain_urls(mapping=mapping) ret['mapping'] = mapping # Collect NF management data log.debug("Collected mapping info:\n%s" % pprint.pformat(ret)) return ret
def __update_nffg_domain(nffg_part, domain_name=None): """ Update domain descriptor of infras: REMOTE -> INTERNAL :param nffg_part: NF-FG need to be updated :type nffg_part: :class:`NFFG` :return: updated NFFG :rtype: :class:`NFFG` """ rewritten = [] if domain_name is None: local_mgr = CONFIG.get_internal_manager() if local_mgr is None: log.error("No local Manager has been initiated! " "Skip domain rewriting!") elif len(local_mgr) > 1: log.warning("Multiple local Manager has been initiated: %s! " "Arbitrarily use the first..." % local_mgr) domain_name = local_mgr.pop() log.debug("Rewrite received NFFG domain to %s..." % domain_name) for infra in nffg_part.infras: infra.domain = domain_name rewritten.append(infra.id) log.debug("Rewritten infrastructure nodes: %s" % rewritten) return nffg_part
def rest_api_get_config(self): """ Implementation of REST-API RPC: get-config. Return with the global resource as an :class:`NFFG` if it has been changed otherwise return with False. :return: global resource view (DoV) :rtype: :class:`NFFG` or False """ self.log.debug("Requesting Virtualizer for %s" % self._core_name) slor_virt = self.__get_slor_resource_view() if slor_virt is not None: # Check the topology is initialized if slor_virt.revision is None: self.log.debug("DoV has not initialized yet! " "Force to get default topology...") else: # Check if the resource is changed if self.api_mgr.topology_revision == slor_virt.revision: # If resource has not been changed return False # This causes to response with the cached topology self.log.debug( "Global resource has not changed (revision: %s)! " % slor_virt.revision) log.debug("Send topology from cache...") if self.api_mgr.last_response is None: log.error("Cached topology is missing!") return else: return self.api_mgr.last_response else: self.log.debug( "Response cache is outdated (new revision: %s)!" % slor_virt.revision) # Get topo view as NFFG res = slor_virt.get_resource_info() self.api_mgr.topology_revision = slor_virt.revision self.log.debug("Updated revision number: %s" % self.api_mgr.topology_revision) if CONFIG.get_rest_api_config(self._core_name)['unify_interface']: self.log.info("Convert internal NFFG to Virtualizer...") res = self.api_mgr.converter.dump_to_Virtualizer(nffg=res) log.debug("Cache acquired topology...") self.api_mgr.last_response = res return res else: log.error("Virtualizer assigned to %s is not found!" % self._core_name)
def api_cfor_get_config(self): """ Implementation of Cf-Or REST-API RPC: get-config. :return: dump of a single BiSBiS view based on DoV :rtype: str """ log.getChild('[Cf-Or]').info("Requesting Virtualizer for REST-API...") virt = self.resource_orchestrator.virtualizerManager.get_virtual_view( virtualizer_id=self.cfor_api.api_id, type=self.cfor_api.virtualizer_type) if virt is not None: log.getChild('[Cf-Or]').info("Generate topo description...") return virt.get_resource_info() else: log.error("Virtualizer(id=%s) assigned to REST-API is not found!" % self.cfor_api.api_id)
def _mapping_finished(self, mapped_nffg): """ Called from a separate thread when the mapping process is finished. :param mapped_nffg: mapped NF-FG :type mapped_nffg: :any:`NFFG` :return: None """ # TODO - rethink threaded/non-threaded function call paths to call port # mapping functions in a joint way only once if mapped_nffg is None: log.error( "Mapping process is failed! Abort orchestration process.") return None # Steps after mapping (optional) if the mapping was threaded log.debug( "Inform actual layer API that NFFG mapping has been finished...") self.raiseEventNoErrors(NFFGMappingFinishedEvent, mapped_nffg)
def initialize(self): """ Initialize NFIB with test data. """ try: try: host, port = CONFIG.get_neo4j_host_port() host = host if host else self.DB_HOST port = port if port else self.DB_PORT log.debug("Initiating Graph database connection[%s:%s]..." % (host, port)) self.graph_db = Graph(host=host, http_port=port) except Unauthorized as e: quit_with_error( "Got Unauthorized error on: %s from neo4j! Disable the authorization " "in /etc/neo4j/neoj4-server.properties!" % e) return self except SocketError: log.warning( "NFIBManager has not been initialized! Only cause problem " "if ESCAPE is used as a Local Orchestrator!") return self self.__initialize() except SocketError as e: log.error( "NFIB is not reachable due to failed neo4j service! Cause: " + str(e)) except KeyboardInterrupt: log.warning("NFIB was interrupted by user!") except Unauthorized: log.error( "neo4j responded with Unauthorized error! Maybe you forgot disabling " "authentication in '/etc/neo4j/neo4j.conf' ?") except IOError as e: if ".neo4j/known_hosts" in str(e): # Skip Permission denied in case of accessing neo4j cache file (v3.0.2) pass else: raise except: log.exception("Got unexpected error during NFIB initialization!") return self
def collect_mapping_info(self, service_id): """ Return with collected information of mapping of a given service. :param service_id: service request ID :type service_id: str :return: mapping info :rtype: dict """ # Get the service NFFG based on service ID request = self.nffgManager.get(service_id) if request is None: log.error("Service request(id: %s) is not found!" % service_id) return "Service request is not found!" # Get the overall view a.k.a. DoV dov = self.virtualizerManager.dov.get_resource_info() # Collect NFs nfs = [nf.id for nf in request.nfs] log.debug("Collected NFs: %s" % nfs) return self.__collect_binding(dov=dov, nfs=nfs)
def map(cls, graph, resource): """ Default mapping algorithm of ESCAPEv2. :param graph: Network Function forwarding Graph :type graph: :any:`NFFG` :param resource: global virtual resource info :type resource: :any:`NFFG` :return: mapped Network Function Forwarding Graph :rtype: :any:`NFFG` """ log.debug("Invoke mapping algorithm: %s - request: %s resource: %s" % (cls.__name__, graph, resource)) if graph is None: log.error("Missing request NFFG! Abort mapping process...") return if resource is None: log.error("Missing resource NFFG! Abort mapping process...") return try: # print graph.dump() mapper_params = CONFIG.get_mapping_config(layer=LAYER_NAME) mapped_nffg = MAP(request=graph.copy(), network=resource.copy(), **mapper_params) # Set mapped NFFG id for original SG request tracking mapped_nffg.id = graph.id mapped_nffg.name = graph.name + "-ros-mapped" log.debug("Mapping algorithm: %s is finished on NF-FG: %s" % (cls.__name__, graph)) # print mapped_nffg.dump() return mapped_nffg except MappingException as e: log.error( "Mapping algorithm unable to map given request! Cause:\n%s" % e.msg) log.warning("Mapping algorithm on %s is aborted!" % graph) return except BadInputException as e: log.error("Mapping algorithm refuse given input! Cause:\n%s" % e.msg) log.warning("Mapping algorithm on %s is aborted!" % graph) return except InternalAlgorithmException as e: log.critical( "Mapping algorithm fails due to implementation error or conceptual " "error! Cause:\n%s" % e.msg) log.warning("Mapping algorithm on %s is aborted!" % graph) raise except: log.exception("Got unexpected error during mapping process!")
def initialize (self): """ Initialize NFIB with test data. """ try: self.__initialize() except SocketError as e: log.error( "NFIB is not reachable due to failed neo4j service! Cause: " + str(e)) except KeyboardInterrupt: log.warning("NFIB was interrupted by user!") except Unauthorized: log.error( "neo4j responded with Unauthorized error! Maybe you forgot disabling " "authentication in '/etc/neo4j/neo4j.conf' ?") except IOError as e: if ".neo4j/known_hosts" in str(e): # Skip Permission denied in case of accessing neo4j cache file (v3.0.2) pass else: raise except: log.exception("Got unexpected error during NFIB initialization!")
def _resolve_external_ports(cls, graph, resource): log.debug("Resolving optional external flowrules...") for infra in graph.infras: for port in infra.ports: if port.role != "EXTERNAL": continue log.debug("Detected external port: %s" % port) bb_node_id = port.properties["node"] bb_port_id = port.properties["port"] try: bb_port_id = int(bb_port_id) except ValueError: pass if bb_node_id not in resource: log.error("Missing external node: %s from resource!" % bb_node_id) continue bb_node = resource[bb_node_id] if bb_port_id not in bb_node.ports: log.error( "Missing external port: %s from resource node: %s!" % (bb_port_id, bb_node)) continue bb_port = bb_node.ports[bb_port_id] if not bb_port.sap: log.error("No SAP tag was found in external port: %s" % bb_port) continue else: log.debug("Detected SAP tag: %s for external port: %s" % (bb_port.sap, bb_port_id)) # Update SAP tag in request from resource port port.sap = bb_port.sap log.debug("Updated external SAP tag: %s" % port.sap) # Add ext SAP/SAP port/BB port based on external port to resource graph res_sap = resource.add_sap(id=port.id) res_sap_port = res_sap.add_port(id=port.id) res_sap_port.sap = bb_port.sap res_sap_port.role = port.role res_sap_port.properties.update(port.properties) res_port = bb_node.add_port(id=port.id) res_port.sap = bb_port.sap res_port.role = port.role res_port.properties.update(port.properties) resource.add_undirected_link(port1=res_port, port2=res_sap_port) log.debug("Created external resource SAP: %s" % res_sap) # Update SAP port in request as well ext_sap = graph[res_sap.id] ext_sap_port = ext_sap.ports.container[0] ext_sap_port.sap = res_sap_port.sap ext_sap_port.role = res_sap_port.role ext_sap_port.properties.update(res_sap_port.properties) log.debug("Updated external SAP: %s" % ext_sap)
def _perform_mapping(self, input_graph, resource_view): """ Orchestrate mapping of given NF-FG on given global resource. :param input_graph: Network Function Forwarding Graph :type input_graph: :any:`NFFG` :param resource_view: global resource view :type resource_view: :any:`DomainVirtualizer` :return: mapped Network Function Forwarding Graph :rtype: :any:`NFFG` """ if input_graph is None: log.error( "Missing mapping request information! Abort mapping process!") return None log.debug("Request %s to launch orchestration on NF-FG: %s with View: " "%s" % (self.__class__.__name__, input_graph, resource_view)) # Steps before mapping (optional) log.debug("Request global resource info...") virt_resource = resource_view.get_resource_info() if virt_resource is None: log.error("Missing resource information! Abort mapping process!") return None # log a warning if resource is empty --> possibly mapping will be failed if virt_resource.is_empty(): log.warning("Resource information is empty!") # Log verbose resource view if it is exist log.log( VERBOSE, "Orchestration Layer resource graph:\n%s" % virt_resource.dump()) # Check if the mapping algorithm is enabled if not CONFIG.get_mapping_enabled(LAYER_NAME): log.warning("Mapping algorithm in Layer: %s is disabled! " "Skip mapping step and return service request " "to lower layer..." % LAYER_NAME) # virt_resource.id = input_graph.id # return virt_resource # Send request forward (probably to Remote ESCAPE) return input_graph # Run actual mapping algorithm if self._threaded: # Schedule a microtask which run mapping algorithm in a Python thread log.info("Schedule mapping algorithm: %s in a worker thread" % self.strategy.__name__) call_as_coop_task(self._start_mapping, graph=input_graph, resource=virt_resource) log.info("NF-FG: %s orchestration is finished by %s" % (input_graph, self.__class__.__name__)) # Return with None return None else: mapped_nffg = self.strategy.map(graph=input_graph, resource=virt_resource) if mapped_nffg is None: log.error( "Mapping process is failed! Abort orchestration process.") else: # Steps after mapping (optional) log.info( "NF-FG: %s orchestration is finished by %s successfully!" % (input_graph, self.__class__.__name__)) return mapped_nffg
def _perform_mapping(self, input_graph, resource_view, continued=False): """ Orchestrate mapping of given NF-FG on given global resource. :param input_graph: Network Function Forwarding Graph :type input_graph: :class:`NFFG` :param resource_view: global resource view :type resource_view: :any:`DomainVirtualizer` :return: mapped Network Function Forwarding Graph :rtype: :class:`NFFG` """ if input_graph is None: log.error( "Missing mapping request information! Abort mapping process!") return None log.debug( "Request %s to launch orchestration on NF-FG: %s with View: " "%s, continued remap: %s" % (self.__class__.__name__, input_graph, resource_view, continued)) # Steps before mapping (optional) log.debug("Request global resource info...") virt_resource = resource_view.get_resource_info() if virt_resource is None: log.error("Missing resource information! Abort mapping process!") return None # log a warning if resource is empty --> possibly mapping will be failed if virt_resource.is_empty(): log.warning("Resource information is empty!") # Log verbose resource view if it is exist log.log( VERBOSE, "Orchestration Layer resource graph:\n%s" % virt_resource.dump()) # Check if the mapping algorithm is enabled if not CONFIG.get_mapping_enabled(LAYER_NAME): log.warning("Mapping algorithm in Layer: %s is disabled! " "Skip mapping step and return service request " "to lower layer..." % LAYER_NAME) # virt_resource.id = input_graph.id # return virt_resource # Send request forward (probably to Remote ESCAPE) input_graph.status = NFFG.MAP_STATUS_SKIPPED log.debug("Mark NFFG status: %s!" % input_graph.status) return input_graph # Run actual mapping algorithm if self._threaded: # Schedule a microtask which run mapping algorithm in a Python thread log.info("Schedule mapping algorithm: %s in a worker thread" % self.strategy.__name__) call_as_coop_task(self._start_mapping, graph=input_graph, resource=virt_resource) log.info("NF-FG: %s orchestration is finished by %s" % (input_graph, self.__class__.__name__)) # Return with None return None else: state = self.last_mapping_state if continued else None mapping_result = self.strategy.map( graph=input_graph, resource=virt_resource, persistent=self.persistent_state, pre_state=state) if isinstance(mapping_result, tuple or list): if len(mapping_result) == 2: mapped_nffg = mapping_result[0] self.persistent_state = mapping_result[1] log.debug("Cache returned persistent state: %s" % self.persistent_state) elif len(mapping_result) == 3: mapped_nffg = mapping_result[0] self.persistent_state = mapping_result[1] log.debug("Cache returned persistent state: %s" % self.persistent_state) self.last_mapping_state = mapping_result[2] log.debug("Cache returned mapping state: %s" % self.last_mapping_state) else: log.error("Mapping result is invalid: %s" % repr(mapping_result)) mapped_nffg = None else: mapped_nffg = mapping_result # Check error result if mapped_nffg is None: log.error( "Mapping process is failed! Abort orchestration process.") else: # Steps after mapping (optional) log.info( "NF-FG: %s orchestration is finished by %s successfully!" % (input_graph, self.__class__.__name__)) log.debug("Last mapping state: %s" % self.last_mapping_state) if self.last_mapping_state: log.debug("Mapping iteration: %s" % self.last_mapping_state.get_number_of_trials() if self.last_mapping_state else None) return mapped_nffg
def map(cls, graph, resource, persistent=None, pre_state=None): """ Default mapping algorithm of ESCAPEv2. :param graph: Network Function forwarding Graph :type graph: :class:`NFFG` :param resource: global virtual resource info :type resource: :class:`NFFG` :param persistent: use persistent state object :type persistent: object :param pre_state: use mapping state for continued mapping :type pre_state: :class:`MappingState` :return: mapped Network Function Forwarding Graph :rtype: :class:`NFFG` """ log.info("Invoke mapping algorithm: %s - request: %s resource: %s, " "previous state: %s" % (cls.__name__, graph, resource, pre_state)) if graph is None: log.error("Missing request NFFG! Abort mapping process...") return if resource is None: log.error("Missing resource NFFG! Abort mapping process...") return try: # Run pre-mapping step to resolve target-less flowrules cls._resolve_external_ports(graph, resource) # Copy mapping config mapper_params = CONFIG.get_mapping_config( layer=cls.LAYER_NAME).copy() mapper_params['persistent'] = persistent if 'mode' in mapper_params and mapper_params['mode']: log.debug("Setup mapping mode from configuration: %s" % mapper_params['mode']) elif graph.mode: mapper_params['mode'] = graph.mode log.debug("Setup mapping mode based on request: %s" % mapper_params['mode']) if CONFIG.get_trial_and_error(layer=cls.LAYER_NAME): log.info("Use 'trial and error' approach for mapping") mapper_params['return_mapping_state'] = True mapper_params['mapping_state'] = pre_state mapping_result = cls.call_mapping_algorithm( request=graph.copy(), topology=resource.copy(), **mapper_params) if isinstance(mapping_result, tuple or list): mapped_nffg = mapping_result[0] else: mapped_nffg = mapping_result # Set mapped NFFG id for original SG request tracking log.debug("Move request metadata into mapping result...") mapped_nffg.id = graph.id mapped_nffg.name = "%s-%s-mapped" % (graph.name, cls.LAYER_NAME) # Explicitly copy metadata mapped_nffg.metadata = graph.metadata.copy() # Explicit copy of SAP data for sap in graph.saps: if sap.id in mapped_nffg: mapped_nffg[sap.id].metadata = graph[ sap.id].metadata.copy() log.info("Mapping algorithm: %s is finished on NF-FG: %s" % (cls.__name__, mapped_nffg)) return mapping_result except MappingException as e: log.error( "Mapping algorithm unable to map given request! Cause:\n%s" % e.msg) log.error("Mapping algorithm on %s is aborted!" % graph) return except BadInputException as e: log.error("Mapping algorithm refuse given input! Cause:\n%s" % e.msg) log.error("Mapping algorithm on %s is aborted!" % graph) return except InternalAlgorithmException as e: log.critical( "Mapping algorithm fails due to internal error! Cause:\n%s" % e.msg) log.error("Mapping algorithm on %s is aborted!" % graph) return except Exception: log.exception("Got unexpected error during mapping process!")
def __proceed_instantiation(self, nffg, resource_nffg): """ Helper function to instantiate the NFFG mapping from different source. :param nffg: pre-mapped service request :type nffg: :class:`NFFG` :return: None """ self.log.info("Invoke instantiation on %s with NF-FG: %s" % (self.__class__.__name__, nffg.name)) stats.add_measurement_start_entry(type=stats.TYPE_ORCHESTRATION, info=LAYER_NAME) # Get shown topology view if resource_nffg is None: log.error("Missing resource for difference calculation!") return log.debug("Got resource view for difference calculation: %s" % resource_nffg) self.log.debug("Store received NFFG request info...") msg_id = self.api_mgr.request_cache.cache_request_by_nffg(nffg=nffg) if msg_id is not None: self.api_mgr.request_cache.set_in_progress(id=msg_id) self.log.debug("Request is stored with id: %s" % msg_id) else: self.log.debug("No request info detected.") # Check if mapping mode is set globally in CONFIG mapper_params = CONFIG.get_mapping_config(layer=LAYER_NAME) if 'mode' in mapper_params and mapper_params['mode'] is not None: mapping_mode = mapper_params['mode'] log.info("Detected mapping mode from configuration: %s" % mapping_mode) elif nffg.mode is not None: mapping_mode = nffg.mode log.info("Detected mapping mode from NFFG: %s" % mapping_mode) else: mapping_mode = None log.info("No mapping mode was defined explicitly!") if not CONFIG.get_mapping_enabled(layer=LAYER_NAME): log.warning("Mapping is disabled! Skip difference calculation...") elif nffg.status == NFFG.MAP_STATUS_SKIPPED: log.debug("Detected NFFG map status: %s! " "Skip difference calculation and " "proceed with original request..." % nffg.status) elif mapping_mode != NFFG.MODE_REMAP: # Calculated ADD-DELETE difference log.debug("Calculate ADD - DELETE difference with mapping mode...") # Recreate SG-hops for diff calc. log.debug("Recreate SG hops for difference calculation...") NFFGToolBox.recreate_all_sghops(nffg=nffg) NFFGToolBox.recreate_all_sghops(nffg=resource_nffg) log.log(VERBOSE, "New NFFG:\n%s" % nffg.dump()) log.log(VERBOSE, "Resource NFFG:\n%s" % resource_nffg.dump()) # Calculate difference add_nffg, del_nffg = NFFGToolBox.generate_difference_of_nffgs( old=resource_nffg, new=nffg, ignore_infras=True) log.log(VERBOSE, "Calculated ADD NFFG:\n%s" % add_nffg.dump()) log.log(VERBOSE, "Calculated DEL NFFG:\n%s" % del_nffg.dump()) if not add_nffg.is_bare() and del_nffg.is_bare(): nffg = add_nffg log.info("DEL NFFG is bare! Calculated mapping mode: %s" % nffg.mode) elif add_nffg.is_bare() and not del_nffg.is_bare(): nffg = del_nffg log.info("ADD NFFG is bare! Calculated mapping mode: %s" % nffg.mode) elif not add_nffg.is_bare() and not del_nffg.is_bare(): log.warning("Both ADD / DEL mode is not supported currently") self.__process_mapping_result(nffg_id=nffg.id, fail=True) stats.add_measurement_end_entry(type=stats.TYPE_ORCHESTRATION, info=LAYER_NAME + "-FAILED") self.raiseEventNoErrors( InstantiationFinishedEvent, id=nffg.id, result=InstantiationFinishedEvent.ABORTED) return else: log.debug("Difference calculation resulted empty subNFFGs!") log.warning( "No change has been detected in request! Skip mapping...") self.log.debug("Invoked instantiation on %s is finished!" % self.__class__.__name__) self.__process_mapping_result(nffg_id=nffg.id, fail=False) stats.add_measurement_end_entry(type=stats.TYPE_ORCHESTRATION, info=LAYER_NAME + "-SKIPPED") return else: log.debug( "Mode: %s detected from config! Skip difference calculation..." % mapping_mode) try: if CONFIG.get_mapping_enabled(layer=LAYER_NAME): # Initiate request mapping mapped_nffg = self.orchestrator.instantiate_nffg(nffg=nffg) else: log.warning("Mapping is disabled! Skip instantiation step...") mapped_nffg = nffg mapped_nffg.status = NFFG.MAP_STATUS_SKIPPED log.debug("Mark NFFG status: %s!" % mapped_nffg.status) # Rewrite REMAP mode for backward compatibility if mapped_nffg is not None and mapping_mode == NFFG.MODE_REMAP: mapped_nffg.mode = mapping_mode log.debug("Rewrite mapping mode: %s into mapped NFFG..." % mapped_nffg.mode) else: log.debug("Skip mapping mode rewriting! Mode remained: %s" % mapping_mode) self.log.debug("Invoked instantiate_nffg on %s is finished!" % self.__class__.__name__) # If mapping is not threaded and finished with OK if mapped_nffg is not None and not self.orchestrator.mapper.threaded: self._proceed_to_install_NFFG(mapped_nffg=mapped_nffg, original_request=nffg) else: log.warning( "Something went wrong in service request instantiation: " "mapped service request is missing!") self.__process_mapping_result(nffg_id=nffg.id, fail=True) stats.add_measurement_end_entry(type=stats.TYPE_ORCHESTRATION, info=LAYER_NAME + "-FAILED") self.raiseEventNoErrors( InstantiationFinishedEvent, id=nffg.id, result=InstantiationFinishedEvent.MAPPING_ERROR) except ProcessorError as e: self.__process_mapping_result(nffg_id=nffg.id, fail=True) stats.add_measurement_end_entry(type=stats.TYPE_ORCHESTRATION, info=LAYER_NAME + "-DENIED") self.raiseEventNoErrors( InstantiationFinishedEvent, id=nffg.id, result=InstantiationFinishedEvent.REFUSED_BY_VERIFICATION, error=e)
def instantiate_nffg (self, nffg): """ Main API function for NF-FG instantiation. :param nffg: NFFG instance :type nffg: :any:`NFFG` :return: mapped NFFG instance :rtype: :any:`NFFG` """ log.debug("Invoke %s to instantiate given NF-FG" % self.__class__.__name__) # Store newly created NF-FG self.nffgManager.save(nffg) # Get Domain Virtualizer to acquire global domain view global_view = self.virtualizerManager.dov # Notify remote visualizer about resource view of this layer if it's needed notify_remote_visualizer(data=global_view.get_resource_info(), id=LAYER_NAME) # Log verbose mapping request log.log(VERBOSE, "Orchestration Layer request graph:\n%s" % nffg.dump()) # Start Orchestrator layer mapping print nffg.dump() if global_view is not None: if isinstance(global_view, AbstractVirtualizer): # If the request is a bare NFFG, it is probably an empty topo for domain # deletion --> skip mapping to avoid BadInputException and forward # topo to adaptation layer if nffg.is_bare(): log.warning("No valid service request (VNFs/Flowrules/SGhops) has " "been detected in SG request! Skip orchestration in " "layer: %s and proceed with the bare %s..." % (LAYER_NAME, nffg)) if nffg.is_virtualized(): if nffg.is_SBB(): log.debug("Request is a bare SingleBiSBiS representation!") else: log.warning( "Detected virtualized representation with multiple BiSBiS " "nodes! Currently this type of virtualization is nut fully" "supported!") else: log.debug("Detected full view representation!") # Return with the original request return nffg else: log.info("Request check: detected valid content!") try: # Run Nf-FG mapping orchestration log.debug("Starting request preprocession...") log.info(int(round(time.time() * 1000))) self.preprocess_nffg(nffg) log.debug("Preprocession ended, start mapping") log.info(int(round(time.time() * 1000))) mapped_nffg = self.mapper.orchestrate(nffg, global_view) log.debug("NF-FG instantiation is finished by %s" % self.__class__.__name__) log.info(int(round(time.time() * 1000))) return mapped_nffg except ProcessorError as e: log.warning("Mapping pre/post processing was unsuccessful! " "Cause: %s" % e) else: log.warning("Global view is not subclass of AbstractVirtualizer!") else: log.warning("Global view is not acquired correctly!") log.error("Abort orchestration process!")
def instantiate_nffg(self, nffg, continued_request_id=None): """ Main API function for NF-FG instantiation. :param nffg: NFFG instance :type nffg: :class:`NFFG` :param continued_request_id: use explicit request id if request is continued after a trial and error (default: False) :type continued_request_id: str or None :return: mapped NFFG instance :rtype: :class:`NFFG` """ log.debug("Invoke %s to instantiate given NF-FG" % self.__class__.__name__) if not continued_request_id: # Store newly created NF-FG self.nffgManager.save(nffg) else: # Use the original NFFG requested for getting the original request nffg = self.nffgManager.get(nffg_id=continued_request_id) log.info("Using original request for remapping: %s" % nffg) # Get Domain Virtualizer to acquire global domain view global_view = self.virtualizerManager.dov # Notify remote visualizer about resource view of this layer if it's needed # notify_remote_visualizer(data=global_view.get_resource_info(), # id=LAYER_NAME) # Log verbose mapping request log.log(VERBOSE, "Orchestration Layer request graph:\n%s" % nffg.dump()) # Start Orchestrator layer mapping if global_view is not None: # If the request is a bare NFFG, it is probably an empty topo for domain # deletion --> skip mapping to avoid BadInputException and forward # topo to adaptation layer if not continued_request_id: if nffg.is_bare(): log.warning( "No valid service request (VNFs/Flowrules/SGhops) has " "been detected in SG request! Skip orchestration in " "layer: %s and proceed with the bare %s..." % (LAYER_NAME, nffg)) if nffg.is_virtualized(): if nffg.is_SBB(): log.debug( "Request is a bare SingleBiSBiS representation!" ) else: log.warning( "Detected virtualized representation with multiple BiSBiS " "nodes! Currently this type of virtualization is nut fully " "supported!") else: log.debug("Detected full view representation!") # Return with the original request return nffg else: log.info("Request check: detected valid NFFG content!") try: # Run NF-FG mapping orchestration mapped_nffg = self.mapper.orchestrate( input_graph=nffg, resource_view=global_view, continued=bool(continued_request_id)) log.debug("NF-FG instantiation is finished by %s" % self.__class__.__name__) return mapped_nffg except ProcessorError as e: log.warning("Mapping pre/post processing was unsuccessful! " "Cause: %s" % e) # Propagate the ProcessError to API layer raise else: log.warning("Global view is not acquired correctly!") log.error("Abort orchestration process!")