Search in sources :

Example 36 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project fabric-tna by stratum.

the class FabricPipeliner method handleVerify.

private ObjectiveError handleVerify(NextObjective nextObjective) {
    Map<GroupBucket, FlowRule> bucketsToFlows = getBucketToFlowMapping(nextObjective);
    if (bucketsToFlows.isEmpty() && !nextObjective.nextTreatments().isEmpty()) {
        log.warn("VERIFY failed due to translation error, bucketsToFlows is empty");
        return ObjectiveError.BADPARAMS;
    }
    if (log.isTraceEnabled()) {
        log.trace("Mapping bucketsToFlows {} has been generated ", bucketsToFlows);
    }
    GroupKey groupKey = nextTranslator.getGroupKey(nextObjective);
    if (groupKey == null) {
        log.warn("VERIFY failed due to translation error, unable to determine group key");
        return ObjectiveError.BADPARAMS;
    }
    Group groupFromStore = groupService.getGroup(deviceId, groupKey);
    if (groupFromStore == null) {
        log.warn("VERIFY failed due to missing group in the store");
        return ObjectiveError.GROUPMISSING;
    }
    // Looking for duplicate buckets - remove them by using a set and comparing size after/before
    Set<GroupBucket> bucketsFromStore = Sets.newHashSet(groupFromStore.buckets().buckets());
    if (groupFromStore.buckets().buckets().size() > bucketsFromStore.size()) {
        log.warn("Duplicated buckets detected in device:{}, nextId:{}, before-size" + ":{} after-size:{} .. correcting", deviceId, nextObjective.id(), groupFromStore.buckets().buckets().size(), bucketsFromStore.size());
        final GroupBuckets bucketToSet = new GroupBuckets(Lists.newArrayList(bucketsFromStore));
        groupService.setBucketsForGroup(deviceId, groupKey, bucketToSet, groupKey, nextObjective.appId());
        // Forge temporary the group to avoid race condition with the store
        groupFromStore = new DefaultGroup(groupFromStore.id(), deviceId, groupFromStore.type(), bucketToSet);
    }
    // Looking for buckets missing in the group but defined in the next
    Map<GroupBucket, FlowRule> toAdd = Maps.newHashMap();
    for (Map.Entry<GroupBucket, FlowRule> entry : bucketsToFlows.entrySet()) {
        if (!groupFromStore.buckets().buckets().contains(entry.getKey())) {
            toAdd.put(entry.getKey(), entry.getValue());
        }
    }
    // Looking for buckets missing in the next but defined in the group
    // FIXME SDFAB-250 we cannot remove associated egress flows
    List<GroupBucket> toRemove = Lists.newArrayList();
    groupFromStore.buckets().buckets().forEach(bucket -> {
        if (!bucketsToFlows.containsKey(bucket)) {
            toRemove.add(bucket);
        }
    });
    if (!toAdd.isEmpty() || !toRemove.isEmpty()) {
        log.warn("Mismatch detected in device:{}, nextId:{}, groupFromTranslation-size:{} " + "groupFromStore-size:{} toAdd-size:{} toRemove-size: {} .. correcting", deviceId, nextObjective.id(), bucketsToFlows.size(), groupFromStore.buckets().buckets().size(), toAdd.size(), toRemove.size());
    }
    if (!toAdd.isEmpty()) {
        if (log.isTraceEnabled()) {
            log.trace("Adding missing buckets {} and flows {}", toAdd.keySet(), toAdd.values());
        }
        final FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
        final FlowRule dummyFlow = getDummyFlow(nextObjective);
        toAdd.values().stream().filter(flowRule -> !flowRule.equals(dummyFlow)).forEach(ops::add);
        final GroupBuckets bucketsToAdd = new GroupBuckets(Lists.newArrayList(toAdd.keySet()));
        groupService.addBucketsToGroup(deviceId, groupKey, bucketsToAdd, groupKey, nextObjective.appId());
        flowRuleService.apply(ops.build());
    }
    if (!toRemove.isEmpty()) {
        if (log.isTraceEnabled()) {
            log.trace("Removing stale buckets {}", toRemove);
        }
        final GroupBuckets bucketsToRemove = new GroupBuckets(toRemove);
        groupService.removeBucketsFromGroup(deviceId, groupKey, bucketsToRemove, groupKey, nextObjective.appId());
    }
    return null;
}
Also used : DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) FabricUtils.outputPort(org.stratumproject.fabric.tna.behaviour.FabricUtils.outputPort) FlowRuleService(org.onosproject.net.flow.FlowRuleService) SharedExecutors(org.onlab.util.SharedExecutors) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) RECIRC_PORTS(org.stratumproject.fabric.tna.Constants.RECIRC_PORTS) V1MODEL_RECIRC_PORT(org.stratumproject.fabric.tna.Constants.V1MODEL_RECIRC_PORT) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) FabricCapabilities(org.stratumproject.fabric.tna.behaviour.FabricCapabilities) PKT_IN_MIRROR_SESSION_ID(org.stratumproject.fabric.tna.Constants.PKT_IN_MIRROR_SESSION_ID) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Collection(java.util.Collection) Set(java.util.Set) FlowObjectiveStore(org.onosproject.net.flowobjective.FlowObjectiveStore) Constants(org.stratumproject.fabric.tna.Constants) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) DEFAULT_VLAN(org.stratumproject.fabric.tna.Constants.DEFAULT_VLAN) PORT_TYPE_INTERNAL(org.stratumproject.fabric.tna.Constants.PORT_TYPE_INTERNAL) Objects(java.util.Objects) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) FWD_IPV4_ROUTING(org.stratumproject.fabric.tna.Constants.FWD_IPV4_ROUTING) Pipeliner(org.onosproject.net.behaviour.Pipeliner) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) ZERO(org.stratumproject.fabric.tna.Constants.ZERO) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) NextGroup(org.onosproject.net.behaviour.NextGroup) GroupKey(org.onosproject.net.group.GroupKey) P4InfoConstants(org.stratumproject.fabric.tna.behaviour.P4InfoConstants) Group(org.onosproject.net.group.Group) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultGroupBucket.createCloneGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createCloneGroupBucket) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) FWD_MPLS(org.stratumproject.fabric.tna.Constants.FWD_MPLS) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Logger(org.slf4j.Logger) GroupService(org.onosproject.net.group.GroupService) AbstractFabricHandlerBehavior(org.stratumproject.fabric.tna.behaviour.AbstractFabricHandlerBehavior) Maps(com.google.common.collect.Maps) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction) KRYO(org.stratumproject.fabric.tna.behaviour.FabricUtils.KRYO) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Collections(java.util.Collections) ONE(org.stratumproject.fabric.tna.Constants.ONE) DefaultGroup(org.onosproject.net.group.DefaultGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket.createCloneGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createCloneGroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Map(java.util.Map)

Example 37 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project fabric-tna by stratum.

the class FabricPipeliner method getBucketToFlowMapping.

private Map<GroupBucket, FlowRule> getBucketToFlowMapping(NextObjective nextObjective) {
    Map<GroupBucket, FlowRule> mapping = Maps.newHashMap();
    NextObjective newNextObjective;
    ObjectiveTranslation result;
    FlowRule dummyFlow = getDummyFlow(nextObjective);
    FlowRule egFlow;
    GroupBucket groupBucket;
    GroupDescription group;
    for (NextTreatment nextTreatment : nextObjective.nextTreatments()) {
        newNextObjective = DefaultNextObjective.builder().withId(nextObjective.id()).withType(nextObjective.type()).fromApp(nextObjective.appId()).withMeta(nextObjective.meta()).addTreatment(nextTreatment).verify();
        result = nextTranslator.translate(newNextObjective);
        if ((result.groups().isEmpty() && result.flowRules().isEmpty()) || result.groups().size() > 1) {
            return Collections.emptyMap();
        }
        group = result.groups().iterator().next();
        egFlow = result.flowRules().stream().filter(flowRule -> flowRule.table().equals(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN)).findFirst().orElse(null);
        if (group.buckets().buckets().isEmpty() || group.buckets().buckets().size() > 1) {
            return Collections.emptyMap();
        }
        groupBucket = group.buckets().buckets().iterator().next();
        if (egFlow == null) {
            mapping.put(groupBucket, dummyFlow);
        } else {
            mapping.put(groupBucket, egFlow);
        }
    }
    return mapping;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) FabricUtils.outputPort(org.stratumproject.fabric.tna.behaviour.FabricUtils.outputPort) FlowRuleService(org.onosproject.net.flow.FlowRuleService) SharedExecutors(org.onlab.util.SharedExecutors) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) RECIRC_PORTS(org.stratumproject.fabric.tna.Constants.RECIRC_PORTS) V1MODEL_RECIRC_PORT(org.stratumproject.fabric.tna.Constants.V1MODEL_RECIRC_PORT) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) FabricCapabilities(org.stratumproject.fabric.tna.behaviour.FabricCapabilities) PKT_IN_MIRROR_SESSION_ID(org.stratumproject.fabric.tna.Constants.PKT_IN_MIRROR_SESSION_ID) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Collection(java.util.Collection) Set(java.util.Set) FlowObjectiveStore(org.onosproject.net.flowobjective.FlowObjectiveStore) Constants(org.stratumproject.fabric.tna.Constants) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) DEFAULT_VLAN(org.stratumproject.fabric.tna.Constants.DEFAULT_VLAN) PORT_TYPE_INTERNAL(org.stratumproject.fabric.tna.Constants.PORT_TYPE_INTERNAL) Objects(java.util.Objects) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) FWD_IPV4_ROUTING(org.stratumproject.fabric.tna.Constants.FWD_IPV4_ROUTING) Pipeliner(org.onosproject.net.behaviour.Pipeliner) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) ZERO(org.stratumproject.fabric.tna.Constants.ZERO) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) NextGroup(org.onosproject.net.behaviour.NextGroup) GroupKey(org.onosproject.net.group.GroupKey) P4InfoConstants(org.stratumproject.fabric.tna.behaviour.P4InfoConstants) Group(org.onosproject.net.group.Group) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultGroupBucket.createCloneGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createCloneGroupBucket) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) FWD_MPLS(org.stratumproject.fabric.tna.Constants.FWD_MPLS) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Logger(org.slf4j.Logger) GroupService(org.onosproject.net.group.GroupService) AbstractFabricHandlerBehavior(org.stratumproject.fabric.tna.behaviour.AbstractFabricHandlerBehavior) Maps(com.google.common.collect.Maps) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction) KRYO(org.stratumproject.fabric.tna.behaviour.FabricUtils.KRYO) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Collections(java.util.Collections) ONE(org.stratumproject.fabric.tna.Constants.ONE) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket.createCloneGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createCloneGroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment)

