Ejemplo n.º 1
0
    def list_resources(self,
                       client_cert,
                       credentials,
                       geni_available,
                       inner_call=False):
        """
        Shows a list with the slivers managed or seen by the resource manager.

        @param client_cert client certificate (X509)
        @param credentials client credential(s), provided by the ClearingHouse
            and generated after the certificates
        @param geni_available flag to describe which slivers are expected
            to be shown
                * geni_available = True : only available (non-allocated,
                                          non-provisioned) will be shown
                * geni_available = False : every slivers will be shown
        @return rspec RSpec document containing a list of the slivers,
            formatted in accordance to GENI schemas
        """
        logger.info("geni_available=%s", geni_available)
        logger.info("inner_call=%s", inner_call)

        sl = "http://www.geni.net/resources/rspec/3/ad.xsd"
        rspec = ROAdvertisementFormatter(schema_location=sl)

        try:
            rspec = ROUtils.generate_list_resources(rspec, \
                geni_available, self._interdomain_available_to_user, inner_call)
        except Exception as e:
            raise geni_ex.GENIv3GeneralError(str(e))

        logger.debug("ROAdvertisementFormatter=%s" % (rspec, ))
        CommonUtils.validate_rspec(rspec.get_rspec())
        return "%s" % rspec
Ejemplo n.º 2
0
    def list_resources(self, client_cert, credentials, geni_available, inner_call=False):
        """
        Shows a list with the slivers managed or seen by the resource manager.

        @param client_cert client certificate (X509)
        @param credentials client credential(s), provided by the ClearingHouse
            and generated after the certificates
        @param geni_available flag to describe which slivers are expected
            to be shown
                * geni_available = True : only available (non-allocated,
                                          non-provisioned) will be shown
                * geni_available = False : every slivers will be shown
        @return rspec RSpec document containing a list of the slivers,
            formatted in accordance to GENI schemas
        """
        logger.info("geni_available=%s", geni_available)
        logger.info("inner_call=%s", inner_call)

        sl = "http://www.geni.net/resources/rspec/3/ad.xsd"
        rspec = ROAdvertisementFormatter(schema_location=sl)

        try:
            rspec = ROUtils.generate_list_resources(rspec, \
                geni_available, self._interdomain_available_to_user, inner_call)
        except Exception as e:
            raise geni_ex.GENIv3GeneralError(str(e))

        logger.debug("ROAdvertisementFormatter=%s" % (rspec,))
        CommonUtils.validate_rspec(rspec.get_rspec())
        return "%s" % rspec
