ONOS-1334 - Allow multi to single intent across a single switch
Change-Id: I8be3dbc403ea1202fd496e666955402247f71bf1
diff --git a/core/net/src/test/java/org/onosproject/net/intent/LinksHaveEntryWithSourceDestinationPairMatcher.java b/core/net/src/test/java/org/onosproject/net/intent/LinksHaveEntryWithSourceDestinationPairMatcher.java
index 48a86c4..d34143c 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/LinksHaveEntryWithSourceDestinationPairMatcher.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/LinksHaveEntryWithSourceDestinationPairMatcher.java
@@ -19,6 +19,7 @@
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
+import org.onosproject.net.EdgeLink;
import org.onosproject.net.Link;
/**
@@ -46,6 +47,14 @@
@Override
public boolean matchesSafely(Collection<Link> links) {
for (Link link : links) {
+ if (source.equals(destination) && link instanceof EdgeLink) {
+ EdgeLink edgeLink = (EdgeLink) link;
+ if (edgeLink.hostLocation().elementId()
+ .toString().endsWith(source)) {
+ return true;
+ }
+ }
+
if (link.src().elementId().toString().endsWith(source) &&
link.dst().elementId().toString().endsWith(destination)) {
return true;
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
index 0d681a7..a3b4525 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
@@ -15,10 +15,14 @@
*/
package org.onosproject.net.intent.impl.compiler;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.hamcrest.Matchers;
import org.junit.Test;
-import org.onosproject.core.ApplicationId;
import org.onosproject.TestApplicationId;
+import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.ElementId;
import org.onosproject.net.Path;
@@ -32,10 +36,7 @@
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.PathService;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
@@ -76,9 +77,11 @@
String[] allHops = new String[pathHops.length + 1];
allHops[0] = src.toString();
- System.arraycopy(pathHops, 0, allHops, 1, pathHops.length);
-
+ if (pathHops.length != 0) {
+ System.arraycopy(pathHops, 0, allHops, 1, pathHops.length);
+ }
result.add(createPath(allHops));
+
return result;
}
@@ -98,7 +101,7 @@
*/
private MultiPointToSinglePointIntent makeIntent(String[] ingressIds, String egressId) {
Set<ConnectPoint> ingressPoints = new HashSet<>();
- ConnectPoint egressPoint = connectPoint(egressId, 1);
+ ConnectPoint egressPoint = connectPoint(egressId, 2);
for (String ingressId : ingressIds) {
ingressPoints.add(connectPoint(ingressId, 1));
@@ -228,4 +231,35 @@
assertThat(linkIntent.links(), linksHasPath("n1", egress));
}
}
+
+ /**
+ * Tests ingress and egress on the same device.
+ */
+ @Test
+ public void testSameDeviceCompilation() {
+ String[] ingress = {"i1", "i2"};
+ String egress = "i1";
+
+ MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
+ assertThat(intent, is(notNullValue()));
+
+ final String[] hops = {"i1", "i2"};
+ MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
+ assertThat(compiler, is(notNullValue()));
+
+ List<Intent> result = compiler.compile(intent, null, null);
+ assertThat(result, is(notNullValue()));
+ assertThat(result, hasSize(1));
+ Intent resultIntent = result.get(0);
+ assertThat(resultIntent, instanceOf(LinkCollectionIntent.class));
+
+ if (resultIntent instanceof LinkCollectionIntent) {
+ LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
+ assertThat(linkIntent.links(), hasSize(ingress.length + 1));
+
+ assertThat(linkIntent.links(), linksHasPath("i2", "i1"));
+
+ assertThat(linkIntent.links(), linksHasPath("i1", "i1"));
+ }
+ }
}