Search in sources :

Example 51 with Objective

use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.

the class PolicyManager method removePolicyInDevice.

// Remove policy in a device according to the type
private void removePolicyInDevice(DeviceId deviceId, Policy policy) {
    PolicyKey policyKey = new PolicyKey(deviceId, policy.policyId());
    Operation operation = Versioned.valueOrNull(operations.get(policyKey.toString()));
    // Policy might be still in pending or not present anymore
    if (operation == null || operation.objectiveOperation() == null) {
        log.warn("There are no ops associated with {}", policyKey);
        operation = Operation.builder().isDone(true).isInstall(false).policy(policy).build();
        operations.put(policyKey.toString(), operation);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Removing {} policy {} in device {}", policy.policyType(), policy.policyId(), deviceId);
        }
        Operation.Builder operationBuilder = Operation.builder().isInstall(false).policy(policy);
        if (policy.policyType() == PolicyType.DROP) {
            operationBuilder.isDone(true);
            operations.put(policyKey.toString(), operationBuilder.build());
        } else if (policy.policyType() == PolicyType.REDIRECT) {
            // REDIRECT has to remove the next objective first
            NextObjective oldObj = (NextObjective) operation.objectiveOperation();
            operations.put(policyKey.toString(), operationBuilder.build());
            NextObjective.Builder builder = oldObj.copy();
            CompletableFuture<Objective> future = new CompletableFuture<>();
            if (log.isDebugEnabled()) {
                log.debug("Removing REDIRECT next objective for dev: {}", deviceId);
            }
            ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
                if (log.isDebugEnabled()) {
                    log.debug("REDIRECT next objective for policy {} removed in dev: {}", policy.policyId(), deviceId);
                }
                future.complete(objective);
            }, (objective, error) -> {
                log.warn("Failed to remove REDIRECT next objective for policy {}: {} in dev: {}", policy.policyId(), error, deviceId);
                future.complete(null);
            });
            NextObjective serializableObjective = builder.remove();
            flowObjectiveService.next(deviceId, builder.remove(context));
            future.whenComplete((objective, ex) -> {
                if (ex != null) {
                    log.error("Exception Removing REDIRECT next objective", ex);
                } else if (objective != null) {
                    operations.computeIfPresent(policyKey.toString(), (k, v) -> {
                        if (!v.isDone() && !v.isInstall()) {
                            v.isDone(true);
                            v.objectiveOperation(serializableObjective);
                        }
                        return v;
                    });
                }
            });
        }
    }
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) PredictableExecutor(org.onlab.util.PredictableExecutor) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Sets(org.glassfish.jersey.internal.guava.Sets) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) EDGE_PORT(org.onosproject.segmentrouting.metadata.SRObjectiveMetadata.EDGE_PORT) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Collectors(java.util.stream.Collectors) TrafficMatchData(org.onosproject.segmentrouting.policy.api.TrafficMatchData) PolicyType(org.onosproject.segmentrouting.policy.api.Policy.PolicyType) Executors(java.util.concurrent.Executors) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Policy(org.onosproject.segmentrouting.policy.api.Policy) TrafficMatchState(org.onosproject.segmentrouting.policy.api.TrafficMatchState) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) HashFunction(com.google.common.hash.HashFunction) DeviceId(org.onosproject.net.DeviceId) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) StorageException(org.onosproject.store.service.StorageException) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) Hashing(com.google.common.hash.Hashing) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) CompletableFuture(java.util.concurrent.CompletableFuture) PolicyState(org.onosproject.segmentrouting.policy.api.PolicyState) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) ArrayList(java.util.ArrayList) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) TrafficMatch(org.onosproject.segmentrouting.policy.api.TrafficMatch) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) TrafficMatchPriority(org.onosproject.segmentrouting.policy.api.TrafficMatchPriority) Maps(com.google.common.collect.Maps) CodecService(org.onosproject.codec.CodecService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) PolicyId(org.onosproject.segmentrouting.policy.api.PolicyId) TrafficMatchId(org.onosproject.segmentrouting.policy.api.TrafficMatchId) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) PolicyData(org.onosproject.segmentrouting.policy.api.PolicyData) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext)

Example 52 with Objective

use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.

the class PolicyManager method installPolicyInDevice.

