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