Simplify MP2S compiler, fix ingress/egress on same switch bug in SP2M compiler
Change-Id: Ib47bba01aac0f358f2caa5525c18e0e90a0b13ff
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
index 43a7fb7..cd7200a 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
@@ -27,7 +27,6 @@
import org.onosproject.core.DefaultGroupId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
-import org.onosproject.net.EdgeLink;
import org.onosproject.net.Link;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultFlowRule;
@@ -78,18 +77,8 @@
SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
for (Link link : intent.links()) {
- DeviceId srcDeviceId;
- DeviceId dstDeviceId;
-
- if (link instanceof EdgeLink) {
- EdgeLink edgeLink = (EdgeLink) link;
- dstDeviceId = edgeLink.hostLocation().deviceId();
- srcDeviceId = dstDeviceId;
- } else {
- inputPorts.put(link.dst().deviceId(), link.dst().port());
- srcDeviceId = link.src().deviceId();
- }
- outputPorts.put(srcDeviceId, link.src().port());
+ inputPorts.put(link.dst().deviceId(), link.dst().port());
+ outputPorts.put(link.src().deviceId(), link.src().port());
}
for (ConnectPoint ingressPoint : intent.ingressPoints()) {
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
index 3a40622..5c158e0 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
@@ -15,12 +15,8 @@
*/
package org.onosproject.net.intent.impl.compiler;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -40,10 +36,11 @@
import org.onosproject.net.resource.link.LinkResourceAllocations;
import org.onosproject.net.topology.PathService;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
-
-import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* An intent compiler for
@@ -73,37 +70,32 @@
public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable,
Set<LinkResourceAllocations> resources) {
Map<DeviceId, Link> links = new HashMap<>();
- Map<DeviceId, Link> edgeLinks = new HashMap<>();
ConnectPoint egressPoint = intent.egressPoint();
for (ConnectPoint ingressPoint : intent.ingressPoints()) {
if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
- edgeLinks.put(ingressPoint.deviceId(), createEdgeLink(ingressPoint, true));
- edgeLinks.put(egressPoint.deviceId(), createEdgeLink(egressPoint, false));
- } else {
- Path path = getPath(ingressPoint, intent.egressPoint());
- for (Link link : path.links()) {
- if (links.containsKey(link.src().deviceId())) {
- // We've already reached the existing tree with the first
- // part of this path. Add the merging point with different
- // incoming port, but don't add the remainder of the path
- // in case it differs from the path we already have.
- links.put(link.src().deviceId(), link);
- break;
- }
-
+ continue;
+ }
+ Path path = getPath(ingressPoint, intent.egressPoint());
+ for (Link link : path.links()) {
+ if (links.containsKey(link.src().deviceId())) {
+ // We've already reached the existing tree with the first
+ // part of this path. Add the merging point with different
+ // incoming port, but don't add the remainder of the path
+ // in case it differs from the path we already have.
links.put(link.src().deviceId(), link);
+ break;
}
+
+ links.put(link.src().deviceId(), link);
}
}
- Set<Link> allLinks = Sets.newHashSet(links.values());
- allLinks.addAll(edgeLinks.values());
Intent result = LinkCollectionIntent.builder()
.appId(intent.appId())
.selector(intent.selector())
.treatment(intent.treatment())
- .links(Sets.newHashSet(allLinks))
+ .links(Sets.newHashSet(links.values()))
.ingressPoints(intent.ingressPoints())
.egressPoints(ImmutableSet.of(intent.egressPoint()))
.priority(intent.priority())
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
index 91341d2..5656590 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
@@ -15,11 +15,7 @@
*/
package org.onosproject.net.intent.impl.compiler;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
+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;
@@ -32,7 +28,10 @@
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.link.LinkResourceAllocations;
-import com.google.common.collect.ImmutableSet;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
@Component(immediate = true)
public class SinglePointToMultiPointIntentCompiler
@@ -59,8 +58,12 @@
List<Intent> installable,
Set<LinkResourceAllocations> resources) {
Set<Link> links = new HashSet<>();
- //FIXME: need to handle the case where ingress/egress points are on same switch
+
for (ConnectPoint egressPoint : intent.egressPoints()) {
+ if (egressPoint.deviceId().equals(intent.ingressPoint().deviceId())) {
+ continue;
+ }
+
Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());
links.addAll(path.links());
}
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 a3b4525..b9b2c54 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,6 @@
*/
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.TestApplicationId;
@@ -36,6 +32,10 @@
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;
@@ -255,11 +255,9 @@
if (resultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
- assertThat(linkIntent.links(), hasSize(ingress.length + 1));
+ assertThat(linkIntent.links(), hasSize(ingress.length));
assertThat(linkIntent.links(), linksHasPath("i2", "i1"));
-
- assertThat(linkIntent.links(), linksHasPath("i1", "i1"));
}
}
}