// Orchestrate policy installation according to the type
private void installPolicyInDevice(DeviceId deviceId, Policy policy) {
    if (!SUPPORTED_POLICIES.contains(policy.policyType())) {
        log.warn("Policy {} type {} not yet supported", policy.policyId(), policy.policyType());
        return;
    }
    PolicyKey policyKey;
    Operation.Builder operation;
    if (log.isDebugEnabled()) {
        log.debug("Installing {} policy {} for dev: {}", policy.policyType(), policy.policyId(), deviceId);
    }
    policyKey = new PolicyKey(deviceId, policy.policyId());
    // Prevent duplicate installation of the policies. With the current
    // implementation is not possible to update a policy since a change
    // in the params will create a new policy. Thus, there is no need to
    // check the equality like we do for the TM
    Operation oldPolicyOp = Versioned.valueOrNull(operations.get(policyKey.toString()));
    if (oldPolicyOp != null && oldPolicyOp.isInstall()) {
        if (log.isDebugEnabled()) {
            log.debug("There is already an install operation for policy {}", policy.policyId());
        }
        // If we add or submit a policy multiple times
        // We skip the installation update the policy state directly
        updatePolicy(policy.policyId(), true);
        return;
    }
    operation = Operation.builder().isInstall(true).policy(policy);
    // TODO To better handle different policy types consider the abstraction of a compiler (subtypes ?)
    if (policy.policyType() == PolicyType.DROP) {
        // DROP policies do not need the next objective installation phase
        // we can update directly the map and signal the ops as done
        operation.isDone(true);
        operations.put(policyKey.toString(), operation.build());
    } else if (policy.policyType() == PolicyType.REDIRECT) {
        // REDIRECT Uses next objective context to update the ops as done when
        // it returns successfully. In the other cases leaves the ops as undone
        // and the relative policy will remain in pending.
        operations.put(policyKey.toString(), operation.build());
        NextObjective.Builder builder = redirectPolicyNextObjective(deviceId, (RedirectPolicy) policy);
        // Handle error here - leave the operation as undone and pending
        if (builder != null) {
            CompletableFuture<Objective> future = new CompletableFuture<>();
            if (log.isDebugEnabled()) {
                log.debug("Installing REDIRECT next objective for dev: {}", deviceId);
            }
            ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
                if (log.isDebugEnabled()) {
                    log.debug("REDIRECT next objective for policy {} installed in dev: {}", policy.policyId(), deviceId);
                }
                future.complete(objective);
            }, (objective, error) -> {
                log.warn("Failed to install REDIRECT next objective for policy {}: {} in dev: {}", policy.policyId(), error, deviceId);
                future.complete(null);
            });
            // Context is not serializable
            NextObjective serializableObjective = builder.add();
            flowObjectiveService.next(deviceId, builder.add(context));
            future.whenComplete((objective, ex) -> {
                if (ex != null) {
                    log.error("Exception installing REDIRECT next objective", ex);
                } else if (objective != null) {
                    operations.computeIfPresent(policyKey.toString(), (k, v) -> {
                        if (!v.isDone() && v.isInstall()) {
                            v.isDone(true);
                            v.objectiveOperation(serializableObjective);
                        }
                        return v;
                    });
                }
            });
        }
    }
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) PredictableExecutor(org.onlab.util.PredictableExecutor) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Sets(org.glassfish.jersey.internal.guava.Sets) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) EDGE_PORT(org.onosproject.segmentrouting.metadata.SRObjectiveMetadata.EDGE_PORT) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Collectors(java.util.stream.Collectors) TrafficMatchData(org.onosproject.segmentrouting.policy.api.TrafficMatchData) PolicyType(org.onosproject.segmentrouting.policy.api.Policy.PolicyType) Executors(java.util.concurrent.Executors) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Policy(org.onosproject.segmentrouting.policy.api.Policy) TrafficMatchState(org.onosproject.segmentrouting.policy.api.TrafficMatchState) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) HashFunction(com.google.common.hash.HashFunction) DeviceId(org.onosproject.net.DeviceId) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) StorageException(org.onosproject.store.service.StorageException) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) Hashing(com.google.common.hash.Hashing) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) CompletableFuture(java.util.concurrent.CompletableFuture) PolicyState(org.onosproject.segmentrouting.policy.api.PolicyState) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) ArrayList(java.util.ArrayList) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) TrafficMatch(org.onosproject.segmentrouting.policy.api.TrafficMatch) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) TrafficMatchPriority(org.onosproject.segmentrouting.policy.api.TrafficMatchPriority) Maps(com.google.common.collect.Maps) CodecService(org.onosproject.codec.CodecService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) PolicyId(org.onosproject.segmentrouting.policy.api.PolicyId) TrafficMatchId(org.onosproject.segmentrouting.policy.api.TrafficMatchId) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) PolicyData(org.onosproject.segmentrouting.policy.api.PolicyData) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext)

