Example #1
0
    def allocate(self,
                 slice_urn,
                 client_cert,
                 credentials,
                 rspec,
                 end_time=None):
        """Documentation see [geniv3rpc] GENIv3DelegateBase."""
        # logger.info("slice_urn=%s" % (slice_urn))
        # logger.info("client_cert=%s" % (client_cert))
        # logger.info("credentials=%s" % (credentials))
        # logger.info("request rspec=%s" % (rspec))
        # logger.info("end_time=%s" % (end_time))
        self.restart_from_db()
        logger.info(">>>>> allocate <<<<< urn=%s" % slice_urn)

        # start_time = datetime.now()
        start_time = get_time_now()
        start_time += timedelta(minutes=2)
        if (isinstance(end_time, type(None)) == True):
            end_time = start_time + timedelta(minutes=10)
            end_time = start_time + timedelta(hours=3)
        else:
            delta = end_time - start_time
            logger.debug("delta days=%s, seconds=%s" %
                         (delta.days, delta.seconds))
            if (delta.days * 24 * 3600 + delta.seconds < 60):
                end_time = start_time + timedelta(seconds=60)
                logger.debug("re-set end_time=%s" % (end_time))

        if slice_urn in dict_slice_urn:
            req = dict_slice_urn[slice_urn]
            for urn in req.urns:
                resv = req.get_reservation(urn)
                logger.info(
                    "delete service=%s: urn=%s, reservation=%s, status=%s" %
                    (resv.service, urn, resv, resv.astatus))
            raise geni_ex.GENIv3GeneralError("slice_urn(%s) is already exit." %
                                             (slice_urn))

        logger.info("allocate: add dict_slice_urn[%s]." % slice_urn)

        start_time_sec = unix_time_sec(start_time)
        end_time_sec = unix_time_sec(end_time)

        req = Request(slice_urn, rspec, start_time, end_time)
        req, error = req.parse_reservations()
        if error is not None:
            raise geni_ex.GENIv3GeneralError(error)

        logger.info("slice=%s, urns=%s" % (slice_urn, str(req.urns)))
        dict_slice_urn[slice_urn] = req

        isError = False
        manifest_body = ""
        for urn in req.urns:
            logger.info("allocate:loop: urn=%s" % urn)
            resv = req.get_reservation(urn)
            resv.ostatus = self.OPERATIONAL_STATE_NOTREADY
            resv.astatus = self.ALLOCATION_STATE_UNALLOCATED
            resv.action = self.OPERATIONAL_ACTION_STOP

            if resv.error is not None:
                isError = True
            manifest_body += resv.get_manifest()

        slice_status = req.get_status()
        req.set_manifest(manifest_body)
        manifest = req.get_manifest()
        # logger.info("manifest=%s" % manifest)

        if isError:
            self.__slice_delete_status(req, get_time_now())
            return (manifest, slice_status)

        for urn in req.urns:
            resv = req.get_reservation(urn)
            logger.info("call reserve %s" % (resv))

            #
            # VLAN range check in Reservation
            #

            try:
                if resv.service == "NSI":
                    rid = nsi_proxy.reserve(
                        resv.gid,
                        resv.path.sep.stp,
                        resv.path.dep.stp,
                        # int(resv.path.sep.vlantag),
                        int(resv.src_vlan),
                        # int(resv.path.dep.vlantag),
                        int(resv.dst_vlan),
                        int(resv.path.sd_bw),
                        unix_time_sec(start_time),
                        unix_time_sec(end_time))

                elif resv.service == "GRE":
                    rid = gre_proxy.reserve(resv)

                else:
                    emes = "Unknown service=%s: urn=%s, reservation=%s" % (
                        resv.service, slice_urn, resv)
                    logger.error(emes)
                    raise ManagerException("tn_rm_delegate:allocate", emes)

                logger.info("urns=%s, rid=%s" % (slice_urn, rid))

                resv.resv_id = rid
                resv.astatus = self.ALLOCATION_STATE_ALLOCATED
                resv.ostatus = self.OPERATIONAL_STATE_READY
                resv.action = self.OPERATIONAL_ACTION_STOP

            except Exception as e:
                logger.error("ex=%s" % (e))
                resv.error = "%s" % (e)
                #resv.src_if.vman.putVlanYellow(resv.path.sep.vlantag)
                #resv.dst_if.vman.putVlanYellow(resv.path.dep.vlantag)
                resv.src_if.vman.putVlanYellow(resv.src_vlan)
                resv.dst_if.vman.putVlanYellow(resv.dst_vlan)
                isError = True

        slice_status = req.get_status()
        manifest = req.get_manifest()

        if isError:
            self.__slice_delete_status(req, get_time_now())
        else:
            for urn in req.urns:
                resv = req.get_reservation(urn)
                self.db.insert(resv)

        return (manifest, slice_status)
