Search in sources :

Example 26 with Objective

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

the class PolicyManager method removeTrafficMatchInDevice.

// Traffic match removal in a device
private void removeTrafficMatchInDevice(DeviceId deviceId, TrafficMatch trafficMatch) {
    if (log.isDebugEnabled()) {
        log.debug("Removing traffic match {} associated to policy {}", trafficMatch.trafficMatchId(), trafficMatch.policyId());
    }
    TrafficMatchKey trafficMatchKey = new TrafficMatchKey(deviceId, trafficMatch.trafficMatchId());
    Operation operation = Versioned.valueOrNull(operations.get(trafficMatchKey.toString()));
    if (operation == null || operation.objectiveOperation() == null) {
        log.warn("There are no ops associated with {}", trafficMatchKey);
        operation = Operation.builder().isDone(true).isInstall(false).trafficMatch(trafficMatch).build();
        operations.put(trafficMatchKey.toString(), operation);
    } else if (!operation.isInstall()) {
        if (log.isDebugEnabled()) {
            log.debug("There is already an uninstall operation for traffic match {} associated to policy {}" + " for device {}", trafficMatch.trafficMatchId(), trafficMatch.policyId(), deviceId);
        }
    } else {
        ForwardingObjective oldObj = (ForwardingObjective) operation.objectiveOperation();
        operation = Operation.builder(operation).isInstall(false).build();
        operations.put(trafficMatchKey.toString(), operation);
        ForwardingObjective.Builder builder = DefaultForwardingObjective.builder(oldObj);
        CompletableFuture<Objective> future = new CompletableFuture<>();
        if (log.isDebugEnabled()) {
            log.debug("Removing forwarding objectives for dev: {}", deviceId);
        }
        ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
            if (log.isDebugEnabled()) {
                log.debug("Forwarding objective for policy {} removed", trafficMatch.policyId());
            }
            future.complete(objective);
        }, (objective, error) -> {
            log.warn("Failed to remove forwarding objective for policy {}: {}", trafficMatch.policyId(), error);
            future.complete(null);
        });
        ForwardingObjective serializableObjective = builder.remove();
        flowObjectiveService.forward(deviceId, builder.remove(context));
        future.whenComplete((objective, ex) -> {
            if (ex != null) {
                log.error("Exception removing forwarding objective", ex);
            } else if (objective != null) {
                operations.computeIfPresent(trafficMatchKey.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) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective)

Example 27 with Objective

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

the class PolicyManager method installTrafficMatchToDevice.

// Orchestrate traffic match installation according to the type
private void installTrafficMatchToDevice(DeviceId deviceId, TrafficMatch trafficMatch) {
    if (log.isDebugEnabled()) {
        log.debug("Installing traffic match {} associated to policy {}", trafficMatch.trafficMatchId(), trafficMatch.policyId());
    }
    TrafficMatchKey trafficMatchKey = new TrafficMatchKey(deviceId, trafficMatch.trafficMatchId());
    Operation oldTrafficOperation = Versioned.valueOrNull(operations.get(trafficMatchKey.toString()));
    if (oldTrafficOperation != null && oldTrafficOperation.isInstall()) {
        if (trafficMatch.equals(oldTrafficOperation.trafficMatch().orElse(null))) {
            if (log.isDebugEnabled()) {
                log.debug("There is already an install operation for traffic match {} associated to policy {} " + "for device {}", trafficMatch.trafficMatchId(), trafficMatch.policyId(), deviceId);
            }
            // If we add or submit a trafficMatch multiple times
            // We skip the installation and update the state directly
            updateTrafficMatch(trafficMatch, true);
            return;
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Starts updating traffic match {} associated to policy {} " + "for device {}", trafficMatch.trafficMatchId(), trafficMatch.policyId(), deviceId);
            }
        }
    }
    // For the DROP policy we need to set an ACL drop in the fwd objective. The other
    // policies require to retrieve the next Id and sets the next step.
    PolicyKey policyKey = new PolicyKey(deviceId, trafficMatch.policyId());
    Operation policyOperation = Versioned.valueOrNull(operations.get(policyKey.toString()));
    if (policyOperation == null || !policyOperation.isDone() || !policyOperation.isInstall() || policyOperation.policy().isEmpty() || (policyOperation.policy().get().policyType() == PolicyType.REDIRECT && policyOperation.objectiveOperation() == null)) {
        log.info("Deferring traffic match {} installation on device {}. Policy {} not yet installed", trafficMatch.trafficMatchId(), deviceId, trafficMatch.policyId());
        return;
    }
    // Updates the store and then send the versatile fwd objective to the pipeliner
    Operation newTrafficOperation = Operation.builder().isInstall(true).trafficMatch(trafficMatch).build();
    operations.put(trafficMatchKey.toString(), newTrafficOperation);
    Policy policy = policyOperation.policy().get();
    ForwardingObjective.Builder builder = trafficMatchFwdObjective(trafficMatch, policy.policyType());
    if (policy.policyType() == PolicyType.DROP) {
        // Firstly builds the fwd objective with the wipeDeferred action.
        TrafficTreatment dropTreatment = DefaultTrafficTreatment.builder().wipeDeferred().build();
        builder.withTreatment(dropTreatment);
    } else if (policy.policyType() == PolicyType.REDIRECT) {
        // Here we need to set only the next step
        builder.nextStep(policyOperation.objectiveOperation().id());
    }
    // Once, the fwd objective has completed its execution, we update the policiesOps map
    CompletableFuture<Objective> addNewFuture = new CompletableFuture<>();
    CompletableFuture<Objective> removeOldFuture = new CompletableFuture<>();
    if (log.isDebugEnabled()) {
        log.debug("Installing forwarding objective for dev: {}", deviceId);
    }
    ObjectiveContext addNewContext = new DefaultObjectiveContext((objective) -> {
        if (log.isDebugEnabled()) {
            log.debug("Forwarding objective for policy {} installed", trafficMatch.policyId());
        }
        addNewFuture.complete(objective);
    }, (objective, error) -> {
        log.warn("Failed to install forwarding objective for policy {}: {}", trafficMatch.policyId(), error);
        addNewFuture.complete(null);
    });
    ObjectiveContext removeOldContext = new DefaultObjectiveContext((objective) -> {
        if (log.isDebugEnabled()) {
            log.debug("Old forwarding objective for policy {} removed, update finished", trafficMatch.policyId());
        }
        removeOldFuture.complete(objective);
    }, (objective, error) -> {
        log.warn("Failed to remove old forwarding objective for policy {}: {}", trafficMatch.policyId(), error);
        removeOldFuture.complete(null);
    });
    // Context is not serializable
    ForwardingObjective serializableObjective = builder.add();
    flowObjectiveService.forward(deviceId, builder.add(addNewContext));
    addNewFuture.whenComplete((objective, ex) -> {
        if (ex != null) {
            log.error("Exception installing forwarding objective", ex);
        } else if (objective != null) {
            // base on priority, selector and metadata change
            if (oldTrafficOperation != null && oldTrafficOperation.objectiveOperation() != null && oldTrafficOperation.isInstall() && (oldTrafficOperation.objectiveOperation().priority() != serializableObjective.priority() || !((ForwardingObjective) oldTrafficOperation.objectiveOperation()).selector().equals(serializableObjective.selector()) || !((ForwardingObjective) oldTrafficOperation.objectiveOperation()).meta().equals(serializableObjective.meta()))) {
                ForwardingObjective oldFwdObj = (ForwardingObjective) oldTrafficOperation.objectiveOperation();
                ForwardingObjective.Builder oldBuilder = DefaultForwardingObjective.builder(oldFwdObj);
                flowObjectiveService.forward(deviceId, oldBuilder.remove(removeOldContext));
            } else {
                operations.computeIfPresent(trafficMatchKey.toString(), (k, v) -> {
                    if (!v.isDone() && v.isInstall()) {
                        v.isDone(true);
                        v.objectiveOperation(serializableObjective);
                    }
                    return v;
                });
            }
        }
    });
    removeOldFuture.whenComplete((objective, ex) -> {
        if (ex != null) {
            log.error("Exception removing old forwarding objective", ex);
        } else if (objective != null) {
            operations.computeIfPresent(trafficMatchKey.toString(), (k, v) -> {
                if (!v.isDone() && v.isInstall()) {
                    v.isDone(true);
                    v.objectiveOperation(serializableObjective);
                }
                return v;
            });
        }
    });
}
Also used : DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) Policy(org.onosproject.segmentrouting.policy.api.Policy) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) 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) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext)

