[ONOS-4595] Harmonize the sb of the Intent Framework
Changes:
- Moves PointToPointIntent to LinkCollectionIntent;
- Moves PointToPointIntent to the new FilteredConnectPoint API;
- Updates unit tests;
Change-Id: Iade5090b9289c5b2d9f4ee41aa0d2d01b5e3699c
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
index ddc7f21..f719a00 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
@@ -83,7 +83,6 @@
List<DeviceId> devices = new LinkedList<>();
compile(this, intent, rules, devices);
-
return ImmutableList.of(new FlowRuleIntent(appId, null, rules, intent.resources(), intent.type()));
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
index ee5f4e2..02b8865 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.intent.impl.compiler;
+import com.google.common.collect.ImmutableSet;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -52,6 +53,7 @@
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentCompilationException;
import org.onosproject.net.intent.IntentId;
+import org.onosproject.net.intent.LinkCollectionIntent;
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.constraint.ProtectionConstraint;
@@ -66,6 +68,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@@ -123,12 +126,12 @@
ConnectPoint egressPoint = intent.egressPoint();
if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
- return createZeroHopIntent(ingressPoint, egressPoint, intent);
+ return createZeroHopLinkCollectionIntent(intent);
}
// proceed with no protected paths
if (!ProtectionConstraint.requireProtectedPath(intent)) {
- return createUnprotectedIntent(ingressPoint, egressPoint, intent);
+ return createUnprotectedLinkCollectionIntent(intent);
}
try {
@@ -149,6 +152,11 @@
intent, PathIntent.ProtectionType.PRIMARY));
}
+ private List<Intent> createZeroHopLinkCollectionIntent(PointToPointIntent intent) {
+ return asList(createLinkCollectionIntent(ImmutableSet.of(), DEFAULT_COST,
+ intent));
+ }
+
private List<Intent> createUnprotectedIntent(ConnectPoint ingressPoint,
ConnectPoint egressPoint,
PointToPointIntent intent) {
@@ -165,6 +173,15 @@
PathIntent.ProtectionType.PRIMARY));
}
+ private List<Intent> createUnprotectedLinkCollectionIntent(PointToPointIntent intent) {
+ Path path = getPath(intent, intent.filteredIngressPoint().connectPoint().deviceId(),
+ intent.filteredEgressPoint().connectPoint().deviceId());
+
+ return asList(createLinkCollectionIntent(ImmutableSet.copyOf(path.links()),
+ path.cost(),
+ intent));
+ }
+
//FIXME: Compatibility with EncapsulationConstraint
private List<Intent> createProtectedIntent(ConnectPoint ingressPoint,
ConnectPoint egressPoint,
@@ -276,7 +293,6 @@
links.add(createEdgeLink(ingressPoint, true));
links.addAll(onlyPath.links());
links.add(createEdgeLink(egressPoint, false));
-
return asList(createPathIntent(new DefaultPath(PID, links, onlyPath.cost(),
onlyPath.annotations()),
intent, PathIntent.ProtectionType.PRIMARY));
@@ -305,12 +321,45 @@
.build();
}
+
+ /**
+ * Creates a link collection intent from the specified path and original
+ * point to point intent.
+ *
+ * @param links the links of the packets
+ * @param cost the cost associated to the links
+ * @param intent the point to point intent we are compiling
+ * @return the link collection intent
+ */
+ private Intent createLinkCollectionIntent(Set<Link> links,
+ double cost,
+ PointToPointIntent intent) {
+
+ return LinkCollectionIntent.builder()
+ .key(intent.key())
+ .appId(intent.appId())
+ .selector(intent.selector())
+ .treatment(intent.treatment())
+ .links(ImmutableSet.copyOf(links))
+ .filteredIngressPoints(ImmutableSet.of(
+ intent.filteredIngressPoint()
+ ))
+ .filteredEgressPoints(ImmutableSet.of(
+ intent.filteredEgressPoint()
+ ))
+ .applyTreatmentOnEgress(true)
+ .constraints(intent.constraints())
+ .priority(intent.priority())
+ .cost(cost)
+ .build();
+ }
+
/**
* Gets primary port number through failover group associated
* with this intent.
*/
private PortNumber getPrimaryPort(PointToPointIntent intent) {
- Group group = groupService.getGroup(intent.ingressPoint().deviceId(),
+ Group group = groupService.getGroup(intent.filteredIngressPoint().connectPoint().deviceId(),
makeGroupKey(intent.id()));
PortNumber primaryPort = null;
if (group != null) {
@@ -323,7 +372,7 @@
Instructions.OutputInstruction outInstruction =
(Instructions.OutputInstruction) individualInstruction;
PortNumber tempPortNum = outInstruction.port();
- Port port = deviceService.getPort(intent.ingressPoint().deviceId(),
+ Port port = deviceService.getPort(intent.filteredIngressPoint().connectPoint().deviceId(),
tempPortNum);
if (port != null && port.isEnabled()) {
primaryPort = tempPortNum;
@@ -585,7 +634,7 @@
}
}
// remove buckets whose watchports are disabled if the failover group exists
- Group group = groupService.getGroup(pointIntent.ingressPoint().deviceId(),
+ Group group = groupService.getGroup(pointIntent.filteredIngressPoint().connectPoint().deviceId(),
makeGroupKey(pointIntent.id()));
if (group != null) {
updateFailoverGroup(pointIntent);
@@ -595,7 +644,7 @@
// Removes buckets whose treatments rely on disabled ports from the
// failover group.
private void updateFailoverGroup(PointToPointIntent pointIntent) {
- DeviceId deviceId = pointIntent.ingressPoint().deviceId();
+ DeviceId deviceId = pointIntent.filteredIngressPoint().connectPoint().deviceId();
GroupKey groupKey = makeGroupKey(pointIntent.id());
Group group = waitForGroup(deviceId, groupKey);
Iterator<GroupBucket> groupIterator = group.buckets().buckets().iterator();
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java
index f7389e7..38aad30 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java
@@ -98,6 +98,11 @@
link(d2p0, d1p0)
);
+ final Set<Link> p2pLinks = ImmutableSet.of(
+ link(d1p0, d2p0),
+ link(d2p1, d3p1)
+ );
+
final TrafficTreatment treatment = emptyTreatment();
final TrafficTreatment ethDstTreatment = macDstTreatment("C0:FF:EE:C0:FF:EE");
final TrafficTreatment decTllTreatment = decTtlTreatment();
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java
index 295a998..eb58cce 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java
@@ -1166,7 +1166,7 @@
/**
* We test the proper compilation of p2p with the VLAN
- * encapsulation and filtered points.
+ * encapsulation and trivial filtered points.
*/
@Test
public void testVlanEncapsulationForP2P() {
@@ -1260,7 +1260,7 @@
/**
* We test the proper compilation of p2p with the MPLS
- * encapsulation and filtered points.
+ * encapsulation and trivial filtered points.
*/
@Test
public void testMplsEncapsulationForP2P() {
@@ -1354,4 +1354,206 @@
}
+ /**
+ * We test the proper compilation of p2p with the VLAN
+ * encapsulation, filtered points, selector and treatment.
+ */
+ @Test
+ public void testVlanEncapsulationNonTrivialForP2P() {
+
+ intent = LinkCollectionIntent.builder()
+ .appId(APP_ID)
+ .selector(ipPrefixSelector)
+ .treatment(ethDstTreatment)
+ .constraints(constraintsForVlan)
+ .links(linksForMp2Sp)
+ .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector)))
+ .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls69Selector)))
+ .build();
+
+ sut.activate();
+ /*
+ * We use the FIRST_FIT to simplify tests.
+ */
+ 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(ipPrefixSelector)
+ .matchInPort(d1p10.port())
+ .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
+ .build()
+ ));
+ assertThat(ruleS1.treatment(), is(
+ DefaultTrafficTreatment
+ .builder()
+ .setVlanId(VlanId.vlanId(LABEL))
+ .setOutput(d1p0.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())
+ .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())
+ .matchVlanId(VlanId.vlanId(LABEL))
+ .build()
+ ));
+ assertThat(ruleS3.treatment(), is(
+ DefaultTrafficTreatment
+ .builder()
+ .setEthDst(((ModEtherInstruction) ethDstTreatment
+ .allInstructions()
+ .stream()
+ .filter(instruction -> instruction instanceof ModEtherInstruction)
+ .findFirst().get()).mac())
+ .popVlan()
+ .pushMpls()
+ .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
+ .setOutput(d3p10.port())
+ .build()
+ ));
+
+ sut.deactivate();
+
+ }
+
+ /**
+ * We test the proper compilation of p2p with the MPLS
+ * encapsulation, filtered points, selector and treatment.
+ */
+ @Test
+ public void testMplsEncapsulationNonTrivialForP2P() {
+
+ intent = LinkCollectionIntent.builder()
+ .appId(APP_ID)
+ .selector(ipPrefixSelector)
+ .treatment(ethDstTreatment)
+ .constraints(constraintsForMPLS)
+ .links(linksForMp2Sp)
+ .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector)))
+ .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls69Selector)))
+ .build();
+
+ sut.activate();
+ /*
+ * We use the FIRST_FIT to simplify tests.
+ */
+ 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(ipPrefixSelector)
+ .matchInPort(d1p10.port())
+ .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
+ .build()
+ ));
+ assertThat(ruleS1.treatment(), is(
+ DefaultTrafficTreatment
+ .builder()
+ .popVlan()
+ .pushMpls()
+ .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(1));
+ FlowRule ruleS2 = rulesS2.iterator().next();
+ 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()
+ .setEthDst(((ModEtherInstruction) ethDstTreatment
+ .allInstructions()
+ .stream()
+ .filter(instruction -> instruction instanceof ModEtherInstruction)
+ .findFirst().get()).mac())
+ .setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label())
+ .setOutput(d3p10.port())
+ .build()
+ ));
+
+ sut.deactivate();
+
+ }
+
}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
index cfbddea..4c45bb4 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
@@ -1079,4 +1079,282 @@
}
+ /**
+ * We test the proper compilation of p2p with
+ * trivial selector and trivial treatment.
+ */
+ @Test
+ public void p2p() {
+
+ intent = LinkCollectionIntent.builder()
+ .appId(APP_ID)
+ .selector(selector)
+ .treatment(treatment)
+ .applyTreatmentOnEgress(true)
+ .links(p2pLinks)
+ .filteredIngressPoints(ImmutableSet.of(
+ new FilteredConnectPoint(d1p10)
+ ))
+ .filteredEgressPoints(ImmutableSet.of(
+ new FilteredConnectPoint(d3p0)
+ ))
+ .build();
+
+ sut.activate();
+
+ 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.is(
+ DefaultTrafficSelector
+ .builder()
+ .matchInPort(d1p10.port())
+ .build()
+ ));
+ assertThat(ruleS1.treatment(), Is.is(
+ DefaultTrafficTreatment
+ .builder()
+ .setOutput(d1p0.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.is(
+ DefaultTrafficSelector
+ .builder()
+ .matchInPort(d2p0.port())
+ .build()
+ ));
+ assertThat(ruleS2.treatment(), Is.is(
+ DefaultTrafficTreatment
+ .builder()
+ .setOutput(d2p1.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.is(
+ DefaultTrafficSelector
+ .builder()
+ .matchInPort(d3p1.port())
+ .build()
+ ));
+ assertThat(ruleS3.treatment(), Is.is(
+ DefaultTrafficTreatment
+ .builder()
+ .setOutput(d3p0.port())
+ .build()
+ ));
+
+ sut.deactivate();
+
+ }
+
+ /**
+ * We test the proper compilation of p2p with
+ * trivial selector, trivial treatment and filtered points.
+ */
+ @Test
+ public void p2pFilteredPoint() {
+
+ intent = LinkCollectionIntent.builder()
+ .appId(APP_ID)
+ .selector(selector)
+ .treatment(treatment)
+ .applyTreatmentOnEgress(true)
+ .links(p2pLinks)
+ .filteredIngressPoints(ImmutableSet.of(
+ new FilteredConnectPoint(d1p10, vlan100Selector)
+ ))
+ .filteredEgressPoints(ImmutableSet.of(
+ new FilteredConnectPoint(d3p0, mpls200Selector)
+ ))
+ .build();
+
+ sut.activate();
+
+ 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.is(
+ DefaultTrafficSelector
+ .builder(vlan100Selector)
+ .matchInPort(d1p10.port())
+ .build()
+ ));
+ assertThat(ruleS1.treatment(), Is.is(
+ DefaultTrafficTreatment
+ .builder()
+ .setOutput(d1p0.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.is(
+ DefaultTrafficSelector
+ .builder(vlan100Selector)
+ .matchInPort(d2p0.port())
+ .build()
+ ));
+ assertThat(ruleS2.treatment(), Is.is(
+ DefaultTrafficTreatment
+ .builder()
+ .setOutput(d2p1.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.is(
+ DefaultTrafficSelector
+ .builder(vlan100Selector)
+ .matchInPort(d3p1.port())
+ .build()
+ ));
+ assertThat(ruleS3.treatment(), Is.is(
+ DefaultTrafficTreatment
+ .builder()
+ .popVlan()
+ .pushMpls()
+ .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
+ .setOutput(d3p0.port())
+ .build()
+ ));
+
+ sut.deactivate();
+
+ }
+
+ /**
+ * We test the proper compilation of p2p with
+ * selector, treatment and filtered points.
+ */
+ @Test
+ public void p2pNonTrivial() {
+
+ intent = LinkCollectionIntent.builder()
+ .appId(APP_ID)
+ .selector(ipPrefixSelector)
+ .treatment(ethDstTreatment)
+ .applyTreatmentOnEgress(true)
+ .links(p2pLinks)
+ .filteredIngressPoints(ImmutableSet.of(
+ new FilteredConnectPoint(d1p10, vlan100Selector)
+ ))
+ .filteredEgressPoints(ImmutableSet.of(
+ new FilteredConnectPoint(d3p0, mpls200Selector)
+ ))
+ .build();
+
+ sut.activate();
+
+ 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.is(
+ DefaultTrafficSelector
+ .builder(ipPrefixSelector)
+ .matchInPort(d1p10.port())
+ .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
+ .build()
+ ));
+ assertThat(ruleS1.treatment(), Is.is(
+ DefaultTrafficTreatment
+ .builder()
+ .setOutput(d1p0.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.is(
+ DefaultTrafficSelector
+ .builder(ipPrefixSelector)
+ .matchInPort(d2p0.port())
+ .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
+ .build()
+ ));
+ assertThat(ruleS2.treatment(), Is.is(
+ DefaultTrafficTreatment
+ .builder()
+ .setOutput(d2p1.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.is(
+ DefaultTrafficSelector
+ .builder(ipPrefixSelector)
+ .matchInPort(d3p1.port())
+ .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId())
+ .build()
+ ));
+ assertThat(ruleS3.treatment(), Is.is(
+ DefaultTrafficTreatment
+ .builder()
+ .setEthDst(((ModEtherInstruction) ethDstTreatment
+ .allInstructions()
+ .stream()
+ .filter(instruction -> instruction instanceof ModEtherInstruction)
+ .findFirst().get()).mac())
+ .popVlan()
+ .pushMpls()
+ .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label())
+ .setOutput(d3p0.port())
+ .build()
+ ));
+
+ sut.deactivate();
+
+ }
+
}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
index e620f0e..d61e01d 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
@@ -15,21 +15,22 @@
*/
package org.onosproject.net.intent.impl.compiler;
+import com.google.common.collect.ImmutableSet;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.onlab.util.Bandwidth;
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.Link;
-import org.onosproject.net.Path;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentTestsMocks;
-import org.onosproject.net.intent.PathIntent;
+import org.onosproject.net.intent.LinkCollectionIntent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.impl.PathNotFoundException;
@@ -37,6 +38,7 @@
import java.util.Collections;
import java.util.List;
+import java.util.Set;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -44,7 +46,6 @@
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.fail;
-import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.net.NetTestTools.connectPoint;
@@ -74,8 +75,8 @@
.appId(APPID)
.selector(selector)
.treatment(treatment)
- .ingressPoint(connectPoint(ingressIdString, 1))
- .egressPoint(connectPoint(egressIdString, 1))
+ .filteredIngressPoint(new FilteredConnectPoint(connectPoint(ingressIdString, 1)))
+ .filteredEgressPoint(new FilteredConnectPoint(connectPoint(egressIdString, 1)))
.build();
}
@@ -93,8 +94,8 @@
.appId(APPID)
.selector(selector)
.treatment(treatment)
- .ingressPoint(connectPoint(ingressIdString, 1))
- .egressPoint(connectPoint(egressIdString, 1))
+ .filteredIngressPoint(new FilteredConnectPoint(connectPoint(ingressIdString, 1)))
+ .filteredEgressPoint(new FilteredConnectPoint(connectPoint(egressIdString, 1)))
.constraints(constraints)
.build();
}
@@ -140,19 +141,23 @@
assertThat(result, is(Matchers.notNullValue()));
assertThat(result, hasSize(1));
Intent forwardResultIntent = result.get(0);
- assertThat(forwardResultIntent instanceof PathIntent, is(true));
+ assertThat(forwardResultIntent instanceof LinkCollectionIntent, is(true));
- if (forwardResultIntent instanceof PathIntent) {
- PathIntent forwardPathIntent = (PathIntent) forwardResultIntent;
+ if (forwardResultIntent instanceof LinkCollectionIntent) {
+ LinkCollectionIntent forwardIntent = (LinkCollectionIntent) forwardResultIntent;
+ FilteredConnectPoint ingressPoint = new FilteredConnectPoint(connectPoint("d1", 1));
+ FilteredConnectPoint egressPoint = new FilteredConnectPoint(connectPoint("d8", 1));
// 7 links for the hops, plus one default lnk on ingress and egress
- assertThat(forwardPathIntent.path().links(), hasSize(hops.length + 1));
- assertThat(forwardPathIntent.path().links(), linksHasPath("d1", "d2"));
- assertThat(forwardPathIntent.path().links(), linksHasPath("d2", "d3"));
- assertThat(forwardPathIntent.path().links(), linksHasPath("d3", "d4"));
- assertThat(forwardPathIntent.path().links(), linksHasPath("d4", "d5"));
- assertThat(forwardPathIntent.path().links(), linksHasPath("d5", "d6"));
- assertThat(forwardPathIntent.path().links(), linksHasPath("d6", "d7"));
- assertThat(forwardPathIntent.path().links(), linksHasPath("d7", "d8"));
+ assertThat(forwardIntent.links(), hasSize(hops.length - 1));
+ assertThat(forwardIntent.links(), linksHasPath("d1", "d2"));
+ assertThat(forwardIntent.links(), linksHasPath("d2", "d3"));
+ assertThat(forwardIntent.links(), linksHasPath("d3", "d4"));
+ assertThat(forwardIntent.links(), linksHasPath("d4", "d5"));
+ assertThat(forwardIntent.links(), linksHasPath("d5", "d6"));
+ assertThat(forwardIntent.links(), linksHasPath("d6", "d7"));
+ assertThat(forwardIntent.links(), linksHasPath("d7", "d8"));
+ assertThat(forwardIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint)));
+ assertThat(forwardIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint)));
}
}
@@ -171,18 +176,22 @@
assertThat(result, is(Matchers.notNullValue()));
assertThat(result, hasSize(1));
Intent reverseResultIntent = result.get(0);
- assertThat(reverseResultIntent instanceof PathIntent, is(true));
+ assertThat(reverseResultIntent instanceof LinkCollectionIntent, is(true));
- if (reverseResultIntent instanceof PathIntent) {
- PathIntent reversePathIntent = (PathIntent) reverseResultIntent;
- assertThat(reversePathIntent.path().links(), hasSize(hops.length + 1));
- assertThat(reversePathIntent.path().links(), linksHasPath("d2", "d1"));
- assertThat(reversePathIntent.path().links(), linksHasPath("d3", "d2"));
- assertThat(reversePathIntent.path().links(), linksHasPath("d4", "d3"));
- assertThat(reversePathIntent.path().links(), linksHasPath("d5", "d4"));
- assertThat(reversePathIntent.path().links(), linksHasPath("d6", "d5"));
- assertThat(reversePathIntent.path().links(), linksHasPath("d7", "d6"));
- assertThat(reversePathIntent.path().links(), linksHasPath("d8", "d7"));
+ if (reverseResultIntent instanceof LinkCollectionIntent) {
+ LinkCollectionIntent reverseLinkCollectionIntent = (LinkCollectionIntent) reverseResultIntent;
+ FilteredConnectPoint egressPoint = new FilteredConnectPoint(connectPoint("d1", 1));
+ FilteredConnectPoint ingressPoint = new FilteredConnectPoint(connectPoint("d8", 1));
+ assertThat(reverseLinkCollectionIntent.links(), hasSize(hops.length - 1));
+ assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d2", "d1"));
+ assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d3", "d2"));
+ assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d4", "d3"));
+ assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d5", "d4"));
+ assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d6", "d5"));
+ assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d7", "d6"));
+ assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d8", "d7"));
+ assertThat(reverseLinkCollectionIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint)));
+ assertThat(reverseLinkCollectionIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint)));
}
}
@@ -191,14 +200,14 @@
*/
@Test
public void testSameSwitchDifferentPortsIntentCompilation() {
- ConnectPoint src = new ConnectPoint(deviceId("1"), portNumber(1));
- ConnectPoint dst = new ConnectPoint(deviceId("1"), portNumber(2));
+ FilteredConnectPoint src = new FilteredConnectPoint(new ConnectPoint(deviceId("1"), portNumber(1)));
+ FilteredConnectPoint dst = new FilteredConnectPoint(new ConnectPoint(deviceId("1"), portNumber(2)));
PointToPointIntent intent = PointToPointIntent.builder()
.appId(APP_ID)
.selector(selector)
.treatment(treatment)
- .ingressPoint(src)
- .egressPoint(dst)
+ .filteredIngressPoint(src)
+ .filteredEgressPoint(dst)
.build();
String[] hops = {"1"};
@@ -207,14 +216,13 @@
List<Intent> compiled = sut.compile(intent, null);
assertThat(compiled, hasSize(1));
- assertThat(compiled.get(0), is(instanceOf(PathIntent.class)));
- Path path = ((PathIntent) compiled.get(0)).path();
+ assertThat(compiled.get(0), is(instanceOf(LinkCollectionIntent.class)));
+ LinkCollectionIntent linkCollectionIntent = (LinkCollectionIntent) compiled.get(0);
+ Set<Link> links = linkCollectionIntent.links();
- assertThat(path.links(), hasSize(2));
- Link firstLink = path.links().get(0);
- assertThat(firstLink, is(createEdgeLink(src, true)));
- Link secondLink = path.links().get(1);
- assertThat(secondLink, is(createEdgeLink(dst, false)));
+ assertThat(links, hasSize(0));
+ assertThat(linkCollectionIntent.filteredIngressPoints(), is(ImmutableSet.of(src)));
+ assertThat(linkCollectionIntent.filteredEgressPoints(), is(ImmutableSet.of(dst)));
}
/**