Search in sources :

Example 51 with ForwardingObjective

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

the class LinkCollectionIntentFlowObjectiveCompiler method createSimpleNextObjective.

private List<Objective> createSimpleNextObjective(ForwardingInstructions instructions, LinkCollectionIntent intent) {
    List<Objective> objectives = Lists.newArrayList();
    ForwardingObjective forwardingObjective;
    NextObjective nextObjective;
    Integer nextId = flowObjectiveService.allocateNextId();
    forwardingObjective = buildForwardingObjective(instructions.selector(), nextId, intent.priority());
    DefaultNextObjective.Builder nxBuilder = DefaultNextObjective.builder();
    nextObjective = nxBuilder.withId(nextId).withMeta(instructions.selector()).addTreatment(instructions.treatment()).withType(NextObjective.Type.SIMPLE).fromApp(appId).makePermanent().withPriority(intent.priority()).add();
    objectives.add(forwardingObjective);
    objectives.add(nextObjective);
    return objectives;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) 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) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective)

Example 52 with ForwardingObjective

use of org.onosproject.net.flowobjective.ForwardingObjective 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)

Example 53 with ForwardingObjective

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

the class FlowObjectiveCompositionTree method updateForwardComposition.

protected ForwardUpdateTable updateForwardComposition(ForwardingObjective forwardingObjective) {
    ForwardUpdateTable leftUpdates = this.leftChild.updateForwardNode(forwardingObjective);
    ForwardUpdateTable rightUpdates = this.rightChild.updateForwardNode(forwardingObjective);
    List<ForwardingObjective> addUpdates = new ArrayList<>();
    List<ForwardingObjective> removeUpdates = new ArrayList<>();
    // Handle ADD
    if (this.operator == FlowObjectiveCompositionManager.PolicyOperator.Parallel || this.operator == FlowObjectiveCompositionManager.PolicyOperator.Sequential) {
        for (ForwardingObjective fo1 : leftUpdates.addObjectives) {
            for (ForwardingObjective fo2 : this.rightChild.forwardTable.getForwardingObjectives()) {
                ForwardingObjective composedFo = null;
                if (this.operator == FlowObjectiveCompositionManager.PolicyOperator.Parallel) {
                    composedFo = FlowObjectiveCompositionUtil.composeParallel(fo1, fo2);
                } else {
                    composedFo = FlowObjectiveCompositionUtil.composeSequential(fo1, fo2, this.priorityMultiplier);
                }
                if (composedFo != null) {
                    addUpdates.add(composedFo);
                    this.leftChild.forwardTable.addGeneratedParentForwardingObjective(fo1, composedFo);
                    this.rightChild.forwardTable.addGeneratedParentForwardingObjective(fo2, composedFo);
                }
            }
        }
        Collection<ForwardingObjective> leftTableWithoutAdd = FlowObjectiveCompositionUtil.minusForwardingObjectives(this.leftChild.forwardTable.getForwardingObjectives(), leftUpdates.addObjectives);
        for (ForwardingObjective fo1 : leftTableWithoutAdd) {
            for (ForwardingObjective fo2 : rightUpdates.addObjectives) {
                ForwardingObjective composedFo = null;
                if (this.operator == FlowObjectiveCompositionManager.PolicyOperator.Parallel) {
                    composedFo = FlowObjectiveCompositionUtil.composeParallel(fo1, fo2);
                } else {
                    composedFo = FlowObjectiveCompositionUtil.composeSequential(fo1, fo2, this.priorityMultiplier);
                }
                if (composedFo != null) {
                    addUpdates.add(composedFo);
                    this.leftChild.forwardTable.addGeneratedParentForwardingObjective(fo1, composedFo);
                    this.rightChild.forwardTable.addGeneratedParentForwardingObjective(fo2, composedFo);
                }
            }
        }
    } else {
        for (ForwardingObjective fo : leftUpdates.addObjectives) {
            ForwardingObjective composedFo = FlowObjectiveCompositionUtil.composeOverride(fo, this.priorityAddend);
            addUpdates.add(composedFo);
            this.leftChild.forwardTable.addGeneratedParentForwardingObjective(fo, composedFo);
        }
        for (ForwardingObjective fo : rightUpdates.addObjectives) {
            ForwardingObjective composedFo = FlowObjectiveCompositionUtil.composeOverride(fo, 0);
            addUpdates.add(composedFo);
            this.rightChild.forwardTable.addGeneratedParentForwardingObjective(fo, composedFo);
        }
    }
    // Handle REMOVE
    for (ForwardingObjective fo : leftUpdates.removeObjectives) {
        List<ForwardingObjective> fos = this.leftChild.forwardTable.getGeneratedParentForwardingObjectiveForRemove(fo);
        removeUpdates.addAll(fos);
    }
    this.leftChild.forwardTable.deleteGeneratedParentForwardingObjective(leftUpdates.removeObjectives);
    for (ForwardingObjective fo : rightUpdates.removeObjectives) {
        List<ForwardingObjective> fos = this.rightChild.forwardTable.getGeneratedParentForwardingObjectiveForRemove(fo);
        removeUpdates.addAll(fos);
    }
    this.rightChild.forwardTable.deleteGeneratedParentForwardingObjective(rightUpdates.removeObjectives);
    ForwardUpdateTable updates = new ForwardUpdateTable();
    updates.addUpdateTable(this.forwardTable.updateForward(addUpdates));
    updates.addUpdateTable(this.forwardTable.updateForward(removeUpdates));
    return updates;
}
Also used : ArrayList(java.util.ArrayList) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective)

