ONOS-1334 - Allow multi to single intent across a single switch
Change-Id: I8be3dbc403ea1202fd496e666955402247f71bf1
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 e9e319e..72077f9 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,6 +27,7 @@
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;
@@ -77,8 +78,18 @@
SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
for (Link link : intent.links()) {
- inputPorts.put(link.dst().deviceId(), link.dst().port());
- outputPorts.put(link.src().deviceId(), link.src().port());
+ 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());
}
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 a20b533..d63d379 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
@@ -43,6 +43,8 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
+import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
+
/**
* An intent compiler for
* {@link org.onosproject.net.intent.MultiPointToSinglePointIntent}.
@@ -71,28 +73,37 @@
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()) {
- 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;
- }
+ 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;
+ }
- links.put(link.src().deviceId(), link);
+ 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(links.values()))
+ .links(Sets.newHashSet(allLinks))
.ingressPoints(intent.ingressPoints())
.egressPoints(ImmutableSet.of(intent.egressPoint()))
.priority(intent.priority())