Search in sources :

Example 6 with MplsLabel

use of org.onlab.packet.MplsLabel in project onos by opennetworkinglab.

the class PiCriterionTranslatorsTest method testMplsCriterion.

@Test
public void testMplsCriterion() throws Exception {
    MplsLabel mplsLabel = MplsLabel.mplsLabel(random.nextInt(1 << 20));
    int bitWidth = 32;
    MplsCriterion criterion = (MplsCriterion) Criteria.matchMplsLabel(mplsLabel);
    PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);
    assertThat(exactMatch.value().asReadOnlyBuffer().getInt(), is(criterion.label().toInt()));
}
Also used : MplsLabel(org.onlab.packet.MplsLabel) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) Test(org.junit.Test)

Example 7 with MplsLabel

use of org.onlab.packet.MplsLabel in project onos by opennetworkinglab.

the class LabelAllocatorTest method testRandomBehaviorNone.

/**
 * To test random behavior. Using NONE optimization
 */
@Test
public void testRandomBehaviorNone() {
    // By default Random is the selection behavior used
    assertThat(this.allocator.getLabelSelection(), instanceOf(RandomSelection.class));
    // It has to be an instance of NONE
    assertEquals(this.allocator.getOptLabelSelection(), LabelAllocator.OptimizationBehavior.NONE);
    // Filter reservations
    this.resourceService.filterAssignment = true;
    // We change the available Ids
    this.resourceService.availableMplsLabels = ImmutableSet.of(1, 2, 3, 4, 5, 6);
    // First allocation on a subset of links
    Map<LinkKey, Identifier<?>> allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links.subList(2, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.MPLS);
    Identifier<?> id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    // value has to be a MPLS label
    assertThat(id, instanceOf(MplsLabel.class));
    // value should not be a forbidden value
    MplsLabel mplsLabel = (MplsLabel) id;
    assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
    // We test the behavior for MPLS
    allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links.subList(1, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.MPLS);
    id = allocation.get(LinkKey.linkKey(d1p1, d3p1));
    assertThat(id, instanceOf(MplsLabel.class));
    mplsLabel = (MplsLabel) id;
    assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
    id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    assertThat(id, instanceOf(MplsLabel.class));
    mplsLabel = (MplsLabel) id;
    assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
}
Also used : LinkKey(org.onosproject.net.LinkKey) Identifier(org.onlab.util.Identifier) RandomSelection(org.onosproject.net.resource.impl.LabelAllocator.RandomSelection) MplsLabel(org.onlab.packet.MplsLabel) Test(org.junit.Test)

Example 8 with MplsLabel

use of org.onlab.packet.MplsLabel in project onos by opennetworkinglab.

the class LabelAllocatorTest method testRandomBehaviorMinSwap.

/**
 * To test the random behavior. Using MIN_SWAP optimization
 */
@Test
public void testRandomBehaviorMinSwap() {
    // By default Random is the selection behavior used
    assertThat(this.allocator.getLabelSelection(), instanceOf(RandomSelection.class));
    // Change to MIN_SWAP
    this.allocator.setOptLabelSelection(minswap);
    assertEquals(this.allocator.getOptLabelSelection(), LabelAllocator.OptimizationBehavior.MIN_SWAP);
    // Filter reservations
    this.resourceService.filterAssignment = true;
    // We change the available Ids
    this.resourceService.availableMplsLabels = ImmutableSet.of(1, 2, 3, 4, 5, 6, 7, 8);
    // First allocation on a subset of links
    Map<LinkKey, Identifier<?>> allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links2.subList(2, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.MPLS);
    Identifier<?> id = allocation.get(LinkKey.linkKey(d3p0, d4p1));
    // value has to be a MPLS label
    assertThat(id, instanceOf(MplsLabel.class));
    // value should not be a forbidden value
    MplsLabel mplsLabel = (MplsLabel) id;
    assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
    // We test the behavior for MPLS
    allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links2.subList(1, 4)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.MPLS);
    id = allocation.get(LinkKey.linkKey(d1p1, d3p1));
    assertThat(id, instanceOf(MplsLabel.class));
    mplsLabel = (MplsLabel) id;
    assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
    id = allocation.get(LinkKey.linkKey(d3p0, d4p1));
    assertThat(id, instanceOf(MplsLabel.class));
    mplsLabel = (MplsLabel) id;
    assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
    id = allocation.get(LinkKey.linkKey(d4p0, d2p1));
    assertThat(id, instanceOf(MplsLabel.class));
    mplsLabel = (MplsLabel) id;
    assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
}
Also used : LinkKey(org.onosproject.net.LinkKey) Identifier(org.onlab.util.Identifier) RandomSelection(org.onosproject.net.resource.impl.LabelAllocator.RandomSelection) MplsLabel(org.onlab.packet.MplsLabel) Test(org.junit.Test)

Example 9 with MplsLabel

use of org.onlab.packet.MplsLabel 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 10 with MplsLabel

use of org.onlab.packet.MplsLabel in project onos by opennetworkinglab.

the class InstructionsTest method testModMplsMethod.

/**
 * Test the modMplsLabel method.
 */
@Test
public void testModMplsMethod() {
    final MplsLabel mplsLabel = MplsLabel.mplsLabel(33);
    final Instruction instruction = Instructions.modMplsLabel(mplsLabel);
    final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction = checkAndConvert(instruction, Instruction.Type.L2MODIFICATION, L2ModificationInstruction.ModMplsLabelInstruction.class);
    assertThat(modMplsLabelInstruction.label(), is(equalTo(mplsLabel)));
    assertThat(modMplsLabelInstruction.subtype(), is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL)));
}
Also used : MplsLabel(org.onlab.packet.MplsLabel) Test(org.junit.Test)

Aggregations

MplsLabel (org.onlab.packet.MplsLabel)18 Test (org.junit.Test)9 VlanId (org.onlab.packet.VlanId)9 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)7 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)7 Identifier (org.onlab.util.Identifier)6 LinkKey (org.onosproject.net.LinkKey)6 List (java.util.List)5 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5 Instruction (org.onosproject.net.flow.instructions.Instruction)5 Set (java.util.Set)4 DeviceId (org.onosproject.net.DeviceId)4 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)4 RandomSelection (org.onosproject.net.resource.impl.LabelAllocator.RandomSelection)4 Collection (java.util.Collection)3 Collections (java.util.Collections)3 Collectors (java.util.stream.Collectors)3 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)3 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)3 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)3