Search in sources :

Example 81 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.

the class McastUtils method nextObjBuilder.

/**
 * Creates a next objective builder for multicast.
 *
 * @param mcastIp multicast group
 * @param assignedVlan assigned VLAN ID
 * @param outPorts set of output port numbers
 * @param nextId the next id
 * @return next objective builder
 */
NextObjective.Builder nextObjBuilder(IpAddress mcastIp, VlanId assignedVlan, Set<PortNumber> outPorts, Integer nextId) {
    // If nextId is null allocate a new one
    if (nextId == null) {
        nextId = srManager.flowObjectiveService.allocateNextId();
    }
    // Build the meta selector with the fwd objective info
    TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(assignedVlan).matchIPDst(mcastIp.toIpPrefix()).build();
    // Define the nextobjective type
    NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.BROADCAST).fromApp(srManager.appId()).withMeta(metadata);
    // Add the output ports
    outPorts.forEach(port -> {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        if (egressVlan().equals(VlanId.NONE)) {
            tBuilder.popVlan();
        }
        tBuilder.setOutput(port);
        nextObjBuilder.addTreatment(tBuilder.build());
    });
    // Done return the complete builder
    return nextObjBuilder;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 82 with NextObjective

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

the class NextObjectiveTranslatorTest method testHashedOutput.

/**
 * Test program ecmp output group for Hashed table.
 */
@Test
public void testHashedOutput() throws Exception {
    PiAction piAction1 = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(P4InfoConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.DMAC, HOST_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.PORT_NUM, PORT_1.toLong())).build();
    PiAction piAction2 = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(P4InfoConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.DMAC, HOST_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.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(P4InfoConstants.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(P4InfoConstants.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(P4InfoConstants.FABRIC_INGRESS_NEXT_HASHED, P4InfoConstants.FABRIC_INGRESS_NEXT_HASHED_PROFILE, 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)

Example 83 with NextObjective

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

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.forEach(treatmentBuilder::setVlanId);
    final TrafficTreatment treatment = treatmentBuilder.build();
    resultBuilder.addFlowRule(flowRule(obj, P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN, 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) 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)

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