Search in sources :

Example 41 with NextObjective

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

the class NextObjectiveTranslator method nextVlan.

private void nextVlan(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
    // We expect NextObjective treatments to contain one or two VLAN instructions.
    // If two, this treatment should be mapped to an action for double-vlan push.
    // In fabric.p4, mapping next IDs to VLAN IDs is done by a direct table (next_vlan),
    // for this reason, we also make sure that all treatments in the NextObjective
    // have exactly the same VLAN instructions, as they will be mapped to a single action
    // Try to extract VLAN instructions in the treatment,
    // later we check if we support multiple VLAN termination.
    final List<List<ModVlanIdInstruction>> vlanInstructions = defaultNextTreatments(obj.nextTreatments(), false).stream().map(defaultNextTreatment -> l2Instructions(defaultNextTreatment.treatment(), VLAN_ID).stream().map(v -> (ModVlanIdInstruction) v).collect(Collectors.toList())).filter(l -> !l.isEmpty()).collect(Collectors.toList());
    final VlanIdCriterion vlanIdCriterion = obj.meta() == null ? null : (VlanIdCriterion) criterion(obj.meta().criteria(), Criterion.Type.VLAN_VID);
    final List<VlanId> vlanIdList;
    if (vlanInstructions.isEmpty() && vlanIdCriterion == null) {
        // No VLAN_ID to apply.
        return;
    }
    if (!vlanInstructions.isEmpty()) {
        // Give priority to what found in the instructions.
        // Expect the same VLAN ID (or two VLAN IDs in the same order) for all instructions.
        final Set<List<VlanId>> vlanIds = vlanInstructions.stream().map(l -> l.stream().map(ModVlanIdInstruction::vlanId).collect(Collectors.toList())).collect(Collectors.toSet());
        if (obj.nextTreatments().size() != vlanInstructions.size() || vlanIds.size() != 1) {
            throw new FabricPipelinerException("Inconsistent VLAN_ID instructions, cannot process " + "next_vlan rule. It is required that all " + "treatments have the same VLAN_ID instructions.");
        }
        vlanIdList = vlanIds.iterator().next();
    } else {
        // Use the value in meta.
        // FIXME: there should be no need to generate a next_vlan rule for
        // the value found in meta. Meta describes the fields that were
        // expected to be matched in previous pipeline stages, i.e.
        // existing packet fields. But, for some reason, if we remove this
        // rule, traffic is not forwarded at spines. We might need to look
        // at the way default VLANs are handled in fabric.p4.
        vlanIdList = List.of(vlanIdCriterion.vlanId());
    }
    final TrafficSelector selector = nextIdSelector(obj.id());
    final TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    vlanIdList.stream().forEach(vlanId -> treatmentBuilder.setVlanId(vlanId));
    final TrafficTreatment treatment = treatmentBuilder.build();
    resultBuilder.addFlowRule(flowRule(obj, FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN, selector, treatment));
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) 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.l2Instructions(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.l2Instructions) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) NextObjective(org.onosproject.net.flowobjective.NextObjective) FabricUtils.l2Instruction(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.l2Instruction) MPLS_LABEL(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.MPLS_LABEL) 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) FabricUtils.outputPort(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.outputPort) 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) 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) 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) FabricUtils(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) FabricCapabilities(org.onosproject.pipelines.fabric.impl.behaviour.FabricCapabilities) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MplsLabel(org.onlab.packet.MplsLabel) Instruction(org.onosproject.net.flow.instructions.Instruction) FabricUtils.criterion(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.criterion) VlanId(org.onlab.packet.VlanId) FabricConstants(org.onosproject.pipelines.fabric.FabricConstants) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PiAction(org.onosproject.net.pi.runtime.PiAction) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Objective(org.onosproject.net.flowobjective.Objective) Collections(java.util.Collections) 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) VlanId(org.onlab.packet.VlanId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 42 with NextObjective

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

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, FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_MPLS, selector, treatment));
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) 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.l2Instructions(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.l2Instructions) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) NextObjective(org.onosproject.net.flowobjective.NextObjective) FabricUtils.l2Instruction(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.l2Instruction) MPLS_LABEL(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.MPLS_LABEL) 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) FabricUtils.outputPort(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.outputPort) 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) 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) 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) FabricUtils(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) FabricCapabilities(org.onosproject.pipelines.fabric.impl.behaviour.FabricCapabilities) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MplsLabel(org.onlab.packet.MplsLabel) Instruction(org.onosproject.net.flow.instructions.Instruction) FabricUtils.criterion(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.criterion) VlanId(org.onlab.packet.VlanId) FabricConstants(org.onosproject.pipelines.fabric.FabricConstants) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PiAction(org.onosproject.net.pi.runtime.PiAction) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) 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 43 with NextObjective

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

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) 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) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Collection(java.util.Collection) PORT_TYPE_INTERNAL(org.onosproject.pipelines.fabric.impl.behaviour.Constants.PORT_TYPE_INTERNAL) Set(java.util.Set) FlowObjectiveStore(org.onosproject.net.flowobjective.FlowObjectiveStore) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) FabricUtils.outputPort(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.outputPort) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) ONE(org.onosproject.pipelines.fabric.impl.behaviour.FabricInterpreter.ONE) Pipeliner(org.onosproject.net.behaviour.Pipeliner) FWD_IPV4_ROUTING(org.onosproject.pipelines.fabric.impl.behaviour.Constants.FWD_IPV4_ROUTING) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) KryoNamespace(org.onlab.util.KryoNamespace) NextGroup(org.onosproject.net.behaviour.NextGroup) GroupKey(org.onosproject.net.group.GroupKey) Group(org.onosproject.net.group.Group) ZERO(org.onosproject.pipelines.fabric.impl.behaviour.FabricInterpreter.ZERO) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) FabricCapabilities(org.onosproject.pipelines.fabric.impl.behaviour.FabricCapabilities) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) SIMPLE(org.onosproject.net.flowobjective.NextObjective.Type.SIMPLE) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Logger(org.slf4j.Logger) GroupService(org.onosproject.net.group.GroupService) FabricConstants(org.onosproject.pipelines.fabric.FabricConstants) Maps(com.google.common.collect.Maps) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction) FabricPipeconfLoader(org.onosproject.pipelines.fabric.impl.FabricPipeconfLoader) AbstractFabricHandlerBehavior(org.onosproject.pipelines.fabric.impl.behaviour.AbstractFabricHandlerBehavior) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Collections(java.util.Collections) 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) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Map(java.util.Map)