Example 53 with Objective

use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.

the class DefaultL2TunnelHandler method deletePolicy.

/**
 * Deletes a given policy using the parameter supplied.
 *
 * @param tunnelId     the tunnel id
 * @param ingress      the ingress point
 * @param ingressInner the ingress inner vlan id
 * @param ingressOuter the ingress outer vlan id
 * @param future       to perform the async operation
 * @param direction    the direction: forward or reverse
 */
private void deletePolicy(long tunnelId, ConnectPoint ingress, VlanId ingressInner, VlanId ingressOuter, VlanId egressVlan, CompletableFuture<ObjectiveError> future, Direction direction) {
    String key = generateKey(tunnelId, direction);
    if (!l2InitiationNextObjStore.containsKey(key)) {
        log.error("Abort delete of policy for tunnel {}: next does not exist in the store", tunnelId);
        if (future != null) {
            future.complete(null);
        }
        return;
    }
    NextObjective nextObjective = l2InitiationNextObjStore.get(key).value();
    int nextId = nextObjective.id();
    List<Objective> objectives = Lists.newArrayList();
    // We create the forwarding objective.
    ForwardingObjective.Builder fwdBuilder = createInitFwdObjective(tunnelId, ingress.port(), nextId);
    ObjectiveContext context = new ObjectiveContext() {

        @Override
        public void onSuccess(Objective objective) {
            log.debug("Previous fwdObj for policy {} removed", tunnelId);
            if (future != null) {
                future.complete(null);
            }
        }

        @Override
        public void onError(Objective objective, ObjectiveError error) {
            log.error("Failed to remove previous fwdObj for policy {}: {}", tunnelId, error);
            if (future != null) {
                future.complete(error);
            }
        }
    };
    objectives.add(fwdBuilder.remove(context));
    // We create the filtering objective to define the
    // permit traffic in the switch
    FilteringObjective.Builder filtBuilder = createFiltObjective(ingress.port(), ingressInner, ingressOuter);
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setTunnelId(tunnelId).setVlanId(egressVlan);
    filtBuilder.withMeta(treatment.build());
    context = new DefaultObjectiveContext((objective) -> log.debug("FilterObj for policy {} revoked", tunnelId), (objective, error) -> log.warn("Failed to revoke filterObj for policy {}", tunnelId, error));
    objectives.add(filtBuilder.remove(context));
    for (Objective objective : objectives) {
        if (objective instanceof ForwardingObjective) {
            srManager.flowObjectiveService.forward(ingress.deviceId(), (ForwardingObjective) objective);
        } else {
            srManager.flowObjectiveService.filter(ingress.deviceId(), (FilteringObjective) objective);
        }
    }
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConsistentMap(org.onosproject.store.service.ConsistentMap) REV(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Direction.REV) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) PwaasUtil(org.onosproject.segmentrouting.pwaas.PwaasUtil) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) FWD(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Direction.FWD) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) Result(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Result) DefaultLink(org.onosproject.net.DefaultLink) Serializer(org.onosproject.store.service.Serializer) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) SRLinkWeigher(org.onosproject.segmentrouting.SRLinkWeigher) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Collectors(java.util.stream.Collectors) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Path(org.onosproject.net.Path) TERMINATION(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Pipeline.TERMINATION) DeviceId(org.onosproject.net.DeviceId) DistributedLock(org.onosproject.store.service.DistributedLock) RandomUtils(org.apache.commons.lang3.RandomUtils) Iterables(com.google.common.collect.Iterables) StorageException(org.onosproject.store.service.StorageException) CompletableFuture(java.util.concurrent.CompletableFuture) KryoNamespace(org.onlab.util.KryoNamespace) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) VERSATILE(org.onosproject.net.flowobjective.ForwardingObjective.Flag.VERSATILE) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) SegmentRoutingManager(org.onosproject.segmentrouting.SegmentRoutingManager) Logger(org.slf4j.Logger) MplsLabel(org.onlab.packet.MplsLabel) INITIATION(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Pipeline.INITIATION) VlanId(org.onlab.packet.VlanId) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) LinkWeigher(org.onosproject.net.topology.LinkWeigher) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 54 with Objective

