def create_tap_service_precommit(self, context):
        """Send tap service creation message to agent.

        This message includes taas_id that is added vlan_range_start to
        so that the vpp taas agent can use taas_id as VLANID.
        """

        # by default, the status is ACTIVE: wait for creation...
        context.tap_service['status'] = constants.PENDING_CREATE
        ts = context.tap_service
        # Get taas id associated with the Tap Service
        tap_id_association = context._plugin.create_tap_id_association(
            context._plugin_context, ts['id'])
        context.tap_id_association = tap_id_association
        self.service_plugin.update_tap_service(
            context._plugin_context, ts['id'],
            {'tap_service': context.tap_service})
        ts = context.tap_service
        tap_id_association = context.tap_id_association
        # taas_vlan_id = (tap_id_association['taas_id'] +
        #                cfg.CONF.taas.vlan_range_start)
        taas_vlan_id = tap_id_association['taas_id']
        port = self.service_plugin._get_port_details(context._plugin_context,
                                                     ts['port_id'])

        if taas_vlan_id > cfg.CONF.taas.vlan_range_end:
            raise taas_ex.TapServiceLimitReached()

        msg = {"tap_service": ts, "taas_id": taas_vlan_id, "port": port}

        self.taas_service.create(port, msg)
        return
Esempio n. 2
0
    def create_tap_service_precommit(self, context):
        """Send tap service creation message to agent.

        This message includes taas_id that is added vlan_range_start to
        so that the vpp taas agent can use taas_id as VLANID.
        """
        LOG.debug("create_tap_service_precommit called.")

        # by default, the status is ACTIVE: wait for creation...
        context.tap_service['status'] = constants.PENDING_CREATE
        ts = context.tap_service
        # Get taas id associated with the Tap Service
        tap_id_association = context._plugin.create_tap_id_association(
            context._plugin_context, ts['id'])
        context.tap_id_association = tap_id_association
        self.service_plugin.update_tap_service(
            context._plugin_context, ts['id'],
            {'tap_service': context.tap_service})
        ts = context.tap_service
        tap_id_association = context.tap_id_association

        # The field port_id always exists as it's a field in the SQL database.
        # For ERSPAN EXT mode, it is set to an empty string
        # If the port_id is empty, we're in ERSPAN Ext mode.
        # If port_id is not empty and erspan_dst_ip is defined, we're in
        # ERSPAN Internal mode.
        # Otherwise we're in normal port tapping mode.
        if ts['port_id'] == '':
            dest_type = 'ERSPAN_EXT'
        elif 'erspan_dst_ip' in ts and ts['erspan_dst_ip'] != '':
            dest_type = 'ERSPAN_INT'
        else:
            dest_type = 'Port'

        if dest_type != 'ERSPAN_EXT':
            taas_vlan_id = tap_id_association['taas_id']
            port = self.service_plugin._get_port_details(
                context._plugin_context, ts['port_id'])

            if taas_vlan_id > cfg.CONF.taas.vlan_range_end:
                raise taas_ex.TapServiceLimitReached()

            msg = {
                "tap_service": ts,
                "taas_id": taas_vlan_id,
                "port": port,
                "dest_type": dest_type
            }
            self.taas_service.create(port, msg)

        else:
            msg = {"tap_service": ts, "dest_type": dest_type}
            self.taas_service.create(None, msg)
            self.service_plugin.update_tap_service(
                context._plugin_context, ts['id'],
                {'tap_service': context.tap_service})

        return
Esempio n. 3
0
    def _allocate_taas_id_with_tap_service_id(self, context, tap_service_id):
        query = context.session.query(TapIdAssociation).filter_by(
            tap_service_id=None).first()
        if not query:
            self._rebuild_taas_id_allocation_range(context)
            # try again
            query = context.session.query(TapIdAssociation).filter_by(
                tap_service_id=None).first()

        if query:
            query.update({"tap_service_id": tap_service_id})
            return query
        # not found
        raise taas.TapServiceLimitReached()
    def create_tap_service(self, context, tap_service):
        LOG.debug("create_tap_service() called")

        tenant_id = self._get_tenant_id_for_create(context,
                                                   tap_service['tap_service'])

        t_s = tap_service['tap_service']
        port_id = t_s['port_id']

        # Get port details
        port = self._get_port_details(context, port_id)

        # Check if the port is owned by the tenant.
        if port['tenant_id'] != tenant_id:
            raise taas_ex.PortDoesNotBelongToTenant()

        # Extract the host where the port is located
        host = port['binding:host_id']

        if host is not None:
            LOG.debug("Host on which the port is created = %s" % host)
        else:
            LOG.debug("Host could not be found, Port Binding disbaled!")

        # Create tap service in the db model
        ts = super(TaasPlugin, self).create_tap_service(context, tap_service)
        # Get taas id associated with the Tap Service
        tap_id_association = self.get_tap_id_association(
            context, tap_service_id=ts['id'])

        taas_vlan_id = (tap_id_association['taas_id'] +
                        cfg.CONF.taas.vlan_range_start)

        if taas_vlan_id > cfg.CONF.taas.vlan_range_end:
            raise taas_ex.TapServiceLimitReached()

        rpc_msg = {'tap_service': ts, 'taas_id': taas_vlan_id, 'port': port}

        self.agent_rpc.create_tap_service(context, rpc_msg, host)

        return ts
Esempio n. 5
0
    def create_tap_service_postcommit(self, context):
        """Send tap service creation RPC message to agent.

        This RPC message includes taas_id that is added vlan_range_start to
        so that taas-ovs-agent can use taas_id as VLANID.
        """
        # Get taas id associated with the Tap Service
        ts = context.tap_service
        tap_id_association = context.tap_id_association
        taas_vlan_id = (tap_id_association['taas_id'] +
                        cfg.CONF.taas.vlan_range_start)
        port = self.service_plugin._get_port_details(context._plugin_context,
                                                     ts['port_id'])
        host = port['binding:host_id']

        if taas_vlan_id > cfg.CONF.taas.vlan_range_end:
            raise taas_ex.TapServiceLimitReached()

        rpc_msg = {'tap_service': ts, 'taas_id': taas_vlan_id, 'port': port}

        self.agent_rpc.create_tap_service(context._plugin_context, rpc_msg,
                                          host)
        return