Ejemplo n.º 1
0
    def add_pnfdev(self, pnfdev):
        """Add a new PNF Dev to the Tenant.

        Args:
            pnfdev, a PNFDev object

        Returns:
            None

        Raises:
            KeyError, if the pnfdev is not available
        """

        pnfdevs = getattr(self, pnfdev.ALIAS)

        if pnfdev.addr in pnfdevs:
            return

        pnfdevs[pnfdev.addr] = pnfdev

        belongs = TblBelongs(tenant_id=self.tenant_id, addr=pnfdev.addr)

        session = Session()
        session.add(belongs)
        session.commit()
Ejemplo n.º 2
0
    def create_account(self, username, password, role, name, surname, email):
        """Create a new account."""

        if username in self.accounts:
            raise ValueError("%s already registered" % username)

        if role not in [ROLE_ADMIN, ROLE_USER]:
            raise ValueError("Invalid role %s" % role)

        session = Session()
        account = TblAccount(username=username,
                             password=password,
                             role=role,
                             name=name,
                             surname=surname,
                             email=email)

        session.add(account)
        session.commit()

        self.accounts[account.username] = Account(account.username,
                                                  account.password,
                                                  account.name,
                                                  account.surname,
                                                  account.email, account.role)
Ejemplo n.º 3
0
    def request_tenant(self, owner, desc, tenant_name, bssid_type,
                       tenant_id=None):
        """Request new Tenant."""

        if tenant_id in self.tenants:
            raise ValueError("Tenant %s exists", tenant_id)

        if self.load_pending_tenant(tenant_id):
            raise ValueError("Tenant %s exists", tenant_id)

        try:

            session = Session()

            if tenant_id:
                request = TblPendingTenant(tenant_id=tenant_id,
                                           owner=owner,
                                           tenant_name=tenant_name,
                                           desc=desc,
                                           bssid_type=bssid_type)
            else:
                request = TblPendingTenant(owner=owner,
                                           tenant_name=tenant_name,
                                           desc=desc,
                                           bssid_type=bssid_type)

            session.add(request)
            session.commit()

        except IntegrityError:
            session.rollback()
            raise ValueError("Tenant name %s exists", tenant_name)

        return request.tenant_id
Ejemplo n.º 4
0
    def add_tenant(self, owner, desc, tenant_name, tenant_id=None):
        """Create new Tenant."""

        if tenant_id in self.tenants:
            raise ValueError("Tenant %s exists", tenant_id)

        try:

            session = Session()

            if tenant_id:
                request = TblTenant(tenant_id=tenant_id,
                                    tenant_name=tenant_name,
                                    owner=owner,
                                    desc=desc)
            else:
                request = TblTenant(owner=owner,
                                    tenant_name=tenant_name,
                                    desc=desc)

            session.add(request)
            session.commit()

        except IntegrityError:
            session.rollback()
            raise ValueError("Tenant name %s exists", tenant_name)

        self.tenants[request.tenant_id] = \
            Tenant(request.tenant_id,
                   request.tenant_name,
                   self.accounts[owner].username,
                   desc)

        return request.tenant_id
Ejemplo n.º 5
0
    def add_pnfdev(self, pnfdev):
        """Add a new PNF Dev to the Tenant.

        Args:
            pnfdev, a PNFDev object

        Returns:
            None

        Raises:
            KeyError, if the pnfdev is not available
        """

        pnfdevs = getattr(self, pnfdev.ALIAS)

        if pnfdev.addr in pnfdevs:
            return

        pnfdevs[pnfdev.addr] = pnfdev

        belongs = TblBelongs(tenant_id=self.tenant_id, addr=pnfdev.addr)

        session = Session()
        session.add(belongs)
        session.commit()
Ejemplo n.º 6
0
    def add_tenant(self,
                   owner,
                   desc,
                   tenant_name,
                   bssid_type,
                   tenant_id=None,
                   plmn_id=None):
        """Create new Tenant."""

        if tenant_id in self.tenants:
            raise ValueError("Tenant %s exists" % tenant_id)

        plmn_ids = [tenant.plmn_id for tenant in self.tenants.values()]

        if plmn_id and plmn_id in plmn_ids:
            raise ValueError("PLMN ID %s exists" % plmn_id)

        if bssid_type not in T_TYPES:
            raise ValueError("Invalid bssid_type %s" % bssid_type)

        session = Session()

        if tenant_id:
            request = TblTenant(tenant_id=tenant_id,
                                tenant_name=tenant_name,
                                owner=owner,
                                desc=desc,
                                bssid_type=bssid_type,
                                plmn_id=plmn_id)
        else:
            request = TblTenant(owner=owner,
                                tenant_name=tenant_name,
                                desc=desc,
                                bssid_type=bssid_type,
                                plmn_id=plmn_id)

        session.add(request)
        session.commit()

        self.tenants[request.tenant_id] = \
            Tenant(request.tenant_id,
                   request.tenant_name,
                   self.accounts[owner].username,
                   desc,
                   request.bssid_type,
                   request.plmn_id)

        # create default queue
        dscp = DSCP()
        descriptor = {}

        self.tenants[request.tenant_id].add_slice(dscp, descriptor)

        return request.tenant_id
