Esempio n. 1
0
    def provision(self, urns, client_cert, credentials, best_effort, end_time,
                  geni_users):
        """Documentation see [geniv3rpc] GENIv3DelegateBase.
        {geni_users} is relevant here."""
        ro_manifest, ro_slivers = ROManifestFormatter(), []
        client_urn = CommonUtils.fetch_user_name_from_geni_users(geni_users)

        slice_urn = db_sync_manager.get_slice_urn(urns)
        slice_monitor = None
        try:
            slice_monitor = SliceMonitoring()
            slice_monitor.add_topology(slice_urn, SliceMonitoring.PROVISIONED,
                                       client_urn)
        except Exception as e:
            logger.warning(
                "Delegate could not send Provision trigger" +
                " to MS. Details: %s", (e, ))

        route = db_sync_manager.get_slice_routing_keys(urns)
        logger.debug("Route=%s" % (route, ))

        for r, v in route.iteritems():
            peer = db_sync_manager.get_configured_peer_by_routing_key(r)
            logger.debug("peer=%s" % (peer, ))
            if peer.get("type") == self._allowed_peers.get("PEER_CRM"):
                com_m_info, com_slivers = COMUtils().manage_provision(
                    peer, v, credentials, best_effort, end_time, geni_users)

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

                ro_slivers.extend(com_slivers)
                # introduce slice-monitoring info for C resources
                try:
                    slice_monitor.add_c_resources(slice_urn,
                                                  com_m_info.get("nodes"))
                except Exception as e:
                    logger.warning(
                        "Delegate could not monitor COM resources" +
                        " upon Provision. Details: %s", (e, ))

            elif peer.get("type") == self._allowed_peers.get("PEER_SDNRM"):
                of_m_info, of_slivers = SDNUtils().manage_provision(
                    peer, v, credentials, best_effort, end_time, geni_users)

                logger.debug("of_m=%s, of_s=%s" % (
                    of_m_info,
                    of_slivers,
                ))
                for s in of_m_info.get("slivers"):
                    ro_manifest.of_sliver(s)

                ro_slivers.extend(of_slivers)
                # introduce slice-monitoring info for SDN resources
                try:
                    slice_monitor.add_sdn_resources(slice_urn,
                                                    of_m_info.get("slivers"))
                except Exception as e:
                    logger.warning(
                        "Delegate could not monitor SDN resources" +
                        " upon Provision. Details: %s", (e, ))

            elif peer.get("type") == self._allowed_peers.get("PEER_TNRM"):
                tn_m_info, tn_slivers = TNUtils().manage_provision(
                    peer, v, credentials, best_effort, end_time, geni_users)

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

                ro_slivers.extend(tn_slivers)
                # introduce slice-monitoring info for TN resources
                try:
                    slice_monitor.add_tn_resources(slice_urn,
                                                   tn_m_info.get("nodes"),
                                                   tn_m_info.get("links"),
                                                   peer)
                except Exception as e:
                    logger.warning(
                        "Delegate could not monitor TN resources" +
                        " upon Provision. Details: %s", (e, ))

            elif peer.get("type") == self._allowed_peers.get("PEER_SERM"):
                se_m_info, se_slivers = SEUtils().manage_provision(
                    peer, v, credentials, best_effort, end_time, geni_users)

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

                ro_slivers.extend(se_slivers)
                # introduce slice-monitoring info for SE resources
                try:
                    slice_monitor.add_se_resources(slice_urn,
                                                   se_m_info.get("nodes"),
                                                   se_m_info.get("links"))
                except Exception as e:
                    logger.warning(
                        "Delegate could not monitor SE resources" +
                        " upon Provision. Details: %s", (e, ))

            elif peer.get("type") == self._allowed_peers.get("PEER_RO"):
                ro_m_info, ro_slivers_ro = ROUtils().manage_provision(
                    peer, v, credentials, best_effort, end_time, geni_users)

                logger.debug("ro_m=%s, ro_s=%s" % (
                    ro_m_info,
                    ro_slivers,
                ))
                ro_manifest = ROUtils.generate_describe_manifest(
                    ro_manifest, ro_m_info)

                ro_slivers.extend(ro_slivers_ro)
                # introduce slice-monitoring info for ALL the resource types!
                try:
                    slice_monitor.add_c_resources(slice_urn,
                                                  ro_m_info.get("com_nodes"))
                    slice_monitor.add_sdn_resources(
                        slice_urn, ro_m_info.get("sdn_slivers"))
                    slice_monitor.add_tn_resources(slice_urn,
                                                   ro_m_info.get("tn_nodes"),
                                                   ro_m_info.get("tn_links"),
                                                   peer)
                    slice_monitor.add_se_resources(slice_urn,
                                                   ro_m_info.get("se_nodes"),
                                                   ro_m_info.get("se_links"))
                except Exception as e:
                    logger.warning(
                        "Delegate could not monitor RO resources" +
                        " upon Provision. Details: %s", (e, ))

        # send slice-monitoring info to the monitoring system
        try:
            # Before sending the slice info, we need to add some "virtual"
            # links (island-to-island)!
            slice_monitor.add_island_to_island_links(slice_urn)
            slice_monitor.send()
            # add slice_monitoring object to the slice table
            db_sync_manager.store_slice_monitoring_info(
                slice_urn, slice_monitor.serialize())
        except Exception as e:
            logger.warning(
                "Delegate could not send (store) slice monitoring" +
                " information upon Provision. Details: %s", (e, ))

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

        # In order to prevent data conversion error, we manipulate the
        # geni-expires parameter. At least 1 parameter should be not null!
        valid_geni_expires = None
        for s in ro_slivers:
            if s["geni_expires"] is not None:
                valid_geni_expires = s["geni_expires"]
                break
        ro_slivers = CommonUtils.convert_sliver_dates_to_datetime(
            ro_slivers, valid_geni_expires)
        return ("%s" % ro_manifest, ro_slivers)