Example 54 with ForwardingObjective

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

the class FlowObjectiveIntentInstaller method buildObjectiveContexts.

/**
 * Builds all objective contexts for a given flow objective Intent with given
 * operation.
 *
 * @param intent the flow objective Intent
 * @param direction the operation of this Intent
 * @return all objective context of the Intent with given operation
 */
private Set<FlowObjectiveInstallationContext> buildObjectiveContexts(FlowObjectiveIntent intent, Direction direction) {
    Objects.requireNonNull(intent);
    Objects.requireNonNull(direction);
    Set<FlowObjectiveInstallationContext> contexts = Sets.newHashSet();
    int size = intent.objectives().size();
    List<Objective> objectives = intent.objectives();
    List<DeviceId> deviceIds = intent.devices();
    if (direction == ADD) {
        // The flow objective system will handle the installation order
        for (int i = 0; i < size; i++) {
            Objective objective = objectives.get(i);
            DeviceId deviceId = deviceIds.get(i);
            FlowObjectiveInstallationContext ctx = buildObjectiveContext(objective, deviceId, direction);
            contexts.add(ctx);
        }
        return contexts;
    } else {
        // basic idea is to chain objective contexts
        for (int i = 0; i < size; i++) {
            Objective objective = intent.objectives().get(i);
            DeviceId deviceId = intent.devices().get(i);
            if (objective instanceof FilteringObjective) {
                // don't need to care ordering of filtering objective
                FlowObjectiveInstallationContext ctx = buildObjectiveContext(objective, deviceId, direction);
                contexts.add(ctx);
            } else if (objective instanceof NextObjective) {
            // need to removed after forwarding objective
            // nothing to do here
            } else if (objective instanceof ForwardingObjective) {
                // forwarding objective, also find next objective if
                // exist
                FlowObjectiveInstallationContext fwdCtx = buildObjectiveContext(objective, deviceId, direction);
                ForwardingObjective fwd = (ForwardingObjective) objective;
                NextObjective nxt = null;
                Integer nextId = fwd.nextId();
                if (nextId != null) {
                    for (int j = 0; j < size; j++) {
                        if (objectives.get(j).id() == nextId) {
                            nxt = (NextObjective) objectives.get(j);
                            break;
                        }
                    }
                    // if a next objective exists in the Intent
                    if (nxt != null) {
                        FlowObjectiveInstallationContext nxtCtx = buildObjectiveContext(nxt, deviceId, direction);
                        fwdCtx.nextContext(nxtCtx);
                    }
                }
                contexts.add(fwdCtx);
            } else {
                // possible here?
                log.warn(UNSUPPORT_OBJ, objective);
            }
        }
    }
    return contexts;
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Objective(org.onosproject.net.flowobjective.Objective) DeviceId(org.onosproject.net.DeviceId) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective)

Example 55 with ForwardingObjective

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

the class ForwardTable method getGeneratedParentForwardingObjectiveForRemove.

public List<ForwardingObjective> getGeneratedParentForwardingObjectiveForRemove(ForwardingObjective child) {
    List<ForwardingObjective> fos = this.generatedParentForwardingObjectiveMap.get(forwardingObjectiveHash(child));
    List<ForwardingObjective> removeFos = new ArrayList<>();
    for (ForwardingObjective fo : fos) {
        removeFos.add(DefaultForwardingObjective.builder().fromApp(fo.appId()).makePermanent().withFlag(fo.flag()).withPriority(fo.priority()).withSelector(fo.selector()).withTreatment(fo.treatment()).remove());
    }
    return removeFos;
}
Also used : ArrayList(java.util.ArrayList) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective)

Aggregations

ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)88 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)57 TrafficSelector (org.onosproject.net.flow.TrafficSelector)50 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)48 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)38 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)37 Test (org.junit.Test)33 NextObjective (org.onosproject.net.flowobjective.NextObjective)32 Objective (org.onosproject.net.flowobjective.Objective)32 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)28 List (java.util.List)24 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)20 FlowRule (org.onosproject.net.flow.FlowRule)20 DeviceId (org.onosproject.net.DeviceId)18 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)18 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)16 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)15 GroupDescription (org.onosproject.net.group.GroupDescription)15 PiAction (org.onosproject.net.pi.runtime.PiAction)14 ArrayList (java.util.ArrayList)13