Ejemplo n.º 7
0
    def add_feed(self):
        """Create new Feed."""

        feed_id = self.feed_id
        RUNTIME.feeds[feed_id] = Feed(feed_id)
        session = Session()
        session.add(TblFeed(feed_id=feed_id,
                            created=RUNTIME.feeds[feed_id].created,
                            updated=RUNTIME.feeds[feed_id].updated))
        session.commit()

        return RUNTIME.feeds[feed_id]
Ejemplo n.º 8
0
    def add_pnfdev(self, addr, label):
        """Add PNFDev."""

        if addr in self.pnfdevs:
            raise ValueError("Device address %s already present" % addr)

        self.pnfdevs[addr] = self.PNFDEV(addr, label)

        session = Session()
        session.add(self.TBL_PNFDEV(addr=addr, label=label))
        session.commit()

        return self.pnfdevs[addr]
Ejemplo n.º 9
0
    def add_feed(self):
        """Create new Feed."""

        feed_id = self.feed_id
        RUNTIME.feeds[feed_id] = Feed(feed_id)
        session = Session()
        session.add(
            TblFeed(feed_id=feed_id,
                    created=RUNTIME.feeds[feed_id].created,
                    updated=RUNTIME.feeds[feed_id].updated))
        session.commit()

        return RUNTIME.feeds[feed_id]
Ejemplo n.º 10
0
    def add_pnfdev(self, addr, label):
        """Add PNFDev."""

        if addr in self.pnfdevs:
            raise KeyError(addr)

        self.pnfdevs[addr] = self.PNFDEV(addr, label)

        session = Session()
        session.add(self.TBL_PNFDEV(addr=addr, label=label))
        session.commit()

        return self.pnfdevs[addr]
Ejemplo n.º 11
0
    def add_pnfdev(self, addr, label):
        """Add PNFDev."""

        if addr in self.pnfdevs:
            raise KeyError(addr)

        self.pnfdevs[addr] = self.PNFDEV(addr, label)

        session = Session()
        session.add(self.TBL_PNFDEV(addr=addr, label=label))
        session.commit()

        return self.pnfdevs[addr]
Ejemplo n.º 12
0
    def add_denied(self, sta_addr, label):
        """ Add entry to ACL. """

        deny = Session().query(TblDeny) \
                        .filter(TblDeny.addr == sta_addr) \
                        .first()
        if deny:
            raise ValueError(sta_addr)

        session = Session()
        session.add(TblDeny(addr=sta_addr, label=label))
        session.commit()

        acl = ACL(sta_addr, label)
        self.denied[sta_addr] = acl

        return acl
Ejemplo n.º 13
0
    def add_allowed(self, sta_addr, label):
        """ Add entry to ACL. """

        allow = Session().query(TblAllow) \
                         .filter(TblAllow.addr == sta_addr) \
                         .first()
        if allow:
            raise ValueError(sta_addr)

        session = Session()
        session.add(TblAllow(addr=sta_addr, label=label))
        session.commit()

        acl = ACL(sta_addr, label)
        self.allowed[sta_addr] = acl

        return acl
Ejemplo n.º 14
0
    def add_denied(self, sta_addr, label):
        """ Add entry to ACL. """

        deny = Session().query(TblDeny) \
                        .filter(TblDeny.addr == sta_addr) \
                        .first()
        if deny:
            raise ValueError(sta_addr)

        session = Session()
        session.add(TblDeny(addr=sta_addr, label=label))
        session.commit()

        acl = ACL(sta_addr, label)
        self.denied[sta_addr] = acl

        return acl
Ejemplo n.º 15
0
    def add_allowed(self, sta_addr, label):
        """ Add entry to ACL. """

        allow = Session().query(TblAllow) \
                         .filter(TblAllow.addr == sta_addr) \
                         .first()
        if allow:
            raise ValueError(sta_addr)

        session = Session()
        session.add(TblAllow(addr=sta_addr, label=label))
        session.commit()

        acl = ACL(sta_addr, label)
        self.allowed[sta_addr] = acl

        return acl
Ejemplo n.º 16
0
    def add_tenant(self,
                   owner,
                   desc,
                   tenant_name,
                   bssid_type,
                   tenant_id=None,
                   plmn_id=None):
        """Create new Tenant."""

        if tenant_id in self.tenants:
            raise ValueError("Tenant %s exists", tenant_id)

        try:

            session = Session()

            if tenant_id:
                request = TblTenant(tenant_id=tenant_id,
                                    tenant_name=tenant_name,
                                    owner=owner,
                                    desc=desc,
                                    bssid_type=bssid_type,
                                    plmn_id=plmn_id)
            else:
                request = TblTenant(owner=owner,
                                    tenant_name=tenant_name,
                                    desc=desc,
                                    bssid_type=bssid_type,
                                    plmn_id=plmn_id)

            session.add(request)
            session.commit()

        except IntegrityError:
            session.rollback()
            raise ValueError("Tenant name %s exists", tenant_name)

        self.tenants[request.tenant_id] = \
            Tenant(request.tenant_id,
                   request.tenant_name,
                   self.accounts[owner].username,
                   desc,
                   request.bssid_type,
                   request.plmn_id)

        return request.tenant_id