Esempio n. 2
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)
Esempio n. 3
0
    def describe(self, urns, client_cert, credentials):
        """Documentation see [geniv3rpc] GENIv3DelegateBase."""

        ro_manifest, ro_slivers, last_slice = ROManifestFormatter(), [], ""

        route = db_sync_manager.get_slice_routing_keys(urns)
        logger.debug("Route=%s" % (route, ))

        for r, v in route.iteritems():
            peer = db_sync_manager.get_configured_peer_by_routing_key(r)
            logger.debug("peer=%s" % (peer, ))
            if peer.get("type") == self._allowed_peers.get("PEER_SDNRM"):
                of_m_info, last_slice, of_slivers =\
                    SDNUtils().manage_describe(peer, v, credentials)

                logger.debug("of_m=%s, of_s=%s, urn=%s" %
                             (of_m_info, of_slivers, last_slice))
                for s in of_m_info.get("slivers"):
                    ro_manifest.of_sliver(s)

                ro_slivers.extend(of_slivers)

            elif peer.get("type") == self._allowed_peers.get("PEER_TNRM"):
                tn_m_info, last_slice, tn_slivers =\
                    TNUtils().manage_describe(peer, v, credentials)

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

                ro_slivers.extend(tn_slivers)

            elif peer.get("type") == self._allowed_peers.get("PEER_SERM"):
                se_m_info, last_slice, se_slivers =\
                    SEUtils().manage_describe(peer, v, credentials)

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

                ro_slivers.extend(se_slivers)

            elif peer.get("type") == self._allowed_peers.get("PEER_CRM"):
                com_m_info, last_slice, com_slivers =\
                    COMUtils().manage_describe(peer, v, credentials)

                logger.debug("com_m=%s, com_s=%s, urn=%s" %
                             (com_m_info, com_slivers, last_slice))
                for n in com_m_info.get("nodes"):
                    ro_manifest.com_node(n)
                ro_slivers.extend(com_slivers)

            elif peer.get("type") == self._allowed_peers.get("PEER_RO"):
                ro_m_info, last_slice, ro_slivers_ro =\
                    ROUtils().manage_describe(peer, v, credentials)

                logger.debug("ro_m=%s, ro_s=%s, urn=%s" %
                             (ro_m_info, ro_slivers, last_slice))
                ro_manifest = ROUtils.generate_describe_manifest(
                    ro_manifest, ro_m_info)
                ro_slivers.extend(ro_slivers_ro)

        logger.debug("RO-ManifestFormatter=%s" % (ro_manifest, ))
        logger.debug("RO-Slivers(%d)=%s" % (
            len(ro_slivers),
            ro_slivers,
        ))
        ro_slivers = CommonUtils.convert_sliver_dates_to_datetime(ro_slivers)

        return {
            "geni_rspec": "%s" % ro_manifest,
            "geni_urn": last_slice,
            "geni_slivers": ro_slivers
        }