Example 44 with NextObjective

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

the class NextObjectiveTranslatorTest method testBroadcastOutput.

/**
 * Test program output group for Broadcast table.
 */
@Test
public void testBroadcastOutput() throws FabricPipelinerException {
    TrafficTreatment treatment1 = DefaultTrafficTreatment.builder().setOutput(PORT_1).build();
    TrafficTreatment treatment2 = DefaultTrafficTreatment.builder().popVlan().setOutput(PORT_2).build();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).addTreatment(treatment1).addTreatment(treatment2).withMeta(VLAN_META).withType(NextObjective.Type.BROADCAST).makePermanent().fromApp(APP_ID).add();
    ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);
    // Should generate 3 flows:
    // - Multicast table flow that matches on next-id and set multicast group (1)
    // - Egress VLAN pop handling for treatment2 (0)
    // - Next VLAN flow (2)
    // And 2 groups:
    // - Multicast group
    // Expected multicast table flow rule.
    PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build();
    TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
    PiAction setMcGroupAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_MCAST_GROUP_ID).withParameter(new PiActionParam(FabricConstants.GROUP_ID, NEXT_ID_1)).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(setMcGroupAction).build();
    FlowRule expectedHashedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(nextObjective.priority()).forTable(FabricConstants.FABRIC_INGRESS_NEXT_MULTICAST).withSelector(nextIdSelector).withTreatment(treatment).build();
    // Expected egress VLAN_PUSH flow rule.
    PiCriterion egressVlanTableMatch = PiCriterion.builder().matchExact(FabricConstants.HDR_EG_PORT, PORT_1.toLong()).build();
    TrafficSelector selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
    PiAction piActionForEgressVlan = PiAction.builder().withId(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_PUSH_VLAN).build();
    TrafficTreatment treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
    FlowRule expectedEgressVlanPushRule = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    // Expected egress VLAN POP flow rule.
    egressVlanTableMatch = PiCriterion.builder().matchExact(FabricConstants.HDR_EG_PORT, PORT_2.toLong()).build();
    selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
    piActionForEgressVlan = PiAction.builder().withId(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN).build();
    treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
    FlowRule expectedEgressVlanPopRule = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    // Expected ALL group.
    TrafficTreatment allGroupTreatment1 = DefaultTrafficTreatment.builder().setOutput(PORT_1).build();
    TrafficTreatment allGroupTreatment2 = DefaultTrafficTreatment.builder().setOutput(PORT_2).build();
    List<TrafficTreatment> allTreatments = ImmutableList.of(allGroupTreatment1, allGroupTreatment2);
    List<GroupBucket> allBuckets = allTreatments.stream().map(DefaultGroupBucket::createAllGroupBucket).collect(Collectors.toList());
    GroupBuckets allGroupBuckets = new GroupBuckets(allBuckets);
    GroupKey allGroupKey = new DefaultGroupKey(FabricPipeliner.KRYO.serialize(NEXT_ID_1));
    GroupDescription expectedAllGroup = new DefaultGroupDescription(DEVICE_ID, GroupDescription.Type.ALL, allGroupBuckets, allGroupKey, NEXT_ID_1, APP_ID);
    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedHashedFlowRule).addFlowRule(vlanMetaFlowRule).addFlowRule(expectedEgressVlanPushRule).addFlowRule(expectedEgressVlanPopRule).addGroup(expectedAllGroup).build();
    assertEquals(expectedTranslation, actualTranslation);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) PiAction(org.onosproject.net.pi.runtime.PiAction) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) Test(org.junit.Test)