Example #2
0
    def allocate(self, slice_urn, client_cert, credentials, rspec,
                 end_time=None):
        """Documentation see [geniv3rpc] GENIv3DelegateBase."""
        # logger.info("slice_urn=%s" % (slice_urn))
        # logger.info("client_cert=%s" % (client_cert))
        # logger.info("credentials=%s" % (credentials))
        # logger.info("request rspec=%s" % (rspec))
        # logger.info("end_time=%s" % (end_time))
        self.restart_from_db()
        logger.info(">>>>> allocate <<<<< urn=%s" % slice_urn)

        # start_time = datetime.now()
        start_time = get_time_now()
        start_time += timedelta(minutes=2)
        if (isinstance(end_time, type(None)) == True):
            end_time = start_time + timedelta(minutes=10)
            end_time = start_time + timedelta(hours=3)
        else:
            delta = end_time - start_time
            logger.debug("delta days=%s, seconds=%s" % (delta.days, delta.seconds))
            if (delta.days * 24 * 3600 + delta.seconds < 60):
                end_time = start_time + timedelta(seconds=60)
                logger.debug("re-set end_time=%s" % (end_time))
                
        if slice_urn in dict_slice_urn:
            req = dict_slice_urn[slice_urn]
            for urn in req.urns:
                resv = req.get_reservation(urn)
                logger.info("exist service=%s: urn=%s, reservation=%s, status=%s" % 
                            (resv.service, urn, resv, resv.astatus))
            raise geni_ex.GENIv3GeneralError("slice_urn(%s) is already exit." % (slice_urn))

        logger.info("allocate: add dict_slice_urn[%s]." % slice_urn)

        start_time_sec = unix_time_sec(start_time)
        end_time_sec = unix_time_sec(end_time)

        req = Request(slice_urn, rspec, start_time, end_time)
        req, error = req.parse_reservations()
        if error is not None:
            raise geni_ex.GENIv3GeneralError(error)

        logger.info("slice=%s, urns=%s" % (slice_urn, str(req.urns)))
        dict_slice_urn[slice_urn] = req

        isError = False
        manifest_body = ""
        for urn in req.urns:
            logger.info("allocate:loop: urn=%s" % urn)
            resv = req.get_reservation(urn)
            resv.ostatus = self.OPERATIONAL_STATE_NOTREADY
            resv.astatus = self.ALLOCATION_STATE_UNALLOCATED
            resv.action = self.OPERATIONAL_ACTION_STOP

            if resv.error is not None:
                isError = True
            manifest_body += resv.get_manifest()

        slice_status = req.get_status()
        req.set_manifest(manifest_body)
        manifest = req.get_manifest()
        # logger.info("manifest=%s" % manifest)

        if isError:
            self.__slice_delete_status(req, get_time_now())
            return (manifest, slice_status)


        for urn in req.urns:
            resv = req.get_reservation(urn)
            logger.info("call reserve %s" % (resv))

            #
            # VLAN range check in Reservation
            #

            try:
                if resv.service == "NSI":
                    rid = nsi_proxy.reserve(resv.gid,
                                            resv.path.sep.stp, 
                                            resv.path.dep.stp,
                                            # int(resv.path.sep.vlantag), 
                                            int(resv.src_vlan), 
                                            # int(resv.path.dep.vlantag), 
                                            int(resv.dst_vlan), 
                                            int(resv.path.sd_bw), 
                                            unix_time_sec(start_time), 
                                            unix_time_sec(end_time))

                elif resv.service == "GRE":
                    rid = gre_proxy.reserve(resv)

                else:
                    emes = "Unknown service=%s: urn=%s, reservation=%s" % (resv.service, slice_urn, resv)
                    logger.error(emes)
                    raise ManagerException("tn_rm_delegate:allocate", emes);
                    
                logger.info("urns=%s, rid=%s" % (slice_urn, rid))

                resv.resv_id = rid
                resv.astatus = self.ALLOCATION_STATE_ALLOCATED
                resv.ostatus = self.OPERATIONAL_STATE_READY
                resv.action = self.OPERATIONAL_ACTION_STOP

            except Exception as e:
                logger.error("ex=%s" % (e))
                resv.error = "%s" % (e)
                #resv.src_if.vman.putVlanYellow(resv.path.sep.vlantag)
                #resv.dst_if.vman.putVlanYellow(resv.path.dep.vlantag)
                resv.src_if.vman.putVlanYellow(resv.src_vlan)
                resv.dst_if.vman.putVlanYellow(resv.dst_vlan)
                isError = True
                    
        slice_status = req.get_status()
        manifest = req.get_manifest()

        if isError:
            self.__slice_delete_status(req, get_time_now())
        else:
            for urn in req.urns:
                resv = req.get_reservation(urn)
                self.db.insert(resv)

        return (manifest, slice_status)