Ejemplo n.º 17
0
    def add_imsi2mac(self, imsi, addr):
        """Add IMSI to MAC mapped value to table."""

        imsi2mac = Session().query(TblIMSI2MAC) \
                         .filter(TblIMSI2MAC.imsi == imsi) \
                         .first()
        if imsi2mac:
            raise ValueError(imsi)

        try:

            session = Session()

            session.add(TblIMSI2MAC(imsi=imsi, addr=addr))
            session.commit()

        except IntegrityError:
            session.rollback()
            raise ValueError("MAC address must be unique %s", addr)

        self.imsi2mac[imsi] = addr
Ejemplo n.º 18
0
    def add_imsi2mac(self, imsi, addr):
        """Add IMSI to MAC mapped value to table."""

        imsi2mac = Session().query(TblIMSI2MAC) \
                         .filter(TblIMSI2MAC.imsi == imsi) \
                         .first()
        if imsi2mac:
            raise ValueError(imsi)

        try:

            session = Session()

            session.add(TblIMSI2MAC(imsi=imsi, addr=addr))
            session.commit()

        except IntegrityError:
            session.rollback()
            raise ValueError("MAC address must be unique %s", addr)

        self.imsi2mac[imsi] = addr
Ejemplo n.º 19
0
def generate_default_accounts():
    """Generate default accounts.

    Three default accounts (one root account and two user accounts are created
    the first time the controller is started.
    """

    if not Session().query(TblAccount).all():

        LOG.info("Generating default accounts")

        session = Session()
        session.add(TblAccount(username="******",
                               password="******",
                               role="admin",
                               name="Administrator",
                               surname="",
                               email="*****@*****.**"))
        session.add(TblAccount(username="******",
                               password="******",
                               role="user",
                               name="Foo",
                               surname="",
                               email="*****@*****.**"))
        session.add(TblAccount(username="******",
                               password="******",
                               role="user",
                               name="Bar",
                               surname="",
                               email="*****@*****.**"))
        session.commit()
Ejemplo n.º 20
0
def generate_default_accounts():
    """Generate default accounts.

    Three default accounts (one root account and two user accounts are created
    the first time the controller is started.
    """

    if not Session().query(TblAccount).all():

        LOG.info("Generating default accounts")

        session = Session()
        session.add(
            TblAccount(username="******",
                       password="******",
                       role="admin",
                       name="Administrator",
                       surname="",
                       email="*****@*****.**"))
        session.add(
            TblAccount(username="******",
                       password="******",
                       role="user",
                       name="Foo",
                       surname="",
                       email="*****@*****.**"))
        session.add(
            TblAccount(username="******",
                       password="******",
                       role="user",
                       name="Bar",
                       surname="",
                       email="*****@*****.**"))
        session.commit()
Ejemplo n.º 21
0
    def add_traffic_rule(self, match, dscp, label, priority=0):
        """Add a new traffic rule to the Tenant.

        Args:
            match, a Match object
            dscp, a slice DSCP code
            label, a humand readable description of the rule
        Returns:
            None

        Raises:
            Nones
        """

        trule = TrafficRule(tenant=self,
                            match=match,
                            dscp=dscp,
                            priority=priority,
                            label=label)

        # Send command to IBN
        from empower.ibnp.ibnpserver import IBNPServer
        ibnp_server = get_module(IBNPServer.__module__)
        if ibnp_server:
            ibnp_server.add_traffic_rule(trule)

        rule = TblTrafficRule(tenant_id=self.tenant_id,
                              match=match,
                              dscp=dscp,
                              priority=priority,
                              label=label)

        try:
            session = Session()
            session.add(rule)
            session.commit()
        except IntegrityError:
            session.rollback()
            raise ValueError("Duplicate (%s, %s)" % (self.tenant_id, match))
Ejemplo n.º 22
0
    def create_account(self, username, password, role, name, surname, email):
        """Create a new account."""

        if username in self.accounts:
            LOG.error("'%s' already registered", username)
            raise ValueError("%s already registered" % username)

        session = Session()
        account = TblAccount(username=username,
                             password=password,
                             role=role,
                             name=name,
                             surname=surname,
                             email=email)

        session.add(account)
        session.commit()

        self.accounts[account.username] = Account(account.username,
                                                  account.password,
                                                  account.name,
                                                  account.surname,
                                                  account.email, account.role)
Ejemplo n.º 23
0
    def create_account(self, username, password, role, name, surname, email):
        """Create a new account."""

        if username in self.accounts:
            LOG.error("'%s' already registered", username)
            raise ValueError("%s already registered" % username)

        session = Session()
        account = TblAccount(username=username,
                             password=password,
                             role=role,
                             name=name,
                             surname=surname,
                             email=email)

        session.add(account)
        session.commit()

        self.accounts[account.username] = Account(account.username,
                                                  account.password,
                                                  account.name,
                                                  account.surname,
                                                  account.email,
                                                  account.role)
Ejemplo n.º 24
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)
Ejemplo n.º 25
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)