use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.

the class DefaultL2TunnelHandler method deployPolicy.

/**
 * Handles the policy establishment which consists in
 * create the filtering and forwarding objectives related
 * to the initiation and termination.
 *
 * @param tunnelId     the tunnel id
 * @param ingress      the ingress point
 * @param ingressInner the ingress inner tag
 * @param ingressOuter the ingress outer tag
 * @param egressVlan   Vlan-id to set, depends on ingress vlan
 *                     combinations. For example, if pw is double tagged
 *                     then this is the value of the outer vlan, if single
 *                     tagged then it is the new value of the single tag.
 *                     Should be None for untagged traffic.
 * @param nextId       the next objective id
 * @return the result of the operation
 */
private Result deployPolicy(long tunnelId, ConnectPoint ingress, VlanId ingressInner, VlanId ingressOuter, VlanId egressVlan, int nextId) {
    log.debug("Starting deploying policy for pseudowire {}.", tunnelId);
    List<Objective> objectives = Lists.newArrayList();
    // We create the forwarding objective for supporting
    // the l2 tunnel.
    ForwardingObjective.Builder fwdBuilder = createInitFwdObjective(tunnelId, ingress.port(), nextId);
    // We create and add objective context.
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("FwdObj for tunnel {} populated", tunnelId), (objective, error) -> log.warn("Failed to populate fwdObj " + "for tunnel {} : {}", tunnelId, error));
    objectives.add(fwdBuilder.add(context));
    // We create the filtering objective to define the
    // permit traffic in the switch
    FilteringObjective.Builder filtBuilder = createFiltObjective(ingress.port(), ingressInner, ingressOuter);
    // We add the metadata.
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setTunnelId(tunnelId).setVlanId(egressVlan);
    filtBuilder.withMeta(treatment.build());
    // We create and add objective context.
    context = new DefaultObjectiveContext((objective) -> log.debug("FilterObj for tunnel {} populated", tunnelId), (objective, error) -> log.warn("Failed to populate filterObj for " + "tunnel {} : {}", tunnelId, error));
    objectives.add(filtBuilder.add(context));
    for (Objective objective : objectives) {
        if (objective instanceof ForwardingObjective) {
            srManager.flowObjectiveService.forward(ingress.deviceId(), (ForwardingObjective) objective);
            log.debug("Creating new FwdObj for initiation NextObj with id={} for tunnel {}", nextId, tunnelId);
        } else {
            srManager.flowObjectiveService.filter(ingress.deviceId(), (FilteringObjective) objective);
            log.debug("Creating new FiltObj for tunnel {}", tunnelId);
        }
    }
    return SUCCESS;
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConsistentMap(org.onosproject.store.service.ConsistentMap) REV(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Direction.REV) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) PwaasUtil(org.onosproject.segmentrouting.pwaas.PwaasUtil) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) FWD(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Direction.FWD) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) Result(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Result) DefaultLink(org.onosproject.net.DefaultLink) Serializer(org.onosproject.store.service.Serializer) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) SRLinkWeigher(org.onosproject.segmentrouting.SRLinkWeigher) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Collectors(java.util.stream.Collectors) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Path(org.onosproject.net.Path) TERMINATION(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Pipeline.TERMINATION) DeviceId(org.onosproject.net.DeviceId) DistributedLock(org.onosproject.store.service.DistributedLock) RandomUtils(org.apache.commons.lang3.RandomUtils) Iterables(com.google.common.collect.Iterables) StorageException(org.onosproject.store.service.StorageException) CompletableFuture(java.util.concurrent.CompletableFuture) KryoNamespace(org.onlab.util.KryoNamespace) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) VERSATILE(org.onosproject.net.flowobjective.ForwardingObjective.Flag.VERSATILE) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) SegmentRoutingManager(org.onosproject.segmentrouting.SegmentRoutingManager) Logger(org.slf4j.Logger) MplsLabel(org.onlab.packet.MplsLabel) INITIATION(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Pipeline.INITIATION) VlanId(org.onlab.packet.VlanId) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) LinkWeigher(org.onosproject.net.topology.LinkWeigher) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 55 with Objective