Esempio n. 4
0
    def provision(self, urns, client_cert, credentials, best_effort, end_time,
                  geni_users):
        """Documentation see [geniv3rpc] GENIv3DelegateBase.
        {geni_users} is relevant here."""
        ro_manifest, ro_slivers = ROManifestFormatter(), []
        client_urn = CommonUtils.fetch_user_name_from_geni_users(geni_users)

        slice_urn = db_sync_manager.get_slice_urn(urns)
        slice_monitor = None
        try:
            slice_monitor = SliceMonitoring()
            slice_monitor.add_topology(slice_urn, SliceMonitoring.PROVISIONED,
                                       client_urn)
        except Exception as e:
            logger.warning("Delegate could not send Provision trigger" +
                           " to MS. Details: %s", (e,))

        route = db_sync_manager.get_slice_routing_keys(urns)
        logger.debug("Route=%s" % (route,))

        for r, v in route.iteritems():
            peer = db_sync_manager.get_configured_peer_by_routing_key(r)
            logger.debug("peer=%s" % (peer,))
            if peer.get("type") == self._allowed_peers.get("PEER_CRM"):
                com_m_info, com_slivers = COMUtils().manage_provision(
                    peer, v, credentials, best_effort, end_time, geni_users)

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

                ro_slivers.extend(com_slivers)
                # introduce slice-monitoring info for C resources
                try:
                    slice_monitor.add_c_resources(
                        slice_urn, com_m_info.get("nodes"))
                except Exception as e:
                    logger.warning("Delegate could not monitor COM resources" +
                                   " upon Provision. Details: %s", (e,))

            elif peer.get("type") == self._allowed_peers.get("PEER_SDNRM"):
                of_m_info, of_slivers = SDNUtils().manage_provision(
                    peer, v, credentials, best_effort, end_time, geni_users)

                logger.debug("of_m=%s, of_s=%s" % (of_m_info, of_slivers,))
                for s in of_m_info.get("slivers"):
                    ro_manifest.of_sliver(s)

                ro_slivers.extend(of_slivers)
                # introduce slice-monitoring info for SDN resources
                try:
                    slice_monitor.add_sdn_resources(
                        slice_urn, of_m_info.get("slivers"))
                except Exception as e:
                    logger.warning("Delegate could not monitor SDN resources" +
                                   " upon Provision. Details: %s", (e,))

            elif peer.get("type") == self._allowed_peers.get("PEER_TNRM"):
                tn_m_info, tn_slivers = TNUtils().manage_provision(
                    peer, v, credentials, best_effort, end_time, geni_users)

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

                ro_slivers.extend(tn_slivers)
                # introduce slice-monitoring info for TN resources
                try:
                    slice_monitor.add_tn_resources(
                        slice_urn, tn_m_info.get("nodes"),
                        tn_m_info.get("links"), peer)
                except Exception as e:
                    logger.warning("Delegate could not monitor TN resources" +
                                   " upon Provision. Details: %s", (e,))

            elif peer.get("type") == self._allowed_peers.get("PEER_SERM"):
                se_m_info, se_slivers = SEUtils().manage_provision(
                    peer, v, credentials, best_effort, end_time, geni_users)

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

                ro_slivers.extend(se_slivers)
                # introduce slice-monitoring info for SE resources
                try:
                    slice_monitor.add_se_resources(
                        slice_urn, se_m_info.get("nodes"),
                        se_m_info.get("links"))
                except Exception as e:
                    logger.warning("Delegate could not monitor SE resources" +
                                   " upon Provision. Details: %s", (e,))

            elif peer.get("type") == self._allowed_peers.get("PEER_RO"):
                ro_m_info, ro_slivers_ro = ROUtils().manage_provision(
                    peer, v, credentials, best_effort, end_time, geni_users)

                logger.debug("ro_m=%s, ro_s=%s" % (ro_m_info, ro_slivers,))
                ro_manifest = ROUtils.generate_describe_manifest(
                    ro_manifest, ro_m_info)

                ro_slivers.extend(ro_slivers_ro)
                # introduce slice-monitoring info for ALL the resource types!
                try:
                    slice_monitor.add_c_resources(
                        slice_urn, ro_m_info.get("com_nodes"))
                    slice_monitor.add_sdn_resources(
                        slice_urn, ro_m_info.get("sdn_slivers"))
                    slice_monitor.add_tn_resources(
                        slice_urn, ro_m_info.get("tn_nodes"),
                        ro_m_info.get("tn_links"), peer)
                    slice_monitor.add_se_resources(
                        slice_urn, ro_m_info.get("se_nodes"),
                        ro_m_info.get("se_links"))
                except Exception as e:
                    logger.warning("Delegate could not monitor RO resources" +
                                   " upon Provision. Details: %s", (e,))

        # send slice-monitoring info to the monitoring system
        try:
            # Before sending the slice info, we need to add some "virtual"
            # links (island-to-island)!
            slice_monitor.add_island_to_island_links(slice_urn)
            slice_monitor.send()
            # add slice_monitoring object to the slice table
            db_sync_manager.store_slice_monitoring_info(
                slice_urn, slice_monitor.serialize())
        except Exception as e:
            logger.warning("Delegate could not send (store) slice monitoring" +
                           " information upon Provision. Details: %s", (e,))

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

        # In order to prevent data conversion error, we manipulate the
        # geni-expires parameter. At least 1 parameter should be not null!
        valid_geni_expires = None
        for s in ro_slivers:
            if s["geni_expires"] is not None:
                valid_geni_expires = s["geni_expires"]
                break
        ro_slivers = CommonUtils.convert_sliver_dates_to_datetime(
            ro_slivers, valid_geni_expires)
        return ("%s" % ro_manifest, ro_slivers)