Example 38 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project fabric-tna by stratum.

the class NextObjectiveTranslator method nextMpls.

private void nextMpls(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
    // Next objective can contain only one mpls push and one mpls label
    // instruction. Pipeliner does not support other configurations.
    final List<List<ModMplsLabelInstruction>> mplsInstructions = defaultNextTreatments(obj.nextTreatments(), false).stream().map(defaultNextTreatment -> l2Instructions(defaultNextTreatment.treatment(), MPLS_LABEL).stream().map(v -> (ModMplsLabelInstruction) v).collect(Collectors.toList())).filter(l -> !l.isEmpty()).collect(Collectors.toList());
    if (mplsInstructions.isEmpty()) {
        // No need to apply next mpls table
        return;
    }
    // We expect one mpls label for each treatment and the label has to be the same
    final Set<MplsLabel> mplsLabels = mplsInstructions.stream().flatMap(Collection::stream).map(ModMplsLabelInstruction::label).collect(Collectors.toSet());
    if (obj.nextTreatments().size() != mplsInstructions.size() || mplsLabels.size() != 1) {
        throw new FabricPipelinerException("Inconsistent MPLS_LABEL instructions, cannot process " + "next_mpls rule. It is required that all " + "treatments have the same MPLS_LABEL instructions.");
    }
    final TrafficSelector selector = nextIdSelector(obj.id());
    final TrafficTreatment treatment = DefaultTrafficTreatment.builder().setMpls(mplsLabels.iterator().next()).build();
    resultBuilder.addFlowRule(flowRule(obj, P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_MPLS, selector, treatment));
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) FabricUtils.criterion(org.stratumproject.fabric.tna.behaviour.FabricUtils.criterion) FabricUtils.l2Instruction(org.stratumproject.fabric.tna.behaviour.FabricUtils.l2Instruction) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) FabricUtils.outputPort(org.stratumproject.fabric.tna.behaviour.FabricUtils.outputPort) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) NextObjective(org.onosproject.net.flowobjective.NextObjective) MPLS_LABEL(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.MPLS_LABEL) FabricCapabilities(org.stratumproject.fabric.tna.behaviour.FabricCapabilities) FabricUtils(org.stratumproject.fabric.tna.behaviour.FabricUtils) Collection(java.util.Collection) Set(java.util.Set) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) FabricUtils.l2Instructions(org.stratumproject.fabric.tna.behaviour.FabricUtils.l2Instructions) VLAN_POP(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_POP) ModMplsLabelInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) GroupBucket(org.onosproject.net.group.GroupBucket) GroupKey(org.onosproject.net.group.GroupKey) P4InfoConstants(org.stratumproject.fabric.tna.behaviour.P4InfoConstants) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) VLAN_ID(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_ID) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MplsLabel(org.onlab.packet.MplsLabel) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PiAction(org.onosproject.net.pi.runtime.PiAction) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) KRYO(org.stratumproject.fabric.tna.behaviour.FabricUtils.KRYO) Objective(org.onosproject.net.flowobjective.Objective) Collections(java.util.Collections) MplsLabel(org.onlab.packet.MplsLabel) Collection(java.util.Collection) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) List(java.util.List) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 39 with NextObjective

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