use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.

the class XconnectManager method revokeFilter.

/**
 * Revokes filtering objectives for given XConnect.
 *
 * @param key       XConnect store key
 * @param endpoints XConnect endpoints
 */
private void revokeFilter(XconnectKey key, Set<XconnectEndpoint> endpoints) {
    // FIXME Improve the logic
    // If port load balancer is not involved, use filtered port. Otherwise, use unfiltered port.
    // The purpose is to make sure existing XConnect logic can still work on a configured port.
    boolean filtered = endpoints.stream().map(ep -> getNextTreatment(key.deviceId(), ep, false)).allMatch(t -> t.type().equals(NextTreatment.Type.TREATMENT));
    endpoints.stream().map(ep -> getPhysicalPorts(key.deviceId(), ep)).flatMap(Set::stream).forEach(port -> {
        FilteringObjective.Builder filtObjBuilder = filterObjBuilder(key, port, filtered);
        ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("XConnect FilterObj for {} on port {} revoked", key, port), (objective, error) -> log.warn("Failed to revoke XConnect FilterObj for {} on port {}: {}", key, port, error));
        flowObjectiveService.filter(key.deviceId(), filtObjBuilder.remove(context));
    });
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) XconnectService(org.onosproject.segmentrouting.xconnect.api.XconnectService) HostLocation(org.onosproject.net.HostLocation) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) XconnectKey(org.onosproject.segmentrouting.xconnect.api.XconnectKey) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) StorageService(org.onosproject.store.service.StorageService) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) XconnectDesc(org.onosproject.segmentrouting.xconnect.api.XconnectDesc) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) Serializable(java.io.Serializable) PortLoadBalancerId(org.onosproject.portloadbalancer.api.PortLoadBalancerId) XconnectLoadBalancerEndpoint(org.onosproject.segmentrouting.xconnect.api.XconnectLoadBalancerEndpoint) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DeviceEvent(org.onosproject.net.device.DeviceEvent) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) DeviceId(org.onosproject.net.DeviceId) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) Host(org.onosproject.net.Host) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) VlanNextObjectiveStoreKey(org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey) PortLoadBalancerService(org.onosproject.portloadbalancer.api.PortLoadBalancerService) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) CompletableFuture(java.util.concurrent.CompletableFuture) KryoNamespace(org.onlab.util.KryoNamespace) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) MapEventListener(org.onosproject.store.service.MapEventListener) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) RemovalNotification(com.google.common.cache.RemovalNotification) DeviceListener(org.onosproject.net.device.DeviceListener) XconnectEndpoint(org.onosproject.segmentrouting.xconnect.api.XconnectEndpoint) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) PortLoadBalancerEvent(org.onosproject.portloadbalancer.api.PortLoadBalancerEvent) XconnectCodec(org.onosproject.segmentrouting.xconnect.api.XconnectCodec) VlanId(org.onlab.packet.VlanId) CodecService(org.onosproject.codec.CodecService) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment) XconnectPortEndpoint(org.onosproject.segmentrouting.xconnect.api.XconnectPortEndpoint) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) PortLoadBalancerListener(org.onosproject.portloadbalancer.api.PortLoadBalancerListener) MapEvent(org.onosproject.store.service.MapEvent) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) Cache(com.google.common.cache.Cache) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Aggregations

Objective (org.onosproject.net.flowobjective.Objective)64 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)58 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)42 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)42 NextObjective (org.onosproject.net.flowobjective.NextObjective)42 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)38 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)37 TrafficSelector (org.onosproject.net.flow.TrafficSelector)37 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)36 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)34 DeviceId (org.onosproject.net.DeviceId)32 DefaultFilteringObjective (org.onosproject.net.flowobjective.DefaultFilteringObjective)29 ConnectPoint (org.onosproject.net.ConnectPoint)27 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)27 List (java.util.List)26 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)26 Set (java.util.Set)25 Lists (com.google.common.collect.Lists)24 CompletableFuture (java.util.concurrent.CompletableFuture)24 Collectors (java.util.stream.Collectors)24