Esempio n. 5
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)
Esempio n. 6
0
    def describe(self, urns, client_cert, credentials):
        """Documentation see [geniv3rpc] GENIv3DelegateBase."""

        ro_manifest, ro_slivers, last_slice = ROManifestFormatter(), [], ""

        route = db_sync_manager.get_slice_routing_keys(urns)
        logger.debug("Route=%s" % (route,))

        for r, v in route.iteritems():
            peer = db_sync_manager.get_configured_peer_by_routing_key(r)
            logger.debug("peer=%s" % (peer,))
            if peer.get("type") == self._allowed_peers.get("PEER_SDNRM"):
                of_m_info, last_slice, of_slivers =\
                    SDNUtils().manage_describe(peer, v, credentials)

                logger.debug("of_m=%s, of_s=%s, urn=%s" %
                             (of_m_info, of_slivers, last_slice))
                for s in of_m_info.get("slivers"):
                    ro_manifest.of_sliver(s)

                ro_slivers.extend(of_slivers)

            elif peer.get("type") == self._allowed_peers.get("PEER_TNRM"):
                tn_m_info, last_slice, tn_slivers =\
                    TNUtils().manage_describe(peer, v, credentials)

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

                ro_slivers.extend(tn_slivers)

            elif peer.get("type") == self._allowed_peers.get("PEER_SERM"):
                se_m_info, last_slice, se_slivers =\
                    SEUtils().manage_describe(peer, v, credentials)

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

                ro_slivers.extend(se_slivers)

            elif peer.get("type") == self._allowed_peers.get("PEER_CRM"):
                com_m_info, last_slice, com_slivers =\
                    COMUtils().manage_describe(peer, v, credentials)

                logger.debug("com_m=%s, com_s=%s, urn=%s" %
                             (com_m_info, com_slivers, last_slice))
                for n in com_m_info.get("nodes"):
                    ro_manifest.com_node(n)
                ro_slivers.extend(com_slivers)

            elif peer.get("type") == self._allowed_peers.get("PEER_RO"):
                ro_m_info, last_slice, ro_slivers_ro =\
                    ROUtils().manage_describe(peer, v, credentials)

                logger.debug("ro_m=%s, ro_s=%s, urn=%s" %
                             (ro_m_info, ro_slivers, last_slice))
                ro_manifest = ROUtils.generate_describe_manifest(
                    ro_manifest, ro_m_info)
                ro_slivers.extend(ro_slivers_ro)

        logger.debug("RO-ManifestFormatter=%s" % (ro_manifest,))
        logger.debug("RO-Slivers(%d)=%s" % (len(ro_slivers), ro_slivers,))
        ro_slivers = CommonUtils.convert_sliver_dates_to_datetime(ro_slivers)

        return {"geni_rspec": "%s" % ro_manifest,
                "geni_urn": last_slice,
                "geni_slivers": ro_slivers}