the class AbstractHPPipeline method forward.

@Override
public void forward(ForwardingObjective fwd) {
    if (fwd.treatment() != null) {
        /* If UNSUPPORTED features included in ForwardingObjective a warning message is generated.
             * FlowRule is anyway sent to the device, device will reply with an OFP_ERROR.
             * Moreover, checkUnSupportedFeatures function generates further warnings specifying
             * each unsupported feature.
             */
        if (checkUnSupportedFeatures(fwd.selector(), fwd.treatment())) {
            log.warn("HP Driver - specified ForwardingObjective contains UNSUPPORTED FEATURES");
        }
        // Deal with SPECIFIC and VERSATILE in the same manner.
        // Create the FlowRule starting from the ForwardingObjective
        FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().forDevice(deviceId).withSelector(fwd.selector()).withTreatment(fwd.treatment()).withPriority(fwd.priority()).fromApp(fwd.appId());
        // Determine the table to be used depends on selector, treatment and specific switch hardware
        ruleBuilder.forTable(tableIdForForwardingObjective(fwd.selector(), fwd.treatment()));
        if (fwd.permanent()) {
            ruleBuilder.makePermanent();
        } else {
            ruleBuilder.makeTemporary(fwd.timeout());
        }
        log.debug("HP Driver - installing ForwadingObjective arrived with treatment {}", fwd);
        installObjective(ruleBuilder, fwd);
    } else {
        NextObjective nextObjective;
        NextGroup next;
        TrafficTreatment treatment;
        if (fwd.op() == ADD) {
            // Give a try to the cache. Doing an operation
            // on the store seems to be very expensive.
            nextObjective = pendingAddNext.getIfPresent(fwd.nextId());
            // We will try with the store
            if (nextObjective == null) {
                next = flowObjectiveStore.getNextGroup(fwd.nextId());
                // the treatment in order to re-build the flow rule.
                if (next == null) {
                    fwd.context().ifPresent(c -> c.onError(fwd, ObjectiveError.GROUPMISSING));
                    return;
                }
                treatment = appKryo.deserialize(next.data());
            } else {
                pendingAddNext.invalidate(fwd.nextId());
                treatment = getTreatment(nextObjective);
                if (treatment == null) {
                    fwd.context().ifPresent(c -> c.onError(fwd, ObjectiveError.UNSUPPORTED));
                    return;
                }
            }
        } else {
            // We get the NextGroup from the remove operation.
            // Doing an operation on the store seems to be very expensive.
            next = flowObjectiveStore.getNextGroup(fwd.nextId());
            treatment = (next != null) ? appKryo.deserialize(next.data()) : null;
        }
        // If the treatment is null we cannot re-build the original flow
        if (treatment == null) {
            fwd.context().ifPresent(c -> c.onError(fwd, ObjectiveError.GROUPMISSING));
            return;
        }
        // Finally we build the flow rule and push to the flowrule subsystem.
        FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().forDevice(deviceId).withSelector(fwd.selector()).fromApp(fwd.appId()).withPriority(fwd.priority()).withTreatment(treatment);
        /* If UNSUPPORTED features included in ForwardingObjective a warning message is generated.
             * FlowRule is anyway sent to the device, device will reply with an OFP_ERROR.
             * Moreover, checkUnSupportedFeatures function generates further warnings specifying
             * each unsupported feature.
             */
        if (checkUnSupportedFeatures(fwd.selector(), treatment)) {
            log.warn("HP Driver - specified ForwardingObjective contains UNSUPPORTED FEATURES");
        }
        // Table to be used depends on the specific switch hardware and ForwardingObjective
        ruleBuilder.forTable(tableIdForForwardingObjective(fwd.selector(), treatment));
        if (fwd.permanent()) {
            ruleBuilder.makePermanent();
        } else {
            ruleBuilder.makeTemporary(fwd.timeout());
        }
        log.debug("HP Driver - installing ForwadingObjective arrived with NULL treatment (intent)");
        installObjective(ruleBuilder, fwd);
    }
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective) NextGroup(org.onosproject.net.behaviour.NextGroup) Builder(org.onosproject.net.flow.FlowRule.Builder) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 40 with NextObjective

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

