Search in sources :

Example 21 with ObjectiveContext

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

the class XconnectManager method populateFwd.

/**
 * Populates bridging forwarding objectives for given XConnect.
 *
 * @param key    XConnect store key
 * @param nextId next objective id
 */
private void populateFwd(XconnectKey key, int nextId) {
    ForwardingObjective.Builder fwdObjBuilder = fwdObjBuilder(key, nextId);
    ObjectiveContext fwdContext = new DefaultObjectiveContext((objective) -> log.debug("XConnect FwdObj for {} populated", key), (objective, error) -> log.warn("Failed to populate XConnect FwdObj for {}: {}", key, error));
    flowObjectiveService.forward(key.deviceId(), fwdObjBuilder.add(fwdContext));
}
Also used : 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 22 with ObjectiveContext

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

the class XconnectManager method populateNext.

/**
 * Populates next objectives for given XConnect.
 *
 * @param key       XConnect store key
 * @param endpoints XConnect endpoints
 * @return next id
 */
private int populateNext(XconnectKey key, Set<XconnectEndpoint> endpoints) {
    int nextId = Versioned.valueOrElse(xconnectNextObjStore.get(key), -1);
    if (nextId != -1) {
        log.debug("NextObj for {} found, id={}", key, nextId);
        return nextId;
    } else {
        NextObjective.Builder nextObjBuilder = nextObjBuilder(key, endpoints);
        if (nextObjBuilder == null) {
            log.warn("Fail to populate {}: {}", key, ERROR_NEXT_OBJ_BUILDER);
            return -1;
        }
        ObjectiveContext nextContext = new DefaultObjectiveContext(// To serialize this with kryo
        (Serializable & Consumer<Objective>) (objective) -> log.debug("XConnect NextObj for {} added", key), (Serializable & BiConsumer<Objective, ObjectiveError>) (objective, error) -> {
            log.warn("Failed to add XConnect NextObj for {}: {}", key, error);
            srService.invalidateNextObj(objective.id());
        });
        NextObjective nextObj = nextObjBuilder.add(nextContext);
        flowObjectiveService.next(key.deviceId(), nextObj);
        xconnectNextObjStore.put(key, nextObj.id());
        log.debug("NextObj for {} not found. Creating new NextObj with id={}", key, nextObj.id());
        return nextObj.id();
    }
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) 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) Serializable(java.io.Serializable) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) BiConsumer(java.util.function.BiConsumer) Consumer(java.util.function.Consumer) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ConnectPoint(org.onosproject.net.ConnectPoint) XconnectLoadBalancerEndpoint(org.onosproject.segmentrouting.xconnect.api.XconnectLoadBalancerEndpoint) XconnectEndpoint(org.onosproject.segmentrouting.xconnect.api.XconnectEndpoint) XconnectPortEndpoint(org.onosproject.segmentrouting.xconnect.api.XconnectPortEndpoint) BiConsumer(java.util.function.BiConsumer)

Example 23 with ObjectiveContext

use of org.onosproject.net.flowobjective.ObjectiveContext 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 24 with ObjectiveContext

use of org.onosproject.net.flowobjective.ObjectiveContext 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 25 with ObjectiveContext

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

the class DefaultL2TunnelHandler method deployPseudoWireInit.

/**
 * Handles the tunnel establishment which consists in
 * create the next objectives related to the initiation.
 *
 * @param l2Tunnel  the tunnel to deploy
 * @param ingress   the ingress connect point
 * @param egress    the egress connect point
 * @param direction the direction of the pw
 * @param nextHop next hop of the initiation point
 * @param oneHop if this pseudowire has only one link
 * @param termVlanId the termination vlan id
 * @return the result of the operation
 */
private Result deployPseudoWireInit(L2Tunnel l2Tunnel, ConnectPoint ingress, ConnectPoint egress, Direction direction, Link nextHop, boolean oneHop, VlanId termVlanId) {
    log.debug("Started deploying init next objectives for pseudowire {} for tunnel {} -> {}.", l2Tunnel.tunnelId(), ingress, egress);
    if (nextHop == null) {
        log.warn("No path between ingress and egress connection points for tunnel {}", l2Tunnel.tunnelId());
        return WRONG_PARAMETERS;
    }
    // We create the next objective without the metadata
    // context and id. We check if it already exists in the
    // store. If not we store as it is in the store.
    NextObjective.Builder nextObjectiveBuilder = createNextObjective(INITIATION, nextHop.src(), nextHop.dst(), l2Tunnel, egress.deviceId(), oneHop, termVlanId);
    if (nextObjectiveBuilder == null) {
        return INTERNAL_ERROR;
    }
    // We set the metadata. We will use this metadata
    // to inform the driver we are doing a l2 tunnel.
    TrafficSelector metadata = DefaultTrafficSelector.builder().matchTunnelId(l2Tunnel.tunnelId()).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);
    l2InitiationNextObjStore.put(key, nextObjectiveBuilder.add());
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Initiation l2 tunnel rule for {} populated", l2Tunnel.tunnelId()), (objective, error) -> {
        log.warn("Failed to populate Initiation l2 tunnel rule for {}: {}", l2Tunnel.tunnelId(), error);
        srManager.invalidateNextObj(objective.id());
    });
    NextObjective nextObjective = nextObjectiveBuilder.add(context);
    srManager.flowObjectiveService.next(ingress.deviceId(), nextObjective);
    log.debug("Initiation next objective for {} not found. Creating new NextObj with id={}", l2Tunnel.tunnelId(), nextObjective.id());
    Result result = SUCCESS;
    result.setNextId(nextObjective.id());
    return result;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) 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) ConnectPoint(org.onosproject.net.ConnectPoint) Result(org.onosproject.segmentrouting.pwaas.L2TunnelHandler.Result)

Aggregations

ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)69 DefaultObjectiveContext (org.onosproject.net.flowobjective.DefaultObjectiveContext)57 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)45 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)41 NextObjective (org.onosproject.net.flowobjective.NextObjective)41 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)37 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)35 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)35 TrafficSelector (org.onosproject.net.flow.TrafficSelector)35 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)35 Objective (org.onosproject.net.flowobjective.Objective)34 ConnectPoint (org.onosproject.net.ConnectPoint)33 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)27 DefaultFilteringObjective (org.onosproject.net.flowobjective.DefaultFilteringObjective)26 CompletableFuture (java.util.concurrent.CompletableFuture)21 MacAddress (org.onlab.packet.MacAddress)19 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)19 DeviceId (org.onosproject.net.DeviceId)17 Set (java.util.Set)16 Lists (com.google.common.collect.Lists)15