use of org.onosproject.net.flow.criteria.MplsCriterion in project onos by opennetworkinglab.
the class LinkCollectionEncapIntentCompilerTest method testCoLocatedFilteredPointsTrivialForMp.
/**
* We test the proper compilation of mp2sp with trivial selector,
* trivial treatment, vlan encapsulation and co-located
* filtered ingress/egress points.
*/
@Test
public void testCoLocatedFilteredPointsTrivialForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).links(linksForMp2SpCoLoc).constraints(constraintsForVlan).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, mpls100Selector), new FilteredConnectPoint(d2p10, mpls200Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls69Selector))).build();
sut.activate();
LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(3));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(2));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p10.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(mpls100Selector).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p11.port()).build()));
ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p0.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId(LABEL)).matchInPort(d1p0.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p11.port()).build()));
Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS2, hasSize(1));
FlowRule ruleS2 = rulesS2.iterator().next();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder(mpls200Selector).matchInPort(d2p10.port()).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().popMpls(IPV4.ethType()).pushVlan().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p0.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.flow.criteria.MplsCriterion in project onos by opennetworkinglab.
the class LinkCollectionEncapIntentCompilerTest method testCoLocatedDifferentFilteredPointsTrivialForSp.
/**
* We test the proper compilation of sp2mp with trivial selector,
* trivial treatment, vlan encapsulation and co-located
* different filtered ingress/egress points.
*/
@Test
public void testCoLocatedDifferentFilteredPointsTrivialForSp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc).constraints(constraintsForVlan).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls100Selector), new FilteredConnectPoint(d2p10, vlan200Selector), new FilteredConnectPoint(d3p10, mpls200Selector))).build();
sut.activate();
LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(3));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(1));
FlowRule ruleS1 = rulesS1.iterator().next();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(vlan100Selector).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d1p0.port()).popVlan().pushMpls().setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p11.port()).build()));
Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS2, hasSize(1));
FlowRule ruleS2 = rulesS2.iterator().next();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p1.port()).setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d2p10.port()).build()));
Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p1.deviceId())).collect(Collectors.toSet());
assertThat(rulesS3, hasSize(1));
FlowRule ruleS3 = rulesS3.iterator().next();
assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId(LABEL)).matchInPort(d3p0.port()).build()));
assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d3p10.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.flow.criteria.MplsCriterion in project onos by opennetworkinglab.
the class LinkCollectionEncapIntentCompilerTest method testMplsEncapsulationDifferentFilterForMp.
/**
* We test the proper compilation of mp2sp with the MPLS
* encapsulation and filtered selectors of different type.
*/
@Test
public void testMplsEncapsulationDifferentFilterForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).constraints(constraintsForMPLS).links(linksForMp2Sp).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls100Selector))).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector), new FilteredConnectPoint(d1p11, mpls200Selector), new FilteredConnectPoint(d2p10, vlan200Selector))).build();
sut.activate();
LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(5));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(2));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p10.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(vlan100Selector).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d1p0.port()).build()));
ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p11.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(mpls200Selector).matchInPort(d1p11.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d1p0.port()).build()));
Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS2, hasSize(2));
FlowRule ruleS2 = rulesS2.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d2p10.port());
}).findFirst().get();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder(vlan200Selector).matchInPort(d2p10.port()).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d2p1.port()).build()));
ruleS2 = rulesS2.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d2p0.port());
}).findFirst().get();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p0.port()).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).matchEthType(Ethernet.MPLS_UNICAST).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d2p1.port()).build()));
Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS3, hasSize(1));
FlowRule ruleS3 = rulesS3.iterator().next();
assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchInPort(d3p0.port()).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).matchEthType(Ethernet.MPLS_UNICAST).build()));
assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d3p10.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.flow.criteria.MplsCriterion in project onos by opennetworkinglab.
the class LinkCollectionCompiler method forwardingTreatment.
/**
* Compares tag type between ingress and egress point and generate
* treatment for egress point of intent.
*
* @param ingress ingress selector for the intent
* @param egress egress selector for the intent
* @param ethType the ethertype to use in mpls_pop
* @return Builder of TrafficTreatment
*/
private TrafficTreatment forwardingTreatment(TrafficSelector ingress, TrafficSelector egress, EthType ethType) {
if (ingress.equals(egress)) {
return DefaultTrafficTreatment.emptyTreatment();
}
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
/*
* "null" means there is no tag for the port
* Tag criterion will be null if port is normal connection point
*/
Criterion ingressTagCriterion = getTagCriterion(ingress);
Criterion egressTagCriterion = getTagCriterion(egress);
if (ingressTagCriterion.type() != egressTagCriterion.type()) {
/*
* Tag type of ingress port and egress port are different.
* Need to remove tag from ingress, then add new tag for egress.
* Remove nothing if ingress port use VXLAN or there is no tag
* on ingress port.
*/
switch(ingressTagCriterion.type()) {
case VLAN_VID:
builder.popVlan();
break;
case MPLS_LABEL:
if (copyTtl) {
builder.copyTtlIn();
}
builder.popMpls(ethType);
break;
default:
break;
}
/*
* Push new tag for egress port.
*/
switch(egressTagCriterion.type()) {
case VLAN_VID:
builder.pushVlan();
break;
case MPLS_LABEL:
builder.pushMpls();
if (copyTtl) {
builder.copyTtlOut();
}
break;
default:
break;
}
}
switch(egressTagCriterion.type()) {
case VLAN_VID:
VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) egressTagCriterion;
builder.setVlanId(vlanIdCriterion.vlanId());
break;
case MPLS_LABEL:
MplsCriterion mplsCriterion = (MplsCriterion) egressTagCriterion;
builder.setMpls(mplsCriterion.label());
break;
case TUNNEL_ID:
TunnelIdCriterion tunnelIdCriterion = (TunnelIdCriterion) egressTagCriterion;
builder.setTunnelId(tunnelIdCriterion.tunnelId());
break;
default:
break;
}
return builder.build();
}
use of org.onosproject.net.flow.criteria.MplsCriterion in project onos by opennetworkinglab.
the class PathCompiler method manageMplsEncap.
/**
* Creates the flow rules for the path intent using MPLS
* encapsulation.
*
* @param creator the flowrules creator
* @param flows the list of flows to fill
* @param devices the devices on the path
* @param intent the PathIntent to compile
*/
private void manageMplsEncap(PathCompilerCreateFlow<T> creator, List<T> flows, List<DeviceId> devices, PathIntent intent) {
Set<Link> linksSet = Sets.newConcurrentHashSet();
for (int i = 1; i <= intent.path().links().size() - 2; i++) {
linksSet.add(intent.path().links().get(i));
}
Map<LinkKey, Identifier<?>> mplsLabels = labelAllocator.assignLabelToLinks(linksSet, intent.key(), EncapsulationType.MPLS);
Iterator<Link> links = intent.path().links().iterator();
Link srcLink = links.next();
Link link = links.next();
// List of flow rules to be installed
// Ingress traffic
MplsLabel mplsLabel = (MplsLabel) mplsLabels.get(linkKey(link));
if (mplsLabel == null) {
throw new IntentCompilationException(ERROR_MPLS + link);
}
MplsLabel prevMplsLabel = mplsLabel;
Optional<MplsCriterion> mplsCriterion = intent.selector().criteria().stream().filter(criterion -> criterion.type() == Criterion.Type.MPLS_LABEL).map(criterion -> (MplsCriterion) criterion).findAny();
// Push MPLS if selector does not include MPLS
TrafficTreatment.Builder treatBuilder = DefaultTrafficTreatment.builder();
if (!mplsCriterion.isPresent()) {
treatBuilder.pushMpls();
}
// Tag the traffic with the new encapsulation MPLS label
treatBuilder.setMpls(mplsLabel);
creator.createFlow(intent.selector(), treatBuilder.build(), srcLink.dst(), link.src(), intent.priority(), true, flows, devices);
ConnectPoint prev = link.dst();
while (links.hasNext()) {
link = links.next();
if (links.hasNext()) {
// Transit traffic
MplsLabel transitMplsLabel = (MplsLabel) mplsLabels.get(linkKey(link));
if (transitMplsLabel == null) {
throw new IntentCompilationException(ERROR_MPLS + link);
}
TrafficSelector transitSelector = DefaultTrafficSelector.builder().matchInPort(prev.port()).matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(prevMplsLabel).build();
TrafficTreatment.Builder transitTreat = DefaultTrafficTreatment.builder();
// Set the new MPLS label only if the previous one is different
if (!prevMplsLabel.equals(transitMplsLabel)) {
transitTreat.setMpls(transitMplsLabel);
}
creator.createFlow(transitSelector, transitTreat.build(), prev, link.src(), intent.priority(), true, flows, devices);
prevMplsLabel = transitMplsLabel;
prev = link.dst();
} else {
TrafficSelector.Builder egressSelector = DefaultTrafficSelector.builder().matchInPort(prev.port()).matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(prevMplsLabel);
TrafficTreatment.Builder egressTreat = DefaultTrafficTreatment.builder(intent.treatment());
// than selector needs to match any VlanId
for (Instruction instruct : intent.treatment().allInstructions()) {
if (instruct instanceof L2ModificationInstruction) {
L2ModificationInstruction l2Mod = (L2ModificationInstruction) instruct;
if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
break;
}
if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_POP || l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
egressSelector.matchVlanId(VlanId.ANY);
}
}
}
if (mplsCriterion.isPresent()) {
egressTreat.setMpls(mplsCriterion.get().label());
} else {
egressTreat.popMpls(getEthType(intent.selector()));
}
creator.createFlow(egressSelector.build(), egressTreat.build(), prev, link.src(), intent.priority(), true, flows, devices);
}
}
}
Aggregations