Ejemplo n.º 3
0
    def allocate(self,
                 slice_urn,
                 client_cert,
                 credentials,
                 rspec,
                 end_time=None):
        """Documentation see [geniv3rpc] GENIv3DelegateBase."""
        logger.info("slice_urn=%s, end_time=%s, rspec=%s" % (
            slice_urn,
            end_time,
            rspec,
        ))

        req_rspec = RORequestParser(from_string=rspec)
        CommonUtils.validate_rspec(req_rspec.get_rspec())

        ro_manifest, ro_slivers, ro_db_slivers = ROManifestFormatter(), [], []
        extend_groups = []

        # If MRO: run mapper path-finder to extend SDN resources
        # by adding an inherent link to the SE device
        # Note: check if we had an explicit/direct TN allocation
        # (in this case just skip the mapper)
        if self._mro_enabled:
            # No TN or SE nodes
            if CommonUtils.is_implicit_allocation(req_rspec):
                logger.info(
                    "Implicit resource allocation: without SE, without TN")
                rspec = TNUtils.add_tn_to_ro_request_rspec(
                    req_rspec, SDNUtils(), VLUtils())
                req_rspec = RORequestParser(from_string=rspec)
            if not CommonUtils.is_explicit_tn_allocation_orig(req_rspec):
                # Before starting the allocation process, we need to find a proper
                # mapping between TN and SDN resources in the islands.
                # We use the tn-links as starting point (STPs)
                logger.info(
                    "Explicit resource allocation: without SE, with TN")
                dpid_port_ids = SDNUtils().find_dpid_port_identifiers(
                    req_rspec.of_groups(), req_rspec.of_matches())
                logger.debug("DPIDs=%s" % (dpid_port_ids, ))
                #paths = TNUtils.find_interdomain_paths_from_tn_links(req_rspec.tn_links())
                paths = TNUtils.find_interdomain_paths_from_tn_links_and_dpids(
                    req_rspec.tn_links(), dpid_port_ids)

                items, se_constraints = SDNUtils().analyze_mapped_path(
                    dpid_port_ids, paths)
                extend_groups.extend(items)
            logger.warning("ReqRSpec must be extended with SDN-groups: %s" %
                           (extend_groups, ))

        # Sequence: SDN, TN, SE, COM
        ## First, the most blocking resources (inter-domain connections: TN, SE) will be requested
        ## If that succeeds, proceed to intra-domain resources (SDN, COM)

        # SDN resources
        se_sdn_info = None
        sliver = req_rspec.of_sliver()
        if sliver is not None:
            try:
                logger.debug("Found an SDN-slivers segment: %s", sliver)
                # Manage the "extend-group" info here: extend the group info
                # introducing the new dpids/ports taken from
                # the mapper (path-finder) module.
                (of_m_info, of_slivers, db_slivers, se_sdn_info) =\
                    SDNUtils().manage_allocate(
                        slice_urn, credentials, end_time, sliver, req_rspec,
                        slice_urn, extend_groups)

                logger.debug("sdn_m=%s, sdn_s=%s, db_s=%s" %
                             (of_m_info, of_slivers, db_slivers))
                for m in of_m_info:
                    for s in m.get("slivers"):
                        ro_manifest.of_sliver(s)

                ro_slivers.extend(of_slivers)
                # insert sdn-resources into slice table
                self.__insert_slice_info("sdn-resources", slice_urn,
                                         db_slivers, ro_db_slivers)

            except delegate_ex.AllocationError as e:
                self.__insert_allocated_reraise_exc("sdn-resources", e,
                                                    ro_db_slivers)

        # TN resources
        se_tn_info = None
        nodes = req_rspec.tn_nodes()
        links = req_rspec.tn_links()
        if (len(nodes) > 0) or (len(links) > 0):
            try:
                logger.debug("Found a TN-nodes segment (%d): %s" % (
                    len(nodes),
                    nodes,
                ))
                logger.debug("Found a TN-links segment (%d): %s" % (
                    len(links),
                    links,
                ))
                (tn_m_info, tn_slivers, db_slivers, se_tn_info) =\
                    TNUtils().manage_allocate(slice_urn, credentials, end_time,
                                              nodes, links)

                logger.debug("tn_m=%s, tn_s=%s, db_s=%s" %
                             (tn_m_info, tn_slivers, db_slivers))
                for m in tn_m_info:
                    for n in m.get("nodes"):
                        ro_manifest.tn_node(n)
                    for l in m.get("links"):
                        ro_manifest.tn_link(l)

                ro_slivers.extend(tn_slivers)
                # insert tn-resources into slice table
                self.__insert_slice_info("tn-resources", slice_urn, db_slivers,
                                         ro_db_slivers)

            except delegate_ex.AllocationError as e:
                self.__insert_allocated_reraise_exc("tn-resources", e,
                                                    ro_db_slivers)

        nodes = []
        links = []
        # SE resources
        se_nodes_in_request = False
        try:
            # SE resources (specifically in request)
            nodes = req_rspec.se_nodes()
            links = req_rspec.se_links()
            if ((len(nodes) > 0) or (len(links) > 0)):
                se_nodes_in_request = True
            else:
                raise Exception("No SE nodes/links available in the request")
        except Exception as e:
            m = "No SE resources in request. Switching to auto-generation."
            m += " Details: %s" % str(e)
            logger.warning(m)
            # SE resources (generated by RO from SE and TN nodes)
            if (se_sdn_info is not None) and (len(se_sdn_info) > 0) and\
               (se_tn_info is not None) and (len(se_tn_info) > 0):
                nodes = se_sdn_info
                links = se_tn_info

        # Common code to process SE nodes, either found or generated
        # [Previous comment] (?) This is an extension provided to allow MRO-RO
        # interoperability and could be very useful for test/debug, too...
        if (len(nodes) > 0) or (len(links) > 0):
            try:
                logger.debug("Found a SE-node segment (%d): %s" % (
                    len(nodes),
                    nodes,
                ))
                logger.debug("Found a SE-link segment (%d): %s" % (
                    len(links),
                    links,
                ))
                if se_nodes_in_request:
                    (se_m_info, se_slivers, db_slivers) =\
                        SEUtils().manage_direct_allocate(
                            slice_urn, credentials, end_time, nodes, links)
                else:
                    (se_m_info, se_slivers, db_slivers) =\
                        SEUtils().manage_allocate(
                            slice_urn, credentials, end_time, nodes, links)

                logger.debug("se_m=%s, se_s=%s, db_s=%s" %
                             (se_m_info, se_slivers, db_slivers))
                for m in se_m_info:
                    for n in m.get("nodes"):
                        ro_manifest.se_node(n)
                    for l in m.get("links"):
                        ro_manifest.se_link(l)

                ro_slivers.extend(se_slivers)
                # insert se-resources into slice table
                self.__insert_slice_info("se-resources", slice_urn, db_slivers,
                                         ro_db_slivers)

            except delegate_ex.AllocationError as e:
                self.__insert_allocated_reraise_exc("se-resources", e,
                                                    ro_db_slivers)

        # COM resources
        slivers = req_rspec.com_slivers()
        nodes = req_rspec.com_nodes()
        if slivers:
            try:
                logger.debug("Found a COM-slivers segment (%d): %s" % (
                    len(slivers),
                    slivers,
                ))
                (com_m_info, com_slivers, db_slivers) =\
                    COMUtils().manage_allocate(
                        slice_urn, credentials, end_time, slivers, req_rspec)

                logger.debug("com_m=%s, com_s=%s, com_s=%s" %
                             (com_m_info, com_slivers, db_slivers))
                for m in com_m_info:
                    for n in m.get("nodes"):
                        ro_manifest.com_node(n)

                ro_slivers.extend(com_slivers)
                # insert com-resources into slice table
                self.__insert_slice_info("com-resources", slice_urn,
                                         db_slivers, ro_db_slivers)

            except delegate_ex.AllocationError as e:
                self.__insert_allocated_reraise_exc("com-resources", e,
                                                    ro_db_slivers)

        logger.debug("RO-ManifestFormatter=%s" % (ro_manifest, ))
        CommonUtils.validate_rspec(ro_manifest.get_rspec())

        ro_slivers = CommonUtils.convert_sliver_dates_to_datetime(ro_slivers)

        logger.info("Allocate successfully completed: %s" % (ro_db_slivers, ))
        self.__schedule_slice_release(end_time, ro_db_slivers)
        self.__schedule_tnres_update(tn_resource_refresh, 1,
                                     "oneshot_tn_resource_refresh")
        return ("%s" % ro_manifest, ro_slivers)