Example 28 with Objective

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

the class DefaultL2TunnelHandler method deployPseudoWireTerm.

/**
 * Handles the tunnel termination, which consists in the creation
 * of a forwarding objective and a next objective.
 *
 * @param l2Tunnel   the tunnel to terminate
 * @param egress     the egress point
 * @param egressVlan the expected vlan at egress
 * @param direction  the direction
 * @return the result of the operation
 */
private Result deployPseudoWireTerm(L2Tunnel l2Tunnel, ConnectPoint egress, VlanId egressVlan, Direction direction, boolean oneHop) {
    log.debug("Started deploying termination objectives for pseudowire {} , direction {}.", l2Tunnel.tunnelId(), direction == FWD ? "forward" : "reverse");
    // We create the group relative to the termination.
    NextObjective.Builder nextObjectiveBuilder = createNextObjective(TERMINATION, egress, null, l2Tunnel, egress.deviceId(), oneHop, egressVlan);
    if (nextObjectiveBuilder == null) {
        return INTERNAL_ERROR;
    }
    TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(egressVlan).build();
    nextObjectiveBuilder.withMeta(metadata);
    int nextId = srManager.flowObjectiveService.allocateNextId();
    if (nextId < 0) {
        log.warn("Not able to allocate a next id for initiation");
        return INTERNAL_ERROR;
    }
    nextObjectiveBuilder.withId(nextId);
    String key = generateKey(l2Tunnel.tunnelId(), direction);
    l2TerminationNextObjStore.put(key, nextObjectiveBuilder.add());
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Termination l2 tunnel rule for {} populated", l2Tunnel.tunnelId()), (objective, error) -> {
        log.warn("Failed to populate termination l2 tunnel rule for {}: {}", l2Tunnel.tunnelId(), error);
        srManager.invalidateNextObj(objective.id());
    });
    NextObjective nextObjective = nextObjectiveBuilder.add(context);
    srManager.flowObjectiveService.next(egress.deviceId(), nextObjective);
    log.debug("Termination next objective for {} not found. Creating new NextObj with id={}", l2Tunnel.tunnelId(), nextObjective.id());
    // We create the flow relative to the termination.
    ForwardingObjective.Builder fwdBuilder = createTermFwdObjective(l2Tunnel.pwLabel(), l2Tunnel.tunnelId(), egress.port(), nextObjective.id());
    context = new DefaultObjectiveContext((objective) -> log.debug("FwdObj for tunnel termination {} populated", l2Tunnel.tunnelId()), (objective, error) -> log.warn("Failed to populate fwdrObj" + " for tunnel termination {} : {}", l2Tunnel.tunnelId(), error));
    srManager.flowObjectiveService.forward(egress.deviceId(), fwdBuilder.add(context));
    log.debug("Creating new FwdObj for termination NextObj with id={} for tunnel {}", nextId, l2Tunnel.tunnelId());
    return SUCCESS;
}
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) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 29 with Objective