Example #3
0
    def re_allocate(self, slice_urn, urn, rspec, start_time, end_time, rid,
                    tvlan, s_opration, s_allocation, s_error, s_action):
        logger.info(">>>>> re_allocate <<<<< urn=%s" % slice_urn)

        delta = end_time - start_time
        start_time_sec = unix_time_sec(start_time)
        end_time_sec = unix_time_sec(end_time)

        req = Request(slice_urn, rspec, start_time, end_time)
        req, error = req.parse_reservations()
        if error is not None:
            if urn in req.dict_reservations:
                resv = req.dict_reservations[urn]
                resv.error = "restart error: ex=%s" % error

        logger.info("slice=%s, urns=%s" % (slice_urn, str(req.urns)))

        if slice_urn in dict_slice_urn:
            req_old = dict_slice_urn[slice_urn]
            req_old.merge(req, urn)
        else:
            logger.info("allocate: add dict_slice_urn[%s]." % slice_urn)
            dict_slice_urn[slice_urn] = req

        isError = False
        manifest_body = ""

        n_urns = len(req.urns)
        if n_urns != 1:
            logger.error("restart: len(new request) is not 1. size=%d" %
                         n_urns)

        for new_urn in req.urns:
            resv = req.get_reservation(new_urn)
            break

        resv.ostatus = self.OPERATIONAL_STATE_NOTREADY
        resv.astatus = self.ALLOCATION_STATE_UNALLOCATED
        resv.action = self.OPERATIONAL_ACTION_STOP

        logger.info("call reserve %s" % (resv))
        new_resv_id = ""

        try:
            if resv.service == "NSI":
                resv.resv_id = rid
            elif resv.service == "GRE":
                resv.trans_vlan = tvlan
                new_resv_id = gre_proxy.reserve(resv)
                resv.resv_id = new_resv_id

            logger.info("slice=%s, rid=%s, resv_id=%s, new_resv_id=%s" %
                        (slice_urn, rid, resv.resv_id, new_resv_id))

            resv.astatus = s_allocation
            resv.ostatus = s_opration
            resv.action = s_action

            if resv.service == "GRE":
                # gre_proxy.swap_id(new_resv_id, rid)
                if resv.action == self.OPERATIONAL_ACTION_START:
                    gre_proxy.re_provision(resv)

        except Exception as e:
            logger.error("error=%s, ex=%s" % (resv.error, e))
            if resv.error is None:
                if s_error == "None":
                    resv.error = "ex=%s" % e
                else:
                    resv.error = "%s: ex=%s" % (s_error, e)
            else:
                resv.error += (": %s: ex=%s" % (s_error, e))

            logger.info("vlan: src=%s, dst=%s" %
                        (resv.src_vlan, resv.dst_vlan))
            resv.src_if.vman.putVlanYellow(int(resv.src_vlan))
            resv.dst_if.vman.putVlanYellow(int(resv.dst_vlan))

        return
