示例#1
0
    def __load_slices(self):
        """Load Slices."""

        slices = Session().query(TblSlice).all()

        for slc in slices:

            tenant = RUNTIME.tenants[slc.tenant_id]

            desc = {
                'dscp': slc.dscp,
                'wtps': {},
                'vbses': {},
                'wifi': json.loads(slc.wifi),
                'lte': json.loads(slc.lte)
            }

            if slc.dscp not in tenant.slices:
                tenant.slices[slc.dscp] = Slice(slc.dscp, tenant, desc)

            t_slice = tenant.slices[slc.dscp]

            belongs = \
                Session().query(TblSliceBelongs) \
                         .filter(TblSliceBelongs.dscp == slc.dscp) \
                         .filter(TblSliceBelongs.tenant_id == slc.tenant_id) \
                         .all()

            for belong in belongs:

                if belong.addr not in self.pnfdevs:
                    continue

                pnfdev = self.pnfdevs[belong.addr]
                pnfdevs = None

                if pnfdev.ALIAS == "vbses":
                    pnfdevs = t_slice.lte[pnfdev.ALIAS]

                    if pnfdev.addr not in pnfdevs:
                        pnfdevs[belong.addr] = {
                            'static-properties': {},
                            'cells': {}
                        }

                else:
                    pnfdevs = t_slice.wifi[pnfdev.ALIAS]

                    if pnfdev.addr not in pnfdevs:
                        pnfdevs[belong.addr] = {
                            'static-properties': {},
                            'blocks': {}
                        }

                pnfdevs[belong.addr]['static-properties'] = \
                        json.loads(belong.properties)
示例#2
0
    def set_slice(self, dscp, request):
        """Update a slice in the Tenant.

        Args:
            dscp, a DSCP object
            request, the slice descriptor in json format

        Returns:
            None

        Raises:
            ValueError, if the dscp is not valid
        """

        # create new instance
        slc = Slice(dscp, self, request)
        tenant_id = self.tenant_id

        # update db
        try:

            session = Session()

            tbl_slice = Session().query(TblSlice) \
                                 .filter(TblSlice.tenant_id == tenant_id) \
                                 .filter(TblSlice.dscp == slc.dscp) \
                                 .first()

            tbl_slice.wifi = json.dumps(slc.wifi['static-properties'])
            tbl_slice.lte = json.dumps(slc.lte['static-properties'])

            for wtp_addr in slc.wifi['wtps']:

                properties = \
                    json.dumps(slc.wifi['wtps'][wtp_addr]['static-properties'])

                tbl_belongs = \
                    Session().query(TblSliceBelongs) \
                             .filter(TblSliceBelongs.tenant_id == tenant_id) \
                             .filter(TblSliceBelongs.dscp == slc.dscp) \
                             .filter(TblSliceBelongs.addr == wtp_addr) \
                             .first()

                if not tbl_belongs:

                    belongs = TblSliceBelongs(tenant_id=self.tenant_id,
                                              dscp=slc.dscp,
                                              addr=wtp_addr,
                                              properties=properties)

                    session.add(belongs)

                else:

                    tbl_belongs.properties = properties

            for vbs_addr in slc.lte['vbses']:

                properties = \
                    json.dumps(slc.lte['vbses'][vbs_addr]['static-properties'])

                tbl_belongs = \
                    Session().query(TblSliceBelongs) \
                             .filter(TblSliceBelongs.tenant_id == tenant_id) \
                             .filter(TblSliceBelongs.dscp == slc.dscp) \
                             .filter(TblSliceBelongs.addr == vbs_addr) \
                             .first()

                if not tbl_belongs:

                    belongs = TblSliceBelongs(tenant_id=self.tenant_id,
                                              dscp=slc.dscp,
                                              addr=vbs_addr,
                                              properties=properties)

                    session.add(belongs)

                else:

                    tbl_belongs.properties = properties

            session.commit()

        except IntegrityError:
            session.rollback()
            raise ValueError()

        # store slice
        self.slices[dscp] = slc

        # create slice on WTPs
        for wtp_addr in self.wtps:

            wtp = self.wtps[wtp_addr]

            if not wtp.is_online():
                continue

            for block in wtp.supports:
                wtp.connection.send_set_slice(block, slc)

        # create slice on VBSes
        for vbs_addr in self.vbses:

            vbs = self.vbses[vbs_addr]

            if not vbs.is_online():
                continue

            current_rntis = []

            # The UEs in the slice must be confirmed

            for ue in list(self.ues.values()):

                if vbs == ue.vbs and dscp == ue.slice:
                    current_rntis.append(ue.rnti)

            for cell in vbs.cells.values():
                vbs.connection.\
                    send_add_set_ran_mac_slice_request(cell,
                                                       slc,
                                                       EP_OPERATION_SET,
                                                       current_rntis)
示例#3
0
    def add_slice(self, dscp, request):
        """Add a new slice to the Tenant.

        Args:
            dscp, a DSCP object
            request, the slice descriptor in json format

        Returns:
            None

        Raises:
            ValueError, if the dscp is not valid
        """

        # create new instance
        slc = Slice(dscp, self, request)

        # descriptors has been parsed, now it is safe to write to the db
        try:

            session = Session()

            tbl_slc = TblSlice(tenant_id=self.tenant_id,
                               dscp=slc.dscp,
                               wifi=json.dumps(slc.wifi['static-properties']),
                               lte=json.dumps(slc.lte['static-properties']))

            session.add(tbl_slc)

            for wtp_addr in slc.wifi['wtps']:

                properties = \
                    json.dumps(slc.wifi['wtps'][wtp_addr]['static-properties'])

                belongs = TblSliceBelongs(tenant_id=self.tenant_id,
                                          dscp=tbl_slc.dscp,
                                          addr=wtp_addr,
                                          properties=properties)

                session.add(belongs)

            for vbs_addr in slc.lte['vbses']:

                properties = \
                    json.dumps(slc.lte['vbses'][vbs_addr]['static-properties'])

                belongs = TblSliceBelongs(tenant_id=self.tenant_id,
                                          dscp=tbl_slc.dscp,
                                          addr=vbs_addr,
                                          properties=properties)

                session.add(belongs)

            session.commit()

        except IntegrityError:
            session.rollback()
            raise ValueError()

        # store slice
        self.slices[dscp] = slc

        # create slice on WTPs
        for wtp_addr in self.wtps:

            wtp = self.wtps[wtp_addr]

            if not wtp.is_online():
                continue

            for block in wtp.supports:
                wtp.connection.send_set_slice(block, slc)

        # create slice on VBSes
        for vbs_addr in self.vbses:

            vbs = self.vbses[vbs_addr]

            if not vbs.is_online():
                continue

            for cell in vbs.cells.values():
                vbs.connection.\
                    send_add_set_ran_mac_slice_request(cell,
                                                       slc,
                                                       EP_OPERATION_ADD)