Search in sources :

Example 21 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)

Example 22 with Objective

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

the class InOrderFlowObjectiveManager method process.

/**
 * Processes given objective on given device.
 * Objectives submitted through this method are guaranteed to be executed in order.
 *
 * @param deviceId Device ID
 * @param originalObjective Flow objective to be executed
 */
private void process(DeviceId deviceId, Objective originalObjective) {
    // Inject ObjectiveContext such that we can get notified when it is completed
    Objective.Builder objBuilder = originalObjective.copy();
    Optional<ObjectiveContext> originalContext = originalObjective.context();
    ObjectiveContext context = new InOrderObjectiveContext(deviceId, originalContext.orElse(null));
    // Preserve Objective.Operation
    Objective objective;
    switch(originalObjective.op()) {
        case ADD:
            objective = objBuilder.add(context);
            break;
        case ADD_TO_EXISTING:
            objective = ((NextObjective.Builder) objBuilder).addToExisting(context);
            break;
        case REMOVE:
            objective = objBuilder.remove(context);
            break;
        case REMOVE_FROM_EXISTING:
            objective = ((NextObjective.Builder) objBuilder).removeFromExisting(context);
            break;
        case MODIFY:
            objective = ((NextObjective.Builder) objBuilder).modify(context);
            break;
        case VERIFY:
            objective = ((NextObjective.Builder) objBuilder).verify(context);
            break;
        default:
            log.error("Unknown flow objecitve operation {}", originalObjective.op());
            return;
    }
    enqueue(deviceId, objective);
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Objective(org.onosproject.net.flowobjective.Objective) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext)

Example 23 with Objective

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

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

the class LinkCollectionIntentFlowObjectiveCompiler method createRules.

@Override
protected List<Objective> createRules(LinkCollectionIntent intent, DeviceId deviceId, Set<PortNumber> inPorts, Set<PortNumber> outPorts, Map<ConnectPoint, Identifier<?>> labels) {
    List<Objective> objectives = new ArrayList<>(inPorts.size() * 2);
    /*
         * Looking for the encapsulation constraint
         */
    Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
    inPorts.forEach(inPort -> {
        ForwardingInstructions instructions = this.createForwardingInstruction(encapConstraint, intent, inPort, outPorts, deviceId, labels);
        Set<TrafficTreatment> treatmentsWithDifferentPort = Sets.newHashSet();
        TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
        for (Instruction inst : instructions.treatment().allInstructions()) {
            if (inst.type() == OUTPUT) {
                treatmentBuilder.add(inst);
                treatmentsWithDifferentPort.add(treatmentBuilder.build());
                treatmentBuilder = DefaultTrafficTreatment.builder();
            } else {
                treatmentBuilder.add(inst);
            }
        }
        EthCriterion ethDst = (EthCriterion) intent.selector().getCriterion(Criterion.Type.ETH_DST);
        boolean broadcastObjective = ethDst != null && (ethDst.mac().isBroadcast() || ethDst.mac().isMulticast());
        FilteringObjective filteringObjective = buildFilteringObjective(intent, instructions.selector(), deviceId, inPort);
        if (filteringObjective != null) {
            objectives.add(filteringObjective);
        }
        if (treatmentsWithDifferentPort.size() < 2 && !broadcastObjective) {
            objectives.addAll(createSimpleNextObjective(instructions, intent));
        } else {
            objectives.addAll(createBroadcastObjective(instructions, treatmentsWithDifferentPort, intent));
        }
    });
    return objectives;
}
Also used : EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) ArrayList(java.util.ArrayList) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instruction(org.onosproject.net.flow.instructions.Instruction) 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) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 25 with Objective

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

the class LinkCollectionIntentFlowObjectiveCompiler method compile.

@Override
public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) {
    SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
    SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
    Map<ConnectPoint, Identifier<?>> labels = ImmutableMap.of();
    Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
    computePorts(intent, inputPorts, outputPorts);
    if (encapConstraint.isPresent()) {
        labels = labelAllocator.assignLabelToPorts(intent.links(), intent.key(), encapConstraint.get().encapType(), encapConstraint.get().suggestedIdentifier());
    }
    ImmutableList.Builder<Intent> intentList = ImmutableList.builder();
    if (this.isDomainProcessingEnabled(intent)) {
        intentList.addAll(this.getDomainIntents(intent, domainService));
    }
    List<Objective> objectives = new ArrayList<>();
    List<DeviceId> devices = new ArrayList<>();
    for (DeviceId deviceId : outputPorts.keySet()) {
        // add only objectives that are not inside of a domain
        if (LOCAL.equals(domainService.getDomain(deviceId))) {
            List<Objective> deviceObjectives = createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId), labels);
            deviceObjectives.forEach(objective -> {
                objectives.add(objective);
                devices.add(deviceId);
            });
        }
    }
    // if any objectives have been created
    if (!objectives.isEmpty()) {
        intentList.add(new FlowObjectiveIntent(appId, intent.key(), devices, objectives, intent.resources(), intent.resourceGroup()));
    }
    return intentList.build();
}
Also used : EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) DeviceId(org.onosproject.net.DeviceId) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) 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) Identifier(org.onlab.util.Identifier) PortNumber(org.onosproject.net.PortNumber)

Aggregations

Objective (org.onosproject.net.flowobjective.Objective)37 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)35 NextObjective (org.onosproject.net.flowobjective.NextObjective)26 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)23 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)20 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)19 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)19 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)16 Test (org.junit.Test)15 DeviceId (org.onosproject.net.DeviceId)14 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)12 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)12 DefaultFilteringObjective (org.onosproject.net.flowobjective.DefaultFilteringObjective)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)8 FlowObjectiveIntent (org.onosproject.net.intent.FlowObjectiveIntent)8 Collection (java.util.Collection)7 Set (java.util.Set)7