Search in sources :

Example 1 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 2 with MplsLabel

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

the class PathIntentCompilerTest method verifyMplsEncapTreatment.

private MplsLabel verifyMplsEncapTreatment(TrafficTreatment trafficTreatment, ConnectPoint egress, boolean isIngress, boolean isEgress) {
    Set<Instructions.OutputInstruction> ruleOutput = trafficTreatment.allInstructions().stream().filter(treat -> treat instanceof Instructions.OutputInstruction).map(treat -> (Instructions.OutputInstruction) treat).collect(Collectors.toSet());
    assertThat(ruleOutput, hasSize(1));
    assertThat((ruleOutput.iterator().next()).port(), is(egress.port()));
    MplsLabel mplsToEncap = MplsLabel.mplsLabel(0);
    if (isIngress && !isEgress) {
        Set<L2ModificationInstruction.ModMplsLabelInstruction> mplsRules = trafficTreatment.allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModMplsLabelInstruction).map(x -> (L2ModificationInstruction.ModMplsLabelInstruction) x).collect(Collectors.toSet());
        assertThat(mplsRules, hasSize(1));
        L2ModificationInstruction.ModMplsLabelInstruction mplsRule = mplsRules.iterator().next();
        assertThat(mplsRule.label().toInt(), greaterThan(0));
        assertThat(mplsRule.label().toInt(), lessThan(MplsLabel.MAX_MPLS));
        mplsToEncap = mplsRule.label();
    } else if (!isIngress && !isEgress) {
        Set<L2ModificationInstruction.ModMplsLabelInstruction> mplsRules = trafficTreatment.allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModMplsLabelInstruction).map(x -> (L2ModificationInstruction.ModMplsLabelInstruction) x).collect(Collectors.toSet());
        assertThat(mplsRules, hasSize(1));
        L2ModificationInstruction.ModMplsLabelInstruction mplsRule = mplsRules.iterator().next();
        assertThat(mplsRule.label().toInt(), greaterThan(0));
        assertThat(mplsRule.label().toInt(), lessThan(MplsLabel.MAX_MPLS));
        mplsToEncap = mplsRule.label();
    } else {
        assertThat(trafficTreatment.allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModMplsLabelInstruction).collect(Collectors.toSet()), hasSize(0));
        assertThat(trafficTreatment.allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModMplsHeaderInstruction).collect(Collectors.toSet()), hasSize(1));
    }
    return mplsToEncap;
}
Also used : DIRECT(org.onosproject.net.Link.Type.DIRECT) Arrays(java.util.Arrays) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) TestApplicationId(org.onosproject.TestApplicationId) CoreService(org.onosproject.core.CoreService) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ApplicationId(org.onosproject.core.ApplicationId) DefaultPath(org.onosproject.net.DefaultPath) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Intent(org.onosproject.net.intent.Intent) OrderingComparison.greaterThan(org.hamcrest.number.OrderingComparison.greaterThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) DefaultLink(org.onosproject.net.DefaultLink) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) EasyMock(org.easymock.EasyMock) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest) Collectors(java.util.stream.Collectors) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) NetTestTools(org.onosproject.net.NetTestTools) FlowRule(org.onosproject.net.flow.FlowRule) ScalarWeight(org.onlab.graph.ScalarWeight) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Set(java.util.Set) MplsLabel(org.onlab.packet.MplsLabel) Instructions(org.onosproject.net.flow.instructions.Instructions) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction)

Example 3 with MplsLabel

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

the class PathIntentCompilerTest method testMplsEncapCompile.

/**
 * Tests the compilation behavior of the path intent compiler in case of
 * encasulation costraint {@link EncapsulationConstraint}.
 */
@Test
public void testMplsEncapCompile() {
    sut.activate();
    List<Intent> compiled = sut.compile(constraintMplsIntent, Collections.emptyList());
    assertThat(compiled, hasSize(1));
    Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
    assertThat(rules, hasSize(3));
    FlowRule rule1 = rules.stream().filter(x -> x.deviceId().equals(d1p0.deviceId())).findFirst().get();
    verifyIdAndPriority(rule1, d1p0.deviceId());
    assertThat(rule1.selector(), is(DefaultTrafficSelector.builder(selector).matchInPort(d1p0.port()).build()));
    MplsLabel mplsLabelToEncap = verifyMplsEncapTreatment(rule1.treatment(), d1p1, true, false);
    FlowRule rule2 = rules.stream().filter(x -> x.deviceId().equals(d2p0.deviceId())).findFirst().get();
    verifyIdAndPriority(rule2, d2p0.deviceId());
    verifyMplsEncapSelector(rule2.selector(), d2p0, mplsLabelToEncap);
    mplsLabelToEncap = verifyMplsEncapTreatment(rule2.treatment(), d2p1, false, false);
    FlowRule rule3 = rules.stream().filter(x -> x.deviceId().equals(d3p0.deviceId())).findFirst().get();
    verifyIdAndPriority(rule3, d3p1.deviceId());
    verifyMplsEncapSelector(rule3.selector(), d3p1, mplsLabelToEncap);
    verifyMplsEncapTreatment(rule3.treatment(), d3p0, false, true);
    sut.deactivate();
}
Also used : MplsLabel(org.onlab.packet.MplsLabel) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 4 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 5 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)

Aggregations

MplsLabel (org.onlab.packet.MplsLabel)15 Test (org.junit.Test)9 VlanId (org.onlab.packet.VlanId)6 Identifier (org.onlab.util.Identifier)6 LinkKey (org.onosproject.net.LinkKey)6 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 List (java.util.List)4 TrafficSelector (org.onosproject.net.flow.TrafficSelector)4 Instruction (org.onosproject.net.flow.instructions.Instruction)4 RandomSelection (org.onosproject.net.resource.impl.LabelAllocator.RandomSelection)4 Set (java.util.Set)3 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)3 FirstFitSelection (org.onosproject.net.resource.impl.LabelAllocator.FirstFitSelection)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayDeque (java.util.ArrayDeque)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Collectors (java.util.stream.Collectors)2 OfdpaGroupHandlerUtility.l2MulticastGroupKey (org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey)2