Example #4
0
    def re_allocate(self, slice_urn, urn, rspec, start_time, end_time, rid, 
                    tvlan, s_opration, s_allocation, s_error, s_action):
        logger.info(">>>>> re_allocate <<<<< urn=%s" % slice_urn)

        delta = end_time - start_time
        start_time_sec = unix_time_sec(start_time)
        end_time_sec = unix_time_sec(end_time)

        req = Request(slice_urn, rspec, start_time, end_time)
        req, error = req.parse_reservations()
        if error is not None:
            if urn in req.dict_reservations:
                resv = req.dict_reservations[urn]
                resv.error = "restart error: ex=%s" % error

        logger.info("slice=%s, urns=%s" % (slice_urn, str(req.urns)))

        if slice_urn in dict_slice_urn:
            req_old = dict_slice_urn[slice_urn]
            req_old.merge(req, urn)
        else:
            logger.info("allocate: add dict_slice_urn[%s]." % slice_urn)
            dict_slice_urn[slice_urn] = req

        isError = False
        manifest_body = ""

        n_urns = len(req.urns)
        if n_urns != 1:
            logger.error("restart: len(new request) is not 1. size=%d" % n_urns)

        for new_urn in req.urns:
            resv = req.get_reservation(new_urn)
            break

        resv.ostatus = self.OPERATIONAL_STATE_NOTREADY
        resv.astatus = self.ALLOCATION_STATE_UNALLOCATED
        resv.action = self.OPERATIONAL_ACTION_STOP

        logger.info("call reserve %s" % (resv))
        new_resv_id = ""

        try:
            if resv.service == "NSI":
                resv.resv_id = rid
            elif resv.service == "GRE":
                resv.trans_vlan = tvlan
                new_resv_id = gre_proxy.reserve(resv)
                resv.resv_id = new_resv_id

            logger.info("slice=%s, rid=%s, resv_id=%s, new_resv_id=%s" % 
                        (slice_urn, rid, resv.resv_id, new_resv_id))

            resv.astatus = s_allocation
            resv.ostatus = s_opration
            resv.action = s_action

            if resv.service == "GRE":
                # gre_proxy.swap_id(new_resv_id, rid)
                if resv.action == self.OPERATIONAL_ACTION_START:
                    gre_proxy.re_provision(resv)

        except Exception as e:
            logger.error("error=%s, ex=%s" % (resv.error, e))
            if resv.error is None:
                if s_error == "None":
                    resv.error = "ex=%s" % e
                else:
                    resv.error = "%s: ex=%s" % (s_error, e)
            else:
                resv.error += (": %s: ex=%s" %(s_error, e))

            logger.info("vlan: src=%s, dst=%s" % (resv.src_vlan, resv.dst_vlan))
            resv.src_if.vman.putVlanYellow(int(resv.src_vlan))
            resv.dst_if.vman.putVlanYellow(int(resv.dst_vlan))

        return