use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.

the class VirtualNetworkPacketManager method pushRule.

/**
 * Pushes packet intercept flow rules to the device.
 *
 * @param device  the device to push the rules to
 * @param request the packet request
 */
private void pushRule(Device device, PacketRequest request) {
    if (!device.type().equals(Device.Type.VIRTUAL)) {
        return;
    }
    ForwardingObjective forwarding = createBuilder(request).add(new ObjectiveContext() {

        @Override
        public void onError(Objective objective, ObjectiveError error) {
            log.warn("Failed to install packet request {} to {}: {}", request, device.id(), error);
        }
    });
    objectiveService.forward(device.id(), forwarding);
}
Also used : ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError)

Example 30 with Objective

use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.

the class InOrderFlowObjectiveManager method dequeue.

/**
 * Dequeue flow objective. Execute the next flow objective in the queue, if any.
 *
 * @param deviceId Device ID
 * @param obj Flow objective
 * @param error ObjectiveError that triggers this dequeue. Null if this is not triggered by an error.
 */
private synchronized void dequeue(DeviceId deviceId, Objective obj, ObjectiveError error) {
    List<Objective> remaining;
    int priority = obj.priority();
    LogLevel logLevel = (obj.op() == Objective.Operation.VERIFY) ? LogLevel.TRACE : LogLevel.DEBUG;
    Tools.log(log, logLevel, "Dequeue {}", obj);
    if (obj instanceof FilteringObjective) {
        FilteringObjQueueKey k = new FilteringObjQueueKey(deviceId, priority, ((FilteringObjective) obj).key());
        if (!Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
            filtObjQueueHead.invalidate(k);
        }
        filtObjQueue.remove(k, obj);
        remaining = filtObjQueue.get(k);
    } else if (obj instanceof ForwardingObjective) {
        ForwardingObjQueueKey k = new ForwardingObjQueueKey(deviceId, priority, ((ForwardingObjective) obj).selector());
        if (!Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
            fwdObjQueueHead.invalidate(k);
        }
        fwdObjQueue.remove(k, obj);
        remaining = fwdObjQueue.get(k);
    } else if (obj instanceof NextObjective) {
        if (error != null) {
            // Remove pendingForwards and pendingNexts if next objective failed
            Set<PendingFlowObjective> removedForwards = pendingForwards.remove(obj.id());
            List<PendingFlowObjective> removedNexts = pendingNexts.remove(obj.id());
            if (removedForwards != null) {
                removedForwards.stream().map(PendingFlowObjective::flowObjective).forEach(pendingObj -> pendingObj.context().ifPresent(c -> c.onError(pendingObj, error)));
            }
            if (removedNexts != null) {
                removedNexts.stream().map(PendingFlowObjective::flowObjective).forEach(pendingObj -> pendingObj.context().ifPresent(c -> c.onError(pendingObj, error)));
            }
        }
        NextObjQueueKey k = new NextObjQueueKey(deviceId, obj.id());
        if (!Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
            nextObjQueueHead.invalidate(k);
        }
        nextObjQueue.remove(k, obj);
        remaining = nextObjQueue.get(k);
    } else {
        log.error("Unknown flow objective instance: {}", obj.getClass().getName());
        return;
    }
    log.trace("{} queue size {}", obj.getClass().getSimpleName(), remaining.size());
    // Submit the next one in the queue, if any
    if (remaining.size() > 0) {
        execute(deviceId, remaining.get(0));
    }
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ObjectiveEvent(org.onosproject.net.flowobjective.ObjectiveEvent) ListMultimap(com.google.common.collect.ListMultimap) Tools(org.onlab.util.Tools) IFOM_OBJ_TIMEOUT_MS_DEFAULT(org.onosproject.net.OsgiPropertyConstants.IFOM_OBJ_TIMEOUT_MS_DEFAULT) NextObjQueueKey(org.onosproject.net.flowobjective.NextObjQueueKey) ComponentContext(org.osgi.service.component.ComponentContext) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Multimaps(com.google.common.collect.Multimaps) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Component(org.osgi.service.component.annotations.Component) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) ObjectiveQueueKey(org.onosproject.net.flowobjective.ObjectiveQueueKey) Map(java.util.Map) NextObjective(org.onosproject.net.flowobjective.NextObjective) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) ForwardingObjQueueKey(org.onosproject.net.flowobjective.ForwardingObjQueueKey) LogLevel(org.onlab.util.Tools.LogLevel) ExecutorService(java.util.concurrent.ExecutorService) FlowObjectiveStoreDelegate(org.onosproject.net.flowobjective.FlowObjectiveStoreDelegate) Logger(org.slf4j.Logger) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Deactivate(org.osgi.service.component.annotations.Deactivate) IFOM_OBJ_TIMEOUT_MS(org.onosproject.net.OsgiPropertyConstants.IFOM_OBJ_TIMEOUT_MS) Set(java.util.Set) FilteringObjQueueKey(org.onosproject.net.flowobjective.FilteringObjQueueKey) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) RemovalListeners(com.google.common.cache.RemovalListeners) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Objective(org.onosproject.net.flowobjective.Objective) Optional(java.util.Optional) RemovalListener(com.google.common.cache.RemovalListener) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) DeviceId(org.onosproject.net.DeviceId) ForwardingObjQueueKey(org.onosproject.net.flowobjective.ForwardingObjQueueKey) FilteringObjQueueKey(org.onosproject.net.flowobjective.FilteringObjQueueKey) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) LogLevel(org.onlab.util.Tools.LogLevel) NextObjQueueKey(org.onosproject.net.flowobjective.NextObjQueueKey) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Objective(org.onosproject.net.flowobjective.Objective) 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