Search in sources :

Example 36 with FilteringObjective

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

Aggregations

FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)36 DefaultFilteringObjective (org.onosproject.net.flowobjective.DefaultFilteringObjective)22 Test (org.junit.Test)21 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)17 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)15 NextObjective (org.onosproject.net.flowobjective.NextObjective)15 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 Objective (org.onosproject.net.flowobjective.Objective)13 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)10 FlowRule (org.onosproject.net.flow.FlowRule)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 FlowObjectiveIntent (org.onosproject.net.intent.FlowObjectiveIntent)9 Intent (org.onosproject.net.intent.Intent)9 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)7 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)7 DefaultLink (org.onosproject.net.DefaultLink)6 DeviceId (org.onosproject.net.DeviceId)6 Link (org.onosproject.net.Link)6 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)6