Example 45 with NextObjective

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

the class NextObjectiveTranslatorTest method testHashedOutput.

/**
 * Test program ecmp output group for Hashed table.
 */
@Test
public void testHashedOutput() throws Exception {
    PiAction piAction1 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, HOST_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build();
    PiAction piAction2 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, HOST_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build();
    TrafficTreatment treatment1 = DefaultTrafficTreatment.builder().piTableAction(piAction1).build();
    TrafficTreatment treatment2 = DefaultTrafficTreatment.builder().piTableAction(piAction2).build();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).withMeta(VLAN_META).addTreatment(treatment1).addTreatment(treatment2).withType(NextObjective.Type.HASHED).makePermanent().fromApp(APP_ID).add();
    ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);
    // Expected hashed table flow rule.
    PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build();
    TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
    PiActionProfileGroupId actionGroupId = PiActionProfileGroupId.of(NEXT_ID_1);
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(actionGroupId).build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(0).forTable(FabricConstants.FABRIC_INGRESS_NEXT_HASHED).withSelector(nextIdSelector).withTreatment(treatment).build();
    // Expected group
    List<TrafficTreatment> treatments = ImmutableList.of(treatment1, treatment2);
    List<GroupBucket> buckets = treatments.stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
    GroupBuckets groupBuckets = new GroupBuckets(buckets);
    PiGroupKey groupKey = new PiGroupKey(FabricConstants.FABRIC_INGRESS_NEXT_HASHED, FabricConstants.FABRIC_INGRESS_NEXT_HASHED_SELECTOR, NEXT_ID_1);
    GroupDescription expectedGroup = new DefaultGroupDescription(DEVICE_ID, GroupDescription.Type.SELECT, groupBuckets, groupKey, NEXT_ID_1, APP_ID);
    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedFlowRule).addFlowRule(vlanMetaFlowRule).addGroup(expectedGroup).build();
    assertEquals(expectedTranslation, actualTranslation);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) PiAction(org.onosproject.net.pi.runtime.PiAction) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) 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