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()));
}
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;
}
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();
}
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);
}
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);
}
Aggregations