Fix ONOS-151 to support installation of PointToPointIntent
- Now support installation of PointToPointIntent that specifies the same
switches as source element ID and destination element ID
Change-Id: If206f3fde77ca198fe1df078e7292a05e5bd7424
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/PointToPointIntentCompiler.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/PointToPointIntentCompiler.java
index a4c8d58..b124602 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/PointToPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/PointToPointIntentCompiler.java
@@ -19,8 +19,6 @@
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.onlab.onos.net.ConnectPoint;
-import org.onlab.onos.net.DefaultEdgeLink;
-import org.onlab.onos.net.DefaultLink;
import org.onlab.onos.net.DefaultPath;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
@@ -35,7 +33,7 @@
import java.util.Set;
import static java.util.Arrays.asList;
-import static org.onlab.onos.net.Link.Type.DIRECT;
+import static org.onlab.onos.net.DefaultEdgeLink.createEdgeLink;
/**
* An intent compiler for {@link org.onlab.onos.net.intent.PointToPointIntent}.
@@ -47,6 +45,8 @@
// TODO: use off-the-shell core provider ID
private static final ProviderId PID =
new ProviderId("core", "org.onlab.onos.core", true);
+ // TODO: consider whether the default cost is appropriate or not
+ public static final int DEFAULT_COST = 1;
@Activate
public void activate() {
@@ -66,17 +66,17 @@
ConnectPoint egressPoint = intent.egressPoint();
if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
- List<Link> links = asList(new DefaultLink(PID, ingressPoint, egressPoint, DIRECT));
- return asList(createPathIntent(new DefaultPath(PID, links, 1), intent));
+ List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false));
+ return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent));
}
List<Link> links = new ArrayList<>();
Path path = getPath(intent, ingressPoint.deviceId(),
egressPoint.deviceId());
- links.add(DefaultEdgeLink.createEdgeLink(ingressPoint, true));
+ links.add(createEdgeLink(ingressPoint, true));
links.addAll(path.links());
- links.add(DefaultEdgeLink.createEdgeLink(egressPoint, false));
+ links.add(createEdgeLink(egressPoint, false));
return asList(createPathIntent(new DefaultPath(PID, links, path.cost(),
path.annotations()), intent));
diff --git a/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestPointToPointIntentCompiler.java b/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestPointToPointIntentCompiler.java
index 6521f24..f57d6d9 100644
--- a/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestPointToPointIntentCompiler.java
+++ b/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestPointToPointIntentCompiler.java
@@ -36,6 +36,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
+import static org.onlab.onos.net.DefaultEdgeLink.createEdgeLink;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.NetTestTools.APP_ID;
import static org.onlab.onos.net.NetTestTools.connectPoint;
@@ -163,9 +164,10 @@
assertThat(compiled.get(0), is(instanceOf(PathIntent.class)));
Path path = ((PathIntent) compiled.get(0)).path();
- assertThat(path.links(), hasSize(1));
- Link link = path.links().get(0);
- assertThat(link.src(), is(src));
- assertThat(link.dst(), is(dst));
+ 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)));
}
}