Ejemplo n.º 1
0
    def _proceed_to_instantiate_NFFG(self, mapped_nffg):
        """
    Send NFFG to Resource Orchestration Sublayer in an implementation-specific
    way.

    General function which is used from microtask and Python thread also.

    This function contains the last steps before the mapped NFFG will be sent
    to the next layer.

    :param mapped_nffg: mapped Service Graph
    :type mapped_nffg: :class:`NFFG`
    :return: None
    """
        # Rebind requirement link fragments for lower layer mapping
        mapped_nffg = NFFGToolBox.rebind_e2e_req_links(nffg=mapped_nffg,
                                                       log=log)
        # Log verbose mapping result in unified way (threaded/non-threaded)
        log.log(VERBOSE,
                "Mapping result of Service Layer:\n%s" % mapped_nffg.dump())
        # Notify remote visualizer about the mapping result if it's needed
        # notify_remote_visualizer(data=mapped_nffg, id=LAYER_NAME)
        sas_res = self.__get_sas_resource_view().get_resource_info()
        # Sending mapped SG / NF-FG to Orchestration layer as an Event
        # Exceptions in event handlers are caught by default in a non-blocking way
        self.raiseEventNoErrors(InstantiateNFFGEvent, mapped_nffg, sas_res)
        log.getChild('API').info(
            "Generated NF-FG: %s has been sent to Orchestration..." %
            mapped_nffg)
Ejemplo n.º 2
0
  def _perform_mapping (self, input_graph, resource_view):
    """
    Orchestrate mapping of given service graph on given virtual resource.

    :param input_graph: Service Graph
    :type input_graph: :any:`NFFG`
    :param resource_view: virtual resource view
    :param resource_view: :any:`AbstractVirtualizer`
    :return: Network Function Forwarding Graph
    :rtype: :any:`NFFG`
    """
    if input_graph is None:
      log.error("Missing service request information! Abort mapping process!")
      return None
    log.debug("Request %s to launch orchestration on SG: %s with View: %s" % (
      self.__class__.__name__, input_graph, resource_view))
    # Steps before mapping (optional)
    log.debug("Request resource info from layer virtualizer...")
    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, "Service layer resource graph:\n%s" % virt_resource.dump())
    # resource_view.sanity_check(input_graph)
    # 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 "
        "forward service request to lower layer..." % LAYER_NAME)
      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("SG: %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)
      # Steps after mapping (optional) if the mapping was not threaded
      if mapped_nffg is None:
        log.error("Mapping process is failed! Abort orchestration process.")
      else:
        log.info("SG: %s orchestration is finished by %s successfully!" % (
          input_graph, self.__class__.__name__))
      return mapped_nffg
Ejemplo n.º 3
0
    def initiate_service_graph(self, sg):
        """
    Main function for initiating Service Graphs.

    :param sg: service graph stored in NFFG instance
    :type sg: :class:`NFFG`
    :return: NF-FG description
    :rtype: :class:`NFFG`
    """
        log.debug("Invoke %s to initiate SG(id=%s)" %
                  (self.__class__.__name__, sg.id))
        # Store newly created SG
        self.sgManager.save(sg)
        # Get virtual resource info as a Virtualizer
        virtual_view = self.virtResManager.virtual_view
        # Notify remote visualizer about resource view of this layer if it's needed
        # notify_remote_visualizer(data=virtual_view.get_resource_info(),
        #                          id=LAYER_NAME)
        # Log verbose service request
        log.log(VERBOSE, "Service layer request graph:\n%s" % sg.dump())
        if virtual_view is not None:
            if isinstance(virtual_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 sg.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, sg))
                    if sg.is_virtualized():
                        if sg.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 sg
                else:
                    log.info("Request check: detected valid NFFG content!")
                try:
                    # Run orchestration before service mapping algorithm
                    mapped_nffg = self.mapper.orchestrate(sg, virtual_view)
                    log.debug("SG initiation 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(
                    "Virtual view is not subclass of AbstractVirtualizer!")
        else:
            log.warning("Virtual view is not acquired correctly!")
        # Only goes there if there is a problem
        log.error("Abort orchestration process!")
Ejemplo n.º 4
0
    def _perform_mapping(self, input_graph, resource_view, continued=False):
        """
    Orchestrate mapping of given service graph on given virtual resource.

    :param input_graph: Service Graph
    :type input_graph: :class:`NFFG`
    :param resource_view: virtual resource view
    :param resource_view: :any:`AbstractVirtualizer`
    :return: Network Function Forwarding Graph
    :rtype: :class:`NFFG`
    """
        if input_graph is None:
            log.error(
                "Missing service request information! Abort mapping process!")
            return None
        log.debug(
            "Request %s to launch orchestration on SG: %s with View: %s,"
            "continued remap: %s" %
            (self.__class__.__name__, input_graph, resource_view, continued))
        # Steps before mapping (optional)
        log.debug("Request resource info from layer virtualizer...")
        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,
                "Service layer resource graph:\n%s" % virt_resource.dump())
        # resource_view.sanity_check(input_graph)
        # 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 "
                "forward service request to lower layer..." % LAYER_NAME)
            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("SG: %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,
                                               pre_state=state)
            if isinstance(mapping_result, tuple or list):
                if len(mapping_result) != 2:
                    log.error("Mapping result is invalid: %s" %
                              repr(mapping_result))
                    mapped_nffg = None
                else:
                    mapped_nffg = mapping_result[0]
                    self.last_mapping_state = mapping_result[1]
                    log.debug("Cache returned mapping state: %s" %
                              self.last_mapping_state)
            else:
                mapped_nffg = mapping_result
            # Steps after mapping (optional) if the mapping was not threaded
            if mapped_nffg is None:
                log.error(
                    "Mapping process is failed! Abort orchestration process.")
            else:
                log.info(
                    "SG: %s orchestration is finished by %s successfully!" %
                    (input_graph, self.__class__.__name__))
            log.debug("Last mapping state: %s" % self.last_mapping_state)
            log.info("Mapping iteration: %s" %
                     self.last_mapping_state.get_number_of_trials() if self.
                     last_mapping_state else None)
            return mapped_nffg