Ejemplo n.º 4
0
    def allocate(self, slice_urn, client_cert, credentials,
                 rspec, end_time=None):
        """Documentation see [geniv3rpc] GENIv3DelegateBase."""
        logger.info("slice_urn=%s, end_time=%s, rspec=%s" % (
            slice_urn, end_time, rspec,))

        req_rspec = RORequestParser(from_string=rspec)
        CommonUtils.validate_rspec(req_rspec.get_rspec())

        ro_manifest, ro_slivers, ro_db_slivers = ROManifestFormatter(), [], []
        extend_groups = []

        # If MRO: run mapper path-finder to extend SDN resources
        # by adding an inherent link to the SE device
        # Note: check if we had an explicit/direct TN allocation
        # (in this case just skip the mapper)
        if self._mro_enabled:
            # No TN or SE nodes
            if CommonUtils.is_implicit_allocation(req_rspec):
                logger.info("Implicit resource allocation: without SE, without TN")
                rspec = TNUtils.add_tn_to_ro_request_rspec(req_rspec, SDNUtils(), VLUtils())
                req_rspec = RORequestParser(from_string=rspec)
            if not CommonUtils.is_explicit_tn_allocation_orig(req_rspec):
                # Before starting the allocation process, we need to find a proper
                # mapping between TN and SDN resources in the islands.
                # We use the tn-links as starting point (STPs)
                logger.info("Explicit resource allocation: without SE, with TN")
                dpid_port_ids = SDNUtils().find_dpid_port_identifiers(
                    req_rspec.of_groups(), req_rspec.of_matches())
                logger.debug("DPIDs=%s" % (dpid_port_ids,))
                #paths = TNUtils.find_interdomain_paths_from_tn_links(req_rspec.tn_links())
                paths = TNUtils.find_interdomain_paths_from_tn_links_and_dpids(req_rspec.tn_links(), dpid_port_ids)
                items, se_constraints = SDNUtils().analyze_mapped_path(dpid_port_ids, paths)
                extend_groups.extend(items)
            logger.warning("ReqRSpec must be extended with SDN-groups: %s" %
                           (extend_groups,))

        # Sequence: TN, SE, SDN, COM
        ## First, the most blocking resources (inter-domain connections: TN, SE) will be requested 
        ## If that succeeds, proceed to intra-domain resources (SDN, COM)

        # SDN resources
        se_sdn_info = None
        sliver = req_rspec.of_sliver()
        if sliver is not None:
            try:
                logger.debug("Found an SDN-slivers segment: %s", sliver)
                # Manage the "extend-group" info here: extend the group info
                # introducing the new dpids/ports taken from
                # the mapper (path-finder) module.
                (of_m_info, of_slivers, db_slivers, se_sdn_info) =\
                    SDNUtils().manage_allocate(
                        slice_urn, credentials, end_time, sliver, req_rspec,
                        slice_urn, extend_groups)

                logger.debug("sdn_m=%s, sdn_s=%s, db_s=%s" %
                             (of_m_info, of_slivers, db_slivers))
                for m in of_m_info:
                    for s in m.get("slivers"):
                        ro_manifest.of_sliver(s)

                ro_slivers.extend(of_slivers)
                # insert sdn-resources into slice table
                self.__insert_slice_info(
                    "sdn-resources", slice_urn, db_slivers, ro_db_slivers)

            except delegate_ex.AllocationError as e:
                self.__insert_allocated_reraise_exc(
                    "sdn-resources", e, ro_db_slivers)

        # TN resources
        se_tn_info = None
        nodes = req_rspec.tn_nodes()
        links = req_rspec.tn_links()
        if (len(nodes) > 0) or (len(links) > 0):
            try:
                logger.debug("Found a TN-nodes segment (%d): %s" %
                             (len(nodes), nodes,))
                logger.debug("Found a TN-links segment (%d): %s" %
                             (len(links), links,))
                (tn_m_info, tn_slivers, db_slivers, se_tn_info) =\
                    TNUtils().manage_allocate(slice_urn, credentials, end_time,
                                              nodes, links)

                logger.debug("tn_m=%s, tn_s=%s, db_s=%s" %
                             (tn_m_info, tn_slivers, db_slivers))
                for m in tn_m_info:
                    for n in m.get("nodes"):
                        ro_manifest.tn_node(n)
                    for l in m.get("links"):
                        ro_manifest.tn_link(l)

                ro_slivers.extend(tn_slivers)
                # insert tn-resources into slice table
                self.__insert_slice_info(
                    "tn-resources", slice_urn, db_slivers, ro_db_slivers)

            except delegate_ex.AllocationError as e:
                self.__insert_allocated_reraise_exc(
                    "tn-resources", e, ro_db_slivers)

        nodes = []
        links = []
        # SE resources
        se_nodes_in_request = False
        try:
            # SE resources (specifically in request)
            nodes = req_rspec.se_nodes()
            links = req_rspec.se_links()
            if ((len(nodes) > 0) or (len(links) > 0)):
                se_nodes_in_request = True
            else:
                raise Exception("No SE nodes/links available in the request")
        except Exception as e:
            m = "No SE resources in request. Switching to auto-generation."
            m += " Details: %s" % str(e)
            logger.warning(m)
            # SE resources (generated by RO from SE and TN nodes)
            if (se_sdn_info is not None) and (len(se_sdn_info) > 0) and\
               (se_tn_info is not None) and (len(se_tn_info) > 0):
                nodes = se_sdn_info
                links = se_tn_info

        # Common code to process SE nodes, either found or generated
        # [Previous comment] (?) This is an extension provided to allow MRO-RO
        # interoperability and could be very useful for test/debug, too...
        if (len(nodes) > 0) or (len(links) > 0):
            try:
                logger.debug("Found a SE-node segment (%d): %s" %
                             (len(nodes), nodes,))
                logger.debug("Found a SE-link segment (%d): %s" %
                             (len(links), links,))
                if se_nodes_in_request:
                    (se_m_info, se_slivers, db_slivers) =\
                        SEUtils().manage_direct_allocate(
                            slice_urn, credentials, end_time, nodes, links)
                else:
                    (se_m_info, se_slivers, db_slivers) =\
                        SEUtils().manage_allocate(
                            slice_urn, credentials, end_time, nodes, links)

                logger.debug("se_m=%s, se_s=%s, db_s=%s" %
                             (se_m_info, se_slivers, db_slivers))
                for m in se_m_info:
                    for n in m.get("nodes"):
                        ro_manifest.se_node(n)
                    for l in m.get("links"):
                        ro_manifest.se_link(l)

                ro_slivers.extend(se_slivers)
                # insert se-resources into slice table
                self.__insert_slice_info(
                    "se-resources", slice_urn, db_slivers, ro_db_slivers)

            except delegate_ex.AllocationError as e:
                self.__insert_allocated_reraise_exc(
                    "se-resources", e, ro_db_slivers)

        # COM resources
        slivers = req_rspec.com_slivers()
        nodes = req_rspec.com_nodes()
        if slivers:
            try:
                logger.debug("Found a COM-slivers segment (%d): %s" %
                             (len(slivers), slivers,))
                (com_m_info, com_slivers, db_slivers) =\
                    COMUtils().manage_allocate(
                        slice_urn, credentials, end_time, slivers, req_rspec)

                logger.debug("com_m=%s, com_s=%s, com_s=%s" %
                             (com_m_info, com_slivers, db_slivers))
                for m in com_m_info:
                    for n in m.get("nodes"):
                        ro_manifest.com_node(n)

                ro_slivers.extend(com_slivers)
                # insert com-resources into slice table
                self.__insert_slice_info(
                    "com-resources", slice_urn, db_slivers, ro_db_slivers)

            except delegate_ex.AllocationError as e:
                self.__insert_allocated_reraise_exc(
                    "com-resources", e, ro_db_slivers)

        logger.debug("RO-ManifestFormatter=%s" % (ro_manifest,))
        CommonUtils.validate_rspec(ro_manifest.get_rspec())

        ro_slivers = CommonUtils.convert_sliver_dates_to_datetime(ro_slivers)

        logger.info("Allocate successfully completed: %s" % (ro_db_slivers,))
        self.__schedule_slice_release(end_time, ro_db_slivers)
        return ("%s" % ro_manifest, ro_slivers)