the class FlowObjectiveManagerTest method nextObjective.

/**
 * Tests adding a next objective.
 */
@Test
public void nextObjective() {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    NextObjective next = DefaultNextObjective.builder().withId(manager.allocateNextId()).addTreatment(treatment).withType(NextObjective.Type.BROADCAST).fromApp(NetTestTools.APP_ID).makePermanent().add();
    manager.next(id1, next);
    TestTools.assertAfter(RETRY_MS, () -> assertThat(nextObjectives, hasSize(1)));
    assertThat(forwardingObjectives, hasSize(0));
    assertThat(filteringObjectives, hasSize(0));
    assertThat(nextObjectives, hasItem("of:d1"));
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Test(org.junit.Test)

Aggregations

NextObjective (org.onosproject.net.flowobjective.NextObjective)83 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)57 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)56 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)55 TrafficSelector (org.onosproject.net.flow.TrafficSelector)51 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)47 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)36 Objective (org.onosproject.net.flowobjective.Objective)31 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)30 DeviceId (org.onosproject.net.DeviceId)29 PortNumber (org.onosproject.net.PortNumber)24 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)24 DefaultObjectiveContext (org.onosproject.net.flowobjective.DefaultObjectiveContext)23 Set (java.util.Set)22 Test (org.junit.Test)22 List (java.util.List)21 Collectors (java.util.stream.Collectors)20 GroupBucket (org.onosproject.net.group.GroupBucket)19 GroupBuckets (org.onosproject.net.group.GroupBuckets)19 Lists (com.google